gluon-firmware/package/gluon-luci-private-wifi/luasrc/usr/lib/lua/luci/model/cbi/admin/privatewifi.lua

68 lines
2.1 KiB
Lua

local uci = require("simple-uci").cursor()
local util = require 'gluon.util'
local f, s, o, ssid
-- where to read the configuration from
local primary_iface = 'wan_radio0'
local ssid = uci:get('wireless', primary_iface, "ssid")
f = SimpleForm("wifi", translate("Private WLAN"))
s = f:section(SimpleSection, nil, translate(
'Your node can additionally extend your private network by bridging the WAN interface '
.. 'with a separate WLAN. This feature is completely independent of the mesh functionality. '
.. 'Please note that the private WLAN and meshing on the WAN interface should not be enabled '
.. 'at the same time.'
))
o = s:option(Flag, "enabled", translate("Enabled"))
o.default = (ssid and not uci:get_bool('wireless', primary_iface, "disabled")) and o.enabled or o.disabled
o.rmempty = false
o = s:option(Value, "ssid", translate("Name (SSID)"))
o:depends("enabled", '1')
o.datatype = "maxlength(32)"
o.default = ssid
o = s:option(Value, "key", translate("Key"), translate("8-63 characters"))
o:depends("enabled", '1')
o.datatype = "wpakey"
o.default = uci:get('wireless', primary_iface, "key")
function f.handle(self, state, data)
if state == FORM_VALID then
util.iterate_radios(
function(radio, index)
local name = "wan_" .. radio
if data.enabled == '1' then
local macaddr = util.get_wlan_mac(radio, index, 4)
-- set up WAN wifi-iface
uci:section('wireless', "wifi-iface", name,
{
device = radio,
network = "wan",
mode = 'ap',
encryption = 'psk2',
ssid = data.ssid,
key = data.key,
macaddr = macaddr,
disabled = false,
}
)
else
-- disable WAN wifi-iface
uci:set('wireless', name, "disabled", true)
end
end
)
uci:save('wireless')
uci:commit('wireless')
end
end
return f