1 -- Copyright 2017 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
4 local fs = require("nixio.fs")
5 local uci = require("luci.model.uci").cursor()
6 local http = require("luci.http")
7 local trmiface = uci.get("travelmate", "global", "trm_iface") or "trm_wwan"
10 m = SimpleForm("add", translate("Add Wireless Uplink Configuration"))
11 m.submit = translate("Save")
12 m.cancel = translate("Back to overview")
15 function m.on_cancel()
16 http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))
20 device = http.formvalue("device"),
21 ssid = http.formvalue("ssid"),
22 bssid = http.formvalue("bssid"),
23 wep = http.formvalue("wep"),
24 wpa_suites = http.formvalue("wpa_suites"),
25 wpa_version = http.formvalue("wpa_version")
28 if m.hidden.ssid ~= "" then
29 wssid = m:field(Value, "ssid", translate("SSID"))
30 wssid.datatype = "rangelength(1,32)"
31 wssid.default = m.hidden.ssid or ""
33 wssid = m:field(Value, "ssid", translate("SSID (hidden)"))
36 bssid = m:field(Value, "bssid", translate("BSSID"))
37 bssid.datatype = "macaddr"
38 bssid.default = m.hidden.bssid or ""
40 if (tonumber(m.hidden.wep) or 0) == 1 then
41 wkey = m:field(Value, "key", translate("WEP passphrase"),
42 translate("Specify the secret encryption key here."))
44 wkey.datatype = "wepkey"
45 elseif (tonumber(m.hidden.wpa_version) or 0) > 0 then
46 if m.hidden.wpa_suites == "PSK" or m.hidden.wpa_suites == "PSK2" then
47 wkey = m:field(Value, "key", translate("WPA passphrase"),
48 translate("Specify the secret encryption key here."))
50 wkey.datatype = "wpakey"
51 elseif m.hidden.wpa_suites == "802.1X" then
52 eaptype = m:field(ListValue, "eap_type", translate("EAP-Method"))
56 eaptype.default = "PEAP"
58 authentication = m:field(ListValue, "auth", translate("Authentication"))
59 authentication:value("PAP")
60 authentication:value("CHAP")
61 authentication:value("MSCHAP")
62 authentication:value("MSCHAPV2")
63 authentication.default = "MSCHAPV2"
65 ident = m:field(Value, "identity", translate("Identity"))
67 pass = m:field(Value, "password", translate("Password"))
68 pass.datatype = "wpakey"
73 function wssid.write(self, section, value)
74 newsection = uci:section("wireless", "wifi-iface", nil, {
77 device = m.hidden.device,
78 ssid = wssid:formvalue(section),
79 bssid = bssid:formvalue(section),
83 val = wkey:formvalue(section)
88 if (tonumber(m.hidden.wep) or 0) == 1 then
89 uci:set("wireless", newsection, "encryption", "wep-open")
90 uci:set("wireless", newsection, "key", "1")
91 uci:set("wireless", newsection, "key1", val)
92 elseif (tonumber(m.hidden.wpa_version) or 0) > 0 then
93 if m.hidden.wpa_suites == "PSK" or m.hidden.wpa_suites == "PSK2" then
94 uci:set("wireless", newsection, "encryption", "psk2")
95 uci:set("wireless", newsection, "key", val)
96 elseif m.hidden.wpa_suites == "802.1X" then
97 uci:set("wireless", newsection, "encryption", "wpa2")
98 uci:set("wireless", newsection, "eap_type", eaptype:formvalue(section))
99 uci:set("wireless", newsection, "auth", authentication:formvalue(section))
100 val = ident:formvalue(section)
104 uci:set("wireless", newsection, "identity", val)
105 val = pass:formvalue(section)
109 uci:set("wireless", newsection, "password", val)
112 uci:set("wireless", newsection, "encryption", "none")
115 uci:commit("wireless")
116 http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))