diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ffluci/controller/admin/uci.lua | 4 | ||||
-rw-r--r-- | src/ffluci/model/cbi/admin_wifi/devices.lua | 4 | ||||
-rw-r--r-- | src/ffluci/model/ipkg.lua | 29 | ||||
-rw-r--r-- | src/ffluci/model/uci.lua | 7 | ||||
-rw-r--r-- | src/ffluci/sys.lua | 25 | ||||
-rw-r--r-- | src/ffluci/util.lua | 27 |
6 files changed, 63 insertions, 33 deletions
diff --git a/src/ffluci/controller/admin/uci.lua b/src/ffluci/controller/admin/uci.lua index 9f8c124996..3c9fc87395 100644 --- a/src/ffluci/controller/admin/uci.lua +++ b/src/ffluci/controller/admin/uci.lua @@ -1,4 +1,6 @@ module("ffluci.controller.admin.uci", package.seeall) +require("ffluci.util") +require("ffluci.sys") -- This function has a higher priority than the admin_uci/apply template function action_apply() @@ -24,7 +26,7 @@ function action_apply() for k, v in pairs(apply) do local cmd = ffluci.config.uci_oncommit[k] if cmd then - output = output .. cmd .. ":" .. ffluci.util.exec(cmd) + output = output .. cmd .. ":" .. ffluci.sys.exec(cmd) end end end diff --git a/src/ffluci/model/cbi/admin_wifi/devices.lua b/src/ffluci/model/cbi/admin_wifi/devices.lua index 7ef794c7e4..0b1b9a2ffe 100644 --- a/src/ffluci/model/cbi/admin_wifi/devices.lua +++ b/src/ffluci/model/cbi/admin_wifi/devices.lua @@ -1,5 +1,4 @@ -- ToDo: Translate, Add descriptions and help texts -require("ffluci.util") m = Map("wireless", "Geräte") @@ -16,8 +15,9 @@ t:value("atheros") t:value("mac80211") t:value("prism2") --[[ +require("ffluci.sys") local c = ". /etc/functions.sh;for i in /lib/wifi/*;do . $i;done;echo $DRIVERS" -for driver in ffluci.util.execl(c)[1]:gmatch("[^ ]+") do +for driver in ffluci.sys.execl(c)[1]:gmatch("[^ ]+") do t:value(driver) end ]]-- diff --git a/src/ffluci/model/ipkg.lua b/src/ffluci/model/ipkg.lua new file mode 100644 index 0000000000..a0ca8a8273 --- /dev/null +++ b/src/ffluci/model/ipkg.lua @@ -0,0 +1,29 @@ +--[[ +FFLuCI - IPKG wrapper library + +Description: +Wrapper for the ipkg Package manager + +Any return value of false or nil can be interpreted as an error + +FileId: +$Id$ + +License: +Copyright 2008 Steven Barth <steven@midlink.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +]]-- +module("ffluci.model.ipkg", package.seeall) +require("ffluci.sys") diff --git a/src/ffluci/model/uci.lua b/src/ffluci/model/uci.lua index 6585c66cb4..94a385c7e1 100644 --- a/src/ffluci/model/uci.lua +++ b/src/ffluci/model/uci.lua @@ -32,6 +32,7 @@ limitations under the License. module("ffluci.model.uci", package.seeall) require("ffluci.util") require("ffluci.fs") +require("ffluci.sys") -- The OS uci command ucicmd = "uci" @@ -135,7 +136,7 @@ end -- Internal functions -- function Session._uci(self, cmd) - local res = ffluci.util.exec(self.ucicmd .. " 2>/dev/null " .. cmd) + local res = ffluci.sys.exec(self.ucicmd .. " 2>/dev/null " .. cmd) if res:len() == 0 then return nil @@ -145,7 +146,7 @@ function Session._uci(self, cmd) end function Session._uci2(self, cmd) - local res = ffluci.util.exec(self.ucicmd .. " 2>&1 " .. cmd) + local res = ffluci.sys.exec(self.ucicmd .. " 2>&1 " .. cmd) if res:len() > 0 then return false, res @@ -155,7 +156,7 @@ function Session._uci2(self, cmd) end function Session._uci3(self, cmd) - local res = ffluci.util.execl(self.ucicmd .. " 2>&1 " .. cmd) + local res = ffluci.sys.execl(self.ucicmd .. " 2>&1 " .. cmd) if res[1]:sub(1, ucicmd:len() + 1) == ucicmd .. ":" then return nil, res[1] end diff --git a/src/ffluci/sys.lua b/src/ffluci/sys.lua index 532324d4bd..367d41e8c1 100644 --- a/src/ffluci/sys.lua +++ b/src/ffluci/sys.lua @@ -27,6 +27,31 @@ limitations under the License. module("ffluci.sys", package.seeall) require("posix") +-- Runs "command" and returns its output +function exec(command) + local pp = io.popen(command) + local data = pp:read("*a") + pp:close() + + return data +end + +-- Runs "command" and returns its output as a array of 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 + -- Returns the hostname function hostname() return io.lines("/proc/sys/kernel/hostname")() diff --git a/src/ffluci/util.lua b/src/ffluci/util.lua index c47a89895d..54ee071ef7 100644 --- a/src/ffluci/util.lua +++ b/src/ffluci/util.lua @@ -103,33 +103,6 @@ function escape(s, c) end --- Runs "command" and returns its output -function exec(command) - local pp = io.popen(command) - local data = pp:read("*a") - pp:close() - - return data -end - - --- Runs "command" and returns its output as a array of 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 - - -- Populate obj in the scope of f as key function extfenv(f, key, obj) local scope = getfenv(f) |