-- acf model for /etc/dhcp/* -- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2 module (..., package.seeall) require("lfs") local subnet = { } local cfgdir = "/etc/dhcp/" subnet_read = function( name ) local filename = cfgdir .. name .. ".subnet" local net = { name = cfe({ type="message", value=name, label="Name" }), defleasetime = cfe({ label="Default Lease Time" }), maxleasetime = cfe({ label="Maximum Lease Time" }), gateway = cfe({ label="Gateway"}), domainname = cfe({ label="Domainname" }), dnssrv1 = cfe({ label="DNS Server 1" }), dnssrv2 = cfe({ label="DNS Server 2" }), subnet = cfe({ label="Subnet" }), netmask = cfe({ label="Netmask" }), leaserangestart = cfe({ label="Lease Range Start" }), leaserangeend = cfe({ label="Lease Range End" }), wpad = cfe({ label="Web Proxy Auto Discovery", type="select", option = { "yes", "no" } }) } for line in io.lines(filename) do if (string.sub(line, 1, 15) == "def-lease-time:") then net.defleasetime.value = string.sub(line, 17) elseif (string.sub(line, 1, 15) == "max-lease-time:") then net.maxleasetime.value = string.sub(line, 17) elseif (string.sub(line, 1, 8) == "gateway:") then net.gateway.value = string.sub(line, 10) elseif (string.sub(line, 1, 12) == "domain-name:") then net.domainname.value = string.sub(line, 14) elseif (string.sub(line, 1, 10) == "dns-srv-1:") then net.dnssrv1.value = string.sub(line, 12) elseif (string.sub(line, 1, 10) == "dns-srv-2:") then net.dnssrv2.value = string.sub(line, 12) elseif (string.sub(line, 1, 7) == "subnet:") then net.subnet.value = string.sub(line, 9) elseif (string.sub(line, 1, 8) == "netmask:") then net.netmask.value = string.sub(line, 10) elseif (string.sub(line, 1, 18) == "lease-range-start:") then net.leaserangestart.value = string.sub(line, 20) elseif (string.sub(line, 1, 16) == "lease-range-end:") then net.leaserangeend.value = string.sub(line, 18) elseif (string.sub(line, 1, 5) == "wpad:") then net.wpad.value = string.sub(line, 7) end end return net end subnet_write = function( net ) local filename = cfgdir .. net.name.value .. ".subnet" local file = io.open( filename, "w+" ) file:write( "def-lease-time: " .. net.defleasetime.value .. "\n" ) file:write( "max-lease-time: " .. net.maxleasetime.value .. "\n" ) file:write( "gateway: " .. net.gateway.value .. "\n" ) file:write( "domain-name: " .. net.domainname.value .. "\n" ) file:write( "dns-srv-1: " .. net.dnssrv1.value .. "\n" ) file:write( "dns-srv-2: " .. net.dnssrv2.value .. "\n" ) file:write( "subnet: " .. net.subnet.value .. "\n" ) file:write( "netmask: " .. net.netmask.value .. "\n" ) file:write( "lease-range-start: " .. net.leaserangestart.value .. "\n" ) file:write( "lease-range-end: " .. net.leaserangeend.value .. "\n" ) file:write( "wpad: " .. net.wpad.value .. "\n" ) file:close() return net end read_file = function ( filename ) local contents = "" local line = "" local file = io.open( filename, "r" ) if file ~= nil then line = file:read( "*l" ) while line ~= nil do contents = contents .. "\n" .. line line = file:read( "*l" ) end file:close() else contents = "\n Error: File not found!\n\n" end return contents end is_running = function( process ) local retval = false local file = io.popen("pidof " .. process) if file ~= nil then local line = file:read( "*l" ) file:close() if #line > 0 then retval = true end end return retval end get_dhcpd_version = function() local retval = "dhcpd" local file = io.popen("/usr/sbin/dhcpd --version") if file ~= nil then local line = file:read( "*a" ) if #line > 0 then retval = line end file:close() end return retval end service_control = function ( command ) local retval = "" local line = "" local file = io.popen( "/etc/init.d/dhcpd " .. command ) if file ~= nil then line = file:read( "*l" ) while line ~= nil do retval = retval .. "\n" .. line line = file:read( "*l" ) end file:close() end return retval end function nonil( value ) local retval = "" if value ~= nil then retval = value end return retval end get_subnets = function () local retval = retval or {} for sn in lfs.dir( cfgdir ) do if string.sub(sn, -7) == ".subnet" then table.insert(retval, string.sub(sn, 1, -8)) end end return retval end