mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2025-12-12 14:36:59 +03:00
luci: Add button "Reset settings"
This commit is contained in:
@@ -22,6 +22,7 @@ return view.extend({
|
|||||||
restart : elems.btn_restart || document.getElementById('btn_restart'),
|
restart : elems.btn_restart || document.getElementById('btn_restart'),
|
||||||
stop : elems.btn_stop || document.getElementById('btn_stop'),
|
stop : elems.btn_stop || document.getElementById('btn_stop'),
|
||||||
update : elems.btn_update || document.getElementById('btn_update'),
|
update : elems.btn_update || document.getElementById('btn_update'),
|
||||||
|
reset : elems.btn_update || document.getElementById('btn_reset'),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ return view.extend({
|
|||||||
btn.restart.disabled = flag;
|
btn.restart.disabled = flag;
|
||||||
btn.stop.disabled = flag;
|
btn.stop.disabled = flag;
|
||||||
btn.update.disabled = true; // TODO
|
btn.update.disabled = true; // TODO
|
||||||
|
btn.reset.disabled = flag;
|
||||||
},
|
},
|
||||||
|
|
||||||
getAppStatus: function() {
|
getAppStatus: function() {
|
||||||
@@ -86,6 +88,7 @@ return view.extend({
|
|||||||
}
|
}
|
||||||
let btn = this.get_svc_buttons(elems);
|
let btn = this.get_svc_buttons(elems);
|
||||||
btn.update.disabled = true; // TODO
|
btn.update.disabled = true; // TODO
|
||||||
|
btn.reset.disabled = false;
|
||||||
|
|
||||||
if (Number.isInteger(svcinfo)) {
|
if (Number.isInteger(svcinfo)) {
|
||||||
ui.addNotification(null, E('p', _('Error')
|
ui.addNotification(null, E('p', _('Error')
|
||||||
@@ -134,7 +137,7 @@ return view.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
serviceActionEx: function(action, button) {
|
serviceActionEx: function(action, button, hide_modal = false) {
|
||||||
if (button) {
|
if (button) {
|
||||||
let elem = document.getElementById(button);
|
let elem = document.getElementById(button);
|
||||||
this.disableButtons(true, elem);
|
this.disableButtons(true, elem);
|
||||||
@@ -142,11 +145,32 @@ return view.extend({
|
|||||||
poll.stop();
|
poll.stop();
|
||||||
|
|
||||||
let _this = this;
|
let _this = this;
|
||||||
|
let exec_cmd = null;
|
||||||
return fs.exec(tools.syncCfgPath)
|
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 = [ '-f' ];
|
||||||
|
errmsg = _('Unable to run uci-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) {
|
.then(function(res) {
|
||||||
if (res.code != 0) {
|
if (res.code != 0) {
|
||||||
ui.addNotification(null, E('p', _('Unable to run sync_config.sh script.') + ' res.code = ' + res.code));
|
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(
|
return _this.getAppStatus().then(
|
||||||
(status_array) => {
|
(status_array) => {
|
||||||
_this.setAppStatus(status_array);
|
_this.setAppStatus(status_array);
|
||||||
@@ -156,7 +180,7 @@ return view.extend({
|
|||||||
return _this.serviceAction(action, null);
|
return _this.serviceAction(action, null);
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
ui.addNotification(null, E('p', _('Unable to run sync_config.sh script.') + ' Error: ' + e.message));
|
ui.addNotification(null, E('p', errmsg + ' Error: ' + e.message));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -192,29 +216,29 @@ return view.extend({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
dialogDestroy: function(ev) {
|
dialogResetCfg: function(ev) {
|
||||||
ev.target.blur();
|
ev.target.blur();
|
||||||
let cancel_button = E('button', {
|
let cancel_button = E('button', {
|
||||||
'class': btn_style_neutral,
|
'class': btn_style_neutral,
|
||||||
'click': ui.hideModal,
|
'click': ui.hideModal,
|
||||||
}, _('Cancel'));
|
}, _('Cancel'));
|
||||||
|
|
||||||
let shutdown_btn = E('button', {
|
let resetcfg_btn = E('button', {
|
||||||
'class': btn_style_warning,
|
'class': btn_style_action,
|
||||||
}, _('Shutdown'));
|
}, _('Reset settings'));
|
||||||
shutdown_btn.onclick = ui.createHandlerFn(this, () => {
|
resetcfg_btn.onclick = ui.createHandlerFn(this, () => {
|
||||||
cancel_button.disabled = true;
|
cancel_button.disabled = true;
|
||||||
return this.appAction('destroy');
|
return this.serviceActionEx('reset', resetcfg_btn, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.showModal(_('Shutdown'), [
|
ui.showModal(_('Reset settings to default'), [
|
||||||
E('div', { 'class': 'cbi-section' }, [
|
E('div', { 'class': 'cbi-section' }, [
|
||||||
E('p', _('The service will be disabled. Continue?')),
|
E('p', _('All settings will be reset to default. Continue?')),
|
||||||
]),
|
]),
|
||||||
E('div', { 'class': 'right' }, [
|
E('div', { 'class': 'right' }, [
|
||||||
shutdown_btn,
|
|
||||||
' ',
|
|
||||||
cancel_button,
|
cancel_button,
|
||||||
|
' ',
|
||||||
|
resetcfg_btn,
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
@@ -294,8 +318,9 @@ return view.extend({
|
|||||||
btn_update.onclick = ui.createHandlerFn(this, () => { this.appAction('update', 'btn_update') });
|
btn_update.onclick = ui.createHandlerFn(this, () => { this.appAction('update', 'btn_update') });
|
||||||
layout_append(_('Update blacklist'), null, [ btn_update ] );
|
layout_append(_('Update blacklist'), null, [ btn_update ] );
|
||||||
|
|
||||||
let btn_destroy = create_btn('btn_destroy', btn_style_negative, _('Shutdown'));
|
let btn_reset = create_btn('btn_reset', btn_style_action, _('Reset settings'));
|
||||||
btn_destroy.onclick = L.bind(this.dialogDestroy, this);
|
btn_reset.onclick = L.bind(this.dialogResetCfg, this);
|
||||||
|
layout_append(_('Reset settings to default'), null, [ btn_reset ] );
|
||||||
|
|
||||||
let elems = {
|
let elems = {
|
||||||
"status": status_string,
|
"status": status_string,
|
||||||
@@ -305,6 +330,7 @@ return view.extend({
|
|||||||
"btn_restart": btn_restart,
|
"btn_restart": btn_restart,
|
||||||
"btn_stop": btn_stop,
|
"btn_stop": btn_stop,
|
||||||
"btn_update": btn_update,
|
"btn_update": btn_update,
|
||||||
|
"btn_reset": btn_reset,
|
||||||
};
|
};
|
||||||
this.setAppStatus(status_array, elems);
|
this.setAppStatus(status_array, elems);
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ return baseclass.extend({
|
|||||||
appName : 'zapret',
|
appName : 'zapret',
|
||||||
execPath : '/etc/init.d/zapret',
|
execPath : '/etc/init.d/zapret',
|
||||||
syncCfgPath : '/opt/zapret/sync_config.sh',
|
syncCfgPath : '/opt/zapret/sync_config.sh',
|
||||||
|
defaultCfgPath : '/opt/zapret/uci-def-cfg.sh',
|
||||||
|
|
||||||
hostsUserFN : '/opt/zapret/ipset/zapret-hosts-user.txt',
|
hostsUserFN : '/opt/zapret/ipset/zapret-hosts-user.txt',
|
||||||
hostsUserExcludeFN: '/opt/zapret/ipset/zapret-hosts-user-exclude.txt',
|
hostsUserExcludeFN: '/opt/zapret/ipset/zapret-hosts-user-exclude.txt',
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
"/etc/init.d/zapret*": [ "exec" ],
|
"/etc/init.d/zapret*": [ "exec" ],
|
||||||
"/bin/ps*": [ "exec" ],
|
"/bin/ps*": [ "exec" ],
|
||||||
"/bin/opkg*": [ "exec" ],
|
"/bin/opkg*": [ "exec" ],
|
||||||
|
"/opt/zapret/uci-def-cfg.sh*": [ "exec" ],
|
||||||
"/opt/zapret/sync_config.sh*": [ "exec" ]
|
"/opt/zapret/sync_config.sh*": [ "exec" ]
|
||||||
},
|
},
|
||||||
"uci": [ "zapret", "network" ],
|
"uci": [ "zapret", "network" ],
|
||||||
|
|||||||
Reference in New Issue
Block a user