diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | dhcp-controller.lua | 22 | ||||
-rw-r--r-- | dhcp-editspc-html.lsp | 23 | ||||
-rw-r--r-- | dhcp-home-html.lsp | 7 | ||||
-rw-r--r-- | dhcp-model.lua | 74 |
5 files changed, 118 insertions, 9 deletions
@@ -4,6 +4,7 @@ VERSION=1.0_alpha1 APP_DIST=dhcp-controller.lua \ dhcp-editnet-html.lsp \ + dhcp-editspc-html.lsp \ dhcp-home-html.lsp \ dhcp-createnet-html.lsp \ dhcp-delnet-html.lsp \ diff --git a/dhcp-controller.lua b/dhcp-controller.lua index d0a046f..c6d2c83 100644 --- a/dhcp-controller.lua +++ b/dhcp-controller.lua @@ -144,6 +144,28 @@ editnet = function ( self ) return ( cfe({ option = option, value = net, errcode = { msg="", fields={} }}) ) end +editspc = 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 = "" + } + + if self.clientdata.cmd == "update" then + tmp = self.clientdata + value = self.model.advglobal_update( tmp.preconfig, tmp.postconfig ) + return ( cfe({ option = option, value = value, errcode = { msg="", 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 diff --git a/dhcp-editspc-html.lsp b/dhcp-editspc-html.lsp new file mode 100644 index 0000000..8a06c9c --- /dev/null +++ b/dhcp-editspc-html.lsp @@ -0,0 +1,23 @@ +<? + local form = ... + local option = form.option; + local errcode = form.errcode +?> +<h1>DHCPd - Advanced Global Configuration</h1> +These fields are copied into the final dhcpd.conf on configuration generation without any validation check. So only +use them if you extactly know what you are doing here. + +<form name="myform" action="<? io.write(option.script .. option.prefix .. + option.controller .. "/" .. option.action .. option.extra) ?>" method="POST"> + +<h2>DHCPd - Pre Main Configuration</h2> +<table><tr><td><textarea name="preconfig" style="width:600px"><? io.write(form.value.preconfig) ?></textarea></td></tr></table> + +<h2>DHCPd - Post Main Configuration</h2> +<table> +<tr><td><textarea name="postconfig" style="width:600px"><? io.write(form.value.postconfig) ?></textarea></td></tr> +<tr><td><input type="submit" name="cmd" value="update" style="width:100px"></form> +<form action="<? io.write(option.script .. option.prefix .. option.controller .. "/home") ?>" method="POST"> +<input type="submit" name="cmd" value="back" style="width:100px"> +</form></td></tr></table> + diff --git a/dhcp-home-html.lsp b/dhcp-home-html.lsp index faf6c6a..c4ad154 100644 --- a/dhcp-home-html.lsp +++ b/dhcp-home-html.lsp @@ -59,6 +59,13 @@ </table> <br> +<h2>DHCPd - Global Config Pre/Post Code</h2> +<table> +<form action="<? io.write(data.script .. data.prefix .. data.controller .. "/editspc") ?>" method="POST"> +<tr><td><input type=submit name="cmd" value="edit" style="width:100px"></td></tr> +</form> +</table><br> + <h2>DHCPd - View Files</h2> <table> <form action="<? io.write(data.script .. data.prefix .. data.controller .. "/view") ?>" method="POST"> diff --git a/dhcp-model.lua b/dhcp-model.lua index 63a0533..1b3c71d 100644 --- a/dhcp-model.lua +++ b/dhcp-model.lua @@ -104,6 +104,9 @@ config_generate = function() tmpfile:write( "authoritative;\n" ) tmpfile:write( "ddns-update-style none;\n\n" ) tmpfile:write( "option local-wpad-server code 252 = text;\n\n" ) + + config_generate_extconfig( tmpfile, "preconfig" ) + if #settings.domainname.value > 0 then tmpfile:write( "option domain-name \"" .. settings.domainname.value .. "\";\n" ) end @@ -171,15 +174,12 @@ config_generate = function() --- generate advanced part / drop in advancedfile = io.open( cfgdir .. net.name.value .. ".advanced", "r" ) if advancedfile ~= nil then - advanceddata = advancedfile:read( "*a" ) - advancedfile:close() - if advanceddata == nil then - advancedfile:close() - msg = "Configuration Generation Failed!\n\n" .. - "Reason: failed to read advanced file for '" .. net.name.value .. "'" - return msg - end - tmpfile:write( advanceddata .. "\n" ) + nxtline = advancedfile:read( "*l" ) + while nxtline ~= nil do + tmpfile:write( " " .. nxtline .. "\n" ) + nxtline = advancedfile:read( "*l" ) + end + advancedfile:close() end --- @@ -194,12 +194,25 @@ config_generate = function() return msg end + config_generate_extconfig( tmpfile, "postconfig" ) + tmpfile:close() os.rename( tmpfilename, "/etc/dhcp/dhcpd.conf" ) return "Configuration Generation Successful!\n" end +config_generate_extconfig = function( outfile, postfix ) + infile = io.open( cfgdir .. "dhcpd." .. postfix, "r" ) + if infile ~= nil then + data = infile:read( "*a" ) + if data ~= nil then + outfile:write( "\n" .. data .. "\n" ) + end + infile:close() + end +end + generate_pool = function( tmpfile, tmpfilename, net ) if not validator.is_ipv4( net.leaserangestart.value ) or not validator.is_ipv4( net.leaserangeend.value ) then @@ -323,6 +336,49 @@ subnet_delete = function( name ) return msg end +advglobal_read = function() + + preconfig = "" + postconfig = "" + + file = io.open( cfgdir .. "dhcpd.preconfig", "r" ) + if file ~= nil then + preconfig = file:read( "*a" ) + if preconfig == nil then + preconfig = "" + end + file:close() + end + + file = io.open( cfgdir .. "dhcpd.postconfig", "r" ) + if file ~= nil then + postconfig = file:read( "*a" ) + if postconfig == nil then + postconfig = "" + end + file:close() + end + + return cfe({ preconfig = preconfig, postconfig = postconfig }) +end + +advglobal_update = function( preconfig, postconfig ) + + file = io.open( cfgdir .. "dhcpd.preconfig", "wb+" ) + if file ~= nil then + file:write( preconfig ) + file:close() + end + + file = io.open( cfgdir .. "dhcpd.postconfig", "wb+" ) + if file ~= nil then + file:write( postconfig ) + file:close() + end + + return cfe({ preconfig = preconfig, postconfig = postconfig }) +end + subnet_read = function( name ) local filename = cfgdir .. name .. ".subnet" local net = create_new_net( name, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ) |