diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2011-10-09 19:28:30 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2011-10-09 19:28:30 +0000 |
commit | b666015dc2d8394854be0259cd80f05994f66dd2 (patch) | |
tree | bcb2a89e0ca2a1464d8bb8896c9a781067fdc8f2 /modules/admin-full | |
parent | be71f1c93a005d35c5b8ecdd00778f31e3785da9 (diff) |
modules/admin-full: rework interface add dialog, now handles floating protocols like PPP correctly
Diffstat (limited to 'modules/admin-full')
-rw-r--r-- | modules/admin-full/luasrc/model/cbi/admin_network/iface_add.lua | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/iface_add.lua b/modules/admin-full/luasrc/model/cbi/admin_network/iface_add.lua index c3bf664bd..0e62ee88c 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_network/iface_add.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_network/iface_add.lua @@ -19,6 +19,8 @@ local utl = require "luci.util" local uci = require "luci.model.uci".cursor() m = SimpleForm("network", translate("Create Interface")) +m.redirect = luci.dispatcher.build_url("admin/network/network") +m.reset = false newnet = m:field(Value, "_netname", translate("Name of the new interface"), translate("The allowed characters are: <code>A-Z</code>, <code>a-z</code>, " .. @@ -29,6 +31,8 @@ newnet:depends("_attach", "") newnet.default = arg[1] and "net_" .. arg[1]:gsub("[^%w_]+", "_") newnet.datatype = "uciname" +newproto = m:field(ListValue, "_netproto", translate("Protocol of the new interface")) + netbridge = m:field(Flag, "_bridge", translate("Create a bridge over multiple interfaces")) @@ -36,41 +40,66 @@ sifname = m:field(Value, "_ifname", translate("Cover the following interface"), translate("Note: If you choose an interface here which is part of another network, it will be moved into this network.")) sifname.widget = "radio" -sifname.template = "cbi/network_ifacelist" +sifname.template = "cbi/network_ifacelist" sifname.nobridges = true -sifname:depends("_bridge", "") mifname = m:field(Value, "_ifnames", translate("Cover the following interfaces"), translate("Note: If you choose an interface here which is part of another network, it will be moved into this network.")) mifname.widget = "checkbox" -mifname.template = "cbi/network_ifacelist" +mifname.template = "cbi/network_ifacelist" mifname.nobridges = true -mifname:depends("_bridge", "1") -function newnet.write(self, section, value) - local bridge = netbridge:formvalue(section) == "1" - local ifaces = bridge and mifname:formvalue(section) or sifname:formvalue(section) - local nn = nw:add_network(value, { proto = "none" }) - if nn then - if bridge then - nn:set("type", "bridge") +local _, p +for _, p in ipairs(nw:get_protocols()) do + if p:is_installed() then + newproto:value(p:proto(), p:get_i18n()) + if not p:is_virtual() then netbridge:depends("_netproto", p:proto()) end + if not p:is_floating() then + sifname:depends({ _bridge = "", _netproto = p:proto()}) + mifname:depends({ _bridge = "1", _netproto = p:proto()}) end + end +end - local iface - for iface in utl.imatch(ifaces) do - nn:add_interface(iface) - if not bridge then - break - end - end +function newproto.validate(self, value, section) + local name = newnet:formvalue(section) + if not name or #name == 0 then + newnet:add_error(section, translate("No network name specified")) + elseif m:get(name) then + newnet:add_error(section, translate("The given network name is not unique")) + end - nw:save("network") - nw:save("wireless") + local proto = nw:get_protocol(value) + if proto and not proto:is_floating() then + local br = (netbridge:formvalue(section) == "1") + local ifn = br and mifname:formvalue(section) or sifname:formvalue(section) + for ifn in utl.imatch(ifn) do + return value + end + return nil, translate("The selected protocol needs a device assigned") + end + return value +end - luci.http.redirect(luci.dispatcher.build_url("admin/network/network", nn:name())) +function newproto.write(self, section, value) + local name = newnet:formvalue(section) + if name and #name > 0 then + local br = (netbridge:formvalue(section) == "1") and "bridge" or nil + local net = nw:add_network(name, { proto = value, type = br }) + if net then + local ifn + for ifn in utl.imatch( + br and mifname:formvalue(section) or sifname:formvalue(section) + ) do + net:add_interface(ifn) + end + nw:save("network") + nw:save("wireless") + end + luci.http.redirect(luci.dispatcher.build_url("admin/network/network", name)) end end |