From b7f8f377687d5d898cdd581d8d5de44ae95ab7a0 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 25 Aug 2010 10:26:36 +0000 Subject: Added ability to create and delete configuration files. Changed edit action to editfile. --- freeswitch-controller.lua | 10 ++++++++- freeswitch-createfile-html.lsp | 1 + freeswitch-edit-html.lsp | 1 - freeswitch-editfile-html.lsp | 1 + freeswitch-listfiles-html.lsp | 32 +++++++++++++++++++++++------ freeswitch-logfile-html.lsp | 7 +++++++ freeswitch-model.lua | 46 ++++++++++++++++++++++++++++++++++++++++++ freeswitch.menu | 1 + freeswitch.roles | 6 +++--- 9 files changed, 94 insertions(+), 11 deletions(-) create mode 120000 freeswitch-createfile-html.lsp delete mode 120000 freeswitch-edit-html.lsp create mode 120000 freeswitch-editfile-html.lsp create mode 100644 freeswitch-logfile-html.lsp diff --git a/freeswitch-controller.lua b/freeswitch-controller.lua index 04d6ea7..6b459cd 100644 --- a/freeswitch-controller.lua +++ b/freeswitch-controller.lua @@ -16,6 +16,14 @@ listfiles = function( self ) return self.model.list_files() end -edit = function( self ) +editfile = function( self ) return controllerfunctions.handle_form(self, function() return self.model.get_file(self.clientdata.filename) end, self.model.update_file, self.clientdata, "Save", "Edit File", "File Saved") end + +function createfile(self) + return controllerfunctions.handle_form(self, self.model.getnewfile, self.model.createfile, self.clientdata, "Create", "Create New Freeswitch File", "Freeswitch File Created") +end + +function deletefile(self) + return self:redirect_to_referrer(self.model.deletefile(self.clientdata.filename)) +end diff --git a/freeswitch-createfile-html.lsp b/freeswitch-createfile-html.lsp new file mode 120000 index 0000000..b532216 --- /dev/null +++ b/freeswitch-createfile-html.lsp @@ -0,0 +1 @@ +../form-html.lap \ No newline at end of file diff --git a/freeswitch-edit-html.lsp b/freeswitch-edit-html.lsp deleted file mode 120000 index 15b1930..0000000 --- a/freeswitch-edit-html.lsp +++ /dev/null @@ -1 +0,0 @@ -../filedetails-html.lsp \ No newline at end of file diff --git a/freeswitch-editfile-html.lsp b/freeswitch-editfile-html.lsp new file mode 120000 index 0000000..15b1930 --- /dev/null +++ b/freeswitch-editfile-html.lsp @@ -0,0 +1 @@ +../filedetails-html.lsp \ No newline at end of file diff --git a/freeswitch-listfiles-html.lsp b/freeswitch-listfiles-html.lsp index caff231..3c96bad 100644 --- a/freeswitch-listfiles-html.lsp +++ b/freeswitch-listfiles-html.lsp @@ -2,7 +2,8 @@ require("viewfunctions") %> -<% displaycommandresults({"edit", "startstop"}, session) %> +<% displaycommandresults({"editfile", "deletefile", "startstop"}, session) %> +<% displaycommandresults({"createfile"}, session, true) %> <% if viewlibrary and viewlibrary.dispatch_component then viewlibrary.dispatch_component("status") @@ -11,18 +12,37 @@ end %>

Configuration

+ -<% - for k,v in ipairs( view.value ) do - io.write( "\n" ) - end -%> +<% for k,v in ipairs( view.value ) do %> + + + + + + +<% end %>
Action File Size Last Modified
" .. html.html_escape(v.filename) .. "" .. html.html_escape(v.size) .."" .. html.html_escape(v.mtime) .."
+ <% if viewlibrary.check_permission("editfile") then %> + <%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/editfile?filename="..v.filename.."&redir="..page_info.orig_action, label="Edit "} %> + <% end %> + <% if viewlibrary.check_permission("deletefile") then %> + <%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/deletefile?filename="..v.filename, label="Delete "} %> + <% end %> + <%= html.html_escape(v.filename) %><%= html.html_escape(v.size) %><%= html.html_escape(v.mtime) %>
+<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createfile") then + local createform = viewlibrary.dispatch_component("createfile", nil, true) %> +

<%= html.html_escape(createform.label) %>

+<% + createform.action = page_info.script .. page_info.prefix .. page_info.controller .. "/createfile" + displayform(createform) +end %> + <% if viewlibrary and viewlibrary.dispatch_component then viewlibrary.dispatch_component("startstop") end %> diff --git a/freeswitch-logfile-html.lsp b/freeswitch-logfile-html.lsp new file mode 100644 index 0000000..4dcc8d0 --- /dev/null +++ b/freeswitch-logfile-html.lsp @@ -0,0 +1,7 @@ +<% local data, viewlibrary = ... +require("viewfunctions") +%> + +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("alpine-baselayout/logfiles/view", {name="/var/log/freeswitch/freeswitch.log"}) +end %> diff --git a/freeswitch-model.lua b/freeswitch-model.lua index 3095cde..149bf32 100644 --- a/freeswitch-model.lua +++ b/freeswitch-model.lua @@ -56,3 +56,49 @@ list_files = function() table.sort(retval, function(a,b) return a.filename < b.filename end) return cfe({ type="structure", value=retval, label="List of Freeswitch files" }) end + +function getnewfile() + local filename = cfe({ label="File Name", descr="Must be in "..baseurl }) + return cfe({ type="group", value={filename=filename}, label="Freeswitch File" }) +end + +function createfile(filedetails) + local success = true + local path = string.match(filedetails.value.filename.value, "^%s*(.*%S)%s*$") or "" + if not string.find(path, "/") then + path = baseurl.."/"..path + end + + if not is_valid_filename(path) then + success = false + filedetails.value.filename.errtxt = "Invalid filename" + else + if not fs.is_dir(baseurl) then fs.create_directory(baseurl) end + if posix.stat(path) then + success = false + filedetails.value.filename.errtxt = "Filename already exists" + end + end + + if success then + fs.create_file(path) + else + filedetails.errtxt = "Failed to Create File" + end + + return filedetails +end + +function deletefile(filename) + local retval = cfe({ label="Delete Freeswitch File result", errtxt = "Failed to delete Freeswitch File - invalid filename" }) + for i,file in ipairs(list_files().value) do + if filename == file.filename then + retval.value = "Deleted Freeswitch File" + retval.errtxt = nil + os.remove(filename) + break + end + end + + return retval +end diff --git a/freeswitch.menu b/freeswitch.menu index 0cb8d87..eeca02f 100644 --- a/freeswitch.menu +++ b/freeswitch.menu @@ -2,3 +2,4 @@ # Cat Group Tab Action Applications 87Freeswitch Status status Applications 87Freeswitch Expert listfiles +Applications 87Freeswitch Logfile logfile diff --git a/freeswitch.roles b/freeswitch.roles index e4a48cf..ce0c26e 100644 --- a/freeswitch.roles +++ b/freeswitch.roles @@ -1,3 +1,3 @@ -USER=freeswitch:status,freeswitch:startstop -EXPERT=freeswitch:listfiles,freeswitch:edit -ADMIN=freeswitch:status,freeswitch:startstop,freeswitch:listfiles,freeswitch:edit +USER=freeswitch:status,freeswitch:startstop,freeswitch:logfile +EXPERT=freeswitch:listfiles,freeswitch:editfile,freeswitch:createfile,freeswitch:deletefile +ADMIN=freeswitch:status,freeswitch:startstop,freeswitch:logfile,freeswitch:listfiles,freeswitch:editfile,freeswitch:createfile,freeswitch:deletefile -- cgit v1.2.3