From 9a0f90972bf1fe723caa55fecb684788933679b9 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 19 Apr 2010 15:01:21 +0000 Subject: Initial cut at freeswitch ACF. --- freeswitch-model.lua | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 freeswitch-model.lua (limited to 'freeswitch-model.lua') 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 -- cgit v1.2.3