diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-04-28 14:58:24 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-04-28 14:58:24 +0000 |
commit | cbac09f609f1cf9ddd85084576ace1dfe7f3690e (patch) | |
tree | e810e6368627ef9b1857e0b980cee9eff861d19d | |
parent | 4d2325161be2448fb521b1aacc02965e9dfaba64 (diff) | |
download | acf-tinydns-cbac09f609f1cf9ddd85084576ace1dfe7f3690e.tar.bz2 acf-tinydns-cbac09f609f1cf9ddd85084576ace1dfe7f3690e.tar.xz |
Now you can delete config-files that you no longer want.
Validation is done so you can't remove wrong files (but you can remove any file within /etc/tinydns/)
git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@1050 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | tinydns-confirmaction-html.lsp | 14 | ||||
-rw-r--r-- | tinydns-controller.lua | 47 | ||||
-rw-r--r-- | tinydns-model.lua | 14 |
3 files changed, 70 insertions, 5 deletions
diff --git a/tinydns-confirmaction-html.lsp b/tinydns-confirmaction-html.lsp index da6753e..5303310 100644 --- a/tinydns-confirmaction-html.lsp +++ b/tinydns-confirmaction-html.lsp @@ -2,13 +2,19 @@ require("viewfunctions") ?> <? ----[[ DEBUG INFORMATION +--[[ 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>") --]] ?> -<BR><BR><CENTER><B>DEBUGGING:</B><BR> -This function still doesn't work.<BR> -Need to get the information on what action we are about to execute and what file to use for this actino.</CENTER><BR><BR> + +<H1>Confirmation</H1> +<form name="myform" action="" method="POST"> +<DL> +<DT><? io.write(form.cmddelete.label or "") ?></DT> +<DD><? io.write(html.form[form.cmddelete.type](form.cmddelete)) ?> <? io.write(html.form[form.cancel.type](form.cancel)) ?> +<input type="hidden" value="<? io.write(form.name.value) ?>" name="name"> +</DD> +</form> diff --git a/tinydns-controller.lua b/tinydns-controller.lua index e13f001..2dd6af4 100644 --- a/tinydns-controller.lua +++ b/tinydns-controller.lua @@ -265,6 +265,7 @@ function expert(self) end if (#create.name.errtxt == 0) then create.cmdnew.descr = "* File was created" + redirect(self, "edit?name=" .. (self.clientdata.name or "")) end end @@ -338,7 +339,7 @@ function edit(self) }) if (self.clientdata.cmddelete) then - redirect(self, "confirmaction") + redirect(self, "confirmaction?action=delete&name=" .. (self.clientdata.name or "")) end if (modifications) then @@ -361,4 +362,48 @@ function edit(self) end function confirmaction(self) + if (self.clientdata.cancel) then + redirect(self, "expert") + end + + -- See to that only allowed files are modified + local fileexists, fileerrros = self.model:get_filedetails(self.clientdata.name) + if not (fileexists) then + redirect(self) + end + + local output = {} + output.cancel = cfe({ + name="cancel", + value="Cancel", + type="submit", + }) + output.cmddelete = cfe({ + name="cmddelete", + label="Are you sure you want to delete?", + value="Delete", + type="submit", + }) + output.name = cfe({ + name="name", + value=self.clientdata.name, + type="hidden", + }) + + output.mhdebug = cfe({ + name="mhdebug", + value=fileexists, + descr=self.clientdata, + errtxt=fileerrros, + }) + if (self.clientdata.cmddelete) then + local removesuccess, removeerrors = self.model:remove_file(self.clientdata.name) + if (removesuccess) then + redirect(self, "expert") + elseif (#removeerrors > 0) then + output.cmddelete.errtxt = removeerrors + end + end + + return output end diff --git a/tinydns-model.lua b/tinydns-model.lua index 7ac2495..29513ab 100644 --- a/tinydns-model.lua +++ b/tinydns-model.lua @@ -734,3 +734,17 @@ function createconfigfile (self, path) end return false, "Something went wrong!" end +function remove_file(self, path) + if not (fs.is_file(path)) then + return false,"File doesn't exist!" + end + if (validfilename(path)) then + local cmd, errors = io.popen( "/bin/rm " .. path, r ) + local cmdoutput = cmd:read("*a") + cmd:close() + return true, cmdoutput + else + return false, "Not a valid filename!" + end + return false, "Something went wrong!" +end |