Commit 364262a1 authored by Ted Trask's avatar Ted Trask
Browse files

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.
parent 6e7e6c4b
module(..., package.seeall)
local mymodule = {}
default_action = "viewauditstats"
mymodule.default_action = "viewauditstats"
function config(self)
function mymodule.config(self)
return self.handle_form(self, self.model.getconfig, self.model.updateconfig, self.clientdata, "Save", "Edit Configuration", "Configuration Saved")
end
function listsources(self)
function mymodule.listsources(self)
return self.model.getsourcelist()
end
function createsource(self)
function mymodule.createsource(self)
return self.handle_form(self, self.model.getnewsource, self.model.createsource, self.clientdata, "Create", "Create new source", "New source created")
end
function deletesource(self)
function mymodule.deletesource(self)
return self.handle_form(self, self.model.getdeletesource, self.model.deletesource, self.clientdata, "Delete", "Delete source", "Source deleted")
end
function editsource(self)
function mymodule.editsource(self)
return self.handle_form(self, function() return self.model.getsource(self.clientdata.sourcename) end, self.model.updatesource, self.clientdata, "Save", "Edit Source", "Source Saved")
end
function testsource(self)
function mymodule.testsource(self)
return self.handle_form(self, self.model.gettestsource, self.model.testsource, self.clientdata, "Test", "Test Source")
end
function importlogs(self)
function mymodule.importlogs(self)
return self.handle_form(self, self.model.getimportlogs, self.model.importlogs, self.clientdata, "Import", "Import Logs")
end
function viewactivitylog(self)
function mymodule.viewactivitylog(self)
return self.model.getactivitylog()
end
function viewweblog(self)
function mymodule.viewweblog(self)
local retval = self.handle_form(self, self.model.getweblogparameters, self.model.getweblog, self.clientdata, "Update", "Display Weblog")
-- We want to get the weblog even if form wasn't submitted
if not self.clientdata.Update then
......@@ -44,8 +44,8 @@ function viewweblog(self)
return retval
end
function downloadweblog(self)
local retval = viewweblog(self)
function mymodule.downloadweblog(self)
local retval = mymodule.viewweblog(self)
local file = cfe({ type="longtext", value="", label="Weblog-"..os.date()..".tab" })
local content = {"sourcename\tclientuserid\tclientip\tlogdatetime\turi\tbytes\treason\tscore\tshortreason\tbadyesno\tdeniedyesno\tbypassyesno"}
for i,log in ipairs(retval.value.log.value) do
......@@ -56,31 +56,31 @@ function downloadweblog(self)
return file
end
function updateselected(self)
function mymodule.updateselected(self)
return self.handle_form(self, self.model.geteditselected, self.model.editselected, self.clientdata, "Submit", "Submit select update", "Select fields updated")
end
function clearselected(self)
function mymodule.clearselected(self)
return self.handle_form(self, self.model.getclearselected, self.model.clearselected, self.clientdata, "Clear", "Clear select fields", "Select fields cleared")
end
function viewusagestats(self)
function mymodule.viewusagestats(self)
return self.model.getusagestats()
end
function viewauditstats(self)
function mymodule.viewauditstats(self)
return self.model.getauditstats()
end
function completeaudit(self)
function mymodule.completeaudit(self)
return self.handle_form(self, self.model.getcompleteaudit, self.model.completeaudit, self.clientdata, "Complete", "Complete Audit", "Audit completed")
end
function adhocquery(self)
function mymodule.adhocquery(self)
return self.handle_form(self, self.model.getnewadhocquery, self.model.adhocquery, self.clientdata, "Submit", "Submit ad-hoc query")
end
function downloadadhocquery(self)
function mymodule.downloadadhocquery(self)
local retval = self.model.getnewadhocquery(self, self.clientdata)
self.handle_clientdata(retval, self.clientdata)
retval = self.model.adhocquery(self, retval)
......@@ -105,18 +105,20 @@ function downloadadhocquery(self)
return file
end
function status(self)
function mymodule.status(self)
return self.model.testdatabase()
end
function createdatabase(self)
function mymodule.createdatabase(self)
return self.handle_form(self, self.model.getnewdatabase, self.model.create_database, self.clientdata, "Create", "Create New Database", "Database Created")
end
function listfiles(self)
function mymodule.listfiles(self)
return self.model.listfiles(self)
end
function editfile(self)
function mymodule.editfile(self)
return self.handle_form(self, self.model.readfile, self.model.updatefile, self.clientdata, "Save", "Edit Weblog File", "Weblog File Saved" )
end
return mymodule
module(..., package.seeall)
local mymodule = {}
-- Load libraries
modelfunctions = require("modelfunctions")
......@@ -714,7 +714,7 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
function getsourcelist()
function mymodule.getsourcelist()
local retval = cfe({ type="list", value={}, label="Weblog Source List" })
local res, err = pcall(function()
databaseconnect(DatabaseUser)
......@@ -728,8 +728,8 @@ function getsourcelist()
return retval
end
function getsource(sourcename)
local sourcedata = getnewsource()
function mymodule.getsource(sourcename)
local sourcedata = mymodule.getnewsource()
sourcedata.value.sourcename.value = sourcename
sourcedata.value.sourcename.errtxt = "Source name does not exist"
sourcedata.value.sourcename.readonly = true
......@@ -774,7 +774,7 @@ local validatesource = function(sourcedata)
return success
end
function updatesource(self, sourcedata)
function mymodule.updatesource(self, sourcedata)
local success = validatesource(sourcedata)
sourcedata.errtxt = "Failed to update source"
if success then
......@@ -797,7 +797,7 @@ function updatesource(self, sourcedata)
return sourcedata
end
function getnewsource()
function mymodule.getnewsource()
local source = {}
source.sourcename = cfe({ label="Source Name", seq=0 })
source.method = cfe({ type="select", value="local", label="Method", option={"http", "https", "local"}, seq=3 })
......@@ -809,7 +809,7 @@ function getnewsource()
return cfe({ type="group", value=source, label="Source" })
end
function createsource(self, sourcedata)
function mymodule.createsource(self, sourcedata)
local success = validatesource(sourcedata)
sourcedata.errtxt = "Failed to create source"
if success then
......@@ -834,13 +834,13 @@ function createsource(self, sourcedata)
return sourcedata
end
function getdeletesource(self, clientdata)
function mymodule.getdeletesource(self, clientdata)
local retval = {}
retval.sourcename = cfe({ value=clientdata.sourcename or "", label="Source Name" })
return cfe({ type="group", value=retval, label="Delete Source" })
end
function deletesource(self, delsource)
function mymodule.deletesource(self, delsource)
delsource.errtxt="Failed to delete source"
local res, err = pcall(function()
databaseconnect(DatabaseUser)
......@@ -858,13 +858,13 @@ function deletesource(self, delsource)
return delsource
end
function gettestsource(self, clientdata)
function mymodule.gettestsource(self, clientdata)
local retval = {}
retval.sourcename = cfe({ value=clientdata.sourcename or "", label="Source Name" })
return cfe({ type="group", value=retval, label="Test Source" })
end
function testsource(self, test)
function mymodule.testsource(self, test)
-- temporary override of logme function to capture messages to result.value
test.descr = {}
local temp = logme
......@@ -963,12 +963,12 @@ local function importlogfile(source, cookiesfile, file, parselog_func)
return res
end
function getimportlogs(self, clientdata)
function mymodule.getimportlogs(self, clientdata)
local retval = {}
return cfe({ type="group", value=retval, label="Import Logs" })
end
function importlogs(self, import)
function mymodule.importlogs(self, import)
local count = 0
local success = true
......@@ -1035,7 +1035,7 @@ function importlogs(self, import)
return import
end
function getactivitylog()
function mymodule.getactivitylog()
local retval = cfe({ type="list", value={}, label="Weblog Activity Log" })
local res, err = pcall(function()
databaseconnect(DatabaseUser)
......@@ -1049,14 +1049,14 @@ function getactivitylog()
return retval
end
function geteditselected()
function mymodule.geteditselected()
local result = {}
result.select = cfe({ type="list", value={}, label="Entries to mark as selected" })
result.deselect = cfe({ type="list", value={}, label="Entries to mark as selected" })
return cfe({ type="group", value=result, label="Select / Deselect log entries" })
end
function editselected(self, data)
function mymodule.editselected(self, data)
local res, err = pcall(function()
databaseconnect(DatabaseOwner)
con:execute("START TRANSACTION")
......@@ -1075,12 +1075,12 @@ function editselected(self, data)
return data
end
function getclearselected(self, clientdata)
function mymodule.getclearselected(self, clientdata)
local retval = {}
return cfe({ type="group", value=retval, label="Clear select fields" })
end
function clearselected(self, clear)
function mymodule.clearselected(self, clear)
clear.errtxt = "Failed to clear select fields"
local res, err = pcall(function()
sql = "UPDATE pubweblog SET selected = false WHERE selected = true"
......@@ -1132,8 +1132,8 @@ local validateweblogparameters = function(params)
return success
end
function getweblogparameters()
local c = getconfig()
function mymodule.getweblogparameters()
local c = mymodule.getconfig()
local result = {}
result.activelog = cfe({ type="select", value="pubweblog", option={"pubweblog", "pubweblog_history"}, label="Active Weblog", seq=1 })
result.starttime = cfe({ value=c.value.auditstart.value, label="Start Time", seq=2 })
......@@ -1151,7 +1151,7 @@ function getweblogparameters()
return cfe({ type="group", value=result, label="Weblog Access Log" })
end
function getweblog(self, result)
function mymodule.getweblog(self, result)
local success = validateweblogparameters(result)
result.value.log = cfe({ type="list", value={}, label="Weblog Access Log" })
result.value.window = cfe({ value=config.window or "5", label="Time Window" })
......@@ -1171,7 +1171,7 @@ function getweblog(self, result)
return result
end
function getusagestats()
function mymodule.getusagestats()
local retval = cfe({ type="list", value={}, label="Weblog Usage Stats" })
local res, err = pcall(function()
databaseconnect(DatabaseUser)
......@@ -1185,7 +1185,7 @@ function getusagestats()
return retval
end
function getauditstats()
function mymodule.getauditstats()
local result = {}
result.auditstart = cfe({ value=config.auditstart or "", label="Audit Start Time" })
result.auditend = cfe({ value=config.auditend or "", label="Audit End Time" })
......@@ -1201,28 +1201,28 @@ function getauditstats()
return cfe({ type="group", value=result, errtxt=err, label="Weblog Audit Statistics" })
end
function getcompleteaudit(self, clientdata)
function mymodule.getcompleteaudit(self, clientdata)
local retval = {}
retval.timestamp = cfe({ value=clientdata.timestamp or "", label="New Audit End Time" })
return cfe({ type="group", value=retval, label="Complete Audit" })
end
function completeaudit(self, complete)
function mymodule.completeaudit(self, complete)
if "" == complete.value.timestamp.value then
local now = os.time()
complete.value.timestamp.value = os.date("%Y-%m-%d %H:%M:%S", now - now%86400 - 86400)
end
local conf = getconfig()
local conf = mymodule.getconfig()
conf.value.auditstart.value = conf.value.auditend.value
conf.value.auditend.value = complete.value.timestamp.value
conf = updateconfig(self, conf)
conf = mymodule.updateconfig(self, conf)
if conf.errtxt then
complete.errtxt = "Failed to complete audit\n"..conf.errtxt.."\n"..conf.value.auditend.errtxt
end
return complete
end
function getconfig()
function mymodule.getconfig()
local result = {}
result.auditstart = cfe({ value=config.auditstart or "", label="Audit Start Time", seq=1 })
result.auditend = cfe({ value=config.auditend or "", label="Audit End Time", seq=2 })
......@@ -1279,7 +1279,7 @@ local function validateconfig(newconfig)
return success, newconfig
end
function updateconfig(self, newconfig)
function mymodule.updateconfig(self, newconfig)
local success = validateconfig(newconfig)
if success then
configcontent = format.update_ini_file(configcontent, "", "auditstart", newconfig.value.auditstart.value)
......@@ -1305,13 +1305,13 @@ function updateconfig(self, newconfig)
return newconfig
end
function getnewadhocquery()
function mymodule.getnewadhocquery()
local query = {}
query.query = cfe({ label="Query select statement" })
return cfe({ type="group", value=query, label="Ad-hoc Query" })
end
function adhocquery(self, query)
function mymodule.adhocquery(self, query)
local success = true
query.value.query.value = query.value.query.value:lower()
if query.value.query.value == "" then
......@@ -1353,7 +1353,7 @@ function adhocquery(self, query)
return query
end
function testdatabase()
function mymodule.testdatabase()
local retval = cfe({ type="boolean", value=false, label="Database present" })
local dbs = listdatabases()
for i,db in ipairs(dbs) do
......@@ -1365,12 +1365,12 @@ function testdatabase()
return retval
end
function getnewdatabase()
function mymodule.getnewdatabase()
local database = {}
local errtxt
database.password = cfe({ type="password", label="Password", seq=0 })
database.password_confirm = cfe({ type="password", label="Password (confirm)", seq=1 })
local test = testdatabase()
local test = mymodule.testdatabase()
if test.value then
errtxt = "Database already exists!"
success = false
......@@ -1378,7 +1378,7 @@ function getnewdatabase()
return cfe({ type="group", value=database, label="Create Database", errtxt=errtxt })
end
function create_database(self, database)
function mymodule.create_database(self, database)
local success = true
local errtxt
......@@ -1390,7 +1390,7 @@ function create_database(self, database)
database.value.password_confirm.errtxt = "Password does not match"
success = false
end
local test = testdatabase()
local test = mymodule.testdatabase()
if test.value then
errtxt = "Database already exists!"
success = false
......@@ -1398,7 +1398,7 @@ function create_database(self, database)
if success then
errtxt = createdatabase(database.value.password.value)
test = testdatabase()
test = mymodule.testdatabase()
if not test.value then
success = false
else
......@@ -1433,7 +1433,7 @@ function create_database(self, database)
return database
end
function listfiles()
function mymodule.listfiles()
local retval = cfe({ type="list", value={}, label="Weblog Files" })
for i,file in ipairs(files) do
local details = fs.stat(file) or {}
......@@ -1443,10 +1443,12 @@ function listfiles()
return retval
end
function readfile(self, clientdata)
function mymodule.readfile(self, clientdata)
return modelfunctions.getfiledetails(clientdata.filename, files)
end
function updatefile(self, filedetails)
function mymodule.updatefile(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, files)
end
return mymodule
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment