2019-08-06 09:42:04 +00:00
|
|
|
-- Copyright 2017-2019 Dirk Brenken (dev@brenken.org)
|
2017-07-19 20:36:47 +00:00
|
|
|
-- This is free software, licensed under the Apache License, Version 2.0
|
|
|
|
|
2017-12-06 16:05:40 +00:00
|
|
|
local fs = require("nixio.fs")
|
|
|
|
local uci = require("luci.model.uci").cursor()
|
|
|
|
local http = require("luci.http")
|
2019-08-06 09:42:04 +00:00
|
|
|
local util = require("luci.util")
|
|
|
|
local scripts = util.split(util.trim(util.exec("ls /etc/travelmate/*.login 2>/dev/null")), "\n", nil, true) or {}
|
2018-03-15 14:38:17 +00:00
|
|
|
local trmiface = uci:get("travelmate", "global", "trm_iface") or "trm_wwan"
|
2019-10-18 10:44:54 +00:00
|
|
|
local encr_psk = {"psk", "psk2", "psk-mixed", "sae", "owe", "sae-mixed"}
|
2017-12-15 18:17:07 +00:00
|
|
|
local encr_wpa = {"wpa", "wpa2", "wpa-mixed"}
|
2017-07-19 20:36:47 +00:00
|
|
|
|
|
|
|
m = SimpleForm("add", translate("Add Wireless Uplink Configuration"))
|
2017-08-05 16:57:20 +00:00
|
|
|
m.submit = translate("Save")
|
2017-07-19 20:36:47 +00:00
|
|
|
m.cancel = translate("Back to overview")
|
|
|
|
m.reset = false
|
|
|
|
|
|
|
|
function m.on_cancel()
|
|
|
|
http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))
|
|
|
|
end
|
|
|
|
|
|
|
|
m.hidden = {
|
|
|
|
device = http.formvalue("device"),
|
|
|
|
ssid = http.formvalue("ssid"),
|
2017-12-06 16:05:40 +00:00
|
|
|
bssid = http.formvalue("bssid"),
|
2019-10-18 10:44:54 +00:00
|
|
|
description = http.formvalue("description"),
|
|
|
|
wep = tonumber(http.formvalue("wep")) or 0,
|
2017-08-03 15:04:58 +00:00
|
|
|
wpa_suites = http.formvalue("wpa_suites"),
|
2019-10-18 10:44:54 +00:00
|
|
|
wpa_version = tonumber(http.formvalue("wpa_version")) or 0
|
2017-07-19 20:36:47 +00:00
|
|
|
}
|
|
|
|
|
2019-10-18 10:44:54 +00:00
|
|
|
if m.hidden.wpa_version == 4 then
|
|
|
|
if string.find(m.hidden.description, "OWE") then
|
|
|
|
m.hidden.wpa_version = 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-28 07:22:19 +00:00
|
|
|
if m.hidden.ssid == "" then
|
|
|
|
wssid = m:field(Value, "ssid", translate("SSID (hidden)"))
|
|
|
|
else
|
2017-07-24 13:30:01 +00:00
|
|
|
wssid = m:field(Value, "ssid", translate("SSID"))
|
|
|
|
end
|
2018-04-05 20:39:46 +00:00
|
|
|
wssid.datatype = "rangelength(1,32)"
|
|
|
|
wssid.default = m.hidden.ssid or ""
|
2017-07-19 20:36:47 +00:00
|
|
|
|
2018-04-06 16:34:41 +00:00
|
|
|
nobssid = m:field(Flag, "no_bssid", translate("Ignore BSSID"))
|
2018-03-28 07:22:19 +00:00
|
|
|
if m.hidden.ssid == "" then
|
2018-04-06 16:34:41 +00:00
|
|
|
nobssid.default = nobssid.disabled
|
2018-03-28 07:22:19 +00:00
|
|
|
else
|
2018-04-06 16:34:41 +00:00
|
|
|
nobssid.default = nobssid.enabled
|
2018-03-28 07:22:19 +00:00
|
|
|
end
|
2018-01-03 08:19:46 +00:00
|
|
|
|
2018-04-06 16:34:41 +00:00
|
|
|
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:depends("no_bssid", 0)
|
|
|
|
bssid.datatype = "macaddr"
|
|
|
|
bssid.default = m.hidden.bssid or ""
|
|
|
|
|
2019-10-18 10:44:54 +00:00
|
|
|
if m.hidden.wep == 1 then
|
2017-12-13 19:21:57 +00:00
|
|
|
encr = m:field(ListValue, "encryption", translate("Encryption"))
|
|
|
|
encr:value("wep", "WEP")
|
|
|
|
encr:value("wep+open", "WEP Open System")
|
|
|
|
encr:value("wep+mixed", "WEP mixed")
|
|
|
|
encr:value("wep+shared", "WEP Shared Key")
|
|
|
|
encr.default = "wep+open"
|
|
|
|
|
|
|
|
wkey = m:field(Value, "key", translate("WEP-Passphrase"))
|
2017-07-19 20:36:47 +00:00
|
|
|
wkey.password = true
|
|
|
|
wkey.datatype = "wepkey"
|
2019-10-18 10:44:54 +00:00
|
|
|
elseif m.hidden.wpa_version > 0 then
|
|
|
|
if m.hidden.wpa_suites == "802.1X" then
|
2017-12-13 19:21:57 +00:00
|
|
|
encr = m:field(ListValue, "encryption", translate("Encryption"))
|
|
|
|
encr:value("wpa", "WPA Enterprise")
|
|
|
|
encr:value("wpa-mixed", "WPA/WPA2 Enterprise mixed")
|
|
|
|
encr:value("wpa2", "WPA2 Enterprise")
|
2019-10-18 10:44:54 +00:00
|
|
|
encr.default = encr_wpa[m.hidden.wpa_version] or "wpa2"
|
2017-12-13 19:21:57 +00:00
|
|
|
|
|
|
|
ciph = m:field(ListValue, "cipher", translate("Cipher"))
|
|
|
|
ciph:value("auto", translate("Automatic"))
|
|
|
|
ciph:value("ccmp", translate("Force CCMP (AES)"))
|
|
|
|
ciph:value("tkip", translate("Force TKIP"))
|
|
|
|
ciph:value("tkip+ccmp", translate("Force TKIP and CCMP (AES)"))
|
|
|
|
ciph.default = "auto"
|
|
|
|
|
2017-12-06 16:05:40 +00:00
|
|
|
eaptype = m:field(ListValue, "eap_type", translate("EAP-Method"))
|
2017-12-13 19:21:57 +00:00
|
|
|
eaptype:value("tls", "TLS")
|
|
|
|
eaptype:value("ttls", "TTLS")
|
|
|
|
eaptype:value("peap", "PEAP")
|
|
|
|
eaptype:value("fast", "FAST")
|
|
|
|
eaptype.default = "peap"
|
2017-12-06 16:05:40 +00:00
|
|
|
|
|
|
|
authentication = m:field(ListValue, "auth", translate("Authentication"))
|
|
|
|
authentication:value("PAP")
|
|
|
|
authentication:value("CHAP")
|
|
|
|
authentication:value("MSCHAP")
|
|
|
|
authentication:value("MSCHAPV2")
|
2017-12-13 19:21:57 +00:00
|
|
|
authentication:value("EAP-GTC")
|
|
|
|
authentication:value("EAP-MD5")
|
|
|
|
authentication:value("EAP-MSCHAPV2")
|
|
|
|
authentication:value("EAP-TLS")
|
2018-01-10 18:48:01 +00:00
|
|
|
authentication:value("auth=PAP")
|
|
|
|
authentication:value("auth=MSCHAPV2")
|
2017-12-13 19:21:57 +00:00
|
|
|
authentication.default = "EAP-MSCHAPV2"
|
2017-12-06 16:05:40 +00:00
|
|
|
|
|
|
|
ident = m:field(Value, "identity", translate("Identity"))
|
|
|
|
|
2017-12-13 19:21:57 +00:00
|
|
|
wkey = m:field(Value, "password", translate("Password"))
|
|
|
|
wkey.password = true
|
|
|
|
wkey.datatype = "wpakey"
|
|
|
|
|
|
|
|
cacert = m:field(Value, "ca_cert", translate("Path to CA-Certificate"))
|
|
|
|
cacert.rmempty = true
|
|
|
|
|
|
|
|
clientcert = m:field(Value, "client_cert", translate("Path to Client-Certificate"))
|
|
|
|
clientcert:depends("eap_type","tls")
|
|
|
|
clientcert.rmempty = true
|
|
|
|
|
|
|
|
privkey = m:field(Value, "priv_key", translate("Path to Private Key"))
|
|
|
|
privkey:depends("eap_type","tls")
|
|
|
|
privkey.rmempty = true
|
|
|
|
|
|
|
|
privkeypwd = m:field(Value, "priv_key_pwd", translate("Password of Private Key"))
|
|
|
|
privkeypwd:depends("eap_type","tls")
|
|
|
|
privkeypwd.datatype = "wpakey"
|
|
|
|
privkeypwd.password = true
|
|
|
|
privkeypwd.rmempty = true
|
2019-10-18 10:44:54 +00:00
|
|
|
else
|
|
|
|
encr = m:field(ListValue, "encryption", translate("Encryption"))
|
|
|
|
encr:value("psk", "WPA-PSK")
|
|
|
|
encr:value("psk2", "WPA2-PSK")
|
|
|
|
encr:value("psk-mixed", "WPA/WPA2 mixed")
|
|
|
|
encr:value("sae", "WPA3-SAE")
|
|
|
|
encr:value("owe", "OWE (open network)")
|
|
|
|
encr:value("sae-mixed", "WPA2/WPA3 mixed")
|
|
|
|
encr.default = encr_psk[m.hidden.wpa_version] or "psk2"
|
|
|
|
|
|
|
|
ciph = m:field(ListValue, "cipher", translate("Cipher"))
|
|
|
|
ciph:value("auto", translate("Automatic"))
|
|
|
|
ciph:value("ccmp", translate("Force CCMP (AES)"))
|
|
|
|
ciph:value("tkip", translate("Force TKIP"))
|
|
|
|
ciph:value("tkip+ccmp", translate("Force TKIP and CCMP (AES)"))
|
|
|
|
ciph:depends("encryption", "psk")
|
|
|
|
ciph:depends("encryption", "psk2")
|
|
|
|
ciph:depends("encryption", "psk-mixed")
|
|
|
|
ciph.default = "auto"
|
|
|
|
|
|
|
|
wkey = m:field(Value, "key", translate("WPA-Passphrase"))
|
|
|
|
wkey.password = true
|
|
|
|
wkey.datatype = "wpakey"
|
|
|
|
wkey:depends("encryption", "psk")
|
|
|
|
wkey:depends("encryption", "psk2")
|
|
|
|
wkey:depends("encryption", "psk-mixed")
|
|
|
|
wkey:depends("encryption", "sae")
|
|
|
|
wkey:depends("encryption", "sae-mixed")
|
2017-12-06 16:05:40 +00:00
|
|
|
end
|
2017-07-19 20:36:47 +00:00
|
|
|
end
|
|
|
|
|
2019-10-21 18:43:27 +00:00
|
|
|
local login_section = (m.hidden.device or "") .. "_" .. (m.hidden.ssid or "") .. "_" .. (m.hidden.bssid or "")
|
2019-08-29 10:02:04 +00:00
|
|
|
login_section = login_section:gsub("[^%w_]", "_")
|
2019-08-06 09:42:04 +00:00
|
|
|
local cmd = uci:get("travelmate", login_section, "command")
|
2019-09-19 21:28:39 +00:00
|
|
|
local cmd_args_default = uci:get("travelmate", login_section, "command_args")
|
2019-08-06 09:42:04 +00:00
|
|
|
cmd_list = m:field(ListValue, "cmdlist", translate("Auto Login Script"),
|
|
|
|
translate("External script reference which will be called for automated captive portal logins."))
|
2019-09-19 21:28:39 +00:00
|
|
|
cmd_args = m:field(Value, "cmdargs", translate("Optional Arguments"),
|
2019-10-18 10:44:54 +00:00
|
|
|
translate("Space separated list of additional arguments passed to the Auto Login Script, i.e. username and password"))
|
2019-08-06 09:42:04 +00:00
|
|
|
for _, z in ipairs(scripts) do
|
|
|
|
cmd_list:value(z)
|
2019-09-19 21:28:39 +00:00
|
|
|
cmd_args:depends("cmdlist", z)
|
2019-08-06 09:42:04 +00:00
|
|
|
end
|
2019-09-19 21:28:39 +00:00
|
|
|
cmd_list:value("none")
|
2019-08-06 09:42:04 +00:00
|
|
|
cmd_list.default = cmd or "none"
|
2019-09-19 21:28:39 +00:00
|
|
|
cmd_args.default = cmd_args_default
|
2019-08-06 09:42:04 +00:00
|
|
|
|
2017-07-19 20:36:47 +00:00
|
|
|
function wssid.write(self, section, value)
|
2019-10-23 08:42:38 +00:00
|
|
|
login_section = (m.hidden.device or "") .. "_" .. (wssid:formvalue(section) or "") .. "_" .. (bssid:formvalue(section) or "")
|
|
|
|
login_section = login_section:gsub("[^%w_]", "_")
|
2019-10-21 18:43:27 +00:00
|
|
|
newsection = uci:section("wireless", "wifi-iface", login_section, {
|
2017-08-03 15:04:58 +00:00
|
|
|
mode = "sta",
|
|
|
|
network = trmiface,
|
|
|
|
device = m.hidden.device,
|
|
|
|
ssid = wssid:formvalue(section),
|
2017-12-06 16:05:40 +00:00
|
|
|
bssid = bssid:formvalue(section),
|
2017-08-03 15:04:58 +00:00
|
|
|
disabled = "1"
|
2017-07-19 20:36:47 +00:00
|
|
|
})
|
2017-12-15 18:17:07 +00:00
|
|
|
|
2019-10-21 18:43:27 +00:00
|
|
|
if encr then
|
2019-10-18 10:44:54 +00:00
|
|
|
if string.find(encr:formvalue(section), '^wep') then
|
|
|
|
uci:set("wireless", newsection, "encryption", encr:formvalue(section))
|
2017-12-13 19:21:57 +00:00
|
|
|
uci:set("wireless", newsection, "key", wkey:formvalue(section) or "")
|
2019-10-18 10:44:54 +00:00
|
|
|
elseif string.find(encr:formvalue(section), '^wpa') then
|
2017-12-06 16:05:40 +00:00
|
|
|
uci:set("wireless", newsection, "eap_type", eaptype:formvalue(section))
|
|
|
|
uci:set("wireless", newsection, "auth", authentication:formvalue(section))
|
2017-12-13 19:21:57 +00:00
|
|
|
uci:set("wireless", newsection, "identity", ident:formvalue(section) or "")
|
|
|
|
uci:set("wireless", newsection, "password", wkey:formvalue(section) or "")
|
|
|
|
uci:set("wireless", newsection, "ca_cert", cacert:formvalue(section) or "")
|
|
|
|
uci:set("wireless", newsection, "client_cert", clientcert:formvalue(section) or "")
|
|
|
|
uci:set("wireless", newsection, "priv_key", privkey:formvalue(section) or "")
|
|
|
|
uci:set("wireless", newsection, "priv_key_pwd", privkeypwd:formvalue(section) or "")
|
2019-10-18 10:44:54 +00:00
|
|
|
elseif encr:formvalue(section) ~= "owe" then
|
|
|
|
uci:set("wireless", newsection, "key", wkey:formvalue(section) or "")
|
|
|
|
end
|
2019-10-21 18:43:27 +00:00
|
|
|
if ciph and ciph:formvalue(section) ~= "auto" then
|
2019-10-18 10:44:54 +00:00
|
|
|
uci:set("wireless", newsection, "encryption", encr:formvalue(section) .. "+" .. ciph:formvalue(section))
|
|
|
|
else
|
|
|
|
uci:set("wireless", newsection, "encryption", encr:formvalue(section))
|
2017-12-06 16:05:40 +00:00
|
|
|
end
|
2017-07-19 20:36:47 +00:00
|
|
|
else
|
|
|
|
uci:set("wireless", newsection, "encryption", "none")
|
|
|
|
end
|
2019-10-18 10:44:54 +00:00
|
|
|
|
2019-08-06 09:42:04 +00:00
|
|
|
if not uci:get("travelmate", login_section) and cmd_list:formvalue(section) ~= "none" then
|
|
|
|
uci:set("travelmate", login_section, "login")
|
|
|
|
end
|
|
|
|
if uci:get("travelmate", login_section) then
|
|
|
|
uci:set("travelmate", login_section, "command", cmd_list:formvalue(section))
|
2019-09-19 21:28:39 +00:00
|
|
|
uci:set("travelmate", login_section, "command_args", cmd_args:formvalue(section))
|
2019-08-06 09:42:04 +00:00
|
|
|
uci:save("travelmate")
|
|
|
|
uci:commit("travelmate")
|
|
|
|
end
|
2017-07-19 20:36:47 +00:00
|
|
|
uci:save("wireless")
|
|
|
|
uci:commit("wireless")
|
2018-04-04 12:19:23 +00:00
|
|
|
luci.sys.call("env -i /bin/ubus call network reload >/dev/null 2>&1")
|
2017-07-19 20:36:47 +00:00
|
|
|
http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))
|
|
|
|
end
|
|
|
|
|
|
|
|
return m
|