privatewifi.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. local uci = require("simple-uci").cursor()
  2. local util = require 'gluon.util'
  3. local f, s, o, ssid
  4. -- where to read the configuration from
  5. local primary_iface = 'wan_radio0'
  6. local ssid = uci:get('wireless', primary_iface, "ssid")
  7. f = SimpleForm("wifi", translate("Private WLAN"))
  8. s = f:section(SimpleSection, nil, translate(
  9. 'Your node can additionally extend your private network by bridging the WAN interface '
  10. .. 'with a separate WLAN. This feature is completely independent of the mesh functionality. '
  11. .. 'Please note that the private WLAN and meshing on the WAN interface should not be enabled '
  12. .. 'at the same time.'
  13. ))
  14. o = s:option(Flag, "enabled", translate("Enabled"))
  15. o.default = (ssid and not uci:get_bool('wireless', primary_iface, "disabled")) and o.enabled or o.disabled
  16. o.rmempty = false
  17. o = s:option(Value, "ssid", translate("Name (SSID)"))
  18. o:depends("enabled", '1')
  19. o.datatype = "maxlength(32)"
  20. o.default = ssid
  21. o = s:option(Value, "key", translate("Key"), translate("8-63 characters"))
  22. o:depends("enabled", '1')
  23. o.datatype = "wpakey"
  24. o.default = uci:get('wireless', primary_iface, "key")
  25. function f.handle(self, state, data)
  26. if state == FORM_VALID then
  27. util.iterate_radios(
  28. function(radio, index)
  29. local name = "wan_" .. radio
  30. if data.enabled == '1' then
  31. local macaddr = util.get_wlan_mac(radio, index, 4)
  32. -- set up WAN wifi-iface
  33. uci:section('wireless', "wifi-iface", name,
  34. {
  35. device = radio,
  36. network = "wan",
  37. mode = 'ap',
  38. encryption = 'psk2',
  39. ssid = data.ssid,
  40. key = data.key,
  41. macaddr = macaddr,
  42. disabled = false,
  43. }
  44. )
  45. else
  46. -- disable WAN wifi-iface
  47. uci:set('wireless', name, "disabled", true)
  48. end
  49. end
  50. )
  51. uci:save('wireless')
  52. uci:commit('wireless')
  53. end
  54. end
  55. return f