X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=modules%2Fadmin-full%2Fluasrc%2Fmodel%2Fcbi%2Fadmin_network%2Fiface_add.lua;h=0e62ee88cffad11a980709a3a1272b644cfd0fbf;hb=c3aff0c622de2cf3e9afe77f66acbde3384ff062;hp=93cdecac78518de8f3632cf4877bffee31031207;hpb=839e150ea931b2989ea3cf9b4b86bcc17360decc;p=project%2Fluci.git 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 93cdecac7..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 @@ -1,7 +1,7 @@ --[[ LuCI - Lua Configuration Interface -Copyright 2009 Jo-Philipp Wich +Copyright 2009-2010 Jo-Philipp Wich Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -10,98 +10,97 @@ 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("a_n_create", "Create Or Attach Network"), - translate("a_n_c_desc", - "If the interface is attached to an existing network it will be bridged " .. - "to the existing interfaces and is covered by the firewall zone of the choosen network.
" .. - "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")) +m.redirect = luci.dispatcher.build_url("admin/network/network") +m.reset = false -attachnet = m:field(Flag, "_attach", translate("a_n_c_attach", "Attach to existing network")) -attachnet.rmempty = false -attachnet.default = "1" - -newnet = m:field(Value, "_netname_new", translate("a_n_c_netname", "Name of the new network"), - translate("a_n_c_netname_desc", - "The allowed characters are: A-Z, a-z, " .. +newnet = m:field(Value, "_netname", translate("Name of the new interface"), + translate("The allowed characters are: A-Z, a-z, " .. "0-9 and _" )) newnet:depends("_attach", "") -newnet.default = "net_" .. arg[1]:gsub("[^%w_]+", "_") +newnet.default = arg[1] and "net_" .. arg[1]:gsub("[^%w_]+", "_") +newnet.datatype = "uciname" -addnet = m:field(Value, "_netname_attach", - translate("a_n_c_network", "Network to attach interface to")) +newproto = m:field(ListValue, "_netproto", translate("Protocol of the new interface")) -addnet.template = "cbi/network_netlist" -addnet.widget = "radio" -addnet.nocreate = true -addnet:depends("_attach", "1") +netbridge = m:field(Flag, "_bridge", translate("Create a bridge over multiple interfaces")) -fwzone = m:field(Value, "_fwzone", - translate("network_interface_fwzone"), - translate("network_interface_fwzone_desc")) -fwzone.template = "cbi/firewall_zonelist" -addnet.widget = "radio" -fwzone:depends("_attach", "") -fwzone.default = "zone_" .. arg[1]:gsub("[^%w_]+", "_") +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.nobridges = true -function attachnet.write(self, section, value) - local net, zone - if value == "1" then - net = nw:get_network(addnet:formvalue(section)) - if net then - net: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]) - end +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 + + +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 - if not net then - self.error = { [section] = "missing" } - else - net:add_interface(arg[1]) +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 - if zone then - fw:del_network(net:name()) - zone:add_network(net:name()) + 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 - - uci:save("wireless") - uci:save("network") - uci:save("firewall") - luci.http.redirect(luci.dispatcher.build_url("admin/network/network", net:name())) + return nil, translate("The selected protocol needs a device assigned") end + return value end -function fwzone.cfgvalue(self, section) - self.iface = section - local z = fw:get_zone_by_network(section) - return z and z: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 return m