diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-08-20 15:39:16 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-09-10 15:28:16 +0200 |
commit | e4bc192012b05078eb7675e42908e0dd9d04ee88 (patch) | |
tree | 527f740c49e7b3738721af05105ce3171b4768fc /modules/luci-mod-network/luasrc/controller/admin | |
parent | 6a2a53a82918ea2ccbbbe23510aa0279827b2783 (diff) |
luci-mod-network: switch to client side interface configuration pages
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-mod-network/luasrc/controller/admin')
-rw-r--r-- | modules/luci-mod-network/luasrc/controller/admin/network.lua | 75 |
1 files changed, 60 insertions, 15 deletions
diff --git a/modules/luci-mod-network/luasrc/controller/admin/network.lua b/modules/luci-mod-network/luasrc/controller/admin/network.lua index b20607e2e9..4578d12578 100644 --- a/modules/luci-mod-network/luasrc/controller/admin/network.lua +++ b/modules/luci-mod-network/luasrc/controller/admin/network.lua @@ -76,30 +76,19 @@ function index() end - page = entry({"admin", "network", "iface_add"}, form("admin_network/iface_add"), nil) - page.leaf = true - page = entry({"admin", "network", "iface_status"}, call("iface_status"), nil) page.leaf = true page = entry({"admin", "network", "iface_reconnect"}, post("iface_reconnect"), nil) page.leaf = true - page = entry({"admin", "network", "network"}, arcombine(cbi("admin_network/network"), cbi("admin_network/ifaces")), _("Interfaces"), 10) + page = entry({"admin", "network", "iface_down"}, post("iface_down"), nil) + page.leaf = true + + page = entry({"admin", "network", "network"}, view("network/interfaces"), _("Interfaces"), 10) page.leaf = true page.subindex = true - if page.inreq then - uci:foreach("network", "interface", - function (section) - local ifc = section[".name"] - if ifc ~= "loopback" then - entry({"admin", "network", "network", ifc}, - true, ifc:upper()) - end - end) - end - if nixio.fs.access("/etc/config/dhcp") then page = node("admin", "network", "dhcp") @@ -268,6 +257,62 @@ function iface_reconnect(iface) luci.http.status(404, "No such interface") end +local function addr2dev(addr, src) + local ip = require "luci.ip" + local route = ip.route(addr, src) + if not src and route and route.src then + route = ip.route(addr, route.src:string()) + end + return route and route.dev +end + +function iface_down(iface, force) + local netmd = require "luci.model.network".init() + local peer = luci.http.getenv("REMOTE_ADDR") + local serv = luci.http.getenv("SERVER_ADDR") + + if force ~= "force" and serv and peer then + local dev = addr2dev(peer, serv) + if dev then + local nets = netmd:get_networks() + local outnet = nil + local _, net, ai + + for _, net in ipairs(nets) do + if net:contains_interface(dev) then + outnet = net + break + end + end + + if outnet:name() == iface then + luci.http.status(409, "Is inbound interface") + return + end + + local peeraddr = outnet:get("peeraddr") + for _, ai in ipairs(peeraddr and nixio.getaddrinfo(peeraddr) or {}) do + local peerdev = addr2dev(ai.address) + for _, net in ipairs(peerdev and nets or {}) do + if net:contains_interface(peerdev) and net:name() == iface then + luci.http.status(409, "Is inbound interface") + return + end + end + end + end + end + + if netmd:get_network(iface) then + luci.sys.call("env -i /sbin/ifdown %s >/dev/null 2>/dev/null" + % luci.util.shellquote(iface)) + luci.http.status(200, "Shut down") + return + end + + luci.http.status(404, "No such interface") +end + function wifi_status(devs) local s = require "luci.tools.status" local rv = { } |