privatewifi.lua 2.3 KB

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