diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-07-05 13:19:26 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-07-05 13:19:26 +0000 |
commit | dba7285654a0e2b918c203c200bc0ebd75482f59 (patch) | |
tree | 3e903dd228ce54de4f94933420702f4c53a8f175 | |
parent | 49a7dc03a16343f7c4abfba998866a8a6abffae7 (diff) | |
download | acf-dnscache-dba7285654a0e2b918c203c200bc0ebd75482f59.tar.bz2 acf-dnscache-dba7285654a0e2b918c203c200bc0ebd75482f59.tar.xz |
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
-rw-r--r-- | dnscache-config-html.lsp | 3 | ||||
-rw-r--r-- | dnscache-controller.lua | 85 | ||||
l---------[-rw-r--r--] | dnscache-createdomain-html.lsp | 18 | ||||
-rw-r--r-- | dnscache-editdomain-html.lsp | 3 | ||||
l---------[-rw-r--r--] | dnscache-editips-html.lsp | 16 | ||||
l---------[-rw-r--r--] | dnscache-expert-html.lsp | 51 | ||||
-rw-r--r-- | dnscache-listdomains-html.lsp | 4 | ||||
-rw-r--r-- | dnscache-model.lua | 72 | ||||
l---------[-rw-r--r--] | dnscache-startstop-html.lsp | 27 | ||||
l---------[-rw-r--r--] | dnscache-status-html.lsp | 20 |
10 files changed, 34 insertions, 265 deletions
diff --git a/dnscache-config-html.lsp b/dnscache-config-html.lsp index d1e414d..d079d72 100644 --- a/dnscache-config-html.lsp +++ b/dnscache-config-html.lsp @@ -1,4 +1,4 @@ -<? local form, viewlibrary = ... +<? local form, viewlibrary, page_info = ... require("viewfunctions") ?> <? @@ -15,6 +15,7 @@ end ?> <H1>Config</H1> <? + form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action displayform(form) ?> diff --git a/dnscache-controller.lua b/dnscache-controller.lua index d50fb63..bed2356 100644 --- a/dnscache-controller.lua +++ b/dnscache-controller.lua @@ -1,40 +1,7 @@ module(..., package.seeall) -- Load libraries -require("format") - -local function handle_form(getFunction, setFunction, clientdata, option, label, descr) - local form = getFunction() - - if clientdata[option] then - form.errtxt = nil - for name,value in pairs(form.value) do - value.errtxt = nil - if value.type == "boolean" then - value.value = (clientdata[name] ~= nil) - elseif value.type == "list" then - value.value = {} - if clientdata[name] and clientdata[name] ~= "" then - for ip in string.gmatch(clientdata[name].."\n", "%s*(%S[^\n]*%S)%s*\n") do - table.insert(value.value, ip) - end - end - else - value.value = clientdata[name] or value.value - end - end - form = setFunction(form) - if not form.errtxt then - form.descr = descr - end - end - - form.type = "form" - form.option = option - form.label = label - - return form -end +require("controllerfunctions") default_action = "status" @@ -43,47 +10,19 @@ function status(self) end function startstop(self) - local result - if self.clientdata.action then - result = self.model.startstop_service(self.clientdata.action) - self.sessiondata.dnscachestartstopresult = result - self.redirect_to_referrer(self) - end - - local status = self.model.getstatus() - status = status.value.status - if self.sessiondata.dnscachestartstopresult then - result = self.sessiondata.dnscachestartstopresult - self.sessiondata.dnscachestartstopresult = nil - end - - return cfe({ type="group", value={status=status, result=result} }) + return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata) end function config(self) - return handle_form(self.model.getconfig, self.model.setconfig, self.clientdata, "Save", "Edit Config", "Configuration Set") + return controllerfunctions.handle_form(self, self.model.getconfig, self.model.setconfig, self.clientdata, "Save", "Edit Config", "Configuration Set") end function expert(self) - local filedetails - if self.clientdata.Save then - filedetails = self.model.setconfigfile(self.clientdata.filecontent) - if not filedetails.errtxt then - filedetails.descr = "Config file set" - end - else - filedetails = self.model.getconfigfile() - end - - filedetails.type = "form" - filedetails.option = "Save" - filedetails.label = "Set config file" - - return filedetails + return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config File", "Configuration File Set") end function editips(self) - return handle_form(self.model.getIPs, self.model.setIPs, self.clientdata, "Save", "Edit IP List", "IP List Set") + return controllerfunctions.handle_form(self, self.model.getIPs, self.model.setIPs, self.clientdata, "Save", "Edit IP List", "IP List Set") end function listdomains(self) @@ -91,20 +30,14 @@ function listdomains(self) end function createdomain(self) - local cmdresult = handle_form(self.model.getNewDomain, self.model.setNewDomain, self.clientdata, "Create", "Create new domain", "New domain created") - if cmdresult.descr then - redirect_to_referrer(self) - end - return cmdresult + return controllerfunctions.handle_form(self, self.model.getNewDomain, self.model.setNewDomain, self.clientdata, "Create", "Create New Domain", "New Domain Created") end function editdomain(self) - return handle_form(function(form) return self.model.getDomain(self.clientdata.domain) end, - self.model.setDomain, self.clientdata, "Save", "Edit domain entry", "Domain saved") + return controllerfunctions.handle_form(self, function(form) return self.model.getDomain(self.clientdata.domain) end, + self.model.setDomain, self.clientdata, "Save", "Edit Domain Entry", "Domain Saved") end function deletedomain(self) - local cmdresult = self.model.deleteDomain(self.clientdata.domain) - redirect_to_referrer(self) - return cmdresult + return self:redirect_to_referrer(self.model.deleteDomain(self.clientdata.domain)) end diff --git a/dnscache-createdomain-html.lsp b/dnscache-createdomain-html.lsp index 4347fc0..4b6b762 100644..120000 --- a/dnscache-createdomain-html.lsp +++ b/dnscache-createdomain-html.lsp @@ -1,17 +1 @@ -<? local form, viewlibrary = ... -require("viewfunctions") -?> -<? ---[[ DEBUG INFORMATION -io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") -io.write(html.cfe_unpack(form)) -io.write("</span>") ---]] -?> - -<H1><?= form.label ?></H1> -<? - form.action = "createdomain" - local order = { } - displayform(form, order) -?> +../form-html.lsp
\ No newline at end of file diff --git a/dnscache-editdomain-html.lsp b/dnscache-editdomain-html.lsp index 34ba902..e04fd66 100644 --- a/dnscache-editdomain-html.lsp +++ b/dnscache-editdomain-html.lsp @@ -1,4 +1,4 @@ -<? local form, viewlibrary = ... +<? local form, viewlibrary, page_info = ... require("viewfunctions") ?> <? @@ -11,6 +11,7 @@ io.write("</span>") <H1><?= form.label ?></H1> <? + form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action form.value.domain.contenteditable = false local order = { "domain", "iplist" } displayform(form, order) diff --git a/dnscache-editips-html.lsp b/dnscache-editips-html.lsp index b88e2c4..4b6b762 100644..120000 --- a/dnscache-editips-html.lsp +++ b/dnscache-editips-html.lsp @@ -1,15 +1 @@ -<? local form, viewlibrary = ... -require("viewfunctions") -?> -<? ---[[ DEBUG INFORMATION -io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") -io.write(html.cfe_unpack(form)) -io.write("</span>") ---]] -?> - -<H1><?= form.label ?></H1> -<? - displayform(form) -?> +../form-html.lsp
\ No newline at end of file diff --git a/dnscache-expert-html.lsp b/dnscache-expert-html.lsp index c4ad955..207f324 100644..120000 --- a/dnscache-expert-html.lsp +++ b/dnscache-expert-html.lsp @@ -1,50 +1 @@ -<? local form, viewlibrary = ... ?> -<? require("viewfunctions") ?> -<? ---[[ DEBUG INFORMATION -io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") -io.write(html.cfe_unpack(form)) -io.write("</span>") ---]] -?> - -<? ---[[ ?> -<? if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("status") -end ?> -<? --]] ?> - -<H1>Configuration</H1> -<H2>Expert Configuration</H2> -<H3>File Details</H3> -<DL> -<? -displayitem(form.value.filename) -displayitem(form.value.filesize) -displayitem(form.value.mtime) -?> -</DL> - -<H3>File Content</H3> -<? if form.descr then ?><P CLASS='descr'><?= string.gsub(form.descr, "\n", "<BR>") ?></P><? end ?> -<? if form.errtxt then ?><P CLASS='error'><?= string.gsub(form.errtxt, "\n", "<BR>") ?></P><? end ?> -<form action="" method="POST"> -<textarea name="filecontent"> -<?= form.value.filecontent.value ?> -</textarea> -<? if form.value.filecontent.errtxt then ?><P CLASS='error'><?= string.gsub(form.value.filecontent.errtxt, "\n", "<BR>") ?></P><? end ?> - -<DL><DT></DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="Save"></DD></DL> -</form> - -<? if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("startstop") -end ?> - -<? ---[[ DEBUG INFORMATION -io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") -io.write(html.cfe_unpack(form)) -io.write("</span>") ---]] -?> +../expert-html.lsp
\ No newline at end of file diff --git a/dnscache-listdomains-html.lsp b/dnscache-listdomains-html.lsp index 9c7ba20..5e4517b 100644 --- a/dnscache-listdomains-html.lsp +++ b/dnscache-listdomains-html.lsp @@ -1,4 +1,4 @@ -<? local data, viewlibrary = ... +<? local data, viewlibrary, page_info, session = ... require("viewfunctions") ?> <? @@ -9,6 +9,8 @@ io.write("</span>") --]] ?> +<? displaycommandresults({"deletedomain"}, session) ?> + <h1>Configuration</h1> <h2>Edit/View DNS server entries</h2> <TABLE> 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 diff --git a/dnscache-startstop-html.lsp b/dnscache-startstop-html.lsp index f963d3b..0ea2627 100644..120000 --- a/dnscache-startstop-html.lsp +++ b/dnscache-startstop-html.lsp @@ -1,26 +1 @@ -<? local data = ... ?> -<? --[[ -io.write(html.cfe_unpack(data)) ---]] ?> - -<H1>Management</H1> -<DL> -<form action="startstop" method="POST"> -<DT>Program control-panel</DT> -<DD> -<input class="submit" type="submit" name="action" value="Start" <? if data.value.status.value== "Enabled" then io.write("disabled") end ?>> -<input class="submit" type="submit" name="action" value="Stop" <? if data.value.status.value== "Disabled" then io.write("disabled") end ?>> -<input class="submit" type="submit" name="action" value="Restart" <? if data.value.status.value== "Disabled" then io.write("disabled") end ?>> -</DD> -</form> - -<? if data.value.result then ?> -<DT>Previous action result</DT> -<DD> -<? if data.value.result.descr then ?> -<P CLASS='descr'><?= string.gsub(data.value.result.descr, "\n", "<BR>") ?></P> -<? end if data.value.result.errtxt then ?> -<P CLASS='error'><?= string.gsub(data.value.result.errtxt, "\n", "<BR>") ?></P> -<? end end ?> -</DD> -</DL> +../startstop-html.lsp
\ No newline at end of file diff --git a/dnscache-status-html.lsp b/dnscache-status-html.lsp index 05b4a7a..b2f8480 100644..120000 --- a/dnscache-status-html.lsp +++ b/dnscache-status-html.lsp @@ -1,19 +1 @@ -<? local data = ... -require("viewfunctions") -?> -<? ---[[ DEBUG INFORMATION -io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") -io.write(html.cfe_unpack(data)) -io.write("</span>") ---]] -?> - -<H1>System Info</H1> -<DL> -<? -displayitem(data.value.status) -displayitem(data.value.version) -displayitem(data.value.autostart) -?> -</DL> +../status-html.lsp
\ No newline at end of file |