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("a_n_create", "Create Or Attach Network"),
20 translate("a_n_c_desc",
21 "If the interface is attached to an existing network it will be <em>bridged</em> " ..
22 "to the existing interfaces and is covered by the firewall zone of the choosen network.<br />" ..
23 "Uncheck the attach option to define a new standalone network for this interface."
29 attachnet = m:field(Flag, "_attach", translate("a_n_c_attach", "Attach to existing network"))
30 attachnet.rmempty = false
31 attachnet.default = "1"
33 newnet = m:field(Value, "_netname_new", translate("a_n_c_netname", "Name of the new network"),
34 translate("a_n_c_netname_desc",
35 "The allowed characters are: <code>A-Z</code>, <code>a-z</code>, " ..
36 "<code>0-9</code> and <code>_</code>"
39 newnet:depends("_attach", "")
40 newnet.default = "net_" .. arg[1]:gsub("[^%w_]+", "_")
42 addnet = m:field(Value, "_netname_attach",
43 translate("a_n_c_network", "Network to attach interface to"))
45 addnet.template = "cbi/network_netlist"
46 addnet.widget = "radio"
47 addnet.nocreate = true
48 addnet:depends("_attach", "1")
50 fwzone = m:field(Value, "_fwzone",
51 translate("network_interface_fwzone"),
52 translate("network_interface_fwzone_desc"))
54 fwzone.template = "cbi/firewall_zonelist"
55 addnet.widget = "radio"
56 fwzone:depends("_attach", "")
57 fwzone.default = "zone_" .. arg[1]:gsub("[^%w_]+", "_")
60 function attachnet.write(self, section, value)
64 net = nw:get_network(addnet:formvalue(section))
69 local zval = fwzone:formvalue(section)
71 net = nw:add_network(newnet:formvalue(section), { proto = "none" })
72 zone = fw:get_zone(zval)
74 if not zone and zval == '-' then
75 zval = m:formvalue(fwzone:cbid(section) .. ".newzone")
76 if zval and #zval > 0 then
77 zone = fw:add_zone(zval)
79 fw:del_network(arg[1])
85 self.error = { [section] = "missing" }
87 net:add_interface(arg[1])
90 fw:del_network(net:name())
91 zone:add_network(net:name())
96 luci.http.redirect(luci.dispatcher.build_url("admin/network/network", net:name()))
100 function fwzone.cfgvalue(self, section)
102 local z = fw:get_zone_by_network(section)
103 return z and z:name()