From 9fcda9ad78f8c42ed291c10e8bfea3e3000c30a3 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 4 Jul 2008 13:35:07 +0000 Subject: Modified syslog to use controllerfunctions, modelfunctions, and common lsp files. Changed status->loginfo and basicstatus->status. Stopped expert from adding blank lines to the end. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1274 ab2d0c66-481e-0410-8bed-d214d4d58bed --- syslog-model.lua | 61 +++++++++++++++----------------------------------------- 1 file changed, 16 insertions(+), 45 deletions(-) (limited to 'syslog-model.lua') diff --git a/syslog-model.lua b/syslog-model.lua index 3d50031..273cc27 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -1,14 +1,14 @@ module(..., package.seeall) +require("modelfunctions") require("fs") -require("procps") require("getopts") require("format") -require("daemoncontrol") require("validator") local configfile = "/etc/conf.d/syslog" -local processname = "syslog" +local processinitname = "syslog" +local processname = "syslogd" local function get_version() local cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin apk_version -v -s busybox | cut -d ' ' -f 1" @@ -136,10 +136,8 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS -function startstop_service ( self, action ) - -- action is validated in daemoncontrol - local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, action) - return cfe({ type="boolean", value=cmdresult, descr=cmdmessage, errtxt=cmderror, label="Start/Stop result" }) +function startstop_service(action) + return modelfunctions.startstop_service(processinitname, action) end function getversion() @@ -150,16 +148,7 @@ function getversion() end function getstatus() - local status = cfe({ - label="Program status", - value=procps.pidof("syslogd"), - }) - if (#status.value > 0) then - status.value = "Enabled" - else - status.value = "Disabled" - end - return status + return modelfunctions.getenabled(processname) end function getlogging() @@ -182,29 +171,7 @@ function getlogging() end function get_filedetails() - local path = configfile - local filedetails = fs.stat(path) - local config = getconfig(path) - local file = {} - file["filename"] = cfe({ - label="File name", - value=path, - }) - file["filesize"] = cfe({ - label="File size", - value=filedetails.size or "0", - }) - file["mtime"] = cfe({ - label="File date", - value=filedetails.mtime or "---", - }) - file["filecontent"] = cfe({ - type="longtext", - label="File content", - value=fs.read_file(path), - }) - - return cfe({ type="group", value=file, label="Config file details" }) + return modelfunctions.getfiledetails(configfile) end function getconfig() @@ -233,14 +200,17 @@ function updateconfig (config) return config end -function update_filecontent (modifications) +function update_filedetails (filedetails) -- Validation before writing - local configcontent = getopts.getoptsfromfile(format.dostounix(modifications), "", "SYSLOGD_OPTS", true) or {} + filedetails.value.filecontent.value = format.dostounix(filedetails.value.filecontent.value) + filedetails.value.filecontent.value = filedetails.value.filecontent.value:gsub("\n+$", "") + local configcontent = getopts.getoptsfromfile(filedetails.value.filecontent.value, "", "SYSLOGD_OPTS", true) or {} local config = makeconfig(configcontent) local success, errtxt success, config = validateconfig(config) if success == true then - fs.write_file(configfile, format.dostounix(modifications)) + fs.write_file(configfile, filedetails.value.filecontent.value) + filedetails = get_filedetails() else local errormessages = {} for x,y in pairs(config.value) do @@ -248,8 +218,9 @@ function update_filecontent (modifications) errormessages[#errormessages + 1] = y.label .. " - " .. y.errtxt end end - errtxt = table.concat(errormessages, "\n") + filedetails.value.filecontent.errtxt = table.concat(errormessages, "\n") + filedetials.errtxt = "Failed to set configuration" end - return cfe({ type="boolean", value=success, errtxt=errtxt, label="Update filecontent result" }) + return filedetails end -- cgit v1.2.3