diff options
author | Andreas Brodmann <andreas.brodmann@gmail.com> | 2007-11-20 16:51:10 +0000 |
---|---|---|
committer | Andreas Brodmann <andreas.brodmann@gmail.com> | 2007-11-20 16:51:10 +0000 |
commit | 7c37e7e2a7883b71f56c399da156e6b87ad33bfa (patch) | |
tree | 56007fabe5ecbb47de8e7291bd25c01677ad7c9e /dhcp-model.lua | |
parent | bde1ff5a701b6e48d9e692a26a1dc08e019c53e3 (diff) | |
download | acf-dhcp-7c37e7e2a7883b71f56c399da156e6b87ad33bfa.tar.bz2 acf-dhcp-7c37e7e2a7883b71f56c399da156e6b87ad33bfa.tar.xz |
Cleaned up the dhcp config generation code in a way that the two
files dhcpd.preconfig / dhcpd.postconfig are not copied into the
config but the config now contains an "include" statement; this
way the dhcpd will read them himself.
Those two files can be used by the admin to place custom
configurations not possible using the gui.
git-svn-id: svn://svn.alpinelinux.org/acf/dhcp/trunk@347 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'dhcp-model.lua')
-rw-r--r-- | dhcp-model.lua | 90 |
1 files changed, 24 insertions, 66 deletions
diff --git a/dhcp-model.lua b/dhcp-model.lua index f0c1ada..858f3f0 100644 --- a/dhcp-model.lua +++ b/dhcp-model.lua @@ -105,7 +105,7 @@ config_generate = function() tmpfile:write( "ddns-update-style none;\n\n" ) tmpfile:write( "option local-wpad-server code 252 = text;\n\n" ) - config_generate_extconfig( tmpfile, "preconfig" ) + tmpfile:write( "include \"/etc/dhcp/dhcpd.preconfig\";\n" ) if #settings.domainname.value > 0 then tmpfile:write( "option domain-name \"" .. settings.domainname.value .. "\";\n" ) @@ -196,7 +196,7 @@ config_generate = function() return msg end - config_generate_extconfig( tmpfile, "postconfig" ) + tmpfile:write( "include \"/etc/dhcp/dhcpd.postconfig\";\n" ) tmpfile:close() os.rename( tmpfilename, "/etc/dhcp/dhcpd.conf" ) @@ -204,17 +204,6 @@ config_generate = function() 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 @@ -243,7 +232,7 @@ end generate_hosts = function( outfile ) - retval = "" + local retval = "" outfile:write( "\n####### STATIC HOSTS BEGIN ######\n\n" ) @@ -255,6 +244,8 @@ generate_hosts = function( outfile ) end end + outfile:write( "###### STATIC HOSTS END ######\n" ) + retval = generate_hosts_dynamic( outfile ) return retval @@ -262,21 +253,25 @@ end generate_hosts_persubnet = function( outfile, netname ) - retval = "" + local retval = "" - hostsfile = io.open( cfgdir .. netname .. ".static", "r" ) + local hostsfile = io.open( cfgdir .. netname .. ".static", "r" ) if hostsfile ~= nil then - hostsdata = hostsfile:read( "*a" ) + local hostsdata = hostsfile:read( "*a" ) + hostsfile:close() if hostsdata ~= nil then + if #hostsdata <= 0 then + return retval + end outfile:write( "# " .. netname .. "\n" ) outfile:write( "group {\n" ) local done = false - hosttoken = tokenizer.new( hostsdata, "\n" ) + local hosttoken = tokenizer.new( hostsdata, "\n" ) while not done do hosttoken, nexthost = tokenizer.next( hosttoken ) if nexthost ~= nil then if string.sub( nexthost, 1, 1) ~= "#" then - spectoken = tokenizer.new( nexthost, ";" ) + local spectoken = tokenizer.new( nexthost, ";" ) spectoken, hostname = tokenizer.next( spectoken ) spectoken, ip = tokenizer.next( spectoken ) spectoken, mac = tokenizer.next( spectoken ) @@ -291,11 +286,9 @@ generate_hosts_persubnet = function( outfile, netname ) end end outfile:write( "}\n\n" ) - outfile:write( "###### STATIC HOSTS END ######\n\n" ) else retval = "Configuration Generation Failed: Failed to read data from subnet static hosts file for " .. netname end - hostsfile:close() end return retval @@ -303,20 +296,24 @@ end generate_hosts_dynamic = function( outfile ) - retval = "" + local retval = "" - hostsfile = io.open( cfgdir .. "dhcpd.dynamic", "r" ) + local hostsfile = io.open( cfgdir .. "dhcpd.dynamic", "r" ) if hostsfile ~= nil then - hostsdata = hostsfile:read( "*a" ) + local hostsdata = hostsfile:read( "*a" ) + hostsfile:close() if hostsdata ~= nil then + if #hostsdata <= 0 then + return retval + end outfile:write( "group {\n" ) local done = false - hosttoken = tokenizer.new( hostsdata, "\n" ) + local hosttoken = tokenizer.new( hostsdata, "\n" ) while not done do hosttoken, nexthost = tokenizer.next( hosttoken ) if nexthost ~= nil then if string.sub( nexthost, 1, 1) ~= "#" then - spectoken = tokenizer.new( nexthost, ";" ) + local spectoken = tokenizer.new( nexthost, ";" ) spectoken, hostname = tokenizer.next( spectoken ) spectoken, mac = tokenizer.next( spectoken ) spectoken, comment = tokenizer.next( spectoken ) @@ -337,45 +334,6 @@ generate_hosts_dynamic = function( outfile ) return retval end -generate_hosts_old = function( tmpfile, tmpfilename, net ) - --- generate dynamic hosts - dynamichostsfile = io.open( cfgdir .. net.name.value .. ".dynamic", "r" ) - if dynamichostsfile ~= nil then - dynamichosts = dynamichostsfile:read( "*a" ) - if dynamichosts == nil then - dynamichostsfile:close() - msg = "Configuration Generation Failed!\n\n" .. - "Reason: failed to read dynamic hosts file for '" .. net.name.value .. "'" - return msg - end - msg = validate_dynamichosts( dynamichosts ) - - --- loop through all hosts - done = false - hosttoken = tokenizer.new( dynamichosts, "\n" ) - while not done do - hosttoken, nexthost = tokenizer.next( hosttoken ) - if nexthost ~= nil then - if string.sub( nexthost, 1, 1) ~= "#" then - spectoken = tokenizer.new( nexthost, ";" ) - spectoken, hostname = tokenizer.next( spectoken ) - spectoken, mac = tokenizer.next( spectoken ) - spectoken, comment = tokenizer.next( spectoken ) - tmpfile:write(" host " .. hostname .. " {\n") - tmpfile:write(" hardware ethernet " .. mac .. ";\n") - tmpfile:write(" }\n") - end - else - done = true - end - end - dynamichostsfile:close() - end - --- - - return "" -end - subnet_delete = function( name ) local msg = "" @@ -642,7 +600,7 @@ end validate_dynamichosts = function( dynamichosts ) local line = 1 - local msg = "" + msg = "" local done = false hosttoken = tokenizer.new( dynamichosts, "\n") while not done do |