modules/admin-full: fix wifi join

This commit is contained in:
Jo-Philipp Wich 2010-11-16 00:04:28 +00:00
parent 3386d649ea
commit ce88550559
3 changed files with 73 additions and 103 deletions

View file

@ -19,6 +19,11 @@ local http = require "luci.http"
local iw = luci.sys.wifi.getiwinfo(http.formvalue("device")) local iw = luci.sys.wifi.getiwinfo(http.formvalue("device"))
if not iw then
luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
return
end
m = SimpleForm("network", translate("Join Network: Settings")) m = SimpleForm("network", translate("Join Network: Settings"))
m.cancel = translate("Back to scan results") m.cancel = translate("Back to scan results")
m.reset = false m.reset = false
@ -48,6 +53,8 @@ m.hidden = {
if iw and iw.mbssid_support then if iw and iw.mbssid_support then
replace = m:field(Flag, "replace", translate("Replace wireless configuration"), replace = m:field(Flag, "replace", translate("Replace wireless configuration"),
translate("An additional network will be created if you leave this unchecked.")) translate("An additional network will be created if you leave this unchecked."))
function replace.cfgvalue() return "1" end
else else
replace = m:field(DummyValue, "replace", translate("Replace wireless configuration")) replace = m:field(DummyValue, "replace", translate("Replace wireless configuration"))
replace.default = translate("The hardware is not multi-SSID capable and existing " .. replace.default = translate("The hardware is not multi-SSID capable and existing " ..
@ -61,75 +68,40 @@ if http.formvalue("wep") == "1" then
translate("Specify the secret encryption key here.")) translate("Specify the secret encryption key here."))
key.password = true key.password = true
key.datatype = "wepkey"
elseif (tonumber(m.hidden.wpa_version) or 0) > 0 and m.hidden.wpa_suites == "PSK" then elseif (tonumber(m.hidden.wpa_version) or 0) > 0 and
(m.hidden.wpa_suites == "PSK" or m.hidden.wpa_suites == "PSK2")
then
key = m:field(Value, "key", translate("WPA passphrase"), key = m:field(Value, "key", translate("WPA passphrase"),
translate("Specify the secret encryption key here.")) translate("Specify the secret encryption key here."))
key.password = true key.password = true
key.datatype = "wpakey"
--m.hidden.wpa_suite = (tonumber(http.formvalue("wpa_version")) or 0) >= 2 and "psk2" or "psk" --m.hidden.wpa_suite = (tonumber(http.formvalue("wpa_version")) or 0) >= 2 and "psk2" or "psk"
end end
attachnet = m:field(Flag, "_attach", translate("Attach to existing network"),
translate("If the interface is attached to an existing network it will be <em>bridged</em> " ..
"to the existing interfaces and is covered by the firewall zone of the choosen network. " ..
"Uncheck this option to define a new standalone network."
))
attachnet.rmempty = false
attachnet.default = http.formvalue("cbi.submit") and nil or "1"
function attachnet.formvalue(self, section)
if not http.formvalue("cbi.submit") then
return m.hidden.mode == "Ad-Hoc" and "0" or "1"
else
return Value.formvalue(self, section) and "1" or "0"
end
end
attachnet.cfgvalue = attachnet.formvalue
newnet = m:field(Value, "_netname_new", translate("Name of the new network"), newnet = m:field(Value, "_netname_new", translate("Name of the new network"),
translate("The allowed characters are: <code>A-Z</code>, <code>a-z</code>, " .. translate("The allowed characters are: <code>A-Z</code>, <code>a-z</code>, " ..
"<code>0-9</code> and <code>_</code>" "<code>0-9</code> and <code>_</code>"
)) ))
newnet:depends("_attach", "") newnet.default = m.hidden.mode == "Ad-Hoc" and "mesh" or "wwan"
newnet.default = m.hidden.mode == "Ad-Hoc" and "mesh" newnet.datatype = "uciname"
addnet = m:field(Value, "_netname_attach",
translate("Network to attach interface to"))
addnet.template = "cbi/network_netlist"
addnet.widget = "radio"
addnet.default = "wan"
addnet.nocreate = true
addnet:depends("_attach", "1")
fwzone = m:field(Value, "_fwzone", fwzone = m:field(Value, "_fwzone",
translate("Create / Assign firewall-zone"), translate("Create / Assign firewall-zone"),
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.")) 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."))
fwzone.template = "cbi/firewall_zonelist" fwzone.template = "cbi/firewall_zonelist"
fwzone:depends("_attach", "") fwzone.default = m.hidden.mode == "Ad-Hoc" and "mesh" or "wan"
fwzone.default = m.hidden.mode == "Ad-Hoc" and "mesh"
function attachnet.parse(self, section) function newnet.parse(self, section)
Flag.parse(self, section)
if http.formvalue("cbi.submit") then
local net, zone local net, zone
local value = self:formvalue(section) local value = self:formvalue(section)
if value == "1" then
net = nw:get_network(addnet:formvalue(section))
if net then
net:type("bridge")
end
else
local zval = fwzone:formvalue(section) local zval = fwzone:formvalue(section)
net = nw:add_network(newnet:formvalue(section), { proto = "dhcp" }) net = nw:add_network(value, { proto = "dhcp" })
zone = fw:get_zone(zval) zone = fw:get_zone(zval)
if not zone and zval == '-' then if not zone and zval == '-' then
@ -138,7 +110,6 @@ function attachnet.parse(self, section)
zone = fw:add_zone(zval) zone = fw:add_zone(zval)
end end
end end
end
if not net then if not net then
self.error = { [section] = "missing" } self.error = { [section] = "missing" }
@ -187,19 +158,13 @@ function attachnet.parse(self, section)
uci:save("network") uci:save("network")
uci:save("firewall") uci:save("firewall")
uci:commit("wireless") luci.http.redirect(luci.dispatcher.build_url(
uci:commit("network") "admin/network/wireless", wdev:name(), wnet:ifname()
uci:commit("firewall") ))
luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless",
wdev:name(), wnet:name()))
end
end end
end end
end end
attachnet.remove = attachnet.write
function fwzone.cfgvalue(self, section) function fwzone.cfgvalue(self, section)
self.iface = section self.iface = section
local z = fw:get_zone_by_network(section) local z = fw:get_zone_by_network(section)

View file

@ -67,6 +67,11 @@ $Id$
local dev = luci.http.formvalue("device") local dev = luci.http.formvalue("device")
local iw = luci.sys.wifi.getiwinfo(dev) local iw = luci.sys.wifi.getiwinfo(dev)
if not iw then
luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
return
end
-%> -%>
<%+header%> <%+header%>

View file

@ -284,7 +284,7 @@ $Id$
</td> </td>
<td class="cbi-value-field" style="width:40px"> <td class="cbi-value-field" style="width:40px">
<a href="<%=net:adminlink()%>"><img style="border:none" src="<%=resource%>/cbi/edit.gif" alt="<%:Edit this network%>" title="<%:Edit this network%>" /></a> <a href="<%=net:adminlink()%>"><img style="border:none" src="<%=resource%>/cbi/edit.gif" alt="<%:Edit this network%>" title="<%:Edit this network%>" /></a>
<a href="<%=luci.dispatcher.build_url("admin/network/wireless_delete", net:ifname())%>"><img style="border:none" src="<%=resource%>/cbi/remove.gif" alt="<%:Delete this network%>" title="<%:Delete this network%>" /></a> <a href="<%=luci.dispatcher.build_url("admin/network/wireless_delete", net:ifname())%>" onclick="return confirm('<%:Really delete this wireless network? The deletion cannot be undone!\nYou might loose access to this router if you are connected via this network.%>')"><img style="border:none" src="<%=resource%>/cbi/remove.gif" alt="<%:Delete this network%>" title="<%:Delete this network%>" /></a>
</td> </td>
</tr> </tr>
<% end %> <% end %>