X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=modules%2Fadmin-full%2Fluasrc%2Fmodel%2Fcbi%2Fadmin_network%2Fwifi.lua;h=cc534f5c935b5b57f25495d64b7e471c9fced305;hb=bc8eaf6875fb195484b0a86e71ea92dc63b82ded;hp=87f7d8ef07df95e933413f2d3ec76070627fc82c;hpb=b9dfdb9d0db4463a168a22293cb4c48fb92823c5;p=project%2Fluci.git diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua b/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua index 87f7d8ef0..cc534f5c9 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua @@ -17,7 +17,6 @@ local nw = require "luci.model.network" local fs = require "nixio.fs" arg[1] = arg[1] or "" -arg[2] = arg[2] or "" m = Map("wireless", "", translate("The Device Configuration section covers physical settings of the radio " .. @@ -30,32 +29,36 @@ m:chain("network") local ifsection function m.on_commit(map) - local wnet = nw:get_wifinet(arg[2]) + local wnet = nw:get_wifinet(arg[1]) if ifsection and wnet then ifsection.section = wnet.sid - m.title = wnet:get_i18n() + m.title = luci.util.pcdata(wnet:get_i18n()) end end nw.init(m.uci) -local wnet = nw:get_wifinet(arg[2]) +local wnet = nw:get_wifinet(arg[1]) +local wdev = wnet and wnet:get_device() -- redirect to overview page if network does not exist anymore (e.g. after a revert) -if not wnet then +if not wnet or not wdev then luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless")) return end -m.title = wnet:get_i18n() +m.title = luci.util.pcdata(wnet:get_i18n()) local iw = luci.sys.wifi.getiwinfo(arg[1]) -local tx_powers = iw.txpwrlist or { } local hw_modes = iw.hwmodelist or { } +local tx_powers = iw.txpwrlist or { } +local tx_power = tostring( + (iw.txpower and iw.txpower > 0 and iw.txpower) or + (#tx_powers > 0 and tx_powers[#tx_powers].dbm) +) - -s = m:section(NamedSection, arg[1], "wifi-device", translate("Device Configuration")) +s = m:section(NamedSection, wdev:name(), "wifi-device", translate("Device Configuration")) s.addremove = false s:tab("general", translate("General Setup")) @@ -70,7 +73,7 @@ back.titleref = luci.dispatcher.build_url("admin", "network", "wireless") st = s:taboption("general", DummyValue, "__status", translate("Status")) st.template = "admin_network/wifi_status" -st.ifname = arg[2] +st.ifname = arg[1] en = s:taboption("general", Flag, "disabled", translate("Enable device")) en.enabled = "0" @@ -82,11 +85,11 @@ function en.cfgvalue(self, section) end -local hwtype = m:get(arg[1], "type") -local htcaps = m:get(arg[1], "ht_capab") and true or false +local hwtype = wdev:get("type") +local htcaps = wdev:get("ht_capab") and true or false -- NanoFoo -local nsantenna = m:get(arg[1], "antenna") +local nsantenna = wdev:get("antenna") ch = s:taboption("general", Value, "channel", translate("Channel")) ch:value("auto", translate("auto")) @@ -105,7 +108,7 @@ if hwtype == "mac80211" then "txpower", translate("Transmit Power"), "dBm") tp.rmempty = true - tp.default = tostring(iw and iw.txpower or tx_powers[#tx_powers]) + tp.default = tx_power for _, p in ipairs(tx_powers or {}) do tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw }) end @@ -156,7 +159,8 @@ if hwtype == "atheros" then "txpower", translate("Transmit Power"), "dBm") tp.rmempty = true - for _, p in ipairs(iw.txpwrlist) do + tp.default = tx_power + for _, p in ipairs(tx_powers or {}) do tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw }) end @@ -216,7 +220,8 @@ if hwtype == "broadcom" then "txpower", translate("Transmit Power"), "dBm") tp.rmempty = true - for _, p in ipairs(iw.txpwrlist) do + tp.default = tx_power + for _, p in ipairs(tx_powers or {}) do tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw }) end @@ -226,14 +231,6 @@ if hwtype == "broadcom" then mode:value("11g", "802.11g") mode:value("11gst", "802.11g + Turbo") - mp = s:taboption("macfilter", ListValue, "macfilter", translate("MAC-Address Filter")) - mp:value("", translate("disable")) - mp:value("allow", translate("Allow listed only")) - mp:value("deny", translate("Allow all except listed")) - ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List")) - ml:depends({macfilter="allow"}) - ml:depends({macfilter="deny"}) - ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna")) ant1.widget = "radio" ant1:depends("diversity", "") @@ -276,7 +273,7 @@ s = m:section(NamedSection, wnet.sid, "wifi-iface", translate("Interface Configu ifsection = s s.addremove = false s.anonymous = true -s.defaults.device = arg[1] +s.defaults.device = wdev:name() s:tab("general", translate("General Setup")) s:tab("encryption", translate("Wireless Security")) @@ -317,7 +314,7 @@ function network.write(self, section, value) else local n = nw:get_network(value) if n then - n:type("bridge") + n:set("type", "bridge") n:add_interface(i) end end @@ -337,6 +334,16 @@ if hwtype == "mac80211" then s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold")) s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold")) + + mp = s:taboption("macfilter", ListValue, "macfilter", translate("MAC-Address Filter")) + mp:value("", translate("disable")) + mp:value("allow", translate("Allow listed only")) + mp:value("deny", translate("Allow all except listed")) + + ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List")) + ml.datatype = "macaddr" + ml:depends({macfilter="allow"}) + ml:depends({macfilter="deny"}) mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")}) mode:value("sta-wds", "%s (%s)" % {translate("Client"), translate("WDS")}) @@ -429,9 +436,11 @@ if hwtype == "atheros" then mp = s:taboption("macfilter", ListValue, "macpolicy", translate("MAC-Address Filter")) mp:value("", translate("disable")) - mp:value("deny", translate("Allow listed only")) - mp:value("allow", translate("Allow all except listed")) + mp:value("allow", translate("Allow listed only")) + mp:value("deny", translate("Allow all except listed")) + ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List")) + ml.datatype = "macaddr" ml:depends({macpolicy="allow"}) ml:depends({macpolicy="deny"}) @@ -502,8 +511,8 @@ if hwtype == "prism2" then mp = s:taboption("macfilter", ListValue, "macpolicy", translate("MAC-Address Filter")) mp:value("", translate("disable")) - mp:value("deny", translate("Allow listed only")) - mp:value("allow", translate("Allow all except listed")) + mp:value("allow", translate("Allow listed only")) + mp:value("deny", translate("Allow all except listed")) ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List")) ml:depends({macpolicy="allow"}) ml:depends({macpolicy="deny"}) @@ -540,7 +549,7 @@ if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then encr:value("psk2", "WPA2-PSK") encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode") encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}) - encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"}) + encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}) elseif hostapd and not supplicant then encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="ap-wds"}, {mode="adhoc"}, {mode="ahdemo"}) encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="ap-wds"}, {mode="adhoc"}, {mode="ahdemo"}) @@ -593,19 +602,70 @@ port:depends({mode="ap-wds", encryption="wpa"}) port:depends({mode="ap-wds", encryption="wpa2"}) port.rmempty = true -key = s:taboption("encryption", Value, "key", translate("Key")) -key:depends("encryption", "wep-open") -key:depends("encryption", "wep-shared") -key:depends("encryption", "psk") -key:depends("encryption", "psk2") -key:depends("encryption", "psk+psk2") -key:depends("encryption", "psk-mixed") -key:depends({mode="ap", encryption="wpa"}) -key:depends({mode="ap", encryption="wpa2"}) -key:depends({mode="ap-wds", encryption="wpa"}) -key:depends({mode="ap-wds", encryption="wpa2"}) -key.rmempty = true -key.password = true +wpakey = s:taboption("encryption", Value, "_wpa_key", translate("Key")) +wpakey:depends("encryption", "psk") +wpakey:depends("encryption", "psk2") +wpakey:depends("encryption", "psk+psk2") +wpakey:depends("encryption", "psk-mixed") +wpakey:depends({mode="ap", encryption="wpa"}) +wpakey:depends({mode="ap", encryption="wpa2"}) +wpakey:depends({mode="ap-wds", encryption="wpa"}) +wpakey:depends({mode="ap-wds", encryption="wpa2"}) +wpakey.datatype = "wpakey" +wpakey.rmempty = true +wpakey.password = true + +wpakey.cfgvalue = function(self, section, value) + local key = m.uci:get("wireless", section, "key") + if key == "1" or key == "2" or key == "3" or key == "4" then + return nil + end + return key +end + +wpakey.write = function(self, section, value) + self.map.uci:set("wireless", section, "key", value) + self.map.uci:delete("wireless", section, "key1") +end + + +wepslot = s:taboption("encryption", ListValue, "_wep_key", translate("Used Key Slot")) +wepslot:depends("encryption", "wep-open") +wepslot:depends("encryption", "wep-shared") +wepslot:value("1", translatef("Key #%d", 1)) +wepslot:value("2", translatef("Key #%d", 2)) +wepslot:value("3", translatef("Key #%d", 3)) +wepslot:value("4", translatef("Key #%d", 4)) + +wepslot.cfgvalue = function(self, section) + local slot = tonumber(m.uci:get("wireless", section, "key")) + if not slot or slot < 1 or slot > 4 then + return 1 + end + return slot +end + +wepslot.write = function(self, section, value) + self.map.uci:set("wireless", section, "key", value) +end + +local slot +for slot=1,4 do + wepkey = s:taboption("encryption", Value, "key" .. slot, translatef("Key #%d", slot)) + wepkey:depends("encryption", "wep-open") + wepkey:depends("encryption", "wep-shared") + wepkey.datatype = "wepkey" + wepkey.rmempty = true + wepkey.password = true + + function wepkey.write(self, section, value) + if value and (#value == 5 or #value == 13) then + value = "s:" .. value + end + return Value.write(self, section, value) + end +end + if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then nasid = s:taboption("encryption", Value, "nasid", translate("NAS ID")) @@ -621,18 +681,26 @@ if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then eaptype:value("peap", "PEAP") eaptype:depends({mode="sta", encryption="wpa"}) eaptype:depends({mode="sta", encryption="wpa2"}) + eaptype:depends({mode="sta-wds", encryption="wpa"}) + eaptype:depends({mode="sta-wds", encryption="wpa2"}) cacert = s:taboption("encryption", FileUpload, "ca_cert", translate("Path to CA-Certificate")) cacert:depends({mode="sta", encryption="wpa"}) cacert:depends({mode="sta", encryption="wpa2"}) + cacert:depends({mode="sta-wds", encryption="wpa"}) + cacert:depends({mode="sta-wds", encryption="wpa2"}) privkey = s:taboption("encryption", FileUpload, "priv_key", translate("Path to Private Key")) privkey:depends({mode="sta", eap_type="tls", encryption="wpa2"}) privkey:depends({mode="sta", eap_type="tls", encryption="wpa"}) + privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"}) + privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa"}) privkeypwd = s:taboption("encryption", Value, "priv_key_pwd", translate("Password of Private Key")) privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa2"}) privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa"}) + privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"}) + privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa"}) auth = s:taboption("encryption", Value, "auth", translate("Authentication")) @@ -644,6 +712,10 @@ if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then auth:depends({mode="sta", eap_type="peap", encryption="wpa"}) auth:depends({mode="sta", eap_type="ttls", encryption="wpa2"}) auth:depends({mode="sta", eap_type="ttls", encryption="wpa"}) + auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"}) + auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa"}) + auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"}) + auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"}) identity = s:taboption("encryption", Value, "identity", translate("Identity")) @@ -651,12 +723,20 @@ if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then identity:depends({mode="sta", eap_type="peap", encryption="wpa"}) identity:depends({mode="sta", eap_type="ttls", encryption="wpa2"}) identity:depends({mode="sta", eap_type="ttls", encryption="wpa"}) + identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"}) + identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa"}) + identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"}) + identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"}) password = s:taboption("encryption", Value, "password", translate("Password")) password:depends({mode="sta", eap_type="peap", encryption="wpa2"}) password:depends({mode="sta", eap_type="peap", encryption="wpa"}) password:depends({mode="sta", eap_type="ttls", encryption="wpa2"}) password:depends({mode="sta", eap_type="ttls", encryption="wpa"}) + password:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"}) + password:depends({mode="sta-wds", eap_type="peap", encryption="wpa"}) + password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"}) + password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"}) end return m