mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2025-12-06 03:26:49 +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([
|
||||
tools.getInitState(tools.appName), // svc_boot
|
||||
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(tools.packager.path, tools.packager.args), // installed packages
|
||||
uci.load(tools.appName), // config
|
||||
@@ -75,7 +75,7 @@ return view.extend({
|
||||
//console.log('svc_en: ' + svc_en.code);
|
||||
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()'));
|
||||
this.disableButtons(true, -1, elems);
|
||||
return;
|
||||
|
||||
@@ -74,6 +74,13 @@ return baseclass.extend({
|
||||
running : { code: 4, name: _('Running') , label: this.infoLabelRunning },
|
||||
},
|
||||
|
||||
callServiceList: rpc.declare({
|
||||
object: 'service',
|
||||
method: 'list',
|
||||
params: [ 'name', 'verbose' ],
|
||||
expect: { '': {} }
|
||||
}),
|
||||
|
||||
callInitState: rpc.declare({
|
||||
object: 'luci',
|
||||
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) {
|
||||
this.init_consts();
|
||||
return this.callInitState(name).then(res => {
|
||||
@@ -201,9 +219,6 @@ return baseclass.extend({
|
||||
},
|
||||
"status": this.statusDict.error,
|
||||
};
|
||||
if (svc_info.code != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (proc_list.code != 0) {
|
||||
return -2;
|
||||
}
|
||||
@@ -212,22 +227,10 @@ return baseclass.extend({
|
||||
if (plist.length < 4) {
|
||||
return -3;
|
||||
}
|
||||
if (typeof(svc_info.stdout) !== 'string') {
|
||||
if (typeof(svc_info) !== 'object') {
|
||||
return -4;
|
||||
}
|
||||
if (svc_info.stdout.length < 3) {
|
||||
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;
|
||||
}
|
||||
let jdata = svc_info;
|
||||
if (typeof(jdata.zapret) == 'object') {
|
||||
result.dmn.inited = true;
|
||||
let dmn_list = jdata.zapret.instances;
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
},
|
||||
"uci": [ "zapret", "network" ],
|
||||
"ubus": {
|
||||
"luci": [ "getInitList", "setInitAction" ]
|
||||
"luci": [ "getInitList", "setInitAction" ],
|
||||
"service": [ "list" ]
|
||||
}
|
||||
},
|
||||
"write": {
|
||||
|
||||
Reference in New Issue
Block a user