luci-app-keepalived: add notification tab master
authorChristian Korber <ckorber@tdt.de>
Fri, 15 Nov 2024 08:18:17 +0000 (09:18 +0100)
committerPaul Donald <newtwen+github@gmail.com>
Sat, 23 Nov 2024 00:03:05 +0000 (01:03 +0100)
This commit adds a tab to modify keepalived.user file.
With this commit it is possible to issue custom commands.

Signed-off-by: Christian Korber <ckorber@tdt.de>
applications/luci-app-keepalived/htdocs/luci-static/resources/view/keepalived/notification.js [new file with mode: 0644]
applications/luci-app-keepalived/root/usr/share/luci/menu.d/luci-app-keepalived.json
applications/luci-app-keepalived/root/usr/share/rpcd/acl.d/luci-app-keepalived.json

diff --git a/applications/luci-app-keepalived/htdocs/luci-static/resources/view/keepalived/notification.js b/applications/luci-app-keepalived/htdocs/luci-static/resources/view/keepalived/notification.js
new file mode 100644 (file)
index 0000000..613971d
--- /dev/null
@@ -0,0 +1,38 @@
+'use strict';
+'require view';
+'require fs';
+'require ui';
+
+var isReadonlyView = !L.hasViewPermission() || null;
+
+return view.extend({
+       load: function() {
+               return L.resolveDefault(fs.read('/etc/keepalived.user'), '');
+       },
+
+       handleSave: function(ev) {
+               var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
+
+               return fs.write('/etc/keepalived.user', value).then(function(rc) {
+                       document.querySelector('textarea').value = value;
+                       ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
+
+                       return fs.exec('/etc/init.d/keepalived', [ 'reload' ]);
+               }).catch(function(e) {
+                       ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
+               });
+       },
+
+       render: function(keepalived) {
+               return E([
+                       E('h2', _('Keepalived.user')),
+                       E('p', { 'class': 'cbi-section-descr' }, _('This is the /etc/keepalived.user file in which custom commands can be defined.')),
+                       E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 25, 'disabled': isReadonlyView }, [ keepalived != null ? keepalived : '' ]))
+               ]);
+       },
+
+       handleSaveApply: null,
+       handleReset: null
+});
+
+
index 93c741918a287d182250fa8cefecddc6eddd3cc8..3afc43eed4df9bf4b79f00c3c2b0ab4b9d521dc6 100644 (file)
                }
        },
 
+       "admin/services/keepalived/notification": {
+               "title": "Notification",
+               "order": 150,
+               "action": {
+                       "type": "view",
+                       "path": "keepalived/notification"
+               }
+       },
+
        "admin/status/keepalived": {
                "title": "VRRP",
                "order": 10,
index 0c8b676e6123468214924243ce6bb5735b6f47c8..c83054408ccdb25b50cfc30f53084718efb1e73d 100644 (file)
@@ -5,12 +5,16 @@
                        "ubus" : {
                                "keepalived" : [ "*" ]
                        },
-                       "uci": [ "keepalived" ]
+                       "uci": [ "keepalived" ],
+                       "file": {
+                               "/etc/keepalived.user": [ "read" ]
+                       }
                },
                "write" : {
                        "uci": [ "keepalived" ],
                        "file" : {
-                               "/etc/keepalived/keys/*" : [ "write" ]
+                               "/etc/keepalived/keys/*" : [ "write" ],
+                               "/etc/keepalived.user": [ "write" ]
                        }
                }
        }