-- the dhcpd controller module (..., package.seeall) default_action = "status" dep = function( self ) -- do the dependancy check msg = self.model.dep_check() -- make sure nobody accidentally calls this action if msg == nil then redirect(self, "home") end -- go ahead return ( cfe ({ msg = msg }) ) end help = function( self ) return ( cfe ({ option = "" }) ) end delnet = function( self ) local net = {} if not self.clientdata.cmd then redirect(self) end if not self.clientdata.network then redirect(self) end local option = { script = self.conf.script, prefix = self.conf.prefix, controller = self.conf.controller, action = self.conf.action, extra = "" } if self.clientdata.cmd == "delete" then if self.clientdata.confirm == "yes" then msg = self.model.subnet_delete( self.clientdata.network ) redirect(self) else net = self.model.subnet_read( self.clientdata.network ); return ( cfe({ option = option, value = net, msg = msg }) ) end end end settings = function( self ) if not self.clientdata.cmd then redirect(self) end local settings = {} local option = { script = self.conf.script, prefix = self.conf.prefix, controller = self.conf.controller, action = self.conf.action, extra = "" } if self.clientdata.cmd == "update" then tmp = self.clientdata settings = self.model.create_new_settings( tmp.defleasetime, tmp.maxleasetime, tmp.domainname ) errcode, settings = self.model.update_settings( settings ) return ( cfe ({ option = option, value = settings, errcode = errcode })) else settings = self.model.read_settings() return ( cfe ({ option = option, value = settings, errcode = { msg = "", fields={} }}) ) end end editnet = function ( self ) if not self.clientdata.cmd then redirect(self) else if self.clientdata.cmd == "back" then redirect(self) end end local net = {} local option = { script = self.conf.script, prefix = self.conf.prefix, controller = self.conf.controller, action = self.conf.action, extra = "" } if self.clientdata.network then if self.clientdata.network == "choose" then redirect(self) end end if self.clientdata.cmd == "update" then tmp = self.clientdata dynamicx = tmp.dynamichosts advancedx = tmp.advanced if tmp.unknownclients == "allow" then dynamicx = tmp.dynamicx end if tmp.useadvanced ~= "use" then advancedx = tmp.advancedx end net = self.model.create_new_net( tmp.name, tmp.defleasetime, tmp.maxleasetime, tmp.gateway, tmp.domainname, tmp.dnssrv1, tmp.dnssrv2, tmp.subnet, tmp.netmask, tmp.leaserangestart, tmp.leaserangeend, tmp.wpad, tmp.statichosts, tmp.unknownclients, dynamicx, advancedx, tmp.useadvanced ) errcode, net = self.model.subnet_write( net ) return ( cfe({ option = option, value = net, errcode = errcode }) ) end net = self.model.subnet_read( self.clientdata.network ); return ( cfe({ option = option, value = net, errcode = { msg="", fields={} }}) ) end editspc = function ( self ) if not self.clientdata.cmd then redirect( self ) end local option = { script = self.conf.script, prefix = self.conf.prefix, controller = self.conf.controller, action = self.conf.action, extra = "" } if self.clientdata.cmd == "update" then msg = "" fields = {} tmp = self.clientdata errmsg = self.model.validate_dynamichosts( tmp.dynamic ) if #errmsg > 0 then msg = errmsg table.insert(fields, "dynamichosts") end value = self.model.advglobal_update( tmp.preconfig, tmp.postconfig, tmp.dynamic ) return ( cfe({ option = option, value = value, errcode = { msg=msg, fields=fields }}) ) end value = self.model.advglobal_read() return ( cfe({ option = option, value = value, errcode = { msg="", fields={} }}) ) end createnet = function ( self ) if not self.clientdata.cmd then redirect(self) end local option = { script = self.conf.script, prefix = self.conf.prefix, controller = self.conf.controller, action = self.conf.action, extra = "" } if self.clientdata.cmd == "new" then net = self.model.create_new_net( "", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ) return ( cfe({ option = option, value = net, errcode = { msg = "", fields = nil }}) ) elseif self.clientdata.cmd == "create" then tmp = self.clientdata net = self.model.create_new_net( tmp.name, tmp.defleasetime, tmp.maxleasetime, tmp.gateway, tmp.domainname, tmp.dnssrv1, tmp.dnssrv2, tmp.subnet, tmp.netmask, tmp.leaserangestart, tmp.leaserangeend, tmp.wpad, "", tmp.unknownclients, "", "", "" ) errcode, net = self.model.subnet_create( net ) if #errcode.msg == 0 then redirect(self, "home") else return ( cfe({ option = option, value = net, errcode = errcode }) ) end end end status = function ( self ) return cfe({ option = { script = self.conf.script, prefix = self.conf.prefix, controller = self.conf.controller, action = self.conf.action, extra = "", }, value = "", genmsg = genmsg, info = self.model.getstatus() }) end home = function ( self ) -- dependancy check for neccessary libs/packages et al. msg = self.model.dep_check() if msg ~= nil then redirect(self, "dep") end local srvctrl = "" if self.clientdata.srvcmd then srvcmd = self.clientdata.srvcmd if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then srvctrl = self.model.service_control(self.clientdata.srvcmd) end end if self.clientdata.cmd == "generate" then genmsg = self.model.config_generate() end local option = { script = self.conf.script, prefix = self.conf.prefix, controller = self.conf.controller, action = self.conf.action, extra = "" } local info = self.model.getstatus() info.subnets = self.model.get_subnets() -- 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 (string.lower(info.status.value) == "enabled") then management.start.disabled = "yes" end if (string.lower(info.status.value) == "disabled") then management.stop.disabled = "yes" end if (string.lower(info.status.value) == "disabled") then management.restart.disabled = "yes" end return ( cfe({ option = option, value = "", genmsg = genmsg, info = info, management = management, }) ) end viewleases = function ( self ) local filename = "/var/lib/dhcp/dhcpd.leases"; local option = { script = self.conf.script, 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 viewconfig = function ( self ) local filename = "/etc/dhcp/dhcpd.conf" local option = { script = self.conf.script, 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