From 7b5422d3943e6243d3b48da4f24cc024c01e49bb Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Thu, 24 Jan 2008 16:48:28 +0000 Subject: Fixed so that acf doesnt brake if the confi-file is missing or is empty git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@641 ab2d0c66-481e-0410-8bed-d214d4d58bed --- syslog-config-html.lsp | 2 +- syslog-controller.lua | 12 ++++++++++-- syslog-model.lua | 23 +++++++++++++++++------ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/syslog-config-html.lsp b/syslog-config-html.lsp index 1167751..6c1d6c3 100644 --- a/syslog-config-html.lsp +++ b/syslog-config-html.lsp @@ -67,7 +67,7 @@

Remote logging

Activate remote logging
-
/> +
/> ",view.errors["SYSLOGD_OPTS"]["-R"] ,"

") end ?> diff --git a/syslog-controller.lua b/syslog-controller.lua index 288ae7b..77cd0ab 100644 --- a/syslog-controller.lua +++ b/syslog-controller.lua @@ -1,9 +1,17 @@ module(..., package.seeall) -mvc = {} -function mvc.on_load(self) +local list_redir = function (self) + self.conf.action = "status" + self.conf.type = "redir" + error (self.conf) end +mvc = {} +mvc.on_load = function(self, parent) + if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then + self.worker[self.conf.action] = list_redir(self) + end +end function status(self) return { status=self.model.getstatus() } diff --git a/syslog-model.lua b/syslog-model.lua index 1d402d3..6fa4bce 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -6,6 +6,7 @@ require("getopts") require("format") local configfile = "/etc/conf.d/syslog" +local config = {} local function get_version() local cmd = "/sbin/apk_version -v -s busybox | cut -d ' ' -f 1" @@ -30,10 +31,10 @@ function getstatus() local status = {} status.version = get_version() status.enabled = procps.pidof("syslogd") - if not ((opts["SYSLOGD_OPTS"]["-R"] ~= "") and not (opts["SYSLOGD_OPTS"]["-L"])) then + if (opts["SYSLOGD_OPTS"]) and not ((opts["SYSLOGD_OPTS"]["-R"] ~= "") and not (opts["SYSLOGD_OPTS"]["-L"])) then status.logfile = opts["SYSLOGD_OPTS"]["-O"] end - if (opts["SYSLOGD_OPTS"]["-R"]) and (opts["SYSLOGD_OPTS"]["-R"] ~= "") then + if (opts["SYSLOGD_OPTS"]) and (opts["SYSLOGD_OPTS"]["-R"]) and (opts["SYSLOGD_OPTS"]["-R"] ~= "") then status.remote = opts["SYSLOGD_OPTS"]["-R"] end return status @@ -42,25 +43,35 @@ end function get_filedetails() local filedetails = {} local path = configfile - filedetails.details = fs.stat(path) - filedetails.content = fs.read_file(path) + if (fs.is_file(path)) then + filedetails.details = fs.stat(path) + filedetails.content = fs.read_file(path) + else + filedetails.details = {path="File is missing", size="0",mtime=""} + filedetails.content = "" + end return filedetails end function getconfig() local errors = {} errors["SYSLOGD_OPTS"] = {} errors["KLOGD_OPTS"] = {} - local config = getopts.getoptsfromfile(configfile) + if (fs.is_file(configfile)) then + config = getopts.getoptsfromfile(configfile) + else + config['SYSLOGD_OPTS']={} + end config["SYSLOGD_OPTS"]["-O"] = config["SYSLOGD_OPTS"]["-O"] or "/var/log/messages" config["SYSLOGD_OPTS"]["-l_list"] = getloglevels() config["SYSLOGD_OPTS"]["-R"] = config["SYSLOGD_OPTS"]["-R"] or "" + config["SYSLOGD_OPTS"]["-s"] = config["SYSLOGD_OPTS"]["-s"] or "" + config["SYSLOGD_OPTS"]["-b"] = config["SYSLOGD_OPTS"]["-b"] or "" if (config["SYSLOGD_OPTS"]["-l"]) and ((tonumber(config["SYSLOGD_OPTS"]["-l"]) == nil) or (tonumber(config["SYSLOGD_OPTS"]["-l"]) > 8)) then errors["SYSLOGD_OPTS"]["-l"] = "Log value is out of range. Please select one of the above." else config["SYSLOGD_OPTS"]["-l"] = config["SYSLOGD_OPTS"]["-l"] or 8 end - return config, errors end -- cgit v1.2.3