luci-app-travelmate: bugfixes
[project/luci.git] / applications / luci-app-travelmate / luasrc / model / cbi / travelmate / wifi_add.lua
index 3186947..f1adae2 100644 (file)
@@ -1,10 +1,12 @@
--- Copyright 2017 Dirk Brenken (dev@brenken.org)
+-- Copyright 2017-2018 Dirk Brenken (dev@brenken.org)
 -- This is free software, licensed under the Apache License, Version 2.0
 
 local fs       = require("nixio.fs")
 local uci      = require("luci.model.uci").cursor()
 local http     = require("luci.http")
-local trmiface = uci.get("travelmate", "global", "trm_iface") or "trm_wwan"
+local trmiface = uci:get("travelmate", "global", "trm_iface") or "trm_wwan"
+local encr_psk = {"psk", "psk2", "psk-mixed"}
+local encr_wpa = {"wpa", "wpa2", "wpa-mixed"}
 
 m = SimpleForm("add", translate("Add Wireless Uplink Configuration"))
 m.submit = translate("Save")
@@ -24,17 +26,22 @@ m.hidden = {
        wpa_version = http.formvalue("wpa_version")
 }
 
-if m.hidden.ssid ~= "" then
-       wssid = m:field(Value, "ssid", translate("SSID"))
-       wssid.datatype = "rangelength(1,32)"
-       wssid.default = m.hidden.ssid or ""
-else
+if m.hidden.ssid == "" then
        wssid = m:field(Value, "ssid", translate("SSID (hidden)"))
+else
+       wssid = m:field(Value, "ssid", translate("SSID"))
 end
+wssid.datatype = "rangelength(1,32)"
+wssid.default = m.hidden.ssid or ""
 
-bssid = m:field(Value, "bssid", translate("BSSID"))
+bssid = m:field(Value, "bssid", translate("BSSID"),
+       translatef("The BSSID information '%s' is optional and only required for hidden networks", m.hidden.bssid or ""))
 bssid.datatype = "macaddr"
-bssid.default = m.hidden.bssid or ""
+if m.hidden.ssid == "" then
+       bssid.default = m.hidden.bssid or ""
+else
+       bssid.default = ""
+end
 
 if (tonumber(m.hidden.wep) or 0) == 1 then
        encr = m:field(ListValue, "encryption", translate("Encryption"))
@@ -53,7 +60,7 @@ elseif (tonumber(m.hidden.wpa_version) or 0) > 0 then
                encr:value("psk", "WPA PSK")
                encr:value("psk-mixed", "WPA/WPA2 mixed")
                encr:value("psk2", "WPA2 PSK")
-               encr.default = "psk2"
+               encr.default = encr_psk[tonumber(m.hidden.wpa_version)] or "psk2"
 
                ciph = m:field(ListValue, "cipher", translate("Cipher"))
                ciph:value("auto", translate("Automatic"))
@@ -70,7 +77,7 @@ elseif (tonumber(m.hidden.wpa_version) or 0) > 0 then
                encr:value("wpa", "WPA Enterprise")
                encr:value("wpa-mixed", "WPA/WPA2 Enterprise mixed")
                encr:value("wpa2", "WPA2 Enterprise")
-               encr.default = "wpa2"
+               encr.default = encr_wpa[tonumber(m.hidden.wpa_version)] or "wpa2"
 
                ciph = m:field(ListValue, "cipher", translate("Cipher"))
                ciph:value("auto", translate("Automatic"))
@@ -95,6 +102,8 @@ elseif (tonumber(m.hidden.wpa_version) or 0) > 0 then
                authentication:value("EAP-MD5")
                authentication:value("EAP-MSCHAPV2")
                authentication:value("EAP-TLS")
+               authentication:value("auth=PAP")
+               authentication:value("auth=MSCHAPV2")
                authentication.default = "EAP-MSCHAPV2"
 
                ident = m:field(Value, "identity", translate("Identity"))
@@ -131,7 +140,7 @@ function wssid.write(self, section, value)
                bssid    = bssid:formvalue(section),
                disabled = "1"
        })
-       
+
        if (tonumber(m.hidden.wep) or 0) == 1 then
                uci:set("wireless", newsection, "encryption", encr:formvalue(section))
                uci:set("wireless", newsection, "key", wkey:formvalue(section) or "")
@@ -163,6 +172,7 @@ function wssid.write(self, section, value)
        end
        uci:save("wireless")
        uci:commit("wireless")
+       luci.sys.call("env -i /bin/ubus call network reload >/dev/null 2>&1")
        http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))
 end