From 3d69b32a0b152ddbc90d272fb970a3e4781763b9 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 2 Nov 2015 14:09:42 +0000 Subject: Modify logfile to get logging info from the config and use common view --- unbound-controller.lua | 2 +- unbound-logfile-html.lsp | 9 +-------- unbound-model.lua | 37 ++++++++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 20 deletions(-) mode change 100644 => 120000 unbound-logfile-html.lsp diff --git a/unbound-controller.lua b/unbound-controller.lua index cca194e..46b38c9 100644 --- a/unbound-controller.lua +++ b/unbound-controller.lua @@ -15,7 +15,7 @@ function mymodule.expert(self) end function mymodule.logfile(self) - return self.model.get_logfile() + return self.model.get_logfile(self, self.clientdata) end return mymodule diff --git a/unbound-logfile-html.lsp b/unbound-logfile-html.lsp deleted file mode 100644 index d718396..0000000 --- a/unbound-logfile-html.lsp +++ /dev/null @@ -1,8 +0,0 @@ -<% 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 %> diff --git a/unbound-logfile-html.lsp b/unbound-logfile-html.lsp new file mode 120000 index 0000000..ac8854f --- /dev/null +++ b/unbound-logfile-html.lsp @@ -0,0 +1 @@ +../logfile-html.lsp \ No newline at end of file diff --git a/unbound-model.lua b/unbound-model.lua index 1743f72..49295ac 100644 --- a/unbound-model.lua +++ b/unbound-model.lua @@ -15,6 +15,24 @@ local config -- ################################################################################ -- LOCAL FUNCTIONS +local parseconfig = function() + if config then return config end + local temp = format.parse_linesandwords(fs.read_file(configfile) or "", "#") + config = {} + local cur = config + for i,line in ipairs(temp) do + local attr = string.match(line[1], "(.*):") + if #line == 1 then + config[attr] = {} + cur = config[attr] + else + table.remove(line, 1) + cur[attr] = table.concat(line, " ") + end + end + return config +end + -- ################################################################################ -- PUBLIC FUNCTIONS @@ -39,19 +57,16 @@ function mymodule.update_filedetails(self, filedetails) end function mymodule.get_logfile(f) + local retval = cfe({ type="structure", value={}, label="Unbound Log Files" }) + config = config or parseconfig() -- Determine the log file from the config file - -- TODO determine how best to parse the file ---[[ - config = config or format.parse_ini_file(fs.read_file(configfile) or "", "") - local files = {} - if config and config.logfile then - files[#files+1] = {path = config.logfile} - end ---]] - if 0 == #files then - files[#files+1] = {path = "/var/log/messages", grep = "unbound"} + if config.server and config.server.logfile and config.server.logfile ~= "" then + retval.value[#retval.value+1] = {filename=config.server.logfile} + else + -- report syslog even if use-syslog == "no" + retval.value[#retval.value+1] = {facility="daemon", grep="unbound"} end - return cfe({ value=files, label="Unbound Log Files" }) + return retval end return mymodule -- cgit v1.2.3