luci: Fix get service info on OpenWrt 21.02

This commit is contained in:
remittor
2025-04-19 17:59:31 +03:00
parent da2cf34f9f
commit 919c91a6c7
3 changed files with 24 additions and 20 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -20,7 +20,8 @@
},
"uci": [ "zapret", "network" ],
"ubus": {
"luci": [ "getInitList", "setInitAction" ]
"luci": [ "getInitList", "setInitAction" ],
"service": [ "list" ]
}
},
"write": {