mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2025-12-06 11:36:48 +03:00
luci: Fix get service info on OpenWrt 21.02
This commit is contained in:
@@ -45,7 +45,7 @@ return view.extend({
|
|||||||
return Promise.all([
|
return Promise.all([
|
||||||
tools.getInitState(tools.appName), // svc_boot
|
tools.getInitState(tools.appName), // svc_boot
|
||||||
fs.exec(tools.execPath, [ 'enabled' ]), // svc_en
|
fs.exec(tools.execPath, [ 'enabled' ]), // svc_en
|
||||||
fs.exec(tools.execPath, [ 'info' ]), // svc_info
|
tools.getSvcInfo(), // svc_info
|
||||||
fs.exec('/bin/busybox', [ 'ps' ]), // process list
|
fs.exec('/bin/busybox', [ 'ps' ]), // process list
|
||||||
fs.exec(tools.packager.path, tools.packager.args), // installed packages
|
fs.exec(tools.packager.path, tools.packager.args), // installed packages
|
||||||
uci.load(tools.appName), // config
|
uci.load(tools.appName), // config
|
||||||
@@ -75,7 +75,7 @@ return view.extend({
|
|||||||
//console.log('svc_en: ' + svc_en.code);
|
//console.log('svc_en: ' + svc_en.code);
|
||||||
svc_en = (svc_en.code == 0) ? true : false;
|
svc_en = (svc_en.code == 0) ? true : false;
|
||||||
|
|
||||||
if (svc_info.code != 0) {
|
if (typeof(svc_info) !== 'object') {
|
||||||
ui.addNotification(null, E('p', _('Unable to read the service info') + ': setAppStatus()'));
|
ui.addNotification(null, E('p', _('Unable to read the service info') + ': setAppStatus()'));
|
||||||
this.disableButtons(true, -1, elems);
|
this.disableButtons(true, -1, elems);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -74,6 +74,13 @@ return baseclass.extend({
|
|||||||
running : { code: 4, name: _('Running') , label: this.infoLabelRunning },
|
running : { code: 4, name: _('Running') , label: this.infoLabelRunning },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
callServiceList: rpc.declare({
|
||||||
|
object: 'service',
|
||||||
|
method: 'list',
|
||||||
|
params: [ 'name', 'verbose' ],
|
||||||
|
expect: { '': {} }
|
||||||
|
}),
|
||||||
|
|
||||||
callInitState: rpc.declare({
|
callInitState: rpc.declare({
|
||||||
object: 'luci',
|
object: 'luci',
|
||||||
method: 'getInitList',
|
method: 'getInitList',
|
||||||
@@ -104,6 +111,17 @@ return baseclass.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getSvcInfo: function(svc_name = null) {
|
||||||
|
this.init_consts();
|
||||||
|
let name = (svc_name) ? svc_name : this.appName;
|
||||||
|
let verbose = 1;
|
||||||
|
return this.callServiceList(name, verbose).then(res => {
|
||||||
|
return res;
|
||||||
|
}).catch(e => {
|
||||||
|
ui.addNotification(null, E('p', _('Failed to get %s service info: %s').format(name, e)));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
getInitState: function(name) {
|
getInitState: function(name) {
|
||||||
this.init_consts();
|
this.init_consts();
|
||||||
return this.callInitState(name).then(res => {
|
return this.callInitState(name).then(res => {
|
||||||
@@ -201,9 +219,6 @@ return baseclass.extend({
|
|||||||
},
|
},
|
||||||
"status": this.statusDict.error,
|
"status": this.statusDict.error,
|
||||||
};
|
};
|
||||||
if (svc_info.code != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (proc_list.code != 0) {
|
if (proc_list.code != 0) {
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
@@ -212,22 +227,10 @@ return baseclass.extend({
|
|||||||
if (plist.length < 4) {
|
if (plist.length < 4) {
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
if (typeof(svc_info.stdout) !== 'string') {
|
if (typeof(svc_info) !== 'object') {
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
if (svc_info.stdout.length < 3) {
|
let jdata = svc_info;
|
||||||
return -5;
|
|
||||||
}
|
|
||||||
let jdata;
|
|
||||||
try {
|
|
||||||
jdata = JSON.parse(svc_info.stdout);
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Incorrect JSON: ' + svc_info.stdout);
|
|
||||||
return -6;
|
|
||||||
}
|
|
||||||
if (typeof(jdata) !== 'object') {
|
|
||||||
return -7;
|
|
||||||
}
|
|
||||||
if (typeof(jdata.zapret) == 'object') {
|
if (typeof(jdata.zapret) == 'object') {
|
||||||
result.dmn.inited = true;
|
result.dmn.inited = true;
|
||||||
let dmn_list = jdata.zapret.instances;
|
let dmn_list = jdata.zapret.instances;
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
},
|
},
|
||||||
"uci": [ "zapret", "network" ],
|
"uci": [ "zapret", "network" ],
|
||||||
"ubus": {
|
"ubus": {
|
||||||
"luci": [ "getInitList", "setInitAction" ]
|
"luci": [ "getInitList", "setInitAction" ],
|
||||||
|
"service": [ "list" ]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"write": {
|
"write": {
|
||||||
|
|||||||
Reference in New Issue
Block a user