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-model.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'freeswitch-model.lua') 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 -- cgit v1.2.3