wifi_edit.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. -- Copyright 2017 Dirk Brenken (dev@brenken.org)
  2. -- This is free software, licensed under the Apache License, Version 2.0
  3. local fs = require("nixio.fs")
  4. local uci = require("luci.model.uci").cursor()
  5. local http = require("luci.http")
  6. m = SimpleForm("edit", translate("Edit Wireless Uplink Configuration"))
  7. m.submit = translate("Save")
  8. m.cancel = translate("Back to overview")
  9. m.reset = false
  10. function m.on_cancel()
  11. http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))
  12. end
  13. m.hidden = {
  14. cfg = http.formvalue("cfg")
  15. }
  16. local s = uci:get_all("wireless", m.hidden.cfg)
  17. if s ~= nil then
  18. wssid = m:field(Value, "ssid", translate("SSID"))
  19. wssid.default = s.ssid
  20. wssid.datatype = "rangelength(1,32)"
  21. if s.encryption and s.key then
  22. wkey = m:field(Value, "key", translatef("Passphrase (%s)", s.encryption))
  23. elseif s.encryption and s.password then
  24. wkey = m:field(Value, "password", translatef("Passphrase (%s)", s.encryption))
  25. end
  26. if s.encryption and (s.key or s.password) then
  27. wkey.password = true
  28. wkey.default = s.key or s.password
  29. if s.encryption == "wep" then
  30. wkey.datatype = "wepkey"
  31. else
  32. wkey.datatype = "wpakey"
  33. end
  34. end
  35. else
  36. m.on_cancel()
  37. end
  38. function wssid.write(self, section, value)
  39. uci:set("wireless", m.hidden.cfg, "ssid", wssid:formvalue(section))
  40. if s.encryption and s.key then
  41. uci:set("wireless", m.hidden.cfg, "key", wkey:formvalue(section))
  42. elseif s.encryption and s.password then
  43. uci:set("wireless", m.hidden.cfg, "password", wkey:formvalue(section))
  44. end
  45. uci:save("wireless")
  46. uci:commit("wireless")
  47. m.on_cancel()
  48. end
  49. return m