diff options
author | Ted Trask <ttrask01@yahoo.com> | 2010-04-19 15:01:21 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2010-04-19 15:01:21 +0000 |
commit | 9a0f90972bf1fe723caa55fecb684788933679b9 (patch) | |
tree | 87d69432bcfc81dd87429993c1371a687b722802 /freeswitch-model.lua | |
download | acf-freeswitch-9a0f90972bf1fe723caa55fecb684788933679b9.tar.bz2 acf-freeswitch-9a0f90972bf1fe723caa55fecb684788933679b9.tar.xz |
Initial cut at freeswitch ACF.v0.1.0
Diffstat (limited to 'freeswitch-model.lua')
-rw-r--r-- | freeswitch-model.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/freeswitch-model.lua b/freeswitch-model.lua new file mode 100644 index 0000000..3095cde --- /dev/null +++ b/freeswitch-model.lua @@ -0,0 +1,58 @@ +module (..., package.seeall) + +-- Load libraries +require("modelfunctions") +require("posix") +require("fs") +require("format") +require("validator") + +-- Set variables +local processname = "freeswitch" +local packagename = "freeswitch" +local baseurl = "/etc/freeswitch" + +-- ################################################################################ +-- LOCAL FUNCTIONS + +local is_valid_filename = function(filename) + local dirname = posix.dirname(filename) + return validator.is_valid_filename(filename) and string.match(dirname, baseurl) and not string.match(dirname, "%.%.") +end + +-- ################################################################################ +-- PUBLIC FUNCTIONS + +get_status = function() + return modelfunctions.getstatus(processname, packagename, "Freeswitch Status") +end + +function startstop_service(action) + return modelfunctions.startstop_service(processname, action, {"Start", "Stop", "Restart"}) +end + +get_file = function(filename) + return modelfunctions.getfiledetails(filename, is_valid_filename) +end + +update_file = function(filedetails) + local ret = modelfunctions.setfiledetails(filedetails, is_valid_filename) + if not ret.errtxt then + posix.chmod(filedetails.value.filename.value, "rw-------") + posix.chown(filedetails.value.filename.value, posix.getpasswd("freeswitch", "uid") or 0, posix.getpasswd("freeswitch", "gid") or 0) + end + return ret +end + +list_files = function() + local retval = {} + for file in fs.find(null, baseurl) do + local details = fs.stat(file) + if details.type == "regular" then + details.filename = file + table.insert(retval, details) + end + end + table.sort(retval, function(a,b) return a.filename < b.filename end) + return cfe({ type="structure", value=retval, label="List of Freeswitch files" }) +end |