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 | |
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
-rwxr-xr-x | tinydns-config-html.lsp | 6 | ||||
-rw-r--r-- | tinydns-controller.lua | 117 | ||||
-rw-r--r-- | tinydns-edit-html.lsp | 17 | ||||
l--------- | tinydns-editfile-html.lsp | 1 | ||||
-rw-r--r-- | tinydns-expert-html.lsp | 42 | ||||
-rw-r--r-- | tinydns-listfiles-html.lsp | 8 | ||||
-rw-r--r-- | tinydns-model.lua | 100 | ||||
l---------[-rw-r--r--] | tinydns-newfile-html.lsp | 18 | ||||
l---------[-rw-r--r--] | tinydns-startstop-html.lsp | 27 | ||||
-rw-r--r-- | tinydns-status-html.lsp | 2 | ||||
-rw-r--r-- | tinydns.roles | 2 |
11 files changed, 52 insertions, 288 deletions
diff --git a/tinydns-config-html.lsp b/tinydns-config-html.lsp index 1119a50..a213785 100755 --- a/tinydns-config-html.lsp +++ b/tinydns-config-html.lsp @@ -1,4 +1,4 @@ -<? local form, viewlibrary = ... +<? local form, viewlibrary, page_info = ... require("viewfunctions") ?> <? @@ -13,9 +13,9 @@ io.write("</span>") viewlibrary.dispatch_component("status") end ?> -<h1>CONFIGURATION</h1> -<h2><?= form.label ?></h2> +<h1><?= form.label ?></h1> <? + form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action displayform(form) ?> diff --git a/tinydns-controller.lua b/tinydns-controller.lua index dd567c5..e0e7e2a 100644 --- a/tinydns-controller.lua +++ b/tinydns-controller.lua @@ -1,12 +1,7 @@ module(..., package.seeall) +require("controllerfunctions") require("validator") --- ################################################################################ --- LOCAL FUNCTIONS - --- ################################################################################ --- PUBLIC FUNCTIONS - default_action = "status" function status(self) @@ -18,71 +13,15 @@ function view(self) end function startstop(self) - local result - if self.clientdata.action then - result = self.model:startstop_service(self.clientdata.action) - self.sessiondata.tinydnsstartstopresult = result - self.redirect_to_referrer(self) - end - - local status = self.model.getstatus() - status = status.value.status - if self.sessiondata.tinydnsstartstopresult then - result = self.sessiondata.tinydnsstartstopresult - self.sessiondata.tinydnsstartstopresult = 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) - local config = self.model.getconfig() - - if self.clientdata.Save then - for name,value in pairs(self.clientdata) do - if config.value[name] then - config.value[name].errtxt = nil - config.value[name].value = value - end - end - - config = self.model.setconfig(config) - if not config.errtxt then - config.descr = "Configuration Set" - end - end - - config.type = "form" - config.option = "Save" - config.label = "Edit configuration" - - return config + return controllerfunctions.handle_form(self, self.model.getconfig, self.model.setconfig, self.clientdata, "Save", "Edit Configuration", "Configuration Saved") end function newfile(self) - local create = self.model.getnewconfigfile() - - -- In case we are trying to create a new configfile - if (self.clientdata.Create) then - for name,value in pairs(self.clientdata) do - if create.value[name] then - create.value[name].errtxt = nil - create.value[name].value = value - end - end - - create = self.model.createconfigfile(create) - if not create.errtxt then - create.descr = "Created new config file" - redirect(self, "listfiles") - end - end - - create.type = "form" - create.option = "Create" - create.label = "Create new config file" - - return create + return controllerfunctions.handle_form(self, self.model.getnewconfigfile, self.model.createconfigfile, self.clientdata, "Create", "Create New Config File", "Config File Created", "listfiles") end function listfiles(self) @@ -96,53 +35,15 @@ function listfiles(self) return cfe({ type="list", value=config, label="Config files" }) end -function edit(self) - local config = self.model.get_filedetails(self.clientdata.filename) - if self.clientdata.Save then - local result = self.model.updatefilecontent(self.clientdata.filename, self.clientdata.filecontent) - if not result.value then - config.value.filecontent.value = self.clientdata.filecontent - config.value.filecontent.errtxt = result.errtxt - config.errtxt = "Failed to save config!" - else - config = self.model.get_filedetails(self.clientdata.filename) - config.descr = "Saved file" - end - elseif self.clientdata.linenumber and validator.is_integer(self.clientdata.linenumber) then +function editfile(self) + config = controllerfunctions.handle_form(self, function() return self.model.get_filedetails(self.clientdata.filename) end, self.model.set_filedetails, self.clientdata, "Save", "Edit Config File", "Config File Saved") + + if self.clientdata.linenumber and validator.is_integer(self.clientdata.linenumber) then config.value.filecontent.linenumber = self.clientdata.linenumber end - - config.type = "form" - config.option = "Save" - config.label = "Edit config file" - - return config -end - -function expert(self) - local config = self.model.get_filedetails(self.clientdata.filename) - if self.clientdata.Save then - local result = self.model.updatefilecontent(self.clientdata.filename, self.clientdata.filecontent) - if not result.value then - config.value.filecontent.value = self.clientdata.filecontent - config.value.filecontent.errtxt = result.errtxt - config.errtxt = "Failed to save config!" - else - config = self.model.get_filedetails(self.clientdata.filename) - config.descr = "Saved file" - end - end - - config.type = "form" - config.option = "Save" - config.label = "Edit config file" - return config end function delete(self) - local cmdresult = self.model.remove_file(self.clientdata.filename) - --self.sessiondata.cmdresult = cmdresult - redirect_to_referrer(self) - return cmdresult + return self:redirect_to_referrer(self.model.remove_file(self.clientdata.filename)) end diff --git a/tinydns-edit-html.lsp b/tinydns-edit-html.lsp index 92cdd21..44cf642 100644 --- a/tinydns-edit-html.lsp +++ b/tinydns-edit-html.lsp @@ -1,5 +1,6 @@ -<? local form, viewlibrary = ... ?> +<? local form, viewlibrary, page_info = ... ?> <? require("viewfunctions") ?> +<? form = viewlibrary.dispatch_component(page_info.prefix .. page_info.controller .. "/editfile", form, true) ?> <script type="text/javascript" src="/js/jquery-latest.js"></script> <script type="text/javascript"> @@ -128,9 +129,9 @@ io.write("</span>") --]] ?> -<H1>CONFIGURATION</H1> -<H2>EXPERT CONFIGURATION</H2> -<H3>FILE DETAILS</H3> +<H1>Configuration</H1> +<H2>Expert Configuration</H2> +<H3>File Details</H3> <DL> <? displayitem(form.value.filename) @@ -139,7 +140,7 @@ displayitem(form.value.mtime) ?> </DL> -<H3>FILE ENTRIES</H3> +<H3>File Entries</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 ?> <TABLE id="entries"> @@ -151,9 +152,9 @@ displayitem(form.value.mtime) </TABLE> <? if form.value.filecontent.errtxt then ?><P CLASS='error'><?= string.gsub(form.value.filecontent.errtxt, "\n", "<BR>") ?></P><? end ?> -<form action="" method="POST"> +<form action="<?= page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action ?>" method="POST"> <input type="hidden" name="filename" value="<?= form.value.filename.value ?>"> <input type="hidden" name="filecontent" value="<?= form.value.filecontent.value ?>"> -<H2>SAVE AND APPLY ABOVE SETTINGS</H2> -<DL><DT>Save/Apply above settings</DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="Save"></DD></DL> +<H2>Save and Apply Above Settings</H2> +<DL><DT></DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="<?= form.option ?>"></DD></DL> </form> diff --git a/tinydns-editfile-html.lsp b/tinydns-editfile-html.lsp new file mode 120000 index 0000000..15b1930 --- /dev/null +++ b/tinydns-editfile-html.lsp @@ -0,0 +1 @@ +../filedetails-html.lsp
\ No newline at end of file diff --git a/tinydns-expert-html.lsp b/tinydns-expert-html.lsp deleted file mode 100644 index 93887dd..0000000 --- a/tinydns-expert-html.lsp +++ /dev/null @@ -1,42 +0,0 @@ -<? 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>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"> -<input type="hidden" name="filename" value="<?= form.value.filename.value ?>"> -<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 ?> - -<H2>SAVE AND APPLY ABOVE SETTINGS</H2> -<DL><DT>Save/Apply above settings</DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="Save"></DD></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/tinydns-listfiles-html.lsp b/tinydns-listfiles-html.lsp index c2407e2..1b53187 100644 --- a/tinydns-listfiles-html.lsp +++ b/tinydns-listfiles-html.lsp @@ -1,4 +1,4 @@ -<? local form, viewlibrary = ... +<? local form, viewlibrary, page_info, session = ... require("viewfunctions") ?> <? @@ -9,7 +9,9 @@ io.write("</span>") --]] ?> -<h1>CONFIGURATION</h1> +<? displaycommandresults({"delete"}, session) ?> + +<h1>Configuration</h1> <h2>Edit/View existing Domains</h2> <TABLE> <TR style="background:#eee;font-weight:bold;"> @@ -24,7 +26,7 @@ io.write("</span>") <? io.write(html.link{value = "delete?filename=" .. file.value.filename.value, label="Delete " }) ?> <? io.write(html.link{value = "view?filename=" .. file.value.filename.value, label="View " }) ?> <? io.write(html.link{value = "edit?filename=" .. file.value.filename.value, label="Edit " }) ?> - <? io.write(html.link{value = "expert?filename=" .. file.value.filename.value, label="Expert " }) ?> + <? io.write(html.link{value = "editfile?filename=" .. file.value.filename.value, label="Expert " }) ?> </TD> <TD style="padding-right:20px;white-space:nowrap;text-align:right;"><?= file.value.filesize.value ?></TD> <TD style="padding-right:20px;white-space:nowrap;"><?= file.value.mtime.value ?></TD> 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 diff --git a/tinydns-newfile-html.lsp b/tinydns-newfile-html.lsp index f727833..4b6b762 100644..120000 --- a/tinydns-newfile-html.lsp +++ b/tinydns-newfile-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>CONFIGURATION</h1> -<h2><?= form.label ?></h2> -<? - form.action = "newfile" - displayform(form) -?> +../form-html.lsp
\ No newline at end of file diff --git a/tinydns-startstop-html.lsp b/tinydns-startstop-html.lsp index f3f7013..0ea2627 100644..120000 --- a/tinydns-startstop-html.lsp +++ b/tinydns-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/tinydns-status-html.lsp b/tinydns-status-html.lsp index d0eae68..f175e92 100644 --- a/tinydns-status-html.lsp +++ b/tinydns-status-html.lsp @@ -4,7 +4,7 @@ io.write(html.cfe_unpack(data)) --]] ?> -<H1>SYSTEM INFO</H1> +<H1>System Info</H1> <DL> <? displayitem(data.value.status) diff --git a/tinydns.roles b/tinydns.roles index d473bb7..09cfaf8 100644 --- a/tinydns.roles +++ b/tinydns.roles @@ -1,2 +1,2 @@ READ=tinydns:status,tinydns:view -UPDATE=tinydns:config,tinydns:listfiles,tinydns:delete,tinydns:edit,tinydns:expert,tinydns:newfile,tinydns:startstop +UPDATE=tinydns:config,tinydns:listfiles,tinydns:delete,tinydns:edit,tinydns:editfile,tinydns:newfile,tinydns:startstop |