summaryrefslogtreecommitdiffstats
path: root/lighttpd-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2015-10-31 02:05:04 +0000
committerTed Trask <ttrask01@yahoo.com>2015-10-31 02:05:04 +0000
commit895eedabe3664b138a9b8ede0afeb3b1103203c8 (patch)
tree0fe404b29ce481a284d99a14bfea8d6fc2abfffc /lighttpd-model.lua
parent6cc25ba14203c8b6bcf1e070b208c16f87e68af5 (diff)
downloadacf-lighttpd-895eedabe3664b138a9b8ede0afeb3b1103203c8.tar.bz2
acf-lighttpd-895eedabe3664b138a9b8ede0afeb3b1103203c8.tar.xz
Modify logfile to get logging info from the config and use common view
Diffstat (limited to 'lighttpd-model.lua')
-rw-r--r--lighttpd-model.lua78
1 files changed, 65 insertions, 13 deletions
diff --git a/lighttpd-model.lua b/lighttpd-model.lua
index 303c980..7dd43ad 100644
--- a/lighttpd-model.lua
+++ b/lighttpd-model.lua
@@ -15,6 +15,45 @@ local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
-- ################################################################################
-- LOCAL FUNCTIONS
+local function replacetags(configtable, name, tags)
+ tags = tags or {}
+ if tags[name] then return tags[name] end
+
+ local value = configtable[name]
+ if not value or value == "" then
+ tags[name] = ""
+ return ""
+ elseif tonumber(value) then
+ tags[name] = tonumber(value)
+ return tonumber(value)
+ end
+
+ -- Split the value into fields based upon '+'
+ local fields = {}
+ local pos=1
+ while pos <= string.len(value) do
+ if string.find(value, "^%s-\"", pos) then
+ local start = string.find(value, "\"", pos)
+ local stop = string.find(value, "\"", start+1)
+ fields[#fields+1] = string.sub(value, start+1, stop-1)
+ pos = string.find(value, "[^%+%s]", stop+1) or stop+1
+ elseif string.find(value, "%+", pos) then
+ local start = string.find(value, "%S", pos)
+ local stop = string.find(value, "%s-%+", start+1)
+ local tag = string.sub(value, start, stop-1)
+ fields[#fields+1] = replacetags(configtable, tag, tags)
+ pos = string.find(value, "[^%+%s]", stop+1) or stop+1
+ else
+ local tag = string.match(value, "%S.*", pos)
+ fields[#fields+1] = replacetags(configtable, tag, tags)
+ break
+ end
+ end
+ value = table.concat(fields)
+ tags[name] = value
+ return value
+end
+
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -51,21 +90,34 @@ function mymodule.updatefiledetails(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, filelist)
end
-function mymodule.getlogfile ()
- local files = {}
- local logfilepath = format.parse_configfile(fs.read_file(filelist[1]) or "").LogFile
- if not logfilepath then
- files[#files+1] = {path = "/var/log/lighttpd/access.log"}
- else
- files[#files+1] = {path=logfilepath}
+function mymodule.get_logfile(self, clientdata)
+ --[[
+ server.errorlog pathname of the error-log
+ server.errorlog-use-syslog send errorlog to syslog
+ accesslog.use-syslog send the accesslog to syslog
+ accesslog.filename name of the file where the accesslog should be written to if syslog is not used
+ --]]
+
+ local retval = cfe({ type="structure", value={}, label="Log File Configuration" })
+ local config = format.parse_ini_file(fs.read_file(filelist[1]), "")
+ local syslogerror = replacetags(config, "server.errorlog-use-syslog")
+ local syslogaccess = replacetags(config, "accesslog.use-syslog")
+
+ if syslogerror == "enable" or syslogaccess == "enable" then
+ retval.value[#retval.value+1] = {facility="daemon", grep="lighttpd"}
end
- logfilepath = format.parse_configfile(fs.read_file(filelist[2]) or "").UpdateLogFile
- if not logfilepath then
- files[#files+1] = {path = "/var/log/lighttpd/error.log"}
- else
- files[#files+1] = {path=logfilepath}
+
+ if syslogaccess ~= "enable" then
+ local accessfile = replacetags(config, "accesslog.filename") or "/var/log/lighttpd/access.log"
+ retval.value[#retval.value+1] = {filename=accessfile}
+ end
+
+ if syslogerror ~= "enable" then
+ local errorfile = replacetags(config, "server.errorlog") or "/var/log/lighttpd/error.log"
+ retval.value[#retval.value+1] = {filename=errorfile}
end
- return cfe({ value=files, label="Lighttpd logfiles" })
+
+ return retval
end
return mymodule