summaryrefslogtreecommitdiffstats
path: root/freeswitch-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2010-08-25 10:26:36 +0000
committerTed Trask <ttrask01@yahoo.com>2010-08-25 10:26:36 +0000
commitb7f8f377687d5d898cdd581d8d5de44ae95ab7a0 (patch)
treecf494d6e7f54949cee64bb9186949d26765102ad /freeswitch-model.lua
parent9a0f90972bf1fe723caa55fecb684788933679b9 (diff)
downloadacf-freeswitch-b7f8f377687d5d898cdd581d8d5de44ae95ab7a0.tar.bz2
acf-freeswitch-b7f8f377687d5d898cdd581d8d5de44ae95ab7a0.tar.xz
Added ability to create and delete configuration files.
Changed edit action to editfile.
Diffstat (limited to 'freeswitch-model.lua')
-rw-r--r--freeswitch-model.lua46
1 files changed, 46 insertions, 0 deletions
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