-- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2 module (..., package.seeall) -- Load libraries require("modelfunctions") --require "posix" require("fs") require("format") require("validator") -- Set variables local processname = "asterisk" local packagename = "asterisk" local baseurl = "/etc/asterisk" -- ################################################################################ -- 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 get_status = function() return modelfunctions.getstatus(processname, packagename, "Asterisk Status") end -- local implementation to add reload actions function startstop_service(action) local cmdresult = cfe({ label="Start/Stop result" }) if (string.lower(action) == "start") or (string.lower(action) == "stop") or (string.lower(action) == "restart") or (string.lower(action) == "reload") then local file = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin /etc/init.d/" .. processname .. " " .. string.lower(action) .. " 2>&1" ) if file ~= nil then cmdresult.value = file:read( "*a" ) file:close() end posix.sleep(2) -- Wait for the process to start|stop else cmdresult.errtxt = "Unknown command!" end return cmdresult end get_file = function(filename) return modelfunctions.getfiledetails(filename, is_valid_filename) end update_file = function(filedetails) return modelfunctions.setfiledetails(filedetails, is_valid_filename) 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 Asterisk files" }) end