+--- Get available channels from given wireless iface.
+-- @param iface Wireless interface (optional)
+-- @return Table of available channels
+function wifi.channels(iface)
+ local cmd = "iwlist " .. ( iface or "" ) .. " freq 2>/dev/null"
+ local cns = { }
+
+ local fd = io.popen(cmd)
+ if fd then
+ local ln, c, f
+ while true do
+ ln = fd:read("*l")
+ if not ln then break end
+ c, f = ln:match("Channel (%d+) : (%d+%.%d+) GHz")
+ if c and f then
+ cns[tonumber(c)] = tonumber(f)
+ end
+ end
+ fd:close()
+ end
+
+ if not ((pairs(cns))(cns)) then
+ cns = {
+ 2.412, 2.417, 2.422, 2.427, 2.432, 2.437,
+ 2.442, 2.447, 2.452, 2.457, 2.462
+ }
+ end
+
+ return cns
+end
+
+
+--- LuCI system utilities / init related functions.
+-- @class module
+-- @name luci.sys.init
+init = {}
+init.dir = "/etc/init.d/"
+
+--- Get the names of all installed init scripts
+-- @return Table containing the names of all inistalled init scripts
+function init.names()
+ local names = { }
+ for _, name in ipairs(luci.fs.glob(init.dir.."*")) do
+ names[#names+1] = luci.fs.basename(name)
+ end
+ return names
+end
+
+--- Test whether the given init script is enabled
+-- @param name Name of the init script
+-- @return Boolean indicating whether init is enabled
+function init.enabled(name)
+ if luci.fs.access(init.dir..name) then
+ return ( call(init.dir..name.." enabled") == 0 )
+ end
+ return false
+end
+
+--- Get the index of he given init script
+-- @param name Name of the init script
+-- @return Numeric index value
+function init.index(name)
+ if luci.fs.access(init.dir..name) then
+ return call("source "..init.dir..name.."; exit $START")
+ end
+end
+
+--- Enable the given init script
+-- @param name Name of the init script
+-- @return Boolean indicating success
+function init.enable(name)
+ if luci.fs.access(init.dir..name) then
+ return ( call(init.dir..name.." enable") == 1 )
+ end
+end
+
+--- Disable the given init script
+-- @param name Name of the init script
+-- @return Boolean indicating success
+function init.disable(name)
+ if luci.fs.access(init.dir..name) then
+ return ( call(init.dir..name.." disable") == 0 )
+ end
+end
+