summaryrefslogtreecommitdiffhomepage
path: root/modules/admin-full
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-11-15 22:11:18 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-11-15 22:11:18 +0000
commit125eb141deaedbc75f9738d1aa45087ca74a6eb8 (patch)
treefffe367f3847252675c9a3861b8b8d84179093f8 /modules/admin-full
parentd26e671b78bec5448a1dfc534f461f6d658127a2 (diff)
modules/admin-full: rework interface add model
Diffstat (limited to 'modules/admin-full')
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_network/iface_add.lua106
1 files changed, 39 insertions, 67 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 f623cac3f5..c3bf664bd0 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
@@ -1,7 +1,7 @@
--[[
LuCI - Lua Configuration Interface
-Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
+Copyright 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -10,96 +10,68 @@ You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id$
+
]]--
-local nw = require "luci.model.network"
-local fw = require "luci.model.firewall"
+local nw = require "luci.model.network".init()
+local fw = require "luci.model.firewall".init()
+local utl = require "luci.util"
local uci = require "luci.model.uci".cursor()
-m = SimpleForm("network", translate("Create Or Attach Network"),
- translate("If the interface is attached to an existing network it will be <em>bridged</em> " ..
- "to the existing interfaces and is covered by the firewall zone of the choosen network.<br />" ..
- "Uncheck the attach option to define a new standalone network for this interface."
- ))
-
-nw.init(uci)
-fw.init(uci)
+m = SimpleForm("network", translate("Create Interface"))
-attachnet = m:field(Flag, "_attach", translate("Attach to existing network"))
-attachnet.rmempty = false
-attachnet.default = "1"
-
-newnet = m:field(Value, "_netname_new", translate("Name of the new network"),
+newnet = m:field(Value, "_netname", translate("Name of the new interface"),
translate("The allowed characters are: <code>A-Z</code>, <code>a-z</code>, " ..
"<code>0-9</code> and <code>_</code>"
))
newnet:depends("_attach", "")
newnet.default = arg[1] and "net_" .. arg[1]:gsub("[^%w_]+", "_")
+newnet.datatype = "uciname"
+
+netbridge = m:field(Flag, "_bridge", translate("Create a bridge over multiple interfaces"))
+
-addnet = m:field(Value, "_netname_attach",
- translate("Network to attach interface to"))
+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."))
-addnet.template = "cbi/network_netlist"
-addnet.widget = "radio"
-addnet.nocreate = true
-addnet:depends("_attach", "1")
+sifname.widget = "radio"
+sifname.template = "cbi/network_ifacelist"
+sifname.nobridges = true
+sifname:depends("_bridge", "")
-fwzone = m:field(Value, "_fwzone",
- translate("Create / Assign firewall-zone"),
- translate("Choose the firewall zone you want to assign to this interface. Select <em>unspecified</em> to remove the interface from the associated zone or fill out the <em>create</em> field to define a new zone and attach the interface to it."))
-fwzone.template = "cbi/firewall_zonelist"
-addnet.widget = "radio"
-fwzone:depends("_attach", "")
-fwzone.default = arg[1] and "zone_" .. arg[1]:gsub("[^%w_]+", "_")
+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.nobridges = true
+mifname:depends("_bridge", "1")
-function attachnet.write(self, section, value)
- local net, zone
+function newnet.write(self, section, value)
+ local bridge = netbridge:formvalue(section) == "1"
+ local ifaces = bridge and mifname:formvalue(section) or sifname:formvalue(section)
- if value == "1" then
- net = nw:get_network(addnet:formvalue(section))
- if net then
- net:type("bridge")
+ local nn = nw:add_network(value, { proto = "none" })
+ if nn then
+ if bridge then
+ nn:set("type", "bridge")
end
- else
- local zval = fwzone:formvalue(section)
-
- net = nw:add_network(newnet:formvalue(section), { proto = "none" })
- zone = fw:get_zone(zval)
-
- if not zone and zval == '-' then
- zval = m:formvalue(fwzone:cbid(section) .. ".newzone")
- if zval and #zval > 0 then
- zone = fw:add_zone(zval)
- else
- fw:del_network(arg[1])
+
+ local iface
+ for iface in utl.imatch(ifaces) do
+ nn:add_interface(iface)
+ if not bridge then
+ break
end
end
- end
-
- if not net then
- self.error = { [section] = "missing" }
- else
- net:add_interface(arg[1])
- if zone then
- fw:del_network(net:name())
- zone:add_network(net:name())
- end
+ nw:save("network")
+ nw:save("wireless")
- uci:save("wireless")
- uci:save("network")
- uci:save("firewall")
- luci.http.redirect(luci.dispatcher.build_url("admin/network/network", net:name()))
+ luci.http.redirect(luci.dispatcher.build_url("admin/network/network", nn:name()))
end
end
-function fwzone.cfgvalue(self, section)
- self.iface = section
- local z = fw:get_zone_by_network(section)
- return z and z:name()
-end
-
return m