summaryrefslogtreecommitdiffstats
path: root/dhcp-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'dhcp-model.lua')
-rw-r--r--dhcp-model.lua45
1 files changed, 30 insertions, 15 deletions
diff --git a/dhcp-model.lua b/dhcp-model.lua
index cad7ba8..d26e2ee 100644
--- a/dhcp-model.lua
+++ b/dhcp-model.lua
@@ -5,6 +5,7 @@ module (..., package.seeall)
--- get additional libraries
require("modelfunctions")
validator = require("acf.validator")
+fs = require("acf.fs")
local subnet = {}
local configfile = "/etc/dhcp/dhcpd.conf"
@@ -418,7 +419,8 @@ create_new_host = function()
return cfe({ type="group", value=host, label="Host" })
end
-host_read = function( name )
+host_read = function(self, clientdata)
+ local name = clientdata.host
config = config or parseconfigfile(fs.read_file(configfile) or "")
local host = create_new_host()
host.value.host.value = name
@@ -484,14 +486,19 @@ host_create = function(self, host)
return host
end
-host_delete = function(name)
+get_host_delete = function()
+ local host = cfe({ label="Host" })
+ return cfe({ type="group", value={host=host}, label="Delete Host" })
+end
+
+host_delete = function(self, host)
local file = fs.read_file(configfile) or ""
config = config or parseconfigfile(file)
local cmdresult = cfe({ value="Failed to delete host - not found", label="Delete host result" })
local hosts = get_hosts()
- for i,host in ipairs(hosts.value) do
- if host == name then
- local start, endd = string.find(file, "host%s*"..replacemagiccharacters(name).."[^{]*{")
+ for i,h in ipairs(hosts.value) do
+ if h == host.value.host.value then
+ local start, endd = string.find(file, "host%s*"..replacemagiccharacters(h).."[^{]*{")
endd = find_section_end(file, endd)
endd = string.find(file, "\n", endd)
file = string.sub(file, 1, start-1) .. string.sub(file, endd+1, -1)
@@ -534,7 +541,8 @@ create_new_subnet = function()
return cfe({ type="group", value=net, label="Subnet" })
end
-subnet_read = function( name )
+subnet_read = function(self, clientdata)
+ local name = clientdata.subnet
config = config or parseconfigfile(fs.read_file(configfile) or "")
local net = create_new_subnet()
net.value.subnet.value = name
@@ -643,24 +651,31 @@ subnet_create = function(self, net)
return net
end
-subnet_delete = function(name)
+get_subnet_delete = function()
+ local subnet = cfe({ label="Subnet" })
+ return cfe({ type="group", value={subnet=subnet}, label="Delete Subnet" })
+end
+
+subnet_delete = function(self, subnet)
local file = fs.read_file(configfile) or ""
config = config or parseconfigfile(file)
- local cmdresult = cfe({ value="Failed to delete subnet - not found", label="Delete subnet result" })
+ subnet.value.subnet.errtxt = "Subnet not found"
+ subnet.errtxt = "Failed to delete subnet"
local subnets = get_subnets()
- for i,subnet in ipairs(subnets.value) do
- if subnet == name then
- local start, endd = string.find(file, "subnet%s*"..replacemagiccharacters(name).."%s*netmask[^{]*{")
+ for i,s in ipairs(subnets.value) do
+ if s == subnet.value.subnet.value then
+ local start, endd = string.find(file, "subnet%s*"..replacemagiccharacters(s).."%s*netmask[^{]*{")
endd = find_section_end(file, endd)
endd = string.find(file, "\n", endd)
file = string.sub(file, 1, start-1) .. string.sub(file, endd+1, -1)
fs.write_file(configfile, string.gsub(file, "\n*$", ""))
config = nil
- cmdresult.value = "Subnet Deleted"
+ subnet.value.subnet.errtxt = nil
+ subnet.errtxt = nil
end
end
- return cmdresult
+ return subnet
end
get_subnets = function ()
@@ -781,8 +796,8 @@ listconfigfiles = function()
return cfe({ type="list", value=listed_files, label="DHCP File List" })
end
-getconfigfile = function(filename)
- return modelfunctions.getfiledetails(filename, filelist)
+getconfigfile = function(self, clientdata)
+ return modelfunctions.getfiledetails(clientdata.filename, filelist)
end
setconfigfile = function(self, filedetails)