diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/service.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/service.js index 3d69b74..7904ec4 100644 --- a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/service.js +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/service.js @@ -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; diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js index da13a0c..b5a199c 100644 --- a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js @@ -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; diff --git a/luci-app-zapret/root/usr/share/rpcd/acl.d/luci-app-zapret.json b/luci-app-zapret/root/usr/share/rpcd/acl.d/luci-app-zapret.json index 2607454..1125074 100644 --- a/luci-app-zapret/root/usr/share/rpcd/acl.d/luci-app-zapret.json +++ b/luci-app-zapret/root/usr/share/rpcd/acl.d/luci-app-zapret.json @@ -20,7 +20,8 @@ }, "uci": [ "zapret", "network" ], "ubus": { - "luci": [ "getInitList", "setInitAction" ] + "luci": [ "getInitList", "setInitAction" ], + "service": [ "list" ] } }, "write": {