mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2025-12-06 03:26:49 +03:00
luci: Show and check versions of installed packages
This commit is contained in:
@@ -40,6 +40,7 @@ return view.extend({
|
||||
tools.getInitState(tools.appName), // svc_state
|
||||
fs.exec(tools.execPath, [ 'info' ]), // svc_info
|
||||
fs.exec('/bin/ps'), // process list
|
||||
fs.exec('/bin/opkg', [ 'list-installed', '*zapret*' ]), // installed packages
|
||||
uci.load(tools.appName), // config
|
||||
]).catch(e => {
|
||||
ui.addNotification(null, E('p', _('Unable to execute or read contents')
|
||||
@@ -61,6 +62,7 @@ return view.extend({
|
||||
let svc_autorun = status_array[0] ? true : false;
|
||||
let svc_info = status_array[1]; // stdout: JSON as text
|
||||
let proc_list = status_array[2]; // stdout: multiline text
|
||||
let pkg_list = status_array[3]; // stdout: installed packages
|
||||
if (svc_info.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to read the service info') + ': setAppStatus()'));
|
||||
this.disableButtons(true, null, elems);
|
||||
@@ -71,6 +73,11 @@ return view.extend({
|
||||
this.disableButtons(true, null, elems);
|
||||
return;
|
||||
}
|
||||
if (pkg_list.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': setAppStatus()'));
|
||||
this.disableButtons(true, null, elems);
|
||||
return;
|
||||
}
|
||||
let svcinfo;
|
||||
if (force_app_status) {
|
||||
svcinfo = force_app_status;
|
||||
@@ -222,6 +229,12 @@ return view.extend({
|
||||
}
|
||||
let cfg = uci.get(tools.appName, 'config');
|
||||
|
||||
let pkg_list = status_array[3];
|
||||
if (pkg_list === undefined || typeof(pkg_list) !== 'object' || pkg_list.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': setAppStatus()'));
|
||||
return;
|
||||
}
|
||||
|
||||
let status_string = E('div', {
|
||||
'id' : 'status',
|
||||
'name' : 'status',
|
||||
@@ -297,11 +310,29 @@ return view.extend({
|
||||
|
||||
poll.add(L.bind(this.statusPoll, this));
|
||||
|
||||
let page_title = _('Zapret');
|
||||
let pkgdict = tools.decode_pkg_list(pkg_list.stdout);
|
||||
page_title += '   ';
|
||||
if (pkgdict['zapret'] === undefined || pkgdict['zapret'] == '') {
|
||||
page_title += 'unknown version';
|
||||
} else {
|
||||
page_title += 'v' + pkgdict['zapret'];
|
||||
}
|
||||
let aux1 = E('em');
|
||||
let aux2 = E('em');
|
||||
if (pkgdict['zapret'] != pkgdict['luci-app-zapret']) {
|
||||
let errtxt = 'LuCI APP v' + pkgdict['luci-app-zapret'] + ' [ incorrect version! ]';
|
||||
aux1 = E('div', { 'class': 'label-status error' }, errtxt);
|
||||
aux2 = E('div', { }, ' ');
|
||||
}
|
||||
|
||||
let url1 = 'https://github.com/bol-van/zapret';
|
||||
let url2 = 'https://github.com/remittor/zapret-openwrt';
|
||||
|
||||
return E([
|
||||
E('h2', { 'class': 'fade-in' }, _('Zapret')),
|
||||
E('h2', { 'class': 'fade-in' }, page_title),
|
||||
aux1,
|
||||
aux2,
|
||||
E('div', { 'class': 'cbi-section-descr fade-in' },
|
||||
E('a', { 'href': url1, 'target': '_blank' }, url1),
|
||||
),
|
||||
|
||||
@@ -104,6 +104,21 @@ return baseclass.extend({
|
||||
return (v && typeof(v) === 'string') ? v.trim().replace(/\r?\n/g, '') : v;
|
||||
},
|
||||
|
||||
decode_pkg_list: function(pkg_list) {
|
||||
let pkg_dict = { };
|
||||
let lines = pkg_list.trim().split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
let line = lines[i].trim();
|
||||
if (line.length >= 4) {
|
||||
let word_list = line.split(' - ');
|
||||
let name = word_list[0].trim();
|
||||
let ver = word_list[1].trim();
|
||||
pkg_dict[name] = ver;
|
||||
}
|
||||
}
|
||||
return pkg_dict;
|
||||
},
|
||||
|
||||
get_pid_list: function(proc_list) {
|
||||
let plist = [ ];
|
||||
let lines = proc_list.trim().split('\n');
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"/etc/crontabs/root": [ "read" ],
|
||||
"/etc/init.d/zapret*": [ "exec" ],
|
||||
"/bin/ps*": [ "exec" ],
|
||||
"/bin/opkg*": [ "exec" ],
|
||||
"/opt/zapret/sync_config.sh*": [ "exec" ]
|
||||
},
|
||||
"uci": [ "zapret", "network" ],
|
||||
|
||||
Reference in New Issue
Block a user