mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2026-01-01 06:09:01 +03:00
config: Add new options to reset settings dialog (choice of NFQWS strategy)
This commit is contained in:
@@ -48,6 +48,7 @@ return view.extend({
|
||||
tools.getSvcInfo(), // svc_info
|
||||
fs.exec('/bin/busybox', [ 'ps' ]), // process list
|
||||
fs.exec(tools.packager.path, tools.packager.args), // installed packages
|
||||
tools.getStratList(), // nfqws strategy list
|
||||
uci.load(tools.appName), // config
|
||||
]).catch(e => {
|
||||
ui.addNotification(null, E('p', _('Unable to execute or read contents')
|
||||
@@ -71,6 +72,7 @@ return view.extend({
|
||||
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
|
||||
this.nfqws_strat_list = status_array[5]; // array of strat names
|
||||
|
||||
//console.log('svc_en: ' + svc_en.code);
|
||||
svc_en = (svc_en.code == 0) ? true : false;
|
||||
@@ -147,7 +149,7 @@ return view.extend({
|
||||
});
|
||||
},
|
||||
|
||||
serviceActionEx: function(action, button, hide_modal = false) {
|
||||
serviceActionEx: function(action, button, args = [ ], hide_modal = false) {
|
||||
if (button) {
|
||||
let elem = document.getElementById(button);
|
||||
this.disableButtons(true, elem);
|
||||
@@ -164,7 +166,7 @@ return view.extend({
|
||||
}
|
||||
else if (action == 'reset') {
|
||||
exec_cmd = tools.defaultCfgPath;
|
||||
exec_arg = [ 'sync' ]; // restore config + sync configs
|
||||
exec_arg = args; // (reset_ipset)(sync) ==> restore all configs + sync config
|
||||
errmsg = _('Unable to run restore-def-cfg.sh script.');
|
||||
action = null;
|
||||
} else {
|
||||
@@ -228,6 +230,33 @@ return view.extend({
|
||||
|
||||
dialogResetCfg: function(ev) {
|
||||
ev.target.blur();
|
||||
|
||||
let reset_base = E('label', [
|
||||
E('input', { type: 'checkbox', id: 'cfg_reset_base', checked: true }),
|
||||
' ', _('Restore all base settings')
|
||||
]);
|
||||
|
||||
let reset_ipset = E('label', [
|
||||
E('input', { type: 'checkbox', id: 'cfg_reset_ipset', checked: true }),
|
||||
' ', _('Restore ipset configs')
|
||||
]);
|
||||
|
||||
let set_autohostlist = E('label', [
|
||||
E('input', { type: 'checkbox', id: 'cfg_autohostlist', checked: true }),
|
||||
' ', _('Set AutoHostList mode')
|
||||
]);
|
||||
|
||||
let strat_list = [ ];
|
||||
strat_list.push( E('option', { value: 'strat__skip__' }, [ '-' ] ) );
|
||||
for (let id = 0; id < this.nfqws_strat_list.length; id++) {
|
||||
let strat = '' + this.nfqws_strat_list[id];
|
||||
strat_list.push( E('option', { value: 'strat_' + id }, [ strat ] ) );
|
||||
}
|
||||
let nfqws_strat = E('label', [
|
||||
_('NFQWS_OPT strategy: '),
|
||||
E('select', { id: 'cfg_nfqws_strat' }, strat_list)
|
||||
]);
|
||||
|
||||
let cancel_button = E('button', {
|
||||
'class': btn_style_neutral,
|
||||
'click': ui.hideModal,
|
||||
@@ -238,12 +267,35 @@ return view.extend({
|
||||
}, _('Reset settings'));
|
||||
resetcfg_btn.onclick = ui.createHandlerFn(this, () => {
|
||||
//cancel_button.disabled = true;
|
||||
return this.serviceActionEx('reset', resetcfg_btn, true);
|
||||
let opt_flags = '';
|
||||
if (document.getElementById('cfg_reset_base').checked == false) {
|
||||
opt_flags += '(skip_base)';
|
||||
};
|
||||
if (document.getElementById('cfg_reset_ipset').checked) {
|
||||
opt_flags += '(reset_ipset)';
|
||||
};
|
||||
if (document.getElementById('cfg_autohostlist').checked) {
|
||||
opt_flags += '(set_mode_autohostlist)';
|
||||
};
|
||||
//console.log('RESET: opt_flags = ' + opt_flags);
|
||||
let sel_strat = document.getElementById('cfg_nfqws_strat');
|
||||
let opt_strat = sel_strat.options[sel_strat.selectedIndex].text;
|
||||
//console.log('RESET: strat = ' + opt_strat);
|
||||
opt_flags += '(sync)';
|
||||
let args = [ opt_flags, opt_strat ];
|
||||
return this.serviceActionEx('reset', resetcfg_btn, args, true);
|
||||
});
|
||||
|
||||
ui.showModal(_('Reset settings to default'), [
|
||||
E('div', { 'class': 'cbi-section' }, [
|
||||
E('p', _('All settings will be reset to default. Continue?')),
|
||||
reset_base,
|
||||
E('br'), E('br'),
|
||||
reset_ipset,
|
||||
E('br'), E('br'),
|
||||
set_autohostlist,
|
||||
E('br'), E('br'),
|
||||
nfqws_strat,
|
||||
E('br'), E('br')
|
||||
]),
|
||||
E('div', { 'class': 'right' }, [
|
||||
cancel_button,
|
||||
|
||||
@@ -39,6 +39,7 @@ return baseclass.extend({
|
||||
appName : 'zapret',
|
||||
execPath : '/etc/init.d/zapret',
|
||||
syncCfgPath : '/opt/zapret/sync_config.sh',
|
||||
defCfgPath : '/opt/zapret/def-cfg.sh',
|
||||
defaultCfgPath : '/opt/zapret/restore-def-cfg.sh',
|
||||
|
||||
hostsGoogleFN : '/opt/zapret/ipset/zapret-hosts-google.txt',
|
||||
@@ -139,6 +140,20 @@ return baseclass.extend({
|
||||
});
|
||||
},
|
||||
|
||||
getStratList: function() {
|
||||
this.init_consts();
|
||||
let exec_cmd = '/bin/busybox';
|
||||
let exec_arg = [ 'awk', '-F', '"', '/if \\[ "\\$strat" = "/ {print $4}', this.defCfgPath ];
|
||||
return fs.exec(exec_cmd, exec_arg).then(res => {
|
||||
if (res.code == 0) {
|
||||
return this.getWordsArray(res.stdout);
|
||||
}
|
||||
return [ ];
|
||||
}).catch(e => {
|
||||
ui.addNotification(null, E('p', _('Failed to get strat list: %s').format(e)));
|
||||
});
|
||||
},
|
||||
|
||||
handleServiceAction: function(name, action) {
|
||||
return this.callInitAction(name, action).then(success => {
|
||||
if (!success) {
|
||||
@@ -154,6 +169,12 @@ return baseclass.extend({
|
||||
return (v && typeof(v) === 'string') ? v.trim().replace(/\r?\n/g, '') : v;
|
||||
},
|
||||
|
||||
getWordsArray: function (text, { trim = true, removeEmpty = true } = {}) {
|
||||
const rawLines = text.split(/\n/);
|
||||
const processed = trim ? rawLines.map(line => line.trim()) : rawLines.slice();
|
||||
return removeEmpty ? processed.filter(line => line.length > 0) : processed;
|
||||
},
|
||||
|
||||
decode_pkg_list: function(pkg_list) {
|
||||
let pkg_dict = { };
|
||||
let lines = pkg_list.trim().split('\n');
|
||||
@@ -448,9 +469,12 @@ return baseclass.extend({
|
||||
if (typeof(value) === 'string') {
|
||||
value = value.trim();
|
||||
if (this.multiline == 2) {
|
||||
value = value.replace(/\n\t\t\t--/g, "\n--");
|
||||
value = value.replace(/\n\t\t--/g, "\n--");
|
||||
value = value.replace(/\n\t--/g, "\n--");
|
||||
value = value.replace(/\n\t/g, "\n");
|
||||
value = value.replace(/\n\t/g, "\n");
|
||||
value = value.replace(/\n\t/g, "\n");
|
||||
value = value.replace(/\n\t/g, "\n");
|
||||
value = value.replace(/\n\t/g, "\n");
|
||||
value = value.replace(/\n\t/g, "\n");
|
||||
value = value.replace(/\n --/g, "\n--");
|
||||
value = value.replace(/\n --/g, "\n--");
|
||||
value = value.replace(/ --/g, "\n--");
|
||||
|
||||
Reference in New Issue
Block a user