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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
-- the dhcpd controller
module (..., package.seeall)
-- 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 = "home"
self.conf.type = "redir"
error (self.conf)
end
local pvt = {}
mvc= {}
mvc.on_load = function(self, parent)
-- If they try to run a bogus action, send them to read
if ( rawget(self.worker, self.conf.action) == nil ) then
list_redir(self)
end
pvt.parent_on_exec = parent.worker.mvc.post_exec
logit ("dhcpd controller on_load has finished")
end
mvc.pre_exec = function (self)
logit ("dhcpd-controller pre_exec activated")
-- pvt.parent_on_exec ()
end
mvc.post_exec = function ( self )
logit ("dhcpd-controller post_exec activated")
return pvt.parent_on_exec()
end
editnet = function ( self )
if not self.clientdata.cmd then
list_redir(self)
end
local net = {}
local option = { script = ENV["SCRIPT_NAME"],
prefix = self.conf.prefix,
controller = self.conf.controller,
action = self.conf.action,
extra = ""
}
if self.clientdata.network then
if self.clientdata.network == "choose" then
list_redir(self)
end
end
if self.clientdata.cmd == "Update" then
net = { name = { label="Name", value=self.model.nonil(self.clientdata.name), type="message" },
defleasetime = { label="Default Lease Time", value=self.model.nonil(self.clientdata.defleasetime), type="text" },
maxleasetime = { label="Maximum Lease Time", value=self.model.nonil(self.clientdata.maxleasetime), type="text" },
gateway = { label="Gateway", value=self.model.nonil(self.clientdata.gateway), type="text" },
domainname = { label="Domainname", value=self.model.nonil(self.clientdata.domainname), type="text" },
dnssrv1 = { label="DNS Server 1", value=self.model.nonil(self.clientdata.dnssrv1), type="text" },
dnssrv2 = { label="DNS Server 2", value=self.model.nonil(self.clientdata.dnssrv2), type="text" },
subnet = { label="Subnet", value=self.model.nonil(self.clientdata.subnet), type="text" },
netmask = { label="Netmask", value=self.model.nonil(self.clientdata.netmask), type="text" },
leaserangestart = { label="Lease Range Start", value=self.model.nonil(self.clientdata.leaserangestart), type="text" },
leaserangeend = { label="Lease Range End", value=self.model.nonil(self.clientdata.leaserangeend), type="text" },
wpad = { label="Web Proxy Auto Discovery", value=self.model.nonil(self.clientdata.wpad),
type="select", option = { "yes", "no"} }
}
self.model.subnet_write( net )
return ( cfe({ option = option, value = net, error = { value = nil, fields = nil }}) )
end
net = self.model.subnet_read( self.clientdata.network );
return ( cfe({ option = option, value = net, error = { value=nil, fields=nil }}) )
end
createnet = function ( self )
if not self.clientdata.cmd then
list_redir(self)
end
local option = { script = ENV["SCRIPT_NAME"],
prefix = self.conf.prefix,
controller = self.conf.controller,
action = self.conf.action,
extra = ""
}
net = { name = { label="Name", value=self.model.nonil(self.clientdata.name), type="message" },
defleasetime = { label="Default Lease Time", value=self.model.nonil(self.clientdata.defleasetime), type="text" },
maxleasetime = { label="Maximum Lease Time", value=self.model.nonil(self.clientdata.maxleasetime), type="text" },
gateway = { label="Gateway", value=self.model.nonil(self.clientdata.gateway), type="text" },
domainname = { label="Domainname", value=self.model.nonil(self.clientdata.domainname), type="text" },
dnssrv1 = { label="DNS Server 1", value=self.model.nonil(self.clientdata.dnssrv1), type="text" },
dnssrv2 = { label="DNS Server 2", value=self.model.nonil(self.clientdata.dnssrv2), type="text" },
subnet = { label="Subnet", value=self.model.nonil(self.clientdata.subnet), type="text" },
netmask = { label="Netmask", value=self.model.nonil(self.clientdata.netmask), type="text" },
leaserangestart = { label="Lease Range Start", value=self.model.nonil(self.clientdata.leaserangestart), type="text" },
leaserangeend = { label="Lease Range End", value=self.model.nonil(self.clientdata.leaserangeend), type="text" },
wpad = { label="Web Proxy Auto Discovery", value=self.model.nonil(self.clientdata.wpad),
type="select", option = { "yes", "no"} }
}
if self.clientdata.cmd == "new" then
return ( cfe({ option = option, value = net, error = { value = nil, fields = nil }}) )
elseif self.clientdata.cmd == "create" then
return ( cfe({ option = option, value = net, error = { value = nil, fields = nil }}) )
end
end
home = function ( self )
local srvctrl = ""
if self.clientdata.srvcmd then
srvctrl = self.model.service_control(self.clientdata.srvcmd)
end
local option = { script = ENV["SCRIPT_NAME"],
prefix = self.conf.prefix,
controller = self.conf.controller,
action = self.conf.action,
extra = ""
}
local info = { status = { value = "stopped" }, version = { value = self.model.get_dhcpd_version() }, srvctrl = { value = srvctrl} };
if self.model.is_running( "dhcpd" ) then
info.status.value = "running"
end
info.subnets = self.model.get_subnets()
return ( cfe({ option = option, value = "", info = info }) )
end
view = function ( self )
local filename = ""
if self.clientdata.conf then
filename = "/etc/dhcp/dhcpd.conf"
elseif self.clientdata.leases then
filename = "/var/lib/dhcpd/dhcpd.leases";
else
list_redir(self)
end
local option = { script = ENV["SCRIPT_NAME"],
prefix = self.conf.prefix,
controller = self.conf.controller,
action = self.conf.action,
extra = ""
}
local value = { filename = { value=filename },
contents = { value=self.model.read_file(filename) }
}
return ( cfe({ option = option, value = value }) )
end
|