diff options
Diffstat (limited to 'dhcp-controller.lua')
-rw-r--r-- | dhcp-controller.lua | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/dhcp-controller.lua b/dhcp-controller.lua new file mode 100644 index 0000000..c0be37d --- /dev/null +++ b/dhcp-controller.lua @@ -0,0 +1,121 @@ +-- 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 ) + + 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 then + 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="text" } + } + self.model.subnet_write( net ) + return ( cfe({ option = option, value = net, error = { value = nil, fields = nil }}) ) + end + end + + net = self.model.subnet_read( self.clientdata.network ); + return ( cfe({ option = option, value = net, error = { value=nil, fields=nil }}) ) +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 + + 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 + |