diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-04-09 13:23:31 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-04-09 13:23:31 +0000 |
commit | f83a1a729f68ab79138857a884308084e23cd595 (patch) | |
tree | 2850811ad13f0ba62a22b36435d34c8377be6f46 | |
parent | 17b2b7ad8ab66c4911cff345ddcbf1594cd2418e (diff) | |
download | acf-alpine-conf-f83a1a729f68ab79138857a884308084e23cd595.tar.bz2 acf-alpine-conf-f83a1a729f68ab79138857a884308084e23cd595.tar.xz |
Cleaning up the code.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-conf/trunk@966 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | lbu-commit-html.lsp | 50 | ||||
-rw-r--r-- | lbu-config-html.lsp | 52 | ||||
-rw-r--r-- | lbu-controller.lua | 26 | ||||
-rw-r--r-- | lbu-expert-html.lsp | 44 | ||||
-rw-r--r-- | lbu-model.lua | 7 | ||||
-rw-r--r-- | lbu-status-html.lsp | 45 |
6 files changed, 60 insertions, 164 deletions
diff --git a/lbu-commit-html.lsp b/lbu-commit-html.lsp index a23b907..fdf44c6 100644 --- a/lbu-commit-html.lsp +++ b/lbu-commit-html.lsp @@ -1,4 +1,6 @@ -<? local form = ... ?> +<? local form = ... +require("viewfunctions") +?> <? --[[ DEBUG INFORMATION io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") @@ -6,67 +8,33 @@ io.write(html.cfe_unpack(form)) io.write("</span>") --]] ?> -<? -function displayinfo(myform,tags,viewonly) - io.write("<DL>") - for k,v in pairs(tags) do - if (myform[v]) and (myform[v]["value"]) then - local val = myform[v] - io.write("\t<DT") - if (#val.errtxt > 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "</DT>\n") - if (viewonly) then - io.write("\t\t<DD>" .. val.value .. "\n") - else - io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n") - end - if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end - if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end - io.write("\t\t</DD>\n") - end - end - io.write("</DL>") -end -?> <H1>SYSTEM INFO</H1> +<DL> <? local myform = form.status local tags = { "status", "version", } displayinfo(myform,tags,"viewonly") ?> +</DL> <H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2> +<DL> <? local myform = form.status local tags = { "LBU_MEDIA", "ENCRYPTION", } displayinfo(myform,tags,"viewonly") ?> +</DL> <H1>MANAGEMENT</H1> <H2>Save to media</h2> <form name="cmd" action="" method="POST"> +<DL> <? local tags = { "lbusimulate", "lbucommit", "lbucleanmedia", } displayinfo(myform,tags) ?> -</form> - -<DL> -<? if (form.cmdresult) then ?> - <dt>Result of previous action</dt> - <dd><pre><?= form.cmdresult ?></pre></DD> -<? end ?> </DL> - -<? ---[[ 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>") ---]] -?> +</form> diff --git a/lbu-config-html.lsp b/lbu-config-html.lsp index 22c1405..d9e1491 100644 --- a/lbu-config-html.lsp +++ b/lbu-config-html.lsp @@ -1,4 +1,6 @@ -<? local form = ... ?> +<? local form = ... +require("viewfunctions") +?> <? --[[ DEBUG INFORMATION io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") @@ -6,80 +8,58 @@ io.write(html.cfe_unpack(form)) io.write("</span>") --]] ?> -<? -function displayinfo(myform,tags,viewonly) - io.write("<DL>") - for k,v in pairs(tags) do - if (myform[v]) and (myform[v]["value"]) then - local val = myform[v] - io.write("\t<DT") - if (#val.errtxt > 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "</DT>\n") - if (viewonly) then - io.write("\t\t<DD>" .. val.value .. "\n") - else - io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n") - end - if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end - if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end - io.write("\t\t</DD>\n") - end - end - io.write("</DL>") -end -?> <H1>SYSTEM INFO</H1> +<DL> <? local myform = form.status local tags = { "status", "version", } displayinfo(myform,tags,"viewonly") ?> +</DL> <H1>CONFIG</H1> <form name="config" action="" method="POST"> <H2>Advanced config</H2> <H3>Storage media</H3> -<? +<DL> +<? local myform = form.config local tags = { "LBU_MEDIA", } displayinfo(myform,tags) ?> +</DL> <H3>Included list</H3> +<DL> <? local tags = { "lbu_included","cmd_delete_included", "item_add_included", "cmd_add_included", } displayinfo(myform,tags) ?> +</DL> <H3>Excluded list</H3> +<DL> <? local tags = { "lbu_excluded","cmd_delete_excluded", "item_add_excluded", "cmd_add_excluded", } displayinfo(myform,tags) ?> +</DL> <H3>Security/Encryption</H3> +<DL> <? local tags = { "ENCRYPTION", "DEFAULT_CIPHER", "PASSWORD", } displayinfo(myform,tags) ?> +</DL> <H2>Save and apply above settings</H2> +<DL> <? local tags = { "config_submit" } displayinfo(myform,tags) ?> - +</DL> </form> - -<? ---[[ 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>") ---]] -?> diff --git a/lbu-controller.lua b/lbu-controller.lua index 6bca902..f258f5f 100644 --- a/lbu-controller.lua +++ b/lbu-controller.lua @@ -1,22 +1,29 @@ module(..., package.seeall) -local list_redir = function(self) +-- Set variables +local cfgfile + +-- ################################################################################ +-- LOCAL FUNCTIONS + +local function list_redir (self) self.conf.action = "status" self.conf.type = "redir" error(self.conf) end -local cfgfile +-- ################################################################################ +-- PUBLIC FUNCTIONS mvc={} -mvc.on_load = function(self, parent) +function mvc.on_load (self, parent) cfgfile = self:new("cfgfile") if (self.worker[self.conf.action] == nil) or (self.conf.action == "init") then self.worker[self.conf.action] = list_redir(self) end end -status = function (self) +function status (self) local cmd = self.clientdata.cmd local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller local status, errors = self.model:getstatus() @@ -26,7 +33,7 @@ status = function (self) url = url, } ) end -config = function (self) +function config (self) local errors = {} local cmdresult if (self.clientdata.cmd_delete_excluded) and (self.clientdata.lbu_excluded) then @@ -145,12 +152,7 @@ function commit(self) end local status, errors = self.model:getstatus() ---[[ if (errors.last) then - self.conf.action = "config" - self.conf.type = "redir" - return config(self) - end ---]] + -- Add buttons status["lbusimulate"] = cfe({ name="lbusimulate", @@ -182,7 +184,7 @@ function commit(self) clientdata = self.clientdata, url = url, } ) end -expert = function (self) +function expert (self) local modifications = self.clientdata.filecontent or "" if ( self.clientdata.cmdsave) then modifications = self.model:update_filecontent(modifications) diff --git a/lbu-expert-html.lsp b/lbu-expert-html.lsp index 219d748..ed87ade 100644 --- a/lbu-expert-html.lsp +++ b/lbu-expert-html.lsp @@ -1,4 +1,6 @@ -<? local form = ... ?> +<? local form = ... +require("viewfunctions") +?> <? --[[ DEBUG INFORMATION io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") @@ -7,38 +9,14 @@ io.write("</span>") --]] ?> -<? -function displayinfo(myform,tags,viewonly) - io.write("<DL>") - for k,v in pairs(tags) do - if (myform[v]) and (myform[v]["value"]) then - local val = myform[v] - io.write("\t<DT") - if (#val.errtxt > 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "</DT>\n") - if (viewonly) then - io.write("\t\t<DD>" .. val.value .. "\n") - else - io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n") - end - if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end - if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end - io.write("\t\t</DD>\n") - end - end - io.write("</DL>") -end -?> - <H1>SYSTEM INFO</H1> +<DL> <? local myform = form.status local tags = { "status", "version", } displayinfo(myform,tags,"viewonly") ?> +</DL> <h1>CONFIGURATION</h1> @@ -46,11 +24,13 @@ displayinfo(myform,tags,"viewonly") <H2>EXPERT CONFIGURATION</H2> <H3>FILE DETAILS</H3> +<DL> <? local myform = form.file local tags = { "filename", "filesize", "mtime", "sumerrors" } displayinfo(myform,tags,"viewonly") ?> +</DL> <H3>FILE CONTENT</H3> <? @@ -58,17 +38,11 @@ io.write(html.form[myform.filecontent.type](myform.filecontent)) ?> <H2>Save and apply above settings</H2> +<DL> <? local myform = form.file local tags = { "cmdsave", } displayinfo(myform,tags) ?> +</DL> </form> - -<? ---[[ 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>") ---]] -?> diff --git a/lbu-model.lua b/lbu-model.lua index da5e22c..6807e87 100644 --- a/lbu-model.lua +++ b/lbu-model.lua @@ -1,10 +1,12 @@ module (..., package.seeall) +-- Load libraries require("fs") require("format") require("getopts") require("daemoncontrol") +-- Set variables local configfile = "/etc/lbu/lbu.conf" -- ################################################################################ @@ -41,7 +43,6 @@ local function getLbuCommit(flag) local err = {} local ret = "" local f = io.popen("/sbin/lbu commit " .. flag .. " 2>&1", "r") --- local ret = f:read("*a") for line in f:lines() do ret = ret .. line .. "\n" --Look for error messages in output @@ -207,8 +208,6 @@ function getconfig () label="Password when encrypting", }) ----[[ - -- Next section is to print errormessages when configs are wrong if (configopts["LBU_MEDIA"] == "") or (configopts["LBU_MEDIA"] == nil) then config.LBU_MEDIA.errtxt = "'Media' needs to be configured!" @@ -219,7 +218,7 @@ function getconfig () for k,v in pairs(errors) do config["errors"] = v end ---]] + return config end diff --git a/lbu-status-html.lsp b/lbu-status-html.lsp index 99d1dbe..eb1997b 100644 --- a/lbu-status-html.lsp +++ b/lbu-status-html.lsp @@ -1,4 +1,6 @@ -<? local form = ... ?> +<? local form = ... +require("viewfunctions") +?> <? --[[ DEBUG INFORMATION io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") @@ -6,55 +8,26 @@ io.write(html.cfe_unpack(form)) io.write("</span>") --]] ?> -<? -function displayinfo(myform,tags,viewonly) - io.write("<DL>") - for k,v in pairs(tags) do - if (myform[v]) and (myform[v]["value"]) then - local val = myform[v] - io.write("\t<DT") - if (#val.errtxt > 0) then io.write(" class='error'") end - io.write(">" .. val.label .. "</DT>\n") - if (viewonly) then - io.write("\t\t<DD>" .. val.value .. "\n") - else - io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n") - end - if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end - if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end - io.write("\t\t</DD>\n") - end - end - io.write("</DL>") -end -?> <H1>SYSTEM INFO</H1> +<DL> <? local myform = form.status local tags = { "status", "version", } displayinfo(myform,tags,"viewonly") ?> +</DL> <H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2> +<DL> <? local tags = { "LBU_MEDIA","ENCRYPTION", } displayinfo(myform,tags,"viewonly") ?> +</DL> <H2>CHANGES SINCE LAST COMMIT</H2> -<dl> +<DL> <dt>Files changed since last commit</dt> <dd><pre><? for i = 1, table.maxn(form.lbustatus) do io.write(form.lbustatus[i]["status"] .. "\t" .. form.lbustatus[i]["name"] .. "\n") end ?><? if (#form.lbustatus == 0) then io.write("None") end ?></pre></DD> -</dl> - - -<? ---[[ 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>") ---]] -?> - -<? -- vim: set filetype=lua : ?> +</DL> |