summaryrefslogtreecommitdiffstats
path: root/kamailio-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'kamailio-model.lua')
-rw-r--r--kamailio-model.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/kamailio-model.lua b/kamailio-model.lua
new file mode 100644
index 0000000..4915787
--- /dev/null
+++ b/kamailio-model.lua
@@ -0,0 +1,53 @@
+module(..., package.seeall)
+
+-- Load libraries
+require("modelfunctions")
+require("fs")
+require("validator")
+
+-- Set variables
+local processname = "kamailio"
+local packagename = "kamailio"
+local baseurl = "/etc/kamailio"
+
+local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "
+
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
+local is_valid_filename = function(filename)
+ local dirname = dirname(filename)
+ return validator.is_valid_filename(filename) and string.match(dirname, baseurl) and not string.match(dirname, "%.%.")
+end
+
+-- ################################################################################
+-- PUBLIC FUNCTIONS
+
+function startstop_service(action)
+ return modelfunctions.startstop_service(processname, action)
+end
+
+function getstatus()
+ return modelfunctions.getstatus(processname, packagename, "Kamailio Status")
+end
+
+function get_filedetails(filename)
+ return modelfunctions.getfiledetails(filename, is_valid_filename)
+end
+
+function update_filedetails(filedetails)
+ return modelfunctions.setfiledetails(filedetails, is_valid_filename)
+end
+
+function list_files()
+ 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 Kamailio files" })
+end