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")
9 m = SimpleForm("edit", translate("Edit Wireless Uplink Configuration"))
10 m.submit = translate("Save")
11 m.cancel = translate("Back to overview")
14 function m.on_cancel()
15 http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))
19 cfg = http.formvalue("cfg")
22 local s = uci:get_all("wireless", m.hidden.cfg)
24 wssid = m:field(Value, "ssid", translate("SSID"))
25 wssid.datatype = "rangelength(1,32)"
26 wssid.default = s.ssid
27 bssid = m:field(Value, "bssid", translate("BSSID"))
28 bssid.datatype = "macaddr"
29 bssid.default = s.bssid
31 ident = m:field(Value, "identity", translate("Identity"))
32 ident.default = s.identity
34 if s.encryption and s.key then
35 wkey = m:field(Value, "key", translatef("Passphrase (%s)", s.encryption))
36 elseif s.encryption and s.password then
37 wkey = m:field(Value, "password", translatef("Passphrase (%s)", s.encryption))
39 if s.encryption and (s.key or s.password) then
41 wkey.default = s.key or s.password
42 if s.encryption == "wep" then
43 wkey.datatype = "wepkey"
45 wkey.datatype = "wpakey"
52 function wssid.write(self, section, value)
53 uci:set("wireless", m.hidden.cfg, "ssid", wssid:formvalue(section))
54 uci:set("wireless", m.hidden.cfg, "bssid", bssid:formvalue(section))
56 val = ident:formvalue(section)
60 uci:set("wireless", m.hidden.cfg, "identity", val)
63 if s.encryption and s.encryption ~= "none" then
64 val = wkey:formvalue(section)
69 uci:set("wireless", m.hidden.cfg, "key", val)
70 elseif s.password then
71 uci:set("wireless", m.hidden.cfg, "password", val)
75 uci:commit("wireless")