2 LuCI - Lua Configuration Interface
4 Copyright 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
16 local nw = require "luci.model.network".init()
17 local fw = require "luci.model.firewall".init()
18 local utl = require "luci.util"
19 local uci = require "luci.model.uci".cursor()
21 m = SimpleForm("network", translate("Create Interface"))
23 newnet = m:field(Value, "_netname", translate("Name of the new interface"),
24 translate("The allowed characters are: <code>A-Z</code>, <code>a-z</code>, " ..
25 "<code>0-9</code> and <code>_</code>"
28 newnet:depends("_attach", "")
29 newnet.default = arg[1] and "net_" .. arg[1]:gsub("[^%w_]+", "_")
30 newnet.datatype = "uciname"
32 netbridge = m:field(Flag, "_bridge", translate("Create a bridge over multiple interfaces"))
35 sifname = m:field(Value, "_ifname", translate("Cover the following interface"),
36 translate("Note: If you choose an interface here which is part of another network, it will be moved into this network."))
38 sifname.widget = "radio"
39 sifname.template = "cbi/network_ifacelist"
40 sifname.nobridges = true
41 sifname:depends("_bridge", "")
44 mifname = m:field(Value, "_ifnames", translate("Cover the following interfaces"),
45 translate("Note: If you choose an interface here which is part of another network, it will be moved into this network."))
47 mifname.widget = "checkbox"
48 mifname.template = "cbi/network_ifacelist"
49 mifname.nobridges = true
50 mifname:depends("_bridge", "1")
52 function newnet.write(self, section, value)
53 local bridge = netbridge:formvalue(section) == "1"
54 local ifaces = bridge and mifname:formvalue(section) or sifname:formvalue(section)
56 local nn = nw:add_network(value, { proto = "none" })
59 nn:set("type", "bridge")
63 for iface in utl.imatch(ifaces) do
64 nn:add_interface(iface)
73 luci.http.redirect(luci.dispatcher.build_url("admin/network/network", nn:name()))