summaryrefslogtreecommitdiffstats
path: root/squid-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-10-21 00:40:56 +0000
committerTed Trask <ttrask01@yahoo.com>2013-10-21 00:40:56 +0000
commit623d92ca06590cca6ed450c7a702cdd50f85f259 (patch)
tree12c1a5e4223ab2043ed01c3bd0d6e020912af31d /squid-model.lua
parentf19f846519d2dde071e39435f3cb37028f99ddf8 (diff)
downloadacf-squid-623d92ca06590cca6ed450c7a702cdd50f85f259.tar.bz2
acf-squid-623d92ca06590cca6ed450c7a702cdd50f85f259.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 'squid-model.lua')
-rw-r--r--squid-model.lua78
1 files changed, 40 insertions, 38 deletions
diff --git a/squid-model.lua b/squid-model.lua
index 3fae971..1574966 100644
--- a/squid-model.lua
+++ b/squid-model.lua
@@ -1,5 +1,5 @@
-- acf model for squid
-module (..., package.seeall)
+local mymodule = {}
-- Load libraries
modelfunctions = require("modelfunctions")
@@ -34,27 +34,27 @@ local validate_config = function(newconfig)
return success, newconfig
end
-getstatus = function()
+mymodule.getstatus = function()
return modelfunctions.getstatus(processname, packagename, "Squid status")
end
-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
-get_configfile = function()
+mymodule.get_configfile = function()
return modelfunctions.getfiledetails(squidconf)
end
-update_configfile = function(self, filedetails)
+mymodule.update_configfile = function(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, {squidconf})
end
-read_digest_userlist = function()
+mymodule.read_digest_userlist = function()
local retval = modelfunctions.getfiledetails(squiddigestusers)
retval.value.filecontent.descr = "List of username:password(plaintext) entries, one per line."
@@ -77,18 +77,18 @@ read_digest_userlist = function()
return retval
end
-update_digest_userlist = function(self, userlistdetails)
+mymodule.update_digest_userlist = function(self, userlistdetails)
-- FIXME - validate
modelfunctions.setfiledetails(self, userlistdetails, {squiddigestusers})
- return read_digest_userlist()
+ return mymodule.read_digest_userlist()
end
-get_enable_digest_userlist = function(self, clientdata)
+mymodule.get_enable_digest_userlist = function(self, clientdata)
local retval = {}
return cfe({ type="group", value=retval, label="Enable Digest User List" })
end
-enable_digest_userlist = function(self, endigest)
+mymodule.enable_digest_userlist = function(self, endigest)
configcontent = configcontent or fs.read_file(squidconf) or ""
local newline = "auth_param digest program /usr/sbin/digest_pw_auth "..squiddigestusers
@@ -126,27 +126,27 @@ enable_digest_userlist = function(self, endigest)
end
--[[
-get_saccess = function()
+mymodule.get_saccess = function()
local config = {}
- config.s_ip = get_file_contents( "/etc/squid/anoniplist" )
- config.s_browser = get_file_contents( "/etc/squid/anonbrowserlist" )
- config.s_domain = get_file_contents( "/etc/squid/anondomainlist" )
+ config.s_ip = mymodule.get_file_contents( "/etc/squid/anoniplist" )
+ config.s_browser = mymodule.get_file_contents( "/etc/squid/anonbrowserlist" )
+ config.s_domain = mymodule.get_file_contents( "/etc/squid/anondomainlist" )
return config
end
-update_saccess = function( config )
+mymodule.update_saccess = function( config )
- write_file_contents( "/etc/squid/anoniplist", config.s_ip )
- write_file_contents( "/etc/squid/anonbrowserlist", config.s_browser )
- write_file_contents( "/etc/squid/anondomainlist", config.s_domain )
+ mymodule.write_file_contents( "/etc/squid/anoniplist", config.s_ip )
+ mymodule.write_file_contents( "/etc/squid/anonbrowserlist", config.s_browser )
+ mymodule.write_file_contents( "/etc/squid/anondomainlist", config.s_domain )
return
end
-write_file_contents = function( name, contents )
+mymodule.write_file_contents = function( name, contents )
local ptr = io.open( name, "wb+" )
if ptr ~= nil then
@@ -157,7 +157,7 @@ write_file_contents = function( name, contents )
return
end
-get_file_contents = function( name )
+mymodule.get_file_contents = function( name )
local retval = ""
@@ -174,7 +174,7 @@ get_file_contents = function( name )
end
--]]
-read_config = function()
+mymodule.read_config = function()
local retval = {
httpports = { type="list", value={}, label="HTTP Ports", descr="List of port, IP:port, or hostname:port entries that Squid will listen on", seq=0 },
accesslog = { type="boolean", value=false, label="Log Access", seq=1 },
@@ -202,7 +202,7 @@ read_config = function()
return cfe({ type="group", value=retval, label="Squid Config" })
end
-update_config = function(self, newconfig)
+mymodule.update_config = function(self, newconfig)
local success, newconfig = validate_config(newconfig)
local lastport, lastlog, lastcache, lastauth
@@ -343,7 +343,7 @@ update_config = function(self, newconfig)
return newconfig
end
--[[
-read_acls = function()
+mymodule.read_acls = function()
local acls = cfe({ type="structure", value={}, label="Squid Access Lists" })
configcontent = configcontent or fs.read_file(squidconf) or ""
config = config or format.parse_linesandwords(configcontent)
@@ -356,7 +356,7 @@ read_acls = function()
return acls
end
-read_acl = function(linenum)
+mymodule.read_acl = function(linenum)
local line = cfe({ label="Squid Access List" })
local linecfe = cfe({ value=linenum, label="Line number" })
configcontent = configcontent or fs.read_file(squidconf) or ""
@@ -364,7 +364,7 @@ read_acl = function(linenum)
return cfe({ type="group", value={line=line, linenum=linecfe}, label="Squid Access List" })
end
-update_acl = function(acl)
+mymodule.update_acl = function(acl)
-- local success, acl = validate_acl(acl)
configcontent = configcontent or fs.read_file(squidconf) or ""
configcontent = format.replaceline(configcontent, acl.value.linenum.value, acl.value.line.value)
@@ -374,7 +374,7 @@ update_acl = function(acl)
return acl
end
-create_acl = function(acl)
+mymodule.create_acl = function(acl)
-- local success, acl = validate_acl(acl)
configcontent = configcontent or fs.read_file(squidconf) or ""
config = config or format.parse_linesandwords(configcontent)
@@ -395,7 +395,7 @@ create_acl = function(acl)
return acl
end
-delete_acl = function(linenum)
+mymodule.delete_acl = function(linenum)
configcontent = configcontent or fs.read_file(squidconf) or ""
configcontent = format.replaceline(configcontent, linenum)
fs.write_file(squidconf, string.gsub(configcontent, "\n+$", ""))
@@ -405,7 +405,7 @@ delete_acl = function(linenum)
end
--]]
-function listfiles()
+function mymodule.listfiles()
local retval = cfe({ type="list", value={}, label="Squid Files" })
if not fs.is_dir(baseurl) then fs.create_directory(baseurl) end
for file in posix.files(baseurl) do
@@ -418,12 +418,12 @@ function listfiles()
return retval
end
-function getnewfile()
+function mymodule.getnewfile()
local filename = cfe({ label="File Name", descr="Must be in "..baseurl })
return cfe({ type="group", value={filename=filename}, label="Squid File" })
end
-function createfile(self, filedetails)
+function mymodule.createfile(self, filedetails)
local success = true
local path = string.match(filedetails.value.filename.value, "^%s*(.*%S)%s*$") or ""
if not string.find(path, "/") then
@@ -450,24 +450,24 @@ function createfile(self, filedetails)
return filedetails
end
-function readfile(filename)
- return modelfunctions.getfiledetails(filename, listfiles().value)
+function mymodule.readfile(filename)
+ return modelfunctions.getfiledetails(filename, mymodule.listfiles().value)
end
-function updatefile(self, filedetails)
- return modelfunctions.setfiledetails(self, filedetails, listfiles().value)
+function mymodule.updatefile(self, filedetails)
+ return modelfunctions.setfiledetails(self, filedetails, mymodule.listfiles().value)
end
-function getdeletefile(self, clientdata)
+function mymodule.getdeletefile(self, clientdata)
local retval = {}
retval.filename = cfe({ value=clientdata.filename or "", label="File Name" })
return cfe({ type="group", value=retval, label="Delete Squid File" })
end
-function deletefile(self, delfile)
+function mymodule.deletefile(self, delfile)
delfile.errtxt = "Failed to delete Squid File"
delfile.value.filename.errtxt = "Invalid filename"
- for i,file in ipairs(listfiles().value) do
+ for i,file in ipairs(mymodule.listfiles().value) do
if delfile.value.filename.value == file then
delfile.errtxt = nil
delfile.value.filename.errtxt = nil
@@ -478,3 +478,5 @@ function deletefile(self, delfile)
return delfile
end
+
+return mymodule