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
|
module(..., package.seeall)
function handle_form(self, getFunction, setFunction, clientdata, option, label, descr, redirectOnSuccess)
local form = getFunction()
if clientdata[option] then
form.errtxt = nil
for name,value in pairs(form.value) do
value.errtxt = nil
if value.type == "boolean" then
value.value = (clientdata[name] ~= nil)
elseif value.type == "list" then
value.value = {}
if clientdata[name] and clientdata[name] ~= "" then
for ip in string.gmatch(clientdata[name].."\n", "%s*(%S[^\n]*%S)%s*\n") do
table.insert(value.value, ip)
end
end
else
value.value = clientdata[name] or value.value
end
end
form = setFunction(form)
if not form.errtxt then
form.descr = descr
end
form = self:redirect_to_referrer(form)
if redirectOnSuccess and not form.errtxt then
self:redirect(redirectOnSuccess)
end
else
form = self:redirect_to_referrer() or form
end
form.type = "form"
form.option = option
form.label = label
return form
end
function handle_startstop(self, startstopfunction, getstatusfunction, clientdata)
local result
if clientdata.action then
result = startstopfunction(clientdata.action)
end
result = self:redirect_to_referrer(result)
local status = getstatusfunction()
if status.value.status then status = status.value.status end
return cfe({ type="group", value={status=status, result=result} })
end
|