2017-07-19 20:36:47 +00:00
|
|
|
-- Copyright 2017 Dirk Brenken (dev@brenken.org)
|
|
|
|
-- 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()
|
2017-07-19 20:36:47 +00:00
|
|
|
local http = require("luci.http")
|
2017-12-06 16:05:40 +00:00
|
|
|
local val = ""
|
2017-07-19 20:36:47 +00:00
|
|
|
|
|
|
|
m = SimpleForm("edit", translate("Edit 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 = {
|
|
|
|
cfg = http.formvalue("cfg")
|
|
|
|
}
|
|
|
|
|
|
|
|
local s = uci:get_all("wireless", m.hidden.cfg)
|
|
|
|
if s ~= nil then
|
|
|
|
wssid = m:field(Value, "ssid", translate("SSID"))
|
2017-08-12 06:03:48 +00:00
|
|
|
wssid.datatype = "rangelength(1,32)"
|
2017-12-06 16:05:40 +00:00
|
|
|
wssid.default = s.ssid
|
|
|
|
bssid = m:field(Value, "bssid", translate("BSSID"))
|
|
|
|
bssid.datatype = "macaddr"
|
|
|
|
bssid.default = s.bssid
|
|
|
|
if s.identity then
|
|
|
|
ident = m:field(Value, "identity", translate("Identity"))
|
|
|
|
ident.default = s.identity
|
|
|
|
end
|
2017-07-19 20:36:47 +00:00
|
|
|
if s.encryption and s.key then
|
|
|
|
wkey = m:field(Value, "key", translatef("Passphrase (%s)", s.encryption))
|
2017-08-12 06:03:48 +00:00
|
|
|
elseif s.encryption and s.password then
|
|
|
|
wkey = m:field(Value, "password", translatef("Passphrase (%s)", s.encryption))
|
|
|
|
end
|
|
|
|
if s.encryption and (s.key or s.password) then
|
2017-07-19 20:36:47 +00:00
|
|
|
wkey.password = true
|
2017-08-12 06:03:48 +00:00
|
|
|
wkey.default = s.key or s.password
|
2017-07-19 20:36:47 +00:00
|
|
|
if s.encryption == "wep" then
|
|
|
|
wkey.datatype = "wepkey"
|
|
|
|
else
|
|
|
|
wkey.datatype = "wpakey"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2017-08-03 15:04:58 +00:00
|
|
|
m.on_cancel()
|
2017-07-19 20:36:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function wssid.write(self, section, value)
|
|
|
|
uci:set("wireless", m.hidden.cfg, "ssid", wssid:formvalue(section))
|
2017-12-06 16:05:40 +00:00
|
|
|
uci:set("wireless", m.hidden.cfg, "bssid", bssid:formvalue(section))
|
|
|
|
if s.identity then
|
|
|
|
val = ident:formvalue(section)
|
|
|
|
if val == "" then
|
|
|
|
val = "changeme"
|
|
|
|
end
|
|
|
|
uci:set("wireless", m.hidden.cfg, "identity", val)
|
|
|
|
end
|
|
|
|
|
|
|
|
if s.encryption and s.encryption ~= "none" then
|
|
|
|
val = wkey:formvalue(section)
|
|
|
|
if val == "" then
|
|
|
|
val = "changeme"
|
|
|
|
end
|
|
|
|
if s.key then
|
|
|
|
uci:set("wireless", m.hidden.cfg, "key", val)
|
|
|
|
elseif s.password then
|
|
|
|
uci:set("wireless", m.hidden.cfg, "password", val)
|
|
|
|
end
|
2017-07-19 20:36:47 +00:00
|
|
|
end
|
|
|
|
uci:save("wireless")
|
|
|
|
uci:commit("wireless")
|
2017-08-03 15:04:58 +00:00
|
|
|
m.on_cancel()
|
2017-07-19 20:36:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return m
|