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 list_redir = function(self)
self.conf.action = "status"
self.conf.type = "redir"
error(self.conf)
end
local cfgfile
mvc={}
mvc.on_load = function(self, parent)
cfgfile = self:new("cfgfile")
if (self.worker[self.conf.action] == nil) or (self.conf.action == "init") then
self.worker[self.conf.action] = list_redir(self)
end
end
status = function (self)
local cmd = self.clientdata.cmd
local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
local status, errors = self.model:getstatus()
return ( {status = status,
errors = errors,
lbustatus = self.model:list(),
url = url, } )
end
config = function (self)
local errors = {}
local cmdresult
if (self.clientdata.cmd_delete_excluded) and (self.clientdata.lbu_excluded) then
cmdresult = self.model:lbuincexcl("exclude", self.clientdata.lbu_excluded, "remove")
end
if (self.clientdata.cmd_delete_included) and (self.clientdata.lbu_included) then
cmdresult = self.model:lbuincexcl("include", self.clientdata.lbu_included, "remove")
end
if (self.clientdata.config_submit) then
local variables="ENCRYPTION LBU_MEDIA DEFAULT_CIPHER PASSWORD"
cmdresult = {}
for var in string.gmatch(variables, "%S+") do
cmdresult[var] = self.model:editconfig(var, self.clientdata[var], "change_value")
end
end
if (self.clientdata.cmd_add_include) and (self.clientdata.item_add_include) then
cmdresult = self.model:lbuincexcl("include", self.clientdata.item_add_include, "add")
end
if (self.clientdata.cmd_add_exclude) and (self.clientdata.item_add_exclude) then
cmdresult = self.model:lbuincexcl("exclude", self.clientdata.item_add_exclude, "add")
end
-- This needs to be done /after/ the editing of the config (done earlier in this code)
local status,errors = self.model:getstatus()
local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
return ( {status = status,
cmdresult = cmdresult,
errors = errors,
clientdata = self.clientdata,
config = self.model:getconfig(),
url = url, } )
end
function commit(self)
local cmdresult, cmderror
local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
local cmdflag = nil
if (self.clientdata.lbucleanmedia) then cmdflag = "-d" else cmdflag = "" end
if (self.clientdata.lbusimulate) then
cmdresult, cmderror = self.model:getsimulate(cmdflag)
end
if (self.clientdata.lbucommit) then
cmdresult, cmderror = self.model:getcommit(cmdflag)
end
-- If no clientdata then do a dryrun and see if it's going to work else report
if not (cmdresult) then
tmp_cmdresult, cmderror = self.model:getsimulate()
end
local status, errors = self.model:getstatus()
if (errors.last) then
self.conf.action = "config"
self.conf.type = "redir"
return config(self)
end
return ( {status = status,
errors = errors,
cmdresult = cmdresult,
cmdflag = cmdflag,
cmderror = cmderror,
clientdata = self.clientdata,
url = url, } )
end
expert = function (self)
local modifications = self.clientdata.modifications or ""
if ( self.clientdata.cmdsave) then
modifications = self.model:update_filecontent(modifications)
end
local status = self.model.getstatus()
local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
return { file = self.model:get_filedetails(),
status = status,
clientdata = self.clientdata,
url = url, }
end
|