diff options
-rw-r--r-- | lighttpd-controller.lua | 2 | ||||
l---------[-rw-r--r--] | lighttpd-logfile-html.lsp | 9 | ||||
-rw-r--r-- | lighttpd-model.lua | 78 |
3 files changed, 67 insertions, 22 deletions
diff --git a/lighttpd-controller.lua b/lighttpd-controller.lua index c6ff50a..c3da08f 100644 --- a/lighttpd-controller.lua +++ b/lighttpd-controller.lua @@ -19,7 +19,7 @@ function mymodule.expert(self) end function mymodule.logfile(self) - return self.model.getlogfile() + return self.model.get_logfile(self, self.clientdata) end return mymodule diff --git a/lighttpd-logfile-html.lsp b/lighttpd-logfile-html.lsp index d718396..ac8854f 100644..120000 --- a/lighttpd-logfile-html.lsp +++ b/lighttpd-logfile-html.lsp @@ -1,8 +1 @@ -<% local data, viewlibrary = ... -%> - -<% if viewlibrary and viewlibrary.dispatch_component then - for i,logfile in ipairs(data.value) do - viewlibrary.dispatch_component("alpine-baselayout/logfiles/view", {filename=logfile.path, grep=logfile.grep}) - end -end %> +../logfile-html.lsp
\ No newline at end of file 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 |