summaryrefslogtreecommitdiffstats
path: root/dhcp-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-10-18 21:31:27 +0000
committerTed Trask <ttrask01@yahoo.com>2013-10-18 21:31:27 +0000
commit0f5d6e086d11bd3cbecbc9d99d832368ed7ef5f4 (patch)
tree9e402edddce43985495c55290fad605d1ffc5e8d /dhcp-model.lua
parentf7a78fe106aeb9119d920b708d822f3a6440895f (diff)
downloadacf-dhcp-0f5d6e086d11bd3cbecbc9d99d832368ed7ef5f4.tar.bz2
acf-dhcp-0f5d6e086d11bd3cbecbc9d99d832368ed7ef5f4.tar.xz
Remove all calls to 'module' in preparation for move to Lua 5.2
Use mymodule parameter for module definition. This was also helpful in revealing places where the code relied on the global environment.
Diffstat (limited to 'dhcp-model.lua')
-rw-r--r--dhcp-model.lua66
1 files changed, 34 insertions, 32 deletions
diff --git a/dhcp-model.lua b/dhcp-model.lua
index 81c758f..6c34931 100644
--- a/dhcp-model.lua
+++ b/dhcp-model.lua
@@ -1,6 +1,6 @@
-- acf model for /etc/dhcp/*
-- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2
-module (..., package.seeall)
+local mymodule = {}
--- get additional libraries
modelfunctions = require("modelfunctions")
@@ -397,19 +397,19 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
-function get_startstop(self, clientdata)
+function mymodule.get_startstop(self, clientdata)
return modelfunctions.get_startstop(processname)
end
-function startstop_service(self, startstop, action)
+function mymodule.startstop_service(self, startstop, action)
return modelfunctions.startstop_service(startstop, action)
end
-function getstatus ()
+function mymodule.getstatus ()
return modelfunctions.getstatus(processname, packagename, "DHCP Status")
end
-create_new_host = function()
+mymodule.create_new_host = function()
host = {
host = cfe({ label="Host Name", seq=1 }),
mac = cfe({ label="MAC Address", seq=2 }),
@@ -419,10 +419,10 @@ create_new_host = function()
return cfe({ type="group", value=host, label="Host" })
end
-host_read = function(self, clientdata)
+mymodule.host_read = function(self, clientdata)
local name = clientdata.host
config = config or parseconfigfile(fs.read_file(configfile) or "")
- local host = create_new_host()
+ local host = mymodule.create_new_host()
host.value.host.value = name
host.value.host.readonly = true
@@ -442,13 +442,13 @@ host_read = function(self, clientdata)
return host
end
-host_update = function(self, host)
+mymodule.host_update = function(self, host)
local success, host = validate_host( host )
if not host.value.host.errtxt then
local previous_success = success
success = false
host.value.host.errtxt = "This host does not exist"
- local hosts = get_hosts()
+ local hosts = mymodule.get_hosts()
for i,ht in ipairs(hosts.value) do
if ht == host.value.host.value then
success = previous_success
@@ -466,10 +466,10 @@ host_update = function(self, host)
return host
end
-host_create = function(self, host)
+mymodule.host_create = function(self, host)
local success, host = validate_host(host)
if not host.value.host.errtxt then
- local hosts = get_hosts()
+ local hosts = mymodule.get_hosts()
for i,ht in ipairs(hosts.value) do
if ht == host.value.host.value then
success = false
@@ -487,16 +487,16 @@ host_create = function(self, host)
return host
end
-get_host_delete = function()
+mymodule.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)
+mymodule.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()
+ local hosts = mymodule.get_hosts()
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).."[^{]*{")
@@ -512,7 +512,7 @@ host_delete = function(self, host)
return cmdresult
end
-get_hosts = function ()
+mymodule.get_hosts = function ()
config = config or parseconfigfile(fs.read_file(configfile) or "")
local retval = {}
for i,entry in ipairs(config) do
@@ -524,7 +524,7 @@ get_hosts = function ()
return cfe({ type="list", value=retval, label="Host list" })
end
-create_new_subnet = function()
+mymodule.create_new_subnet = function()
net = {
subnet = cfe({ label="Subnet", seq=1 }),
netmask = cfe({ label="Netmask", seq=2 }),
@@ -542,10 +542,10 @@ create_new_subnet = function()
return cfe({ type="group", value=net, label="Subnet" })
end
-subnet_read = function(self, clientdata)
+mymodule.subnet_read = function(self, clientdata)
local name = clientdata.subnet
config = config or parseconfigfile(fs.read_file(configfile) or "")
- local net = create_new_subnet()
+ local net = mymodule.create_new_subnet()
net.value.subnet.value = name
net.value.subnet.readonly = true
local pools = 0
@@ -608,13 +608,13 @@ subnet_read = function(self, clientdata)
return net
end
-subnet_update = function(self, net)
+mymodule.subnet_update = function(self, net)
local success, net = validate_subnet( net )
if not net.value.subnet.errtxt then
local previous_success = success
success = false
net.value.subnet.errtxt = "This subnet does not exist"
- local subnets = get_subnets()
+ local subnets = mymodule.get_subnets()
for i,subnet in ipairs(subnets.value) do
if subnet == net.value.subnet.value then
success = previous_success
@@ -632,10 +632,10 @@ subnet_update = function(self, net)
return net
end
-subnet_create = function(self, net)
+mymodule.subnet_create = function(self, net)
local success, net = validate_subnet(net)
if not net.value.subnet.errtxt then
- local subnets = get_subnets()
+ local subnets = mymodule.get_subnets()
for i,subnet in ipairs(subnets.value) do
if subnet == net.value.subnet.value then
success = false
@@ -653,17 +653,17 @@ subnet_create = function(self, net)
return net
end
-get_subnet_delete = function()
+mymodule.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)
+mymodule.subnet_delete = function(self, subnet)
local file = fs.read_file(configfile) or ""
config = config or parseconfigfile(file)
subnet.value.subnet.errtxt = "Subnet not found"
subnet.errtxt = "Failed to delete subnet"
- local subnets = get_subnets()
+ local subnets = mymodule.get_subnets()
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[^{]*{")
@@ -680,7 +680,7 @@ subnet_delete = function(self, subnet)
return subnet
end
-get_subnets = function ()
+mymodule.get_subnets = function ()
config = config or parseconfigfile(fs.read_file(configfile) or "")
local retval = {}
for i,entry in ipairs(config) do
@@ -692,7 +692,7 @@ get_subnets = function ()
return cfe({ type="list", value=retval, label="Subnet list" })
end
-read_settings = function()
+mymodule.read_settings = function()
config = config or parseconfigfile(fs.read_file(configfile) or "")
local settings = {}
settings.domainname = cfe({ label="Domain Name", seq=1 })
@@ -719,7 +719,7 @@ read_settings = function()
return cfe({ type="group", value=settings, label = "Global settings" })
end
-update_settings = function (self, settings)
+mymodule.update_settings = function (self, settings)
success, settings = validate_settings(settings)
if success then
local file = fs.read_file(configfile) or ""
@@ -787,7 +787,7 @@ update_settings = function (self, settings)
return settings
end
-listconfigfiles = function()
+mymodule.listconfigfiles = function()
local listed_files = {}
for i,name in ipairs(filelist) do
local filedetails = fs.stat(name) or {}
@@ -798,14 +798,16 @@ listconfigfiles = function()
return cfe({ type="list", value=listed_files, label="DHCP File List" })
end
-getconfigfile = function(self, clientdata)
+mymodule.getconfigfile = function(self, clientdata)
return modelfunctions.getfiledetails(clientdata.filename, filelist)
end
-setconfigfile = function(self, filedetails)
+mymodule.setconfigfile = function(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, filelist)
end
-getleases = function()
+mymodule.getleases = function()
return modelfunctions.getfiledetails(leasefile)
end
+
+return mymodule