luci-mod-system: use new "rc" ubus object for init.d scripts
authorRafał Miłecki <rafal@milecki.pl>
Fri, 11 Sep 2020 11:26:45 +0000 (13:26 +0200)
committerPaul Donald <itsascambutmailmeanyway@gmail.com>
Sat, 30 Dec 2023 23:38:19 +0000 (23:38 +0000)
Convert startup.js and system.js to use the generic ubus rc method to
handle /etc/init.d/ scripts for enable/disable/start/restart/reload/stop
operation.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
[ reword commit description, convert system.js ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
modules/luci-mod-system/htdocs/luci-static/resources/view/system/startup.js
modules/luci-mod-system/htdocs/luci-static/resources/view/system/system.js
modules/luci-mod-system/root/usr/share/rpcd/acl.d/luci-mod-system.json

index 4d1defbd2b2eff453e5c275c29c3216840e572b6..d0345007132fe1ca0b16f5057a45071bbac6398a 100644 (file)
@@ -7,29 +7,28 @@
 var isReadonlyView = !L.hasViewPermission() || null;
 
 return view.extend({
-       callInitList: rpc.declare({
-               object: 'luci',
-               method: 'getInitList',
+       callRcList: rpc.declare({
+               object: 'rc',
+               method: 'list',
                expect: { '': {} }
        }),
 
-       callInitAction: rpc.declare({
-               object: 'luci',
-               method: 'setInitAction',
+       callRcInit: rpc.declare({
+               object: 'rc',
+               method: 'init',
                params: [ 'name', 'action' ],
-               expect: { result: false }
        }),
 
        load: function() {
                return Promise.all([
                        L.resolveDefault(fs.read('/etc/rc.local'), ''),
-                       this.callInitList()
+                       this.callRcList()
                ]);
        },
 
        handleAction: function(name, action, ev) {
-               return this.callInitAction(name, action).then(function(success) {
-                       if (success != true)
+               return this.callRcInit(name, action).then(function(ret) {
+                       if (ret)
                                throw _('Command failed');
 
                        return true;
@@ -80,19 +79,19 @@ return view.extend({
                ]);
 
                for (var init in initList)
-                       if (initList[init].index < 100)
+                       if (initList[init].start < 100)
                                list.push(Object.assign({ name: init }, initList[init]));
 
                list.sort(function(a, b) {
-                       if (a.index != b.index)
-                               return a.index - b.index
+                       if (a.start != b.start)
+                               return a.start - b.start
 
                        return a.name > b.name;
                });
 
                for (var i = 0; i < list.length; i++) {
                        rows.push([
-                               '%02d'.format(list[i].index),
+                               '%02d'.format(list[i].start),
                                list[i].name,
                                E('div', [
                                        this.renderEnableDisable(list[i]),
index 767bc8c619fb14f756ccbcf56bb617e99ca8827d..754793c6b33d71e9f799df3f33f64ab0551547a7 100644 (file)
@@ -7,12 +7,12 @@
 'require form';
 'require tools.widgets as widgets';
 
-var callInitList, callInitAction, callTimezone,
+var callRcList, callRcInit, callTimezone,
     callGetLocaltime, callSetLocaltime, CBILocalTime;
 
-callInitList = rpc.declare({
-       object: 'luci',
-       method: 'getInitList',
+callRcList = rpc.declare({
+       object: 'rc',
+       method: 'list',
        params: [ 'name' ],
        expect: { '': {} },
        filter: function(res) {
@@ -22,9 +22,9 @@ callInitList = rpc.declare({
        }
 });
 
-callInitAction = rpc.declare({
-       object: 'luci',
-       method: 'setInitAction',
+callRcInit = rpc.declare({
+       object: 'rc',
+       method: 'init',
        params: [ 'name', 'action' ],
        expect: { result: false }
 });
@@ -83,7 +83,7 @@ CBILocalTime = form.DummyValue.extend({
                                this.ntpd_support ? E('button', {
                                        'class': 'cbi-button cbi-button-apply',
                                        'click': ui.createHandlerFn(this, function() {
-                                               return callInitAction('sysntpd', 'restart');
+                                               return callRcInit('sysntpd', 'restart');
                                        }),
                                        'disabled': (this.readonly != null) ? this.readonly : this.map.readonly
                                }, _('Sync with NTP-Server')) : ''
@@ -95,7 +95,7 @@ CBILocalTime = form.DummyValue.extend({
 return view.extend({
        load: function() {
                return Promise.all([
-                       callInitList('sysntpd'),
+                       callRcList('sysntpd'),
                        callTimezone(),
                        callGetLocaltime(),
                        uci.load('luci'),
@@ -271,7 +271,7 @@ return view.extend({
                                else
                                        uci.unset('system', 'ntp', 'enabled');
 
-                               return callInitAction('sysntpd', 'enable');
+                               return callRcInit('sysntpd', 'enable');
                        };
                        o.load = function(section_id) {
                                return (ntpd_enabled == 1 &&
index 732a73a760c6db97e263d59a931982464cd5f4e6..4fa39613b7b1265a117d6225de258778e29d11e0 100644 (file)
@@ -3,14 +3,16 @@
                "description": "Grant access to system configuration",
                "read": {
                        "ubus": {
-                               "luci": [ "getInitList", "getLEDs", "getTimezones", "getUSBDevices" ],
+                               "luci": [ "getLEDs", "getTimezones", "getUSBDevices" ],
+                               "rc": [ "list" ],
                                "system": [ "info" ]
                        },
                        "uci": [ "luci", "system" ]
                },
                "write": {
                        "ubus": {
-                               "luci": [ "setInitAction", "setLocaltime", "setPassword" ]
+                               "luci": [ "setLocaltime", "setPassword" ],
+                               "rc": [ "init" ],
                        },
                        "uci": [ "luci", "system" ]
                }
@@ -61,7 +63,7 @@
                        },
                        "ubus": {
                                "file": [ "read" ],
-                               "luci": [ "getInitList" ]
+                               "rc": [ "list" ]
                        }
                },
                "write": {
@@ -70,7 +72,7 @@
                        },
                        "ubus": {
                                "file": [ "write" ],
-                               "luci": [ "setInitAction" ]
+                               "rc": [ "init" ]
                        }
                }
        },