luci-base, luci-mod-network: invoke ifdown directly in interface overview
authorJo-Philipp Wich <jo@mein.io>
Sun, 3 Nov 2019 16:29:29 +0000 (17:29 +0100)
committerJo-Philipp Wich <jo@mein.io>
Sun, 3 Nov 2019 16:56:58 +0000 (17:56 +0100)
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>
modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json
modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js

index ea19f32d49d3cb78077c8d6083eac534178b85e2..540fc72c10e326567baed3818a2f38ba2bf3aa3c 100644 (file)
@@ -63,6 +63,7 @@
                                "/etc/sysupgrade.conf": [ "write" ],
                                "/sbin/block": [ "exec" ],
                                "/sbin/firstboot": [ "exec" ],
+                               "/sbin/ifdown": [ "exec" ],
                                "/sbin/ifup": [ "exec" ],
                                "/sbin/reboot": [ "exec" ],
                                "/sbin/sysupgrade": [ "exec" ],
index 60d61adfec8134d558f9aedbc51fc08d5025414a..12d28808fb39c68c8b63dcf6fc48b16febc941ce 100644 (file)
@@ -158,9 +158,50 @@ function iface_updown(up, id, ev, force) {
        btns[0].disabled = true;
        btns[1].disabled = true;
 
-       dsc.setAttribute(up ? 'reconnect' : 'disconnect', force ? 'force' : '');
-       L.dom.content(dsc, E('em',
-               up ? _('Interface is reconnecting...') : _('Interface is shutting down...')));
+       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' : '');
+               L.dom.content(dsc, E('em', up ? _('Interface is reconnecting...') : _('Interface is shutting down...')));
+       }
 }
 
 function get_netmask(s, use_cfgvalue) {
@@ -939,34 +980,11 @@ return L.view.extend({
                                                        L.ui.addNotification(null, E('p', e.message));
                                                }));
                                        }
-                                       else if (dsc.getAttribute('disconnect') == '' || dsc.getAttribute('disconnect') == 'force') {
-                                               var force = dsc.getAttribute('disconnect');
+                                       else if (dsc.getAttribute('disconnect') == '') {
                                                dsc.setAttribute('disconnect', '1');
-                                               tasks.push(L.Request.post(
-                                                       L.url('admin/network/iface_down', section_ids[i], force),
-                                                       '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() {}));
+                                               tasks.push(fs.exec('/sbin/ifdown', [section_ids[i]]).catch(function(e) {
+                                                       L.ui.addNotification(null, E('p', e.message));
+                                               }));
                                        }
                                        else if (dsc.getAttribute('reconnect') == '1') {
                                                dsc.removeAttribute('reconnect');