diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-07-08 13:27:06 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-07-08 13:27:06 +0000 |
commit | d6eaceb7368639a4d634b06b2e1f09498c81e1e4 (patch) | |
tree | a8b6c9286c95eeb331620b83842a9e186d90dd70 /tinydns-model.lua | |
parent | 450023d50615816c7db2d4abfaface18132a1c47 (diff) | |
download | acf-tinydns-d6eaceb7368639a4d634b06b2e1f09498c81e1e4.tar.bz2 acf-tinydns-d6eaceb7368639a4d634b06b2e1f09498c81e1e4.tar.xz |
Modified tinydns to use controllerfunctions, modelfunctions, common lsp files, and new view without action functionality.
git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@1290 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'tinydns-model.lua')
-rw-r--r-- | tinydns-model.lua | 100 |
1 files changed, 21 insertions, 79 deletions
diff --git a/tinydns-model.lua b/tinydns-model.lua index 43bf8ea..193af6e 100644 --- a/tinydns-model.lua +++ b/tinydns-model.lua @@ -1,12 +1,10 @@ module(..., package.seeall) -- Load libraries -require("procps") +require("modelfunctions") require("getopts") require("fs") require("format") -require("processinfo") -require("daemoncontrol") require("validator") -- Set variables @@ -118,55 +116,29 @@ 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(processname, action) end -- Present some general status function getstatus() - local status = {} + local status = modelfunctions.getstatus(processname, packagename, "TinyDNS 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=procps.pidof(processname), - }) - if (#status.status.value > 0) then - status.status.value = "Enabled" - else - status.status.value = "Disabled" - end - - status.configdir = cfe({ + status.value.configdir = cfe({ label="Config directory", value=configdir, }) - status.configfiles = cfe({ + status.value.configfiles = cfe({ type="list", label="Config files", value=configfiles, }) - local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname) - status.autostart = cfe({ - label="Autostart sequence", - value=autostart_sequense, - errtxt=autostart_errtxt, - }) - local config = getconfig() - status.listen = config.value.listen + status.value.listen = config.value.listen - return cfe({ type="group", value=status, label="DNS Status" }) + return status end function getconfig() @@ -277,51 +249,21 @@ function getfilelist () end function get_filedetails(path) - local file = {} - local filedetails = {} - local filenameerrtxt - if (path) and (fs.is_file(path)) then - filedetails = fs.stat(path) - else - filenameerrtxt="Config file '".. tostring(path) .. "' is missing!" - end - - file["filename"] = cfe({ - label="File name", - value=path, - errtxt=filenameerrtxt - }) - 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(path) end -function updatefilecontent (path, modifications) - local success = false - local errtxt - if not (fs.is_file(path)) then - errtxt = "Not a filename" - elseif (validfilename(path)) then - modifications = string.gsub(format.dostounix(modifications), "\n*$", "") - fs.write_file(path, modifications) - success = true +function set_filedetails (filedetails) + filedetails.value.filecontent.value = string.gsub(format.dostounix(filedetails.value.filecontent.value), "\n+$", "") + local success, errtxt = validfilename(filedetails.value.filename.value) + if success then + fs.write_file(filedetails.value.filename.value, filedetails.value.filecontent.value) + filedetails = get_filedetails(filedetails.value.filename.value) else - errtxt = "Not a valid filename!" + filedetails.value.filename.errtxt = errtxt + filedetails.errtxt = "Failed to set config file" end - return cfe({ type="boolean", value=success, label="Update file result", errtxt=errtxt }) + return filedetails end function getnewconfigfile() @@ -350,7 +292,7 @@ function createconfigfile(configfile) end function remove_file(path) - local success = false + local success = "Failed to delete file" local errtxt if not (fs.is_file(path)) then errtxt = "File doesn't exist!" @@ -358,9 +300,9 @@ function remove_file(path) local cmd, errors = io.popen( "/bin/rm " .. path, r ) local cmdoutput = cmd:read("*a") cmd:close() - success = true + success = "File Deleted" else errtxt = "Not a valid filename!" end - return cfe({ type="boolean", value=success, label="Delete config file result", errtxt=errtxt }) + return cfe({ value=success, label="Delete config file result", errtxt=errtxt }) end |