Moved luci.sys.exec, luci.sys.execl and luci.sys.bigendian to luci.util
authorSteven Barth <steven@midlink.org>
Wed, 6 Aug 2008 20:11:15 +0000 (20:11 +0000)
committerSteven Barth <steven@midlink.org>
Wed, 6 Aug 2008 20:11:15 +0000 (20:11 +0000)
13 files changed:
applications/luci-splash/luasrc/controller/splash/splash.lua
applications/luci-splash/root/usr/sbin/luci-splash
libs/cbi/luasrc/cbi.lua
libs/core/luasrc/sys.lua
libs/core/luasrc/sys/iptparser.lua
libs/core/luasrc/util.lua
libs/ipkg/luasrc/model/ipkg.lua
modules/admin-full/luasrc/controller/admin/system.lua
modules/admin-full/luasrc/controller/admin/uci.lua
modules/admin-full/luasrc/model/cbi/admin_network/dhcp.lua
modules/admin-full/luasrc/model/cbi/admin_wifi/devices.lua
modules/admin-mini/luasrc/controller/mini/system.lua
modules/admin-mini/luasrc/controller/mini/uci.lua

index 7dbf488a4ed98176a957b9c011c933a3b786b56c..dbd266f46178061be522c61a25122ddbc8939e4d 100644 (file)
@@ -10,7 +10,7 @@ end
 
 function action_dispatch()
        local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR")) or ""
-       local status = luci.sys.execl("luci-splash status "..mac)[1]
+       local status = luci.util.execl("luci-splash status "..mac)[1]
        if #mac > 0 and ( status == "whitelisted" or status == "lease" ) then
                luci.http.redirect(luci.dispatcher.build_url())
        else
index 72456c01e61509ab36e9672aa3e6f031b740c6f7..0b645fab75e5b1fdeda5b2383b6d0966bf493bc7 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/lua
 
 require("luci.http")
-require("luci.sys")
+require("luci.util")
 require("luci.model.uci")
 
 -- Init state session
@@ -140,7 +140,7 @@ end
 function listrules()
        local cmd = "iptables -t nat -L luci_splash_leases | grep RETURN |"
        cmd = cmd .. "egrep -io [0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+"
-       return luci.util.split(luci.sys.exec(cmd))
+       return luci.util.split(luci.util.exec(cmd))
 end
 
 
index 8c8f68b24a5adfd103cec4a519f200e7a5eacdda..d5be48edba96c9133c0584175226b5b19b0701c0 100644 (file)
@@ -167,7 +167,7 @@ function Map.parse(self, ...)
                for i, config in ipairs(self.parsechain) do
                        uci.commit(config)
                        if luci.config.uci_oncommit and luci.config.uci_oncommit[config] then
-                               luci.sys.exec(luci.config.uci_oncommit[config])
+                               luci.util.exec(luci.config.uci_oncommit[config])
                        end
 
                        -- Refresh data because commit changes section names
index 8e8aab731515cd8b342c19f4b3e40772f8e9a6e0..c291f678961ee2c98dad87d529405bb3f05ea63b 100644 (file)
@@ -31,41 +31,6 @@ require("luci.bits")
 require("luci.util")
 require("luci.fs")
 
---- Test whether the current system is operating in big endian mode.
--- @return     Boolean value indicating whether system is big endian
-function bigendian()
-       return string.byte(string.dump(function() end), 7) == 0
-end
-
---- Execute given commandline and gather stdout.
--- @param command      String containing command to execute
--- @return                     String containing the command's stdout
-function exec(command)
-       local pp   = io.popen(command)
-       local data = pp:read("*a")
-       pp:close()
-
-       return data
-end
-
---- Execute given commandline and gather stdout.
--- @param command      String containing the command to execute
--- @return                     Table containing the command's stdout splitted up in lines
-function execl(command)
-       local pp   = io.popen(command)
-       local line = ""
-       local data = {}
-
-       while true do
-               line = pp:read()
-               if (line == nil) then break end
-               table.insert(data, line)
-       end
-       pp:close()
-
-       return data
-end
-
 --- Invoke the luci-flash executable to write an image to the flash memory.
 -- @param kpattern     Pattern of files to keep over flash process
 -- @return                     Return value of os.execute()
@@ -97,10 +62,12 @@ function hostname()
 end
 
 --- Returns the contents of a documented referred by an URL.
--- @param url  The URL to retrieve
+-- @param url   The URL to retrieve
+-- @param stream Return a stream instead of a buffer
 -- @return             String containing the contents of given the URL
-function httpget(url)
-       return exec("wget -qO- '"..url:gsub("'", "").."'")
+function httpget(url, stream)
+       local source = stream and io.open or luci.util.exec
+       return source("wget -qO- '"..url:gsub("'", "").."'")
 end
 
 --- Returns the absolute path to LuCI base directory.
@@ -146,21 +113,21 @@ function sysinfo()
        local c7 = "cat /proc/meminfo|grep MemFree|awk {' print $2 '} 2>/dev/null"
        local c8 = "cat /proc/meminfo|grep Buffers|awk {' print $2 '} 2>/dev/null"
 
-       local system = luci.util.trim(exec(c1))
+       local system = luci.util.trim(luci.util.exec(c1))
        local model = ""
-       local memtotal = luci.util.trim(exec(c5))
-       local memcached = luci.util.trim(exec(c6))
-       local memfree = luci.util.trim(exec(c7))
-       local membuffers = luci.util.trim(exec(c8))
+       local memtotal = luci.util.trim(luci.util.exec(c5))
+       local memcached = luci.util.trim(luci.util.exec(c6))
+       local memfree = luci.util.trim(luci.util.exec(c7))
+       local membuffers = luci.util.trim(luci.util.exec(c8))
        local perc_memfree = math.floor((memfree/memtotal)*100)
        local perc_membuffers = math.floor((membuffers/memtotal)*100)
        local perc_memcached = math.floor((memcached/memtotal)*100)
 
        if system == "" then
-               system = luci.util.trim(exec(c2))
-               model = luci.util.trim(exec(c3))
+               system = luci.util.trim(luci.util.exec(c2))
+               model = luci.util.trim(luci.util.exec(c3))
        else
-               model = luci.util.trim(exec(c4))
+               model = luci.util.trim(luci.util.exec(c4))
        end
 
        return system, model, memtotal, memcached, membuffers, memfree, perc_memfree, perc_membuffers, perc_memcached
@@ -169,7 +136,7 @@ end
 --- Retrieves the output of the "logread" command.
 -- @return     String containing the current log buffer
 function syslog()
-       return exec("logread")
+       return luci.util.exec("logread")
 end
 
 --- Generates a random id with specified length.
@@ -305,7 +272,7 @@ function net.hexip4(hex, be)
                return nil
        end
 
-       be = be or bigendian()
+       be = be or luci.util.bigendian()
 
        local hexdec = luci.bits.Hex2Dec
 
@@ -442,7 +409,7 @@ wifi = {}
 --- Get iwconfig output for all wireless devices.
 -- @return     Table of tables containing the iwconfing output for each wifi device
 function wifi.getiwconfig()
-       local cnt = exec("/usr/sbin/iwconfig 2>/dev/null")
+       local cnt = luci.util.exec("/usr/sbin/iwconfig 2>/dev/null")
        local iwc = {}
 
        for i, l in pairs(luci.util.split(luci.util.trim(cnt), "\n\n")) do
@@ -459,7 +426,7 @@ end
 --- Get iwlist scan output from all wireless devices.
 -- @return     Table of tables contaiing all scan results
 function wifi.iwscan()
-       local cnt = exec("iwlist scan 2>/dev/null")
+       local cnt = luci.util.exec("iwlist scan 2>/dev/null")
        local iws = {}
 
        for i, l in pairs(luci.util.split(luci.util.trim(cnt), "\n\n")) do
index 6450c30729e8c1b7540915fdd82f5dc3348cc355..2e8085a55df681e048c1bb1ec9249ac07bc1d58f 100644 (file)
@@ -20,7 +20,6 @@ $Id$
 ]]--
 
 module("luci.sys.iptparser", package.seeall)
-require("luci.sys")
 require("luci.util")
 
 
@@ -180,7 +179,7 @@ function IptParser._parse_rules( self )
 
        for i, tbl in ipairs({ "filter", "nat", "mangle" }) do
 
-               for i, rule in ipairs(luci.sys.execl("iptables -t " .. tbl .. " --line-numbers -nxvL")) do
+               for i, rule in ipairs(luci.util.execl("iptables -t " .. tbl .. " --line-numbers -nxvL")) do
 
                        if rule:find( "Chain " ) == 1 then
                
index a4ea2d29f889059f5176c8880f533300885ada2b..2f6cfad4c21a8f1e06e01a0343be4b9111946029 100644 (file)
@@ -573,6 +573,45 @@ function vspairs(t)
 end
 
 
+--
+-- System utility functions
+--
+
+--- Test whether the current system is operating in big endian mode.
+-- @return     Boolean value indicating whether system is big endian
+function bigendian()
+       return string.byte(string.dump(function() end), 7) == 0
+end
+
+--- Execute given commandline and gather stdout.
+-- @param command      String containing command to execute
+-- @return                     String containing the command's stdout
+function exec(command)
+       local pp   = io.popen(command)
+       local data = pp:read("*a")
+       pp:close()
+
+       return data
+end
+
+--- Execute given commandline and gather stdout.
+-- @param command      String containing the command to execute
+-- @return                     Table containing the command's stdout splitted up in lines
+function execl(command)
+       local pp   = io.popen(command)
+       local line = ""
+       local data = {}
+
+       while true do
+               line = pp:read()
+               if (line == nil) then break end
+               table.insert(data, line)
+       end
+       pp:close()
+
+       return data
+end
+
 --
 -- Coroutine safe xpcall and pcall versions modified for Luci
 -- original version:
index 075acc4c3a10e639a65148ab6b662b45d93777ea..4c2716a383435f88185f8b9ccc38e9accc9ef6de 100644 (file)
@@ -26,7 +26,6 @@ limitations under the License.
 
 ]]--
 module("luci.model.ipkg", package.seeall)
-require("luci.sys")
 require("luci.util")
 require("luci.fs")
 
@@ -89,7 +88,7 @@ function _lookup(act, pkg)
                cmd = cmd .. " '" .. pkg:gsub("'", "") .. "'"
        end
        
-       return _parselist(luci.sys.exec(cmd .. " 2>/dev/null"))
+       return _parselist(luci.util.exec(cmd .. " 2>/dev/null"))
 end
 
 -- Internal parser function
index 8e3a3d79999da1f4f1a1a507d6b7842cf44a19ff..9abdb2ababf6a3626b146a9a8e1acac750def4a8 100644 (file)
@@ -189,7 +189,7 @@ function action_backup()
                luci.ltn12.pump.all(luci.ltn12.source.file(backup_fpi), luci.http.write)
        elseif reset then
                luci.template.render("admin_system/applyreboot")
-               luci.sys.exec("mtd -r erase rootfs_data")
+               luci.util.exec("mtd -r erase rootfs_data")
        else
                luci.template.render("admin_system/backup", {reset_avail = reset_avail})
        end
index d2acdeca132896ec761ee9b3f0046bce49f6644a..215889f85ff1af4146fa495dfc394622b986892e 100644 (file)
@@ -77,7 +77,7 @@ function action_apply()
                
                -- Search for post-commit commands
                for cmd, i in pairs(run) do
-                       output = output .. cmd .. ":" .. luci.sys.exec(cmd) .. "\n"
+                       output = output .. cmd .. ":" .. luci.util.exec(cmd) .. "\n"
                end
        end
        
index 20adcdf1007ba89ac974e440d25df30355e4d0c3..f85eb5219825f02f7856db3ebcd1cf7bfb826c7c 100644 (file)
@@ -13,6 +13,7 @@ $Id$
 ]]--
 require("luci.model.uci")
 require("luci.sys")
+require("luci.util")
 
 m = Map("dhcp", "DHCP")
 
@@ -46,7 +47,7 @@ s:option(Value, "netmask", translate("netmask")).optional = true
 
 s:option(Flag, "force").optional = true
 
-for i, line in pairs(luci.sys.execl("dnsmasq --help dhcp")) do
+for i, line in pairs(luci.util.execl("dnsmasq --help dhcp")) do
        k, v = line:match("([^ ]+) +([^ ]+)")
        s:option(Value, "dhcp"..k, v).optional = true
 end
index d463157d198ea01a690c049d9c020369e1c56bdf..de226191928789d13c641ed2e4ada4a6d6fd4fc7 100644 (file)
@@ -33,7 +33,7 @@ t:value("prism2")
 --[[
 require("luci.sys")
 local c = ". /etc/functions.sh;for i in /lib/wifi/*;do . $i;done;echo $DRIVERS"
-for driver in luci.sys.execl(c)[1]:gmatch("[^ ]+") do
+for driver in luci.util.execl(c)[1]:gmatch("[^ ]+") do
        t:value(driver)
 end
 ]]--
index ef1489b9b13644ad2491a2cac99d64f1ed1490cc..0df4f8cc47e25040e867841d2eac448356449400 100644 (file)
@@ -62,7 +62,7 @@ function action_backup()
                luci.ltn12.pump.all(luci.ltn12.source.file(backup_fpi), luci.http.write)
        elseif reset then
                luci.template.render("mini/applyreboot")
-               luci.sys.exec("mtd -r erase rootfs_data")
+               luci.util.exec("mtd -r erase rootfs_data")
        else
                luci.template.render("mini/backup", {reset_avail = reset_avail})
        end
index b56a70287e65c78eb4fa65d6221fe18c84bdf1ed..4eceae6293360f98c7f100b3bf7de51472d2872b 100644 (file)
@@ -74,7 +74,7 @@ function action_apply()
                
                -- Search for post-commit commands
                for cmd, i in pairs(run) do
-                       output = output .. cmd .. ":" .. luci.sys.exec(cmd) .. "\n"
+                       output = output .. cmd .. ":" .. luci.util.exec(cmd) .. "\n"
                end
        end