summaryrefslogtreecommitdiffstats
path: root/syslog-controller.lua
blob: 12a79290e1ee316702999ba8e5ede60f792c745a (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
69
70
71
72
73
74
75
76
module(..., package.seeall)

default_action = "status"

function status(self)
	return self.model.getlogging()
end

function config(self)
	local config = self.model.getconfig()
	if self.clientdata.Save then
		for name,value in pairs(config.value) do
			if value.type == "boolean" then
				value.value = (self.clientdata[name] ~= nil)
			elseif clientdata[name] then
				value.value = clientdata[name]
			end
		end
		config = self.model.updateconfig(config)
		if not config.errtxt then
			config.descr = "Saved config"
		end
	end

	config.type = "form"
	config.label = "Edit config"
	config.option = "Save"

	return config
end

function expert(self)
	-- Save changes
	local config = self.model.get_filedetails()
	if self.clientdata.Save then
		local modifications = self.clientdata.filecontent or ""
		local result = self.model.update_filecontent(modifications)
		if not result.value then
			config.value.filecontent.value = modifications
			config.value.filecontent.errtxt = result.errtxt
			config.errtxt = "Failed to save config!"
		else	
			config = self.model.get_filedetails()
			config.descr = "Saved File"
		end
	end

	config.type = "form"
	config.label = "Edit config"
	config.option = "Save"

	return config
end

function startstop(self)
	local result
	if self.clientdata.action then
		result = self.model:startstop_service(self.clientdata.action)
		self.sessiondata.syslogstartstopresult = result
		self.redirect_to_referrer(self)
	end

	local status = self.model.getstatus()
	if self.sessiondata.syslogstartstopresult then
		result = self.sessiondata.syslogstartstopresult
		self.sessiondata.syslogstartstopresult = nil
	end
	
	return cfe({ type="group", value={status=status, result=result} })
end

function basicstatus(self)
	status = self.model.getstatus()
	version = self.model.getversion()
	return cfe({ type="group", value={status=status, version=version} })
end