luci-base, luci-mod-network: invoke ifdown directly in interface overview

Replace the `iface_down` endpoint with a direct invocation of `/sbin/ifdown`
and replace the interface connectivity check with a call to the new
`remote_addr` endpoint.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-11-03 17:29:29 +01:00
parent 9cb4aa1306
commit f16a47042c
2 changed files with 49 additions and 30 deletions

View file

@ -63,6 +63,7 @@
"/etc/sysupgrade.conf": [ "write" ], "/etc/sysupgrade.conf": [ "write" ],
"/sbin/block": [ "exec" ], "/sbin/block": [ "exec" ],
"/sbin/firstboot": [ "exec" ], "/sbin/firstboot": [ "exec" ],
"/sbin/ifdown": [ "exec" ],
"/sbin/ifup": [ "exec" ], "/sbin/ifup": [ "exec" ],
"/sbin/reboot": [ "exec" ], "/sbin/reboot": [ "exec" ],
"/sbin/sysupgrade": [ "exec" ], "/sbin/sysupgrade": [ "exec" ],

View file

@ -158,9 +158,50 @@ function iface_updown(up, id, ev, force) {
btns[0].disabled = true; btns[0].disabled = true;
btns[1].disabled = true; btns[1].disabled = true;
if (!up) {
L.Request.get(L.url('admin/network/remote_addr')).then(function(res) {
var info = res.json();
if (L.isObject(info) &&
Array.isArray(info.inbound_interfaces) &&
info.inbound_interfaces.filter(function(i) { return i == id })[0]) {
L.ui.showModal(_('Confirm disconnect'), [
E('p', _('You appear to be currently connected to the device via the "%h" interface. Do you really want to shut down the interface?').format(id)),
E('div', { 'class': 'right' }, [
E('button', {
'class': 'cbi-button cbi-button-neutral',
'click': function(ev) {
btns[1].classList.remove('spinning');
btns[1].disabled = false;
btns[0].disabled = false;
L.ui.hideModal();
}
}, _('Cancel')),
' ',
E('button', {
'class': 'cbi-button cbi-button-negative important',
'click': function(ev) {
dsc.setAttribute('disconnect', '');
L.dom.content(dsc, E('em', _('Interface is shutting down...')));
L.ui.hideModal();
}
}, _('Disconnect'))
])
]);
}
else {
dsc.setAttribute('disconnect', '');
L.dom.content(dsc, E('em', _('Interface is shutting down...')));
}
});
}
else {
dsc.setAttribute(up ? 'reconnect' : 'disconnect', force ? 'force' : ''); dsc.setAttribute(up ? 'reconnect' : 'disconnect', force ? 'force' : '');
L.dom.content(dsc, E('em', L.dom.content(dsc, E('em', up ? _('Interface is reconnecting...') : _('Interface is shutting down...')));
up ? _('Interface is reconnecting...') : _('Interface is shutting down...'))); }
} }
function get_netmask(s, use_cfgvalue) { function get_netmask(s, use_cfgvalue) {
@ -939,34 +980,11 @@ return L.view.extend({
L.ui.addNotification(null, E('p', e.message)); L.ui.addNotification(null, E('p', e.message));
})); }));
} }
else if (dsc.getAttribute('disconnect') == '' || dsc.getAttribute('disconnect') == 'force') { else if (dsc.getAttribute('disconnect') == '') {
var force = dsc.getAttribute('disconnect');
dsc.setAttribute('disconnect', '1'); dsc.setAttribute('disconnect', '1');
tasks.push(L.Request.post( tasks.push(fs.exec('/sbin/ifdown', [section_ids[i]]).catch(function(e) {
L.url('admin/network/iface_down', section_ids[i], force), L.ui.addNotification(null, E('p', e.message));
'token=' + L.env.token, }));
{ headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
).then(L.bind(function(ifname, res) {
if (res.status == 409) {
L.ui.showModal(_('Confirm disconnect'), [
E('p', _('You appear to be currently connected to the device via the "%h" interface. Do you really want to shut down the interface?').format(ifname)),
E('div', { 'class': 'right' }, [
E('button', {
'class': 'cbi-button cbi-button-neutral',
'click': L.ui.hideModal
}, _('Cancel')),
' ',
E('button', {
'class': 'cbi-button cbi-button-negative important',
'click': function(ev) {
iface_updown(false, ifname, ev, true);
L.ui.hideModal();
}
}, _('Disconnect'))
])
]);
}
}, this, section_ids[i]), function() {}));
} }
else if (dsc.getAttribute('reconnect') == '1') { else if (dsc.getAttribute('reconnect') == '1') {
dsc.removeAttribute('reconnect'); dsc.removeAttribute('reconnect');