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