privatewifi.lua 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. local uci = luci.model.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. 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('wireless', 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.datatype = "maxlength(32)"
  21. o.default = ssid
  22. o = s:option(Value, "key", translate("Key"), translate("8-63 characters"))
  23. o:depends("enabled", '1')
  24. o.datatype = "wpakey"
  25. o.default = uci:get('wireless', primary_iface, "key")
  26. function f.handle(self, state, data)
  27. if state == FORM_VALID then
  28. util.iterate_radios(
  29. function(radio, index)
  30. local name = "wan_" .. radio
  31. if data.enabled == '1' then
  32. local macaddr = util.get_wlan_mac(radio, index, 4)
  33. -- set up WAN wifi-iface
  34. uci:section('wireless', "wifi-iface", name,
  35. {
  36. device = radio,
  37. network = "wan",
  38. mode = 'ap',
  39. encryption = 'psk2',
  40. ssid = data.ssid,
  41. key = data.key,
  42. macaddr = macaddr,
  43. disabled = 0,
  44. }
  45. )
  46. else
  47. -- disable WAN wifi-iface
  48. uci:set('wireless', name, "disabled", 1)
  49. end
  50. end
  51. )
  52. uci:save('wireless')
  53. uci:commit('wireless')
  54. end
  55. end
  56. return f