treewide: get rid of luci.util outside of config mode/advanced settings
This commit is contained in:
parent
6cf03bab37
commit
c83b5b3cab
@ -5,7 +5,6 @@ local sysconfig = require 'gluon.sysconfig'
|
|||||||
local util = require 'gluon.util'
|
local util = require 'gluon.util'
|
||||||
|
|
||||||
local ip = require 'luci.ip'
|
local ip = require 'luci.ip'
|
||||||
local lutil = require 'luci.util'
|
|
||||||
local uci = require('simple-uci').cursor()
|
local uci = require('simple-uci').cursor()
|
||||||
|
|
||||||
|
|
||||||
@ -41,13 +40,13 @@ local interfaces = uci:get('network', 'client', 'ifname') or {}
|
|||||||
if type(interfaces) == 'string' then
|
if type(interfaces) == 'string' then
|
||||||
local ifname = interfaces
|
local ifname = interfaces
|
||||||
interfaces = {}
|
interfaces = {}
|
||||||
for iface in ifname:gmatch("[^%s]+") do
|
for iface in ifname:gmatch('%S+') do
|
||||||
util.add_to_set(interfaces, iface)
|
util.add_to_set(interfaces, iface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if sysconfig.lan_ifname and not ifname and not uci:get_bool('network', 'mesh_lan', 'auto') then
|
if sysconfig.lan_ifname and not ifname and not uci:get_bool('network', 'mesh_lan', 'auto') then
|
||||||
for _, lanif in ipairs(lutil.split(sysconfig.lan_ifname, ' ')) do
|
for lanif in sysconfig.lan_ifname:gmatch('%S+') do
|
||||||
util.add_to_set(interfaces, lanif)
|
util.add_to_set(interfaces, lanif)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,10 +8,10 @@ if sysconfig.primary_mac then
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local util = require 'gluon.util'
|
||||||
local platform = require 'gluon.platform'
|
local platform = require 'gluon.platform'
|
||||||
|
|
||||||
local fs = require 'nixio.fs'
|
local fs = require 'nixio.fs'
|
||||||
local util = require 'luci.util'
|
|
||||||
|
|
||||||
|
|
||||||
local try_files = {
|
local try_files = {
|
||||||
|
@ -5,7 +5,6 @@ local util = require 'gluon.util'
|
|||||||
local sysconfig = require 'gluon.sysconfig'
|
local sysconfig = require 'gluon.sysconfig'
|
||||||
|
|
||||||
local uci = require('simple-uci').cursor()
|
local uci = require('simple-uci').cursor()
|
||||||
local lutil = require 'luci.util'
|
|
||||||
|
|
||||||
if not sysconfig.lan_ifname then
|
if not sysconfig.lan_ifname then
|
||||||
os.exit(0)
|
os.exit(0)
|
||||||
@ -27,8 +26,8 @@ if uci:get('network', 'mesh_lan', 'auto') == nil then
|
|||||||
local interfaces = uci:get_list('network', 'client', 'ifname')
|
local interfaces = uci:get_list('network', 'client', 'ifname')
|
||||||
|
|
||||||
if interfaces then
|
if interfaces then
|
||||||
for _, lanif in ipairs(lutil.split(sysconfig.lan_ifname, ' ')) do
|
for lanif in sysconfig.lan_ifname:gmatch('%S+') do
|
||||||
if lutil.contains(interfaces, lanif) then
|
if util.contains(interfaces, lanif) then
|
||||||
enable = false
|
enable = false
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
@ -2,13 +2,19 @@
|
|||||||
|
|
||||||
local fs = require 'nixio.fs'
|
local fs = require 'nixio.fs'
|
||||||
local site = require 'gluon.site_config'
|
local site = require 'gluon.site_config'
|
||||||
local util = require 'luci.util'
|
local util = require 'gluon.util'
|
||||||
|
|
||||||
|
|
||||||
local subst = {}
|
local subst = {}
|
||||||
|
|
||||||
|
|
||||||
|
local f = io.popen('. /etc/openwrt_release; echo "$DISTRIB_CODENAME"; echo "$DISTRIB_TARGET"; echo "$DISTRIB_ARCH"')
|
||||||
|
subst['%%n'] = f:read()
|
||||||
|
subst['%%S'] = f:read()
|
||||||
|
subst['%%A'] = f:read()
|
||||||
|
f:close()
|
||||||
|
|
||||||
subst['%%v'] = util.trim(fs.readfile('/etc/openwrt_version'))
|
subst['%%v'] = util.trim(fs.readfile('/etc/openwrt_version'))
|
||||||
subst['%%n'], subst['%%S'], subst['%%A'] = util.exec('. /etc/openwrt_release; echo "$DISTRIB_CODENAME"; echo "$DISTRIB_TARGET"; echo "$DISTRIB_ARCH"'):match('([^\n]*)\n([^\n]*)\n([^\n]*)')
|
|
||||||
subst['%%GS'] = site.site_code
|
subst['%%GS'] = site.site_code
|
||||||
subst['%%GV'] = util.trim(fs.readfile('/lib/gluon/gluon-version'))
|
subst['%%GV'] = util.trim(fs.readfile('/lib/gluon/gluon-version'))
|
||||||
subst['%%GR'] = util.trim(fs.readfile('/lib/gluon/release'))
|
subst['%%GR'] = util.trim(fs.readfile('/lib/gluon/release'))
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
local sysconfig = require 'gluon.sysconfig'
|
local sysconfig = require 'gluon.sysconfig'
|
||||||
|
|
||||||
local fs = require 'nixio.fs'
|
local fs = require 'nixio.fs'
|
||||||
local util = require 'luci.util'
|
local util = require 'gluon.util'
|
||||||
|
|
||||||
|
|
||||||
-- Save the Gluon version in the sysconfig so we know which version we
|
-- Save the Gluon version in the sysconfig so we know which version we
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
local platform_info = require 'platform_info'
|
local platform_info = require 'platform_info'
|
||||||
local util = require 'luci.util'
|
local util = require 'gluon.util'
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
@ -27,5 +27,3 @@ function match(target, subtarget, boards)
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ local os = os
|
|||||||
local string = string
|
local string = string
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
|
local pairs = pairs
|
||||||
local table = table
|
local table = table
|
||||||
|
|
||||||
local nixio = require 'nixio'
|
local nixio = require 'nixio'
|
||||||
@ -35,12 +36,24 @@ 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_config'
|
||||||
local uci = require('simple-uci').cursor()
|
local uci = require('simple-uci').cursor()
|
||||||
local lutil = require 'luci.util'
|
|
||||||
local fs = require 'nixio.fs'
|
local fs = require 'nixio.fs'
|
||||||
|
|
||||||
|
|
||||||
module 'gluon.util'
|
module 'gluon.util'
|
||||||
|
|
||||||
|
function trim(str)
|
||||||
|
return str:gsub("^%s*(.-)%s*$", "%1")
|
||||||
|
end
|
||||||
|
|
||||||
|
function contains(table, value)
|
||||||
|
for k, v in pairs(table) do
|
||||||
|
if value == v then
|
||||||
|
return k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
function add_to_set(t, itm)
|
function add_to_set(t, itm)
|
||||||
for _,v in ipairs(t) do
|
for _,v in ipairs(t) do
|
||||||
if v == itm then return false end
|
if v == itm then return false end
|
||||||
@ -117,7 +130,7 @@ end
|
|||||||
local function find_phy_by_macaddr(macaddr)
|
local function find_phy_by_macaddr(macaddr)
|
||||||
local addr = macaddr:lower()
|
local addr = macaddr:lower()
|
||||||
for file in fs.glob('/sys/class/ieee80211/*/macaddress') do
|
for file in fs.glob('/sys/class/ieee80211/*/macaddress') do
|
||||||
if lutil.trim(fs.readfile(file)) == addr then
|
if trim(fs.readfile(file)) == addr then
|
||||||
return file:match('([^/]+)/macaddress$')
|
return file:match('([^/]+)/macaddress$')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,6 @@ $Id$
|
|||||||
]]--
|
]]--
|
||||||
|
|
||||||
local uci = require("simple-uci").cursor()
|
local uci = require("simple-uci").cursor()
|
||||||
local lutil = require 'luci.util'
|
|
||||||
local sysconfig = require 'gluon.sysconfig'
|
local sysconfig = require 'gluon.sysconfig'
|
||||||
local util = require 'gluon.util'
|
local util = require 'gluon.util'
|
||||||
|
|
||||||
@ -130,7 +129,7 @@ function f.handle(self, state, data)
|
|||||||
|
|
||||||
local interfaces = uci:get_list("network", "client", "ifname")
|
local interfaces = uci:get_list("network", "client", "ifname")
|
||||||
|
|
||||||
for _, lanif in ipairs(lutil.split(sysconfig.lan_ifname, ' ')) do
|
for lanif in sysconfig.lan_ifname:gmatch('%S+') do
|
||||||
if data.mesh_lan == '1' then
|
if data.mesh_lan == '1' then
|
||||||
util.remove_from_set(interfaces, lanif)
|
util.remove_from_set(interfaces, lanif)
|
||||||
else
|
else
|
||||||
|
@ -5,7 +5,6 @@ local users = require 'gluon.users'
|
|||||||
local util = require 'gluon.util'
|
local util = require 'gluon.util'
|
||||||
|
|
||||||
local uci = require('simple-uci').cursor()
|
local uci = require('simple-uci').cursor()
|
||||||
local lutil = require 'luci.util'
|
|
||||||
|
|
||||||
|
|
||||||
-- The previously used user is removed, we need root privileges to use the packet_mark option
|
-- The previously used user is removed, we need root privileges to use the packet_mark option
|
||||||
@ -25,11 +24,11 @@ local syslog_level = uci:get('fastd', 'mesh_vpn', 'syslog_level') or 'verbose'
|
|||||||
local methods
|
local methods
|
||||||
|
|
||||||
if site.fastd_mesh_vpn.configurable then
|
if site.fastd_mesh_vpn.configurable then
|
||||||
local has_null = lutil.contains(site.fastd_mesh_vpn.methods, 'null')
|
local has_null = util.contains(site.fastd_mesh_vpn.methods, 'null')
|
||||||
|
|
||||||
local old_methods = uci:get('fastd', 'mesh_vpn', 'method')
|
local old_methods = uci:get('fastd', 'mesh_vpn', 'method')
|
||||||
if old_methods then
|
if old_methods then
|
||||||
has_null = lutil.contains(old_methods, 'null')
|
has_null = util.contains(old_methods, 'null')
|
||||||
end
|
end
|
||||||
|
|
||||||
methods = {}
|
methods = {}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/lua
|
#!/usr/bin/lua
|
||||||
local uci = require('simple-uci').cursor()
|
local uci = require('simple-uci').cursor()
|
||||||
require 'luci.util'
|
local util = require 'gluon.util'
|
||||||
|
|
||||||
local sname = uci:get_first('gluon-node-info', 'location')
|
local sname = uci:get_first('gluon-node-info', 'location')
|
||||||
if sname then
|
if sname then
|
||||||
@ -8,7 +8,7 @@ if sname then
|
|||||||
for _, option in ipairs(options) do
|
for _, option in ipairs(options) do
|
||||||
local value = uci:get('gluon-node-info', sname, option)
|
local value = uci:get('gluon-node-info', sname, option)
|
||||||
if value then
|
if value then
|
||||||
uci:set('gluon-node-info', sname, option, value:trim())
|
uci:set('gluon-node-info', sname, option, util.trim(value))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
uci:save('gluon-node-info')
|
uci:save('gluon-node-info')
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
#!/usr/bin/lua
|
#!/usr/bin/lua
|
||||||
|
|
||||||
util = require 'luci.util'
|
util = require 'gluon.util'
|
||||||
json = require 'luci.jsonc'
|
|
||||||
fs = require 'nixio.fs'
|
fs = require 'nixio.fs'
|
||||||
|
json = require 'luci.jsonc'
|
||||||
|
|
||||||
io.write("Access-Control-Allow-Origin: *\n")
|
io.write("Access-Control-Allow-Origin: *\n")
|
||||||
io.write("Content-type: application/json\n\n")
|
io.write("Content-type: application/json\n\n")
|
||||||
|
|
||||||
list = util.exec('batctl if')
|
f = io.popen('batctl if')
|
||||||
|
|
||||||
interfaces = {}
|
interfaces = {}
|
||||||
|
|
||||||
for _, line in ipairs(util.split(list)) do
|
for line in f:lines() do
|
||||||
ifname = line:match('^(.-):')
|
ifname = line:match('^(.-):')
|
||||||
if ifname ~= nil then
|
if ifname ~= nil then
|
||||||
pcall(function()
|
pcall(function()
|
||||||
@ -21,4 +22,6 @@ for _, line in ipairs(util.split(list)) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
f:close()
|
||||||
|
|
||||||
io.write(json.stringify(interfaces))
|
io.write(json.stringify(interfaces))
|
||||||
|
Loading…
Reference in New Issue
Block a user