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()
18 local http = require "luci.http"
20 local iw = luci.sys.wifi.getiwinfo(http.formvalue("device"))
23 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
27 m = SimpleForm("network", translate("Join Network: Settings"))
28 m.cancel = translate("Back to scan results")
31 function m.on_cancel()
32 local dev = http.formvalue("device")
33 http.redirect(luci.dispatcher.build_url(
34 dev and "admin/network/wireless_join?device=" .. dev
35 or "admin/network/wireless"
43 device = http.formvalue("device"),
44 join = http.formvalue("join"),
45 channel = http.formvalue("channel"),
46 mode = http.formvalue("mode"),
47 bssid = http.formvalue("bssid"),
48 wep = http.formvalue("wep"),
49 wpa_suites = http.formvalue("wpa_suites"),
50 wpa_version = http.formvalue("wpa_version")
53 if iw and iw.mbssid_support then
54 replace = m:field(Flag, "replace", translate("Replace wireless configuration"),
55 translate("An additional network will be created if you leave this unchecked."))
57 function replace.cfgvalue() return "1" end
59 replace = m:field(DummyValue, "replace", translate("Replace wireless configuration"))
60 replace.default = translate("The hardware is not multi-SSID capable and existing " ..
61 "configuration will be replaced if you proceed.")
63 function replace.formvalue() return "1" end
66 if http.formvalue("wep") == "1" then
67 key = m:field(Value, "key", translate("WEP passphrase"),
68 translate("Specify the secret encryption key here."))
71 key.datatype = "wepkey"
73 elseif (tonumber(m.hidden.wpa_version) or 0) > 0 and
74 (m.hidden.wpa_suites == "PSK" or m.hidden.wpa_suites == "PSK2")
76 key = m:field(Value, "key", translate("WPA passphrase"),
77 translate("Specify the secret encryption key here."))
80 key.datatype = "wpakey"
81 --m.hidden.wpa_suite = (tonumber(http.formvalue("wpa_version")) or 0) >= 2 and "psk2" or "psk"
84 newnet = m:field(Value, "_netname_new", translate("Name of the new network"),
85 translate("The allowed characters are: <code>A-Z</code>, <code>a-z</code>, " ..
86 "<code>0-9</code> and <code>_</code>"
89 newnet.default = m.hidden.mode == "Ad-Hoc" and "mesh" or "wwan"
90 newnet.datatype = "uciname"
92 fwzone = m:field(Value, "_fwzone",
93 translate("Create / Assign firewall-zone"),
94 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."))
96 fwzone.template = "cbi/firewall_zonelist"
97 fwzone.default = m.hidden.mode == "Ad-Hoc" and "mesh" or "wan"
99 function newnet.parse(self, section)
101 local value = self:formvalue(section)
102 local zval = fwzone:formvalue(section)
104 net = nw:add_network(value, { proto = "dhcp" })
105 zone = fw:get_zone(zval)
107 if not zone and zval == '-' then
108 zval = m:formvalue(fwzone:cbid(section) .. ".newzone")
109 if zval and #zval > 0 then
110 zone = fw:add_zone(zval)
115 self.error = { [section] = "missing" }
117 local wdev = nw:get_wifidev(m.hidden.device)
119 wdev:set("disabled", false)
120 wdev:set("channel", m.hidden.channel)
122 if replace:formvalue(section) then
124 for _, n in ipairs(wdev:get_wifinets()) do
130 device = m.hidden.device,
131 ssid = m.hidden.join,
132 mode = (m.hidden.mode == "Ad-Hoc" and "adhoc" or "sta"),
136 if m.hidden.wep == "1" then
137 wconf.encryption = "wep"
138 wconf.key = key and key:formvalue(section) or ""
139 elseif (tonumber(m.hidden.wpa_version) or 0) > 0 then
140 wconf.encryption = (tonumber(m.hidden.wpa_version) or 0) >= 2 and "psk2" or "psk"
141 wconf.key = key and key:formvalue(section) or ""
143 wconf.encryption = "none"
146 if wconf.mode == "adhoc" then
147 wconf.bssid = m.hidden.bssid
150 local wnet = wdev:add_wifinet(wconf)
153 fw:del_network(net:name())
154 zone:add_network(net:name())
161 luci.http.redirect(luci.dispatcher.build_url(
162 "admin/network/wireless", wdev:name(), wnet:ifname()
168 function fwzone.cfgvalue(self, section)
170 local z = fw:get_zone_by_network(section)
171 return z and z:name()