gluon-core, gluon-client-bridge: use new gluon.site library in gluon.util

In particular, this affects users of gluon.util.iterate_radios.
This commit is contained in:
Matthias Schiffer 2017-08-08 14:07:09 +02:00
parent 53b6065500
commit 293a45456b
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
3 changed files with 21 additions and 27 deletions

View File

@ -7,14 +7,11 @@ local uci = require('simple-uci').cursor()
local function is_disabled(config, name) local function is_disabled(config, name)
local disabled
if uci:get('wireless', name) then if uci:get('wireless', name) then
disabled = uci:get_bool('wireless', name, 'disabled') return uci:get_bool('wireless', name, 'disabled')
else
disabled = config and config.disabled
end end
return disabled return config.disabled(false)
end end
local function configure_client(config, radio, index, suffix) local function configure_client(config, radio, index, suffix)
@ -23,7 +20,7 @@ local function configure_client(config, radio, index, suffix)
uci:delete('wireless', name) uci:delete('wireless', name)
if not config then if not config() then
return return
end end
@ -36,7 +33,7 @@ local function configure_client(config, radio, index, suffix)
device = radio, device = radio,
network = 'client', network = 'client',
mode = 'ap', mode = 'ap',
ssid = config.ssid, ssid = config.ssid(),
macaddr = macaddr, macaddr = macaddr,
ifname = suffix and 'client' .. suffix, ifname = suffix and 'client' .. suffix,
disabled = disabled or false, disabled = disabled or false,

View File

@ -1,7 +1,7 @@
#!/usr/bin/lua #!/usr/bin/lua
local util = require 'gluon.util' local util = require 'gluon.util'
local site = require 'gluon.site_config' local site = require 'gluon.site'
local sysconfig = require 'gluon.sysconfig' local sysconfig = require 'gluon.sysconfig'
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
@ -12,11 +12,12 @@ if not sysconfig.gluon_version then
end end
local function get_channel(radio, config) local function get_channel(radio, config)
local channel
if uci:get_first('gluon-core', 'wireless', 'preserve_channels') then if uci:get_first('gluon-core', 'wireless', 'preserve_channels') then
return uci:get('wireless', radio, 'channel') or config.channel channel = uci:get('wireless', radio, 'channel')
else
return config.channel
end end
return channel or config.channel()
end end
local function is_disabled(name) local function is_disabled(name)
@ -134,7 +135,7 @@ local function fixup_wan(radio, index)
end end
local function configure_radio(radio, index, config) local function configure_radio(radio, index, config)
if not config then if not config() then
return return
end end
@ -149,29 +150,27 @@ local function configure_radio(radio, index, config)
uci:set('wireless', radio, 'channel', channel) uci:set('wireless', radio, 'channel', channel)
uci:set('wireless', radio, 'htmode', 'HT20') uci:set('wireless', radio, 'htmode', 'HT20')
uci:set('wireless', radio, 'country', site.regdom) uci:set('wireless', radio, 'country', site.regdom())
uci:set_list('wireless', radio, 'supported_rates', config.supported_rates) uci:set_list('wireless', radio, 'supported_rates', config.supported_rates())
uci:set_list('wireless', radio, 'basic_rate', config.basic_rate) uci:set_list('wireless', radio, 'basic_rate', config.basic_rate())
local ibss_disabled = is_disabled('ibss_' .. radio) local ibss_disabled = is_disabled('ibss_' .. radio)
local mesh_disabled = is_disabled('mesh_' .. radio) local mesh_disabled = is_disabled('mesh_' .. radio)
configure_ibss(config.ibss, radio, index, suffix, configure_ibss(config.ibss(), radio, index, suffix,
first_non_nil( first_non_nil(
ibss_disabled, ibss_disabled,
mesh_disabled, mesh_disabled,
(config.ibss or {}).disabled, -- will be nil if config.ibss or config.ibss.disabled is unset config.ibss.disabled(false)
false
) )
) )
configure_mesh(config.mesh, radio, index, suffix, configure_mesh(config.mesh(), radio, index, suffix,
first_non_nil( first_non_nil(
mesh_disabled, mesh_disabled,
ibss_disabled, ibss_disabled,
(config.mesh or {}).disabled, -- will be nil if config.mesh or config.mesh.disabled is unset config.mesh.disabled(false)
false
) )
) )

View File

@ -35,7 +35,7 @@ local table = table
local nixio = require 'nixio' local nixio = require 'nixio'
local hash = require 'hash' local hash = require 'hash'
local sysconfig = require 'gluon.sysconfig' local sysconfig = require 'gluon.sysconfig'
local site = require 'gluon.site_config' local site = require 'gluon.site'
local fs = require 'nixio.fs' local fs = require 'nixio.fs'
@ -131,7 +131,7 @@ function site_seed_bytes(key, length)
-- cryptographic strength -- cryptographic strength
while ret:len() < 2*length do while ret:len() < 2*length do
i = i + 1 i = i + 1
v = hash.md5(v .. key .. site.site_seed:lower() .. i) v = hash.md5(v .. key .. site.site_seed():lower() .. i)
ret = ret .. v ret = ret .. v
end end
@ -253,11 +253,9 @@ end
function iterate_radios(uci, f) function iterate_radios(uci, f)
local radios = {} local radios = {}
uci:foreach('wireless', 'wifi-device', uci:foreach('wireless', 'wifi-device', function(s)
function(s)
table.insert(radios, s['.name']) table.insert(radios, s['.name'])
end end)
)
for index, radio in ipairs(radios) do for index, radio in ipairs(radios) do
local hwmode = uci:get('wireless', radio, 'hwmode') local hwmode = uci:get('wireless', radio, 'hwmode')