privatewifi.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. local f, s, o, ssid
  2. local uci = luci.model.uci.cursor()
  3. local config = 'wireless'
  4. -- where to read the configuration from
  5. local primary_iface = 'wan_radio0'
  6. local ssid = uci:get(config, primary_iface, "ssid")
  7. f = SimpleForm("wifi", translate("Private WLAN"))
  8. f.template = "admin/expertmode"
  9. s = f:section(SimpleSection, nil, translate(
  10. 'Your node can additionally extend your private network by bridging the WAN interface '
  11. .. 'with a separate WLAN. This feature is completely independent of the mesh functionality. '
  12. .. 'Please note that the private WLAN and meshing on the WAN interface should not be enabled '
  13. .. 'at the same time.'
  14. ))
  15. o = s:option(Flag, "enabled", translate("Enabled"))
  16. o.default = (ssid and not uci:get_bool(config, primary_iface, "disabled")) and o.enabled or o.disabled
  17. o.rmempty = false
  18. o = s:option(Value, "ssid", translate("Name (SSID)"))
  19. o:depends("enabled", '1')
  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(config, primary_iface, "key")
  25. function f.handle(self, state, data)
  26. if state == FORM_VALID then
  27. uci:foreach(config, "wifi-device",
  28. function(s)
  29. local device = s['.name']
  30. local name = "wan_" .. device
  31. if data.enabled == '1' then
  32. -- set up WAN wifi-iface
  33. uci:section(config, "wifi-iface", name,
  34. {
  35. device = device,
  36. network = "wan",
  37. mode = 'ap',
  38. encryption = 'psk2',
  39. ssid = data.ssid,
  40. key = data.key,
  41. disabled = 0,
  42. }
  43. )
  44. else
  45. -- disable WAN wifi-iface
  46. uci:set(config, name, "disabled", 1)
  47. end
  48. end)
  49. uci:save(config)
  50. uci:commit(config)
  51. end
  52. end
  53. return f