summaryrefslogtreecommitdiffstats
path: root/dhcp-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'dhcp-model.lua')
-rw-r--r--dhcp-model.lua74
1 files changed, 65 insertions, 9 deletions
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 )