2 LuCI - Lua Configuration Interface
4 Copyright 2009 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
15 local nw = require "luci.model.network"
16 local fw = require "luci.model.firewall"
17 local uci = require "luci.model.uci".cursor()
19 m = SimpleForm("network", translate("Create Or Attach Network"),
20 translate("If the interface is attached to an existing network it will be <em>bridged</em> " ..
21 "to the existing interfaces and is covered by the firewall zone of the choosen network.<br />" ..
22 "Uncheck the attach option to define a new standalone network for this interface."
28 attachnet = m:field(Flag, "_attach", translate("Attach to existing network"))
29 attachnet.rmempty = false
30 attachnet.default = "1"
32 newnet = m:field(Value, "_netname_new", translate("Name of the new network"),
33 translate("The allowed characters are: <code>A-Z</code>, <code>a-z</code>, " ..
34 "<code>0-9</code> and <code>_</code>"
37 newnet:depends("_attach", "")
38 newnet.default = arg[1] and "net_" .. arg[1]:gsub("[^%w_]+", "_")
40 addnet = m:field(Value, "_netname_attach",
41 translate("Network to attach interface to"))
43 addnet.template = "cbi/network_netlist"
44 addnet.widget = "radio"
45 addnet.nocreate = true
46 addnet:depends("_attach", "1")
48 fwzone = m:field(Value, "_fwzone",
49 translate("Create / Assign firewall-zone"),
50 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."))
52 fwzone.template = "cbi/firewall_zonelist"
53 addnet.widget = "radio"
54 fwzone:depends("_attach", "")
55 fwzone.default = arg[1] and "zone_" .. arg[1]:gsub("[^%w_]+", "_")
58 function attachnet.write(self, section, value)
62 net = nw:get_network(addnet:formvalue(section))
67 local zval = fwzone:formvalue(section)
69 net = nw:add_network(newnet:formvalue(section), { proto = "none" })
70 zone = fw:get_zone(zval)
72 if not zone and zval == '-' then
73 zval = m:formvalue(fwzone:cbid(section) .. ".newzone")
74 if zval and #zval > 0 then
75 zone = fw:add_zone(zval)
77 fw:del_network(arg[1])
83 self.error = { [section] = "missing" }
85 net:add_interface(arg[1])
88 fw:del_network(net:name())
89 zone:add_network(net:name())
95 luci.http.redirect(luci.dispatcher.build_url("admin/network/network", net:name()))
99 function fwzone.cfgvalue(self, section)
101 local z = fw:get_zone_by_network(section)
102 return z and z:name()