summaryrefslogtreecommitdiffstats
path: root/freeswitch-model.lua
blob: 3095cde715bd9261d0fee74f34e34ad8a089013b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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