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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
module (..., package.seeall)
require("posix")
-- Cause an http redirect to our "read" action
-- We use the self.conf table because it already has prefix,controller,etc
-- The redir code is defined in the application error handler (acf-controller)
local list_redir = function (self)
self.conf.action = "status"
self.conf.type = "redir"
error (self.conf)
end
mvc={}
mvc.on_load = function(self, parent)
if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then
self.worker[self.conf.action] = list_redir(self)
end
end
local function getstatus(self)
local status = self.model.getstatus()
if (#status.status.value > 0) then
status.status.value = "Enabled"
else
status.status.value = "Disabled"
end
return status
end
local function displaycmdmanagement(disablestart,disablestop,disablerestart)
-- 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",
})
-- Disable management buttons based on if the process is running or not
if (disablestart) then management.start.disabled = "yes" end
if (disablestop) then management.stop.disabled = "yes" end
if (disablerestart) then management.restart.disabled = "yes" end
return management
end
function status(self)
local srvcmdresult = nil
local srvcmd = self.clientdata.srvcmd
local status = getstatus(self)
local alerts,alertresult = self.model:read_alert()
return ({
status = status,
alerts=alerts,
alertresult=alertresult,
url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
end
function expert(self)
local cmd = self.clientdata.cmd
local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
local modifications = self.clientdata.filecontent or ""
if ( self.clientdata.cmdsave ) then
modifications = self.model:update_filecontent(modifications)
end
-- Start/Stop/Restart process
local cmdmanagement
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)
}),
})
local actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
end
local status = getstatus(self)
local file = self.model:get_filedetails()
-- Add buttons
file.cmdsave = cfe ({
name="cmdsave",
label="Apply settings",
value="Apply",
type="submit",
})
if (self.clientdata.cmdsave) then
file.cmdsave.descr="* Changes has been saved!"
end
-- Management buttons
local disablestart,disablestop,disablerestart
-- Disable management buttons based on if the process is running or not
if (string.lower(status.status.value) == "enabled" ) then
disablestart = "yes"
else
disablestop = "yes"
end
-- Display management buttons
local management = displaycmdmanagement(disablestart,disablestop,disablerestart)
-- if ( cmd ~= nil ) then
-- startstop = self.model:startstop_service( cmd )
-- end
return ( {
management = management,
cmdmanagement = cmdmanagement,
status = status,
file = file,
modifications = modifications,
url = url, } )
end
|