From 3f7c448060b852c4fdde1d9698dbde5794d5c980 Mon Sep 17 00:00:00 2001 From: Andreas Brodmann Date: Mon, 19 Nov 2007 15:56:10 +0000 Subject: /acf/dhcp: added global pre/post config generation input for proprietary config code by the user git-svn-id: svn://svn.alpinelinux.org/acf/dhcp/trunk@337 ab2d0c66-481e-0410-8bed-d214d4d58bed --- Makefile | 1 + dhcp-controller.lua | 22 +++++++++++++++ dhcp-editspc-html.lsp | 23 ++++++++++++++++ dhcp-home-html.lsp | 7 +++++ dhcp-model.lua | 74 ++++++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 dhcp-editspc-html.lsp diff --git a/Makefile b/Makefile index 332a627..a229b23 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ + +

DHCPd - Advanced Global Configuration

+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. + +
" method="POST"> + +

DHCPd - Pre Main Configuration

+
+ +

DHCPd - Post Main Configuration

+ + +
+
" method="POST"> + +
+ 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 @@
+

DHCPd - Global Config Pre/Post Code

+ +" method="POST"> + + +

+

DHCPd - View Files

" 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 ) -- cgit v1.2.3