mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2026-01-27 12:50:35 +03:00
Compare commits
2 Commits
v0.8.20260
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83bf86b2f8 | ||
|
|
e2c6c0552e |
@@ -50,7 +50,7 @@ return view.extend({
|
||||
fs.exec(tools.execPath, [ 'enabled' ]), // svc_en
|
||||
tools.getSvcInfo(), // svc_info
|
||||
fs.exec('/bin/busybox', [ 'ps' ]), // process list
|
||||
fs.exec(tools.packager.path, tools.packager.args), // installed packages
|
||||
tools.getPackageDict(), // installed packages
|
||||
tools.getStratList(), // nfqws strategy list
|
||||
fs.exec('/bin/cat', [ '/etc/openwrt_release' ]), // CPU arch
|
||||
uci.load(tools.appName), // config
|
||||
@@ -75,7 +75,7 @@ return view.extend({
|
||||
let svc_en = status_array[1]; // stdout: empty or error text
|
||||
let svc_info = status_array[2]; // stdout: JSON as text
|
||||
let proc_list = status_array[3]; // stdout: multiline text
|
||||
let pkg_list = status_array[4]; // stdout: installed packages
|
||||
let pkg_dict = status_array[4]; // stdout: installed packages
|
||||
let stratlist = status_array[5]; // array of strat names
|
||||
let sys_info = status_array[6]; // stdout: openwrt distrib info
|
||||
|
||||
@@ -95,8 +95,8 @@ return view.extend({
|
||||
this.disableButtons(true, -1, elems);
|
||||
return;
|
||||
}
|
||||
if (pkg_list.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': setAppStatus()'));
|
||||
if (!pkg_dict) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': getPackageDict()'));
|
||||
this.disableButtons(true, -1, elems);
|
||||
return;
|
||||
}
|
||||
@@ -135,89 +135,51 @@ return view.extend({
|
||||
}
|
||||
},
|
||||
|
||||
serviceAction: function(action, button) {
|
||||
if (button) {
|
||||
let elem = document.getElementById(button);
|
||||
this.disableButtons(true, elem);
|
||||
}
|
||||
serviceActionEx: async function(action, button, args = [ ], hide_modal = false, btn_dis = true)
|
||||
{
|
||||
let btn = document.getElementById(button);
|
||||
this.disableButtons(true, btn);
|
||||
poll.stop();
|
||||
|
||||
let _this = this;
|
||||
|
||||
return tools.handleServiceAction(tools.appName, action)
|
||||
.then(() => {
|
||||
return _this.getAppStatus().then(
|
||||
(status_array) => {
|
||||
_this.setAppStatus(status_array);
|
||||
let errmsg = null;
|
||||
try {
|
||||
let exec_cmd = null;
|
||||
let exec_arg = [ ];
|
||||
if (action == 'start' || action == 'restart') {
|
||||
if (tools.checkUnsavedChanges()) {
|
||||
ui.changes.apply(true);
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
}
|
||||
exec_cmd = tools.syncCfgPath;
|
||||
errmsg = _('Unable to run sync_config.sh script.');
|
||||
}
|
||||
if (action == 'reset') {
|
||||
exec_cmd = tools.defaultCfgPath;
|
||||
exec_arg = args; // (reset_ipset)(sync) ==> restore all configs + sync config
|
||||
errmsg = _('Unable to run restore-def-cfg.sh script.');
|
||||
action = null;
|
||||
}
|
||||
if (exec_cmd) {
|
||||
let res = await fs.exec(exec_cmd, exec_arg);
|
||||
if (res.code != 0) {
|
||||
throw Error('res.code = ' + res.code);
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(e => {
|
||||
ui.addNotification(null, E('p', _('Unable to run service action.') + ' Error: ' + e.message));
|
||||
});
|
||||
},
|
||||
|
||||
serviceActionEx: function(action, button, args = [ ], hide_modal = false) {
|
||||
if (button) {
|
||||
let elem = document.getElementById(button);
|
||||
this.disableButtons(true, elem);
|
||||
}
|
||||
poll.stop();
|
||||
|
||||
let _this = this;
|
||||
let exec_cmd = null;
|
||||
let exec_arg = [ ];
|
||||
let errmsg = 'ERROR:';
|
||||
if (action == 'start' || action == 'restart') {
|
||||
exec_cmd = tools.syncCfgPath;
|
||||
errmsg = _('Unable to run sync_config.sh script.');
|
||||
}
|
||||
else if (action == 'reset') {
|
||||
exec_cmd = tools.defaultCfgPath;
|
||||
exec_arg = args; // (reset_ipset)(sync) ==> restore all configs + sync config
|
||||
errmsg = _('Unable to run restore-def-cfg.sh script.');
|
||||
action = null;
|
||||
} else {
|
||||
ui.addNotification(null, E('p', 'ERROR: unknown action'));
|
||||
return null;
|
||||
}
|
||||
return fs.exec(exec_cmd, exec_arg)
|
||||
.then(function(res) {
|
||||
if (res.code != 0) {
|
||||
ui.addNotification(null, E('p', errmsg + ' res.code = ' + res.code));
|
||||
action = null; // return with error
|
||||
}
|
||||
if (hide_modal) {
|
||||
ui.hideModal();
|
||||
}
|
||||
if (!action) {
|
||||
return _this.getAppStatus().then(
|
||||
(status_array) => {
|
||||
_this.setAppStatus(status_array);
|
||||
}
|
||||
);
|
||||
errmsg = null;
|
||||
await tools.handleServiceAction(tools.appName, action);
|
||||
} catch(e) {
|
||||
let msg = errmsg ? errmsg : _('Unable to run service action') + ' "' + action + '".';
|
||||
ui.addNotification(null, E('p', msg + ' Error: ' + e.message));
|
||||
} finally {
|
||||
if (!poll.active()) {
|
||||
poll.start();
|
||||
}
|
||||
if (btn && btn_dis) {
|
||||
setTimeout(() => { btn.disabled = true; }, 0);
|
||||
}
|
||||
return _this.serviceAction(action, null);
|
||||
})
|
||||
.catch(e => {
|
||||
ui.addNotification(null, E('p', errmsg + ' Error: ' + e.message));
|
||||
});
|
||||
},
|
||||
|
||||
appAction: function(action, button) {
|
||||
if (button) {
|
||||
let elem = document.getElementById(button);
|
||||
this.disableButtons(true, elem);
|
||||
}
|
||||
poll.stop();
|
||||
return fs.exec_direct(tools.execPath, [ action ]).then(res => {
|
||||
return this.getAppStatus().then(
|
||||
(status_array) => {
|
||||
this.setAppStatus(status_array);
|
||||
ui.hideModal();
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
statusPoll: function() {
|
||||
@@ -226,7 +188,12 @@ return view.extend({
|
||||
);
|
||||
},
|
||||
|
||||
dialogResetCfg: function(ev) {
|
||||
dialogResetCfg: function(ev)
|
||||
{
|
||||
if (tools.checkUnsavedChanges()) {
|
||||
ui.addNotification(null, E('p', _('You have unapplied changes')));
|
||||
return;
|
||||
}
|
||||
ev.target.blur();
|
||||
|
||||
let reset_base = E('label', [
|
||||
@@ -274,7 +241,7 @@ return view.extend({
|
||||
let resetcfg_btn = E('button', {
|
||||
'class': btn_style_action,
|
||||
}, _('Reset settings'));
|
||||
resetcfg_btn.onclick = ui.createHandlerFn(this, () => {
|
||||
resetcfg_btn.onclick = ui.createHandlerFn(this, async () => {
|
||||
//cancel_button.disabled = true;
|
||||
let opt_flags = '';
|
||||
if (document.getElementById('cfg_reset_base').checked == false) {
|
||||
@@ -342,9 +309,9 @@ return view.extend({
|
||||
}
|
||||
let cfg = uci.get(tools.appName, 'config');
|
||||
|
||||
let pkg_list = status_array[4];
|
||||
if (pkg_list === undefined || typeof(pkg_list) !== 'object' || pkg_list.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': setAppStatus()'));
|
||||
let pkgdict = status_array[4];
|
||||
if (pkgdict == null) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': render()'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -390,9 +357,9 @@ return view.extend({
|
||||
};
|
||||
|
||||
let btn_enable = create_btn('btn_enable', btn_style_success, _('Enable'));
|
||||
btn_enable.onclick = ui.createHandlerFn(this, this.serviceAction, 'enable', 'btn_enable');
|
||||
btn_enable.onclick = ui.createHandlerFn(this, this.serviceActionEx, 'enable', 'btn_enable');
|
||||
let btn_disable = create_btn('btn_disable', btn_style_warning, _('Disable'));
|
||||
btn_disable.onclick = ui.createHandlerFn(this, this.serviceAction, 'disable', 'btn_disable');
|
||||
btn_disable.onclick = ui.createHandlerFn(this, this.serviceActionEx, 'disable', 'btn_disable');
|
||||
layout_append(_('Service autorun control'), null, [ btn_enable, btn_disable ] );
|
||||
|
||||
let btn_start = create_btn('btn_start', btn_style_action, _('Start'));
|
||||
@@ -400,7 +367,7 @@ return view.extend({
|
||||
let btn_restart = create_btn('btn_restart', btn_style_action, _('Restart'));
|
||||
btn_restart.onclick = ui.createHandlerFn(this, this.serviceActionEx, 'restart', 'btn_restart');
|
||||
let btn_stop = create_btn('btn_stop', btn_style_warning, _('Stop'));
|
||||
btn_stop.onclick = ui.createHandlerFn(this, this.serviceAction, 'stop', 'btn_stop');
|
||||
btn_stop.onclick = ui.createHandlerFn(this, this.serviceActionEx, 'stop', 'btn_stop');
|
||||
layout_append(_('Service daemons control'), null, [ btn_start, btn_restart, btn_stop ] );
|
||||
|
||||
let btn_reset = create_btn('btn_reset', btn_style_action, _('Reset settings'));
|
||||
@@ -428,15 +395,15 @@ return view.extend({
|
||||
};
|
||||
this.setAppStatus(status_array, elems);
|
||||
|
||||
poll.add(L.bind(this.statusPoll, this));
|
||||
poll.add(L.bind(this.statusPoll, this), 2); // interval 2 sec
|
||||
|
||||
let page_title = tools.AppName;
|
||||
let pkgdict = tools.decode_pkg_list(pkg_list.stdout, false);
|
||||
page_title += '   ';
|
||||
if (pkgdict[tools.appName] === undefined || pkgdict[tools.appName] == '') {
|
||||
page_title += 'unknown version';
|
||||
} else {
|
||||
page_title += 'v' + pkgdict[tools.appName];
|
||||
page_title = page_title.replace(/-r1$/, '');
|
||||
}
|
||||
let aux1 = E('em');
|
||||
let aux2 = E('em');
|
||||
|
||||
@@ -101,6 +101,30 @@ return baseclass.extend({
|
||||
});
|
||||
},
|
||||
|
||||
getPackageDict: function()
|
||||
{
|
||||
let ses_var_name = this.appName+'_pkgdict';
|
||||
let exec_cmd = this.packager.path;
|
||||
let exec_arg = this.packager.args;
|
||||
return fs.exec(exec_cmd, exec_arg).then(res => {
|
||||
let pdict_json = sessionStorage.getItem(ses_var_name);
|
||||
if (res.code != 0) {
|
||||
console.log(this.appName + ': Unable to enumerate installed packages. code = ' + res.code);
|
||||
if (pdict_json != null) {
|
||||
return JSON.parse(pdict_json); // return cached value
|
||||
}
|
||||
return null;
|
||||
}
|
||||
let pdict = this.decode_pkg_list(res.stdout);
|
||||
if (pdict != pdict_json) {
|
||||
sessionStorage.setItem(ses_var_name, JSON.stringify(pdict)); // renew cache
|
||||
}
|
||||
return pdict;
|
||||
}).catch(e => {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages.') + ' Error: %s'.format(e)));
|
||||
});
|
||||
},
|
||||
|
||||
getStratList: function() {
|
||||
let exec_cmd = '/bin/busybox';
|
||||
let exec_arg = [ 'awk', '-F', '"', '/if \\[ "\\$strat" = "/ {print $4}', this.defCfgPath ];
|
||||
@@ -124,6 +148,13 @@ return baseclass.extend({
|
||||
ui.addNotification(null, E('p', _('Service action failed "%s %s": %s').format(name, action, e)));
|
||||
});
|
||||
},
|
||||
|
||||
checkUnsavedChanges: function()
|
||||
{
|
||||
if (!ui.changes) return false;
|
||||
if (!ui.changes.changes) return false;
|
||||
return ui.changes.changes[this.appName] ? true : false;
|
||||
},
|
||||
|
||||
normalizeValue: function(v) {
|
||||
return (v && typeof(v) === 'string') ? v.trim().replace(/\r?\n/g, '') : v;
|
||||
@@ -141,7 +172,7 @@ return baseclass.extend({
|
||||
return m ? m[2] : defval;
|
||||
},
|
||||
|
||||
decode_pkg_list: function(pkg_list, with_suffix_r1 = true) {
|
||||
decode_pkg_list: function(pkg_list) {
|
||||
let pkg_dict = { };
|
||||
if (!pkg_list) {
|
||||
return pkg_dict;
|
||||
@@ -180,11 +211,7 @@ return baseclass.extend({
|
||||
}
|
||||
}
|
||||
if (rev >= 0) {
|
||||
if (rev == 1 && !with_suffix_r1) {
|
||||
// nothing
|
||||
} else {
|
||||
ver += '-r' + rev;
|
||||
}
|
||||
ver += '-r' + rev;
|
||||
}
|
||||
pkg_dict[name] = ver;
|
||||
}
|
||||
|
||||
@@ -136,6 +136,10 @@ return baseclass.extend({
|
||||
|
||||
openUpdateDialog: function(pkg_arch)
|
||||
{
|
||||
if (tools.checkUnsavedChanges()) {
|
||||
ui.addNotification(null, E('p', _('You have unapplied changes')));
|
||||
return;
|
||||
}
|
||||
this.stage = 0;
|
||||
this.pkg_arch = pkg_arch;
|
||||
this.pkg_url = null;
|
||||
|
||||
Reference in New Issue
Block a user