privatewifi.lua 1.6 KB

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