From cbac09f609f1cf9ddd85084576ace1dfe7f3690e Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Mon, 28 Apr 2008 14:58:24 +0000 Subject: 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 --- tinydns-confirmaction-html.lsp | 14 +++++++++---- tinydns-controller.lua | 47 +++++++++++++++++++++++++++++++++++++++++- 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") ?> DEBUGGING

DEBUG INFO: CFE

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

DEBUGGING:
-This function still doesn't work.
-Need to get the information on what action we are about to execute and what file to use for this actino.


+ +

Confirmation

+
+
+
+
+ +
+ 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 -- cgit v1.2.3