diff --git a/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/300-gluon-client-bridge-network b/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/300-gluon-client-bridge-network index fbc97a1f..bc3139a2 100755 --- a/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/300-gluon-client-bridge-network +++ b/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/300-gluon-client-bridge-network @@ -5,7 +5,6 @@ local sysconfig = require 'gluon.sysconfig' local util = require 'gluon.util' local ip = require 'luci.ip' -local lutil = require 'luci.util' local uci = require('simple-uci').cursor() @@ -41,13 +40,13 @@ local interfaces = uci:get('network', 'client', 'ifname') or {} if type(interfaces) == 'string' then local ifname = interfaces interfaces = {} - for iface in ifname:gmatch("[^%s]+") do + for iface in ifname:gmatch('%S+') do util.add_to_set(interfaces, iface) end end 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) end end diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac b/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac index c4f44065..ba6c3c4c 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac @@ -8,10 +8,10 @@ if sysconfig.primary_mac then end +local util = require 'gluon.util' local platform = require 'gluon.platform' local fs = require 'nixio.fs' -local util = require 'luci.util' local try_files = { diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan b/package/gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan index 9ff04650..0a093133 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan @@ -5,7 +5,6 @@ local util = require 'gluon.util' local sysconfig = require 'gluon.sysconfig' local uci = require('simple-uci').cursor() -local lutil = require 'luci.util' if not sysconfig.lan_ifname then os.exit(0) @@ -27,8 +26,8 @@ if uci:get('network', 'mesh_lan', 'auto') == nil then local interfaces = uci:get_list('network', 'client', 'ifname') if interfaces then - for _, lanif in ipairs(lutil.split(sysconfig.lan_ifname, ' ')) do - if lutil.contains(interfaces, lanif) then + for lanif in sysconfig.lan_ifname:gmatch('%S+') do + if util.contains(interfaces, lanif) then enable = false break end diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg b/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg index 353cf8d8..4b17471d 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg @@ -2,13 +2,19 @@ local fs = require 'nixio.fs' local site = require 'gluon.site_config' -local util = require 'luci.util' +local util = require 'gluon.util' 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['%%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['%%GV'] = util.trim(fs.readfile('/lib/gluon/gluon-version')) subst['%%GR'] = util.trim(fs.readfile('/lib/gluon/release')) diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/999-version b/package/gluon-core/luasrc/lib/gluon/upgrade/999-version index 9731692e..608545b7 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/999-version +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/999-version @@ -3,7 +3,7 @@ local sysconfig = require 'gluon.sysconfig' 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 diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua index 6483ad2e..5b4f559a 100644 --- a/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua +++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua @@ -1,5 +1,5 @@ local platform_info = require 'platform_info' -local util = require 'luci.util' +local util = require 'gluon.util' local setmetatable = setmetatable @@ -27,5 +27,3 @@ function match(target, subtarget, boards) return true end - - diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua index 68c25445..973b27fa 100644 --- a/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua +++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua @@ -28,6 +28,7 @@ local os = os local string = string local tonumber = tonumber local ipairs = ipairs +local pairs = pairs local table = table local nixio = require 'nixio' @@ -35,12 +36,24 @@ local hash = require 'hash' local sysconfig = require 'gluon.sysconfig' local site = require 'gluon.site_config' local uci = require('simple-uci').cursor() -local lutil = require 'luci.util' local fs = require 'nixio.fs' 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) for _,v in ipairs(t) do if v == itm then return false end @@ -117,7 +130,7 @@ end local function find_phy_by_macaddr(macaddr) local addr = macaddr:lower() 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$') end end diff --git a/package/gluon-luci-portconfig/luasrc/usr/lib/lua/luci/model/cbi/admin/portconfig.lua b/package/gluon-luci-portconfig/luasrc/usr/lib/lua/luci/model/cbi/admin/portconfig.lua index 2af1cbb8..13d87b51 100644 --- a/package/gluon-luci-portconfig/luasrc/usr/lib/lua/luci/model/cbi/admin/portconfig.lua +++ b/package/gluon-luci-portconfig/luasrc/usr/lib/lua/luci/model/cbi/admin/portconfig.lua @@ -13,7 +13,6 @@ $Id$ ]]-- local uci = require("simple-uci").cursor() -local lutil = require 'luci.util' local sysconfig = require 'gluon.sysconfig' local util = require 'gluon.util' @@ -130,7 +129,7 @@ function f.handle(self, state, data) 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 util.remove_from_set(interfaces, lanif) else diff --git a/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd b/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd index 27e2b3cd..f6793eca 100755 --- a/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd +++ b/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd @@ -5,7 +5,6 @@ local users = require 'gluon.users' local util = require 'gluon.util' 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 @@ -25,11 +24,11 @@ local syslog_level = uci:get('fastd', 'mesh_vpn', 'syslog_level') or 'verbose' local methods 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') if old_methods then - has_null = lutil.contains(old_methods, 'null') + has_null = util.contains(old_methods, 'null') end methods = {} diff --git a/package/gluon-node-info/files/lib/gluon/upgrade/520-node-info-whitespace-fix b/package/gluon-node-info/files/lib/gluon/upgrade/520-node-info-whitespace-fix index d062ab91..62cd4beb 100755 --- a/package/gluon-node-info/files/lib/gluon/upgrade/520-node-info-whitespace-fix +++ b/package/gluon-node-info/files/lib/gluon/upgrade/520-node-info-whitespace-fix @@ -1,6 +1,6 @@ #!/usr/bin/lua local uci = require('simple-uci').cursor() -require 'luci.util' +local util = require 'gluon.util' local sname = uci:get_first('gluon-node-info', 'location') if sname then @@ -8,7 +8,7 @@ if sname then for _, option in ipairs(options) do local value = uci:get('gluon-node-info', sname, option) if value then - uci:set('gluon-node-info', sname, option, value:trim()) + uci:set('gluon-node-info', sname, option, util.trim(value)) end end uci:save('gluon-node-info') diff --git a/package/gluon-status-page-api/luasrc/lib/gluon/status-page/www/cgi-bin/interfaces b/package/gluon-status-page-api/luasrc/lib/gluon/status-page/www/cgi-bin/interfaces index 4eabf815..0277b789 100755 --- a/package/gluon-status-page-api/luasrc/lib/gluon/status-page/www/cgi-bin/interfaces +++ b/package/gluon-status-page-api/luasrc/lib/gluon/status-page/www/cgi-bin/interfaces @@ -1,17 +1,18 @@ #!/usr/bin/lua -util = require 'luci.util' -json = require 'luci.jsonc' +util = require 'gluon.util' + fs = require 'nixio.fs' +json = require 'luci.jsonc' io.write("Access-Control-Allow-Origin: *\n") io.write("Content-type: application/json\n\n") -list = util.exec('batctl if') +f = io.popen('batctl if') interfaces = {} -for _, line in ipairs(util.split(list)) do +for line in f:lines() do ifname = line:match('^(.-):') if ifname ~= nil then pcall(function() @@ -21,4 +22,6 @@ for _, line in ipairs(util.split(list)) do end end +f:close() + io.write(json.stringify(interfaces))