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-config-html.lsp | 3 +- dnscache-controller.lua | 85 +++++------------------------------------- dnscache-createdomain-html.lsp | 18 +-------- dnscache-editdomain-html.lsp | 3 +- dnscache-editips-html.lsp | 16 +------- dnscache-expert-html.lsp | 51 +------------------------ dnscache-listdomains-html.lsp | 4 +- dnscache-model.lua | 72 +++++++---------------------------- dnscache-startstop-html.lsp | 27 +------------- dnscache-status-html.lsp | 20 +--------- 10 files changed, 34 insertions(+), 265 deletions(-) mode change 100644 => 120000 dnscache-createdomain-html.lsp mode change 100644 => 120000 dnscache-editips-html.lsp mode change 100644 => 120000 dnscache-expert-html.lsp mode change 100644 => 120000 dnscache-startstop-html.lsp mode change 100644 => 120000 dnscache-status-html.lsp 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 @@ -

Config

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 deleted file mode 100644 index 4347fc0..0000000 --- a/dnscache-createdomain-html.lsp +++ /dev/null @@ -1,17 +0,0 @@ - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - -

- diff --git a/dnscache-createdomain-html.lsp b/dnscache-createdomain-html.lsp new file mode 120000 index 0000000..4b6b762 --- /dev/null +++ b/dnscache-createdomain-html.lsp @@ -0,0 +1 @@ +../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 @@ - ")

-DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - -

- diff --git a/dnscache-editips-html.lsp b/dnscache-editips-html.lsp new file mode 120000 index 0000000..4b6b762 --- /dev/null +++ b/dnscache-editips-html.lsp @@ -0,0 +1 @@ +../form-html.lsp \ No newline at end of file diff --git a/dnscache-expert-html.lsp b/dnscache-expert-html.lsp deleted file mode 100644 index c4ad955..0000000 --- a/dnscache-expert-html.lsp +++ /dev/null @@ -1,50 +0,0 @@ - - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - - - - - -

Configuration

-

Expert Configuration

-

File Details

-
- -
- -

File Content

-

") ?>

-

") ?>

-
- -

") ?>

- -
-
- - - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> diff --git a/dnscache-expert-html.lsp b/dnscache-expert-html.lsp new file mode 120000 index 0000000..207f324 --- /dev/null +++ b/dnscache-expert-html.lsp @@ -0,0 +1 @@ +../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 @@ - ") --]] ?> + +

Configuration

Edit/View DNS server entries

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 deleted file mode 100644 index f963d3b..0000000 --- a/dnscache-startstop-html.lsp +++ /dev/null @@ -1,26 +0,0 @@ - - - -

Management

-
-
-
Program control-panel
-
-> -> -> -
- - - -
Previous action result
-
- -

") ?>

- -

") ?>

- -
-
diff --git a/dnscache-startstop-html.lsp b/dnscache-startstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/dnscache-startstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp \ No newline at end of file diff --git a/dnscache-status-html.lsp b/dnscache-status-html.lsp deleted file mode 100644 index 05b4a7a..0000000 --- a/dnscache-status-html.lsp +++ /dev/null @@ -1,19 +0,0 @@ - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(data)) -io.write("
") ---]] -?> - -

System Info

-
- -
diff --git a/dnscache-status-html.lsp b/dnscache-status-html.lsp new file mode 120000 index 0000000..b2f8480 --- /dev/null +++ b/dnscache-status-html.lsp @@ -0,0 +1 @@ +../status-html.lsp \ No newline at end of file -- cgit v1.2.3