summaryrefslogtreecommitdiffstats
path: root/fetchmail-controller.lua
blob: 03668f6b387ba6b0a86582c861b70a46e483549a (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
module(..., package.seeall)

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

local function displaycmdsave(self)
	-- Add a cmd button to the view
	local cmdsave = cfe({ name="cmdsave",
		label="Save/Apply above settings",
		value="Save",
		type="submit",
		})
	return cmdsave
end

local function displaycmdmanagement(pidofstatus)
	-- Add a management buttons
	local management = {}
	management.start = cfe({ name="cmdmanagement",
		label="Program control-panel",
		value="Start",
		type="submit",
		})
	management.stop = cfe({ name="cmdmanagement",
		label="Program control-panel",
		value="Stop",
		type="submit",
		})
	management.restart = cfe({ name="cmdmanagement",
		label="Program control-panel",
		value="Restart",
		type="submit",
		})
	-- next CFE can be used to present the result of the previous action
	management.actionresult = cfe({ name="actionresult",
		label="Previous action result",
		})

	-- Disable management buttons based on if the process is running or not
	if (pidofstatus) then 
		management.start.disabled = "yes"
	else
		management.stop.disabled = "yes"
		management.restart.disabled = "yes"
	end

	return management
end

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

default_action = "status"

function status(self)
	return { status=self.model:getstatus(self) }
end

function expert(self)
	-- Start/Stop/Restart process
	local cmdmanagement, actionresult
	if ( self.clientdata.cmdmanagement) then
	cmdmanagement = cfe({ 
		name="cmdmanagement",
		label="Previous action result",
		action=cfe({ 
			name="cmdmanagement", 
			value=string.lower(self.clientdata.cmdmanagement),  -- This row contains start/stop/restart (one of these commands)
			}),
		})
		actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
	end

	-- Save changes
	local modifications = self.clientdata.filecontent or ""
	if ( self.clientdata.cmdsave) then
		modifications = self.model:update_filecontent(modifications)
	end

	local status = self.model:getstatus(self)
	local config = self.model:get_filedetails()


	-- Display save button
	config.cmdsave = displaycmdsave()


---[[	-- Management buttons (Hide/show buttons
	local pidofstatus
	if (string.lower(status.status.value) == "enabled" ) then pidofstatus = true end
	management = displaycmdmanagement(pidofstatus)
	if (actionresult) then
		management.actionresult.descr=cmdmanagement.descr
		management.actionresult.errtxt=cmdmanagement.errtxt
	end
--]]

	return { 	
		option={ script=self.conf.script,
			prefix=self.conf.prefix,
			controller = self.conf.controller,
			action = "expert", },
		management = management,
		config = config, 
		status = status,
		}

end