luci-mod-admin-full: do not override iface section in wireless cbi map
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_network / wifi.lua
index 094b415..cacaa25 100644 (file)
@@ -7,6 +7,17 @@ local ut = require "luci.util"
 local nt = require "luci.sys".net
 local fs = require "nixio.fs"
 
+local acct_port, acct_secret, acct_server, anonymous_identity, ant1, ant2,
+       auth, auth_port, auth_secret, auth_server, bssid, cacert, cacert2,
+       cc, ch, cipher, clientcert, clientcert2, ea, eaptype, en, encr,
+       ft_protocol, ft_psk_generate_local, hidden, htmode, identity,
+       ieee80211r, ieee80211w, ifname, isolate, key_retries,
+       legacyrates, max_timeout, meshfwd, meshid, ml, mobility_domain, mode,
+       mp, nasid, network, password, pmk_r1_push, privkey, privkey2, privkeypwd,
+       privkeypwd2, r0_key_lifetime, r0kh, r1_key_holder, r1kh,
+       reassociation_deadline, retry_timeout, ssid, st, tp, wepkey, wepslot,
+       wmm, wpakey, wps
+
 arg[1] = arg[1] or ""
 
 m = Map("wireless", "",
@@ -19,16 +30,6 @@ m:chain("network")
 m:chain("firewall")
 m.redirect = luci.dispatcher.build_url("admin/network/wireless")
 
-local ifsection
-
-function m.on_commit(map)
-       local wnet = nw:get_wifinet(arg[1])
-       if ifsection and wnet then
-               ifsection.section = wnet.sid
-               m.title = luci.util.pcdata(wnet:get_i18n())
-       end
-end
-
 nw.init(m.uci)
 
 local wnet = nw:get_wifinet(arg[1])
@@ -40,38 +41,6 @@ if not wnet or not wdev then
        return
 end
 
--- wireless toggle was requested, commit and reload page
-function m.parse(map)
-       local new_cc = m:formvalue("cbid.wireless.%s.country" % wdev:name())
-       local old_cc = m:get(wdev:name(), "country")
-
-       if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then
-               if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
-                       wnet:set("disabled", nil)
-               else
-                       wnet:set("disabled", "1")
-               end
-               wdev:set("disabled", nil)
-
-               nw:commit("wireless")
-               luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null")
-
-               luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1]))
-               return
-       end
-
-       Map.parse(map)
-
-       if m:get(wdev:name(), "type") == "mac80211" and new_cc and new_cc ~= old_cc then
-               luci.sys.call("iw reg set %q" % new_cc)
-               luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1]))
-               return
-       end
-end
-
-m.title = luci.util.pcdata(wnet:get_i18n())
-
-
 local function txpower_list(iw)
        local list = iw.txpwrlist or { }
        local off  = tonumber(iw.txpower_offset) or 0
@@ -112,6 +81,57 @@ local hw_modes      = iw.hwmodelist or { }
 local tx_power_list = txpower_list(iw)
 local tx_power_cur  = txpower_current(wdev:get("txpower"), tx_power_list)
 
+-- wireless toggle was requested, commit and reload page
+function m.parse(map)
+       local new_cc = m:formvalue("cbid.wireless.%s.country" % wdev:name())
+       local old_cc = m:get(wdev:name(), "country")
+
+       if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then
+               if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
+                       wnet:set("disabled", nil)
+               else
+                       wnet:set("disabled", "1")
+               end
+               wdev:set("disabled", nil)
+               m.apply_needed = true
+               m.redirect = nil
+       end
+
+       Map.parse(map)
+
+       if m:get(wdev:name(), "type") == "mac80211" and new_cc and new_cc ~= old_cc then
+               luci.sys.call("iw reg set %s" % ut.shellquote(new_cc))
+
+               local old_ch = tonumber(m:formvalue("cbid.wireless.%s._mode_freq.channel" % wdev:name()) or "")
+               if old_ch then
+                       local _, c, new_ch
+                       for _, c in ipairs(iw.freqlist) do
+                               if c.channel > old_ch or (old_ch <= 14 and c.channel > 14) then
+                                       break
+                               end
+                               new_ch = c.channel
+                       end
+                       if new_ch ~= old_ch then
+                               wdev:set("channel", new_ch)
+                               m.message = translatef("Channel %d is not available in the %s regulatory domain and has been auto-adjusted to %d.",
+                                       old_ch, new_cc, new_ch)
+                       end
+               end
+       end
+
+       if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
+               en.title      = translate("Wireless network is disabled")
+               en.inputtitle = translate("Enable")
+               en.inputstyle = "apply"
+       else
+               en.title      = translate("Wireless network is enabled")
+               en.inputtitle = translate("Disable")
+               en.inputstyle = "reset"
+       end
+end
+
+m.title = luci.util.pcdata(wnet:get_i18n())
+
 s = m:section(NamedSection, wdev:name(), "wifi-device", translate("Device Configuration"))
 s.addremove = false
 
@@ -119,29 +139,12 @@ s:tab("general", translate("General Setup"))
 s:tab("macfilter", translate("MAC-Filter"))
 s:tab("advanced", translate("Advanced Settings"))
 
---[[
-back = s:option(DummyValue, "_overview", translate("Overview"))
-back.value = ""
-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[1]
 
 en = s:taboption("general", Button, "__toggle")
 
-if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
-       en.title      = translate("Wireless network is disabled")
-       en.inputtitle = translate("Enable")
-       en.inputstyle = "apply"
-else
-       en.title      = translate("Wireless network is enabled")
-       en.inputtitle = translate("Disable")
-       en.inputstyle = "reset"
-end
-
-
 local hwtype = wdev:get("type")
 
 -- NanoFoo
@@ -170,9 +173,7 @@ if found_sta then
                found_sta.channel or "(auto)", table.concat(found_sta.names, ", "))
 else
        ch = s:taboption("general", Value, "_mode_freq", '<br />'..translate("Operating frequency"))
-       ch.hwmodes = hw_modes
-       ch.htmodes = iw.htmodelist
-       ch.freqlist = iw.freqlist
+       ch.iwinfo = iw
        ch.template = "cbi/wireless_modefreq"
 
        function ch.cfgvalue(self, section)
@@ -228,7 +229,7 @@ if hwtype == "mac80211" then
                s:taboption("advanced", Value, "country", translate("Country Code"), translate("Use ISO/IEC 3166 alpha2 country codes."))
        end
 
-       legacyrates = s:taboption("advanced", Flag, "legacy_rates", translate("802.11b rates"))
+       legacyrates = s:taboption("advanced", Flag, "legacy_rates", translate("Allow legacy 802.11b rates"))
        legacyrates.rmempty = false
        legacyrates.default = "1"
 
@@ -341,7 +342,6 @@ end
 ----------------------- Interface -----------------------
 
 s = m:section(NamedSection, wnet.sid, "wifi-iface", translate("Interface Configuration"))
-ifsection = s
 s.addremove = false
 s.anonymous = true
 s.defaults.device = wdev:name()
@@ -360,7 +360,7 @@ mode:value("adhoc", translate("Ad-Hoc"))
 meshid = s:taboption("general", Value, "mesh_id", translate("Mesh Id"))
 meshid:depends({mode="mesh"})
 
-meshfwd = s:taboption("advanced", Flag, "mesh_fwding", translate("internal forwarding of Mesh-peers"))
+meshfwd = s:taboption("advanced", Flag, "mesh_fwding", translate("Forward mesh peer traffic"))
 meshfwd.rmempty = false
 meshfwd.default = "1"
 meshfwd:depends({mode="mesh"})
@@ -1049,7 +1049,7 @@ if hwtype == "mac80211" then
                retry_timeout.rmempty = true
        end
 
-       local key_retries = s:taboption("encryption", Flag, "wpa_disable_eapol_key_retries",
+       key_retries = s:taboption("encryption", Flag, "wpa_disable_eapol_key_retries",
                translate("Enable key reinstallation (KRACK) countermeasures"),
                translate("Complicates key reinstallation attacks on the client side by disabling retransmission of EAPOL-Key frames that are used to install keys. This workaround might cause interoperability issues and reduced robustness of key negotiation especially in environments with heavy traffic load."))