diff options
author | Ted Trask <ttrask01@yahoo.com> | 2012-05-02 15:02:43 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2012-05-02 15:19:01 +0000 |
commit | c27539b794af5181fb8894f7953b5afe03f55cae (patch) | |
tree | ce7406efefd799de8f6076c8b7f9f0f62e5b0c4e | |
parent | 92da5f880fdfc1386bae4f8fb0e8bc9d948b422a (diff) | |
download | acf-alpine-conf-c27539b794af5181fb8894f7953b5afe03f55cae.tar.bz2 acf-alpine-conf-c27539b794af5181fb8894f7953b5afe03f55cae.tar.xz |
Modified include / exclude to use lbu commands rather than directly access the files
(cherry picked from commit 00683234ac99e50f9c5e8e3612388bcf2e13759e)
-rw-r--r-- | lbu-model.lua | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/lbu-model.lua b/lbu-model.lua index 24e1aa4..1022e32 100644 --- a/lbu-model.lua +++ b/lbu-model.lua @@ -9,8 +9,6 @@ validator = require("acf.validator") -- Set variables local configfile = "/etc/lbu/lbu.conf" -local includefile = "/etc/lbu/include" -local excludefile = "/etc/lbu/exclude" -- ################################################################################ -- LOCAL FUNCTIONS @@ -93,19 +91,6 @@ local function getciphers() return opensslciphers end -local function getincexl(state) - local incexl = {} - if (string.lower(state) == "include") or (string.lower(state) == "exclude") then - local f = io.popen("PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin lbu " .. string.lower(state) .. " -l 2>&1", "r") - if not (f) then return incexl end - for line in f:lines() do - table.insert(incexl,tostring(line)) - end - f:close() - end - return incexl -end - local function validateconfig(config) -- Set errormessages when configs are wrong config.value.LBU_MEDIA.errtxt = "Invalid Media" @@ -324,12 +309,16 @@ end function getincluded () local included = cfe({ - value=fs.read_file(includefile) or "", label="Included item(s)", type="longtext", descr="List one file/directory per line\nAssumes root directory, no leading '/' necessary", }) - + + -- Read the list + local f = io.popen("PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin lbu include -l") + included.value = f:read("*a") or "" + f:close() + validatefilelist(included) return cfe({ type="group", value={included = included} }) @@ -338,7 +327,12 @@ end function setincluded (self, included) validatefilelist(included.value.included) if not included.value.included.errtxt then - fs.write_file(includefile, included.value.included.value) + local f = io.popen("PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin lbu include -l | xargs /sbin/lbu include -r 2>&1") + f:close() + local cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin lbu include "..string.gsub(included.value.included.value, "[%s%c]+", " ") + f = io.popen(cmd) + included.descr = f:read("*a") + f:close() else included.errtxt = "Failed to set included" end @@ -347,12 +341,16 @@ end function getexcluded () local excluded = cfe({ - value=fs.read_file(excludefile) or "", label="Excluded item(s)", type="longtext", descr="List one file/directory per line\nAssumes root directory, no leading '/' necessary", }) + -- Read the list + local f = io.popen("PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin lbu exclude -l") + excluded.value = f:read("*a") or "" + f:close() + validatefilelist(excluded) return cfe({ type="group", value={excluded = excluded} }) @@ -361,7 +359,12 @@ end function setexcluded (self, excluded) validatefilelist(excluded.value.excluded) if not excluded.value.excluded.errtxt then - fs.write_file(excludefile, excluded.value.excluded.value) + local f = io.popen("PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin lbu exclude -l | xargs /sbin/lbu exclude -r 2>&1") + f:close() + local cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin lbu exclude "..string.gsub(excluded.value.excluded.value, "[%s%c]+", " ") + f = io.popen(cmd) + excluded.descr = f:read("*a") + f:close() else excluded.errtxt = "Failed to set excluded" end |