From dba7285654a0e2b918c203c200bc0ebd75482f59 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 5 Jul 2008 13:19:26 +0000 Subject: Modified dnscache to use controllerfunctions, modelfunctions, and common lsp files. git-svn-id: svn://svn.alpinelinux.org/acf/dnscache/trunk@1282 ab2d0c66-481e-0410-8bed-d214d4d58bed --- dnscache-model.lua | 72 ++++++++++-------------------------------------------- 1 file changed, 13 insertions(+), 59 deletions(-) (limited to 'dnscache-model.lua') diff --git a/dnscache-model.lua b/dnscache-model.lua index 157bccb..a756c5d 100644 --- a/dnscache-model.lua +++ b/dnscache-model.lua @@ -1,14 +1,12 @@ module(..., package.seeall) -- Load libraries +require("modelfunctions") require("fs") -require("procps") require("getopts") require("format") require("posix") -require("daemoncontrol") require("validator") -require("processinfo") -- Set variables local configfile = "/etc/conf.d/dnscache" @@ -21,15 +19,6 @@ local descr = { -- ################################################################################ -- LOCAL FUNCTIONS -local function process_status_text(procname) - local t = procps.pidof(procname) - if (t) and (#t > 0) then - return "Enabled" - else - return "Disabled" - end -end - local function validateconfig(config) local success = true if config.value.IPSEND and not validator.is_ipv4(config.value.IPSEND.value) then @@ -47,22 +36,6 @@ local function validateconfig(config) return success, config end -local function getfiledetails(file) - local filename = cfe({ value=file, label="File name" }) - local filecontent = cfe({ type="longtext", label="File content" }) - local filesize = cfe({ value="0", label="File size" }) - local mtime = cfe({ value="---", label="File date" }) - if fs.is_file(file) then - local filedetails = fs.stat(file) - filecontent.value = fs.read_file(file) - filesize.value = filedetails.size - mtime.value = filedetails.mtime - else - filename.errtxt = "File not found" - end - return cfe({ type="group", value={filename=filename, filecontent=filecontent, filesize=filesize, mtime=mtime}, label="Config file details" }) -end - local function validatedomain(domain) local success = false local domains = getDomains() @@ -88,34 +61,11 @@ end -- PUBLIC FUNCTIONS function startstop_service(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" }) + return modelfunctions.startstop_service(processname, action) end function getstatus() - local status = {} - - local value, errtxt = processinfo.package_version(packagename) - status.version = cfe({ - label="Program version", - value=value, - errtxt=errtxt, - }) - - status.status = cfe({ - label="Program status", - value=process_status_text(processname), - }) - - local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname) - status.autostart = cfe({ - label="Autostart sequence", - value=autostart_sequense, - errtxt=autostart_errtxt, - }) - - return cfe({ type="group", value=status, label="DNS Cache Status" }) + return modelfunctions.getstatus(processname, packagename, "DNS Cache Status") end function getconfig() @@ -152,18 +102,22 @@ function setconfig(config) end function getconfigfile() - local config = getfiledetails(configfile) + local config = modelfunctions.getfiledetails(configfile) + + -- Validate + return config end -function setconfigfile(modifications) - local configcontent = string.gsub(format.dostounix(modifications), "\n*$", "") - local config +function setconfigfile(config) + local configcontent = string.gsub(format.dostounix(config.value.filecontent.value), "\n*$", "") + + -- Validate + if fs.is_file(configfile) then fs.write_file(configfile, configcontent) - config = getfile(configfile) + config = modelfunctions.getfiledetails(configfile) else - config = getfile(configfile) config.value.filecontent.value = configcontent config.errtxt = "Failed to set config" end -- cgit v1.2.3