lighttpd-model.lua 2.05 KB
Newer Older
Jeff Bilyk's avatar
Jeff Bilyk committed
1 2 3 4 5 6 7 8 9 10
module(..., package.seeall)

-- Load libraries
require("modelfunctions")
require("fs")
require("format")

-- Set variables
local processname = "lighttpd"
local packagename = "lighttpd"
11
local filelist = {"/etc/lighttpd/lighttpd.conf", "/etc/lighttpd/mod_cgi.conf", "/etc/lighttpd/mod_fastcgi.conf", "/etc/lighttpd/mod_fastcgi_fpm.conf"}
Jeff Bilyk's avatar
Jeff Bilyk committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25

local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "

-- ################################################################################
-- LOCAL FUNCTIONS

-- ################################################################################
-- PUBLIC FUNCTIONS

function startstop_service(action)
	return modelfunctions.startstop_service(processname, action)
end

function getstatus()
26
	return modelfunctions.getstatus(processname, packagename, "Lighttpd Status")
Jeff Bilyk's avatar
Jeff Bilyk committed
27 28 29
end

function getstatusdetails()
30
	return cfe({ type="longtext", value="", label="Lighttpd Status Details" })
Jeff Bilyk's avatar
Jeff Bilyk committed
31 32 33 34 35 36 37 38 39 40 41 42
end

function getfilelist()
	local listed_files = {}

	for i,name in ipairs(filelist) do
		local filedetails = fs.stat(name) or {}
		table.insert ( listed_files , {filename=name, mtime=filedetails.mtime or "---", filesize=filedetails.size or "0"} )
	end

	table.sort(listed_files, function (a,b) return (a.filename < b.filename) end )

43
	return cfe({ type="list", value=listed_files, label="Lighttpd File List" })
Jeff Bilyk's avatar
Jeff Bilyk committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57
end

function getfiledetails(filename)
	return modelfunctions.getfiledetails(filename, filelist)
end

function updatefiledetails(filedetails)
	return modelfunctions.setfiledetails(filedetails, filelist)
end

function getlogfile ()
	local files = {}
	local logfilepath = format.parse_configfile(fs.read_file(filelist[1]) or "").LogFile
	if not logfilepath then
58
		files[#files+1] = {path = "/var/log/lighttpd/access.log"}
Jeff Bilyk's avatar
Jeff Bilyk committed
59 60 61 62 63
	else
		files[#files+1] = {path=logfilepath}
	end
	logfilepath = format.parse_configfile(fs.read_file(filelist[2]) or "").UpdateLogFile
	if not logfilepath then
64
		files[#files+1] = {path = "/var/log/lighttpd/error.log"}
Jeff Bilyk's avatar
Jeff Bilyk committed
65 66 67 68 69
	else
		files[#files+1] = {path=logfilepath}
	end
	return cfe({ value=files, label="Lighttpd logfiles" })
end