summaryrefslogtreecommitdiffstats
path: root/fetchcrl-model.lua
blob: 3d3a5fe09b68de537c25e892226da6d4d1115e8c (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
59
60
61
62
63
64
65
66
67
68
module (..., package.seeall)

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

-- Set variables
local packagename = "fetch-crl"
local configfile = "/etc/fetch-crl/fetch-crl"
local outputdirectory = "/etc/grid-security/certificates"

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

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

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

get_status = function()
	local status = {}
	
	local value, errtxt = processinfo.package_version(packagename)
	status.version = cfe({
		label="Program version",
		value=value,
		errtxt=errtxt,
		name=packagename
	})

	return cfe({ type="group", value=status, label="Fetch-CRL Status" })
end

function startstop_service(action)
	local result = {}
	result.actions = cfe({ type="list", value={"Download", "Delete"}, label="Start/Stop actions" })
	if action then
		result.result = cfe({ label="Start/Stop result" })
	
		if (string.lower(action) == "download") then
			local file = io.popen(path .. "fetch-crl 2>&1")
			if file ~= nil then
				result.result.value = file:read( "*a" )
				file:close()
			end
		elseif (string.lower(action) == "delete") then
			local config = format.parse_ini_file(fs.read_file(configfile) or "", "")
			local dir = config.CRLDIR or outputdirectory
			for file in fs.find(".*\.r0", dir) do
				os.remove(file)
			end
			result.result.value = "Deleted CRL Files"
		else
			result.result.errtxt = "Unknown command!"
		end
	end
	return cfe({ type="group", value=result, label="Start/Stop result" })
end

get_configfile = function()
	return modelfunctions.getfiledetails(configfile)
end

update_configfile = function(filedetails)
	return modelfunctions.setfiledetails(filedetails, {configfile})
end