From b107185f3794c982ec0c988087232346e67a8203 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Thu, 2 Jul 2009 15:21:39 +0000 Subject: Adding delete() to be able to remove .rrd DB's Hiding some debug information in the listrrd view-file. --- rrdtool-controller.lua | 5 +++++ rrdtool-listrrd-html.lsp | 3 ++- rrdtool-model.lua | 29 ++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/rrdtool-controller.lua b/rrdtool-controller.lua index 56b9a1e..e565c51 100644 --- a/rrdtool-controller.lua +++ b/rrdtool-controller.lua @@ -32,3 +32,8 @@ function createrrd(self) return controllerfunctions.handle_form(self, self.model.createnewrrd, self.model.write_file, self.clientdata, "Save", "Edit Interfaces file", "File saved") end + +function delete(self) + return self:redirect_to_referrer(self.model.remove_file(self, self.clientdata.filename, sessiondata.userinfo.userid)) +end + diff --git a/rrdtool-listrrd-html.lsp b/rrdtool-listrrd-html.lsp index 24c48d1..5da37a4 100644 --- a/rrdtool-listrrd-html.lsp +++ b/rrdtool-listrrd-html.lsp @@ -2,10 +2,11 @@ require("viewfunctions") %> <% ----[[ DEBUG INFORMATION +--[[ DEBUG INFORMATION io.write("

DEBUGGING

DEBUG INFO: CFE

") io.write(html.cfe_unpack(form)) io.write("
") +--]] %> <% displaycommandresults({"delete", "edit", "editfile"}, session) %> diff --git a/rrdtool-model.lua b/rrdtool-model.lua index 9e9295f..f85f08b 100644 --- a/rrdtool-model.lua +++ b/rrdtool-model.lua @@ -43,13 +43,13 @@ local function file_info ( path ) return lastmod,size end -local function list_files ( ... ) +local function list_files () local listed_files = {} local open_files = {} local files = {} local k,v -- Generate a single table with all the files - for k,v in pairs{...} do + for k,v in pairs{databases} do recursedir(v, files) end @@ -68,6 +68,15 @@ local function list_files ( ... ) end +local function validfilename(path) + local files = list_files() + for k,v in pairs(files.value) do + if (v["value"]["filename"]["value"] == path) then + return true, tostring(v["value"]["filename"]["value"]) + end + end + return false, "Not a valid filename!" +end -- ################################################################################ -- PUBLIC FUNCTIONS @@ -89,7 +98,7 @@ function setconfigfile(filedetails) end function getrrdlist() - return list_files(databases) + return list_files() end function createnewrrd() @@ -102,3 +111,17 @@ DS:ds-name:COMPUTE:rpn-expression"}) newdb.rra = cfe({label="Round Robin Archive",value="",descr="RRA:AVERAGE | MIN | MAX | LAST:xff:steps:rows"}) return {value=newdb} end + +function remove_file(self, path, userid) + local success = "Failed to delete file" + local errtxt + if not (fs.is_file(path)) then + errtxt = "File doesn't exist!" + elseif (validfilename(path)) then + os.remove(path) + success = "File Deleted" + else + errtxt = "Not a valid filename!" + end + return cfe({ value=success, label="Delete config file result", errtxt=errtxt }) +end -- cgit v1.2.3