summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-10-17 18:59:27 +0000
committerTed Trask <ttrask01@yahoo.com>2013-10-17 18:59:27 +0000
commitc0e0377e384c8167172ee06d8c11ef2f782522c7 (patch)
treebb89301e467ff61d93a39642354bcfe382571529 /app
parentfcaab1b363fcd5ff2dccce8f98cacabc5635ba5f (diff)
downloadacf-core-c0e0377e384c8167172ee06d8c11ef2f782522c7.tar.bz2
acf-core-c0e0377e384c8167172ee06d8c11ef2f782522c7.tar.xz
Remove all calls to 'module' in preparation for move to Lua 5.2
Use mymodule parameter for module definition. This was also helpfule in revealing places where the code relied on the global environment.
Diffstat (limited to 'app')
-rw-r--r--app/acf-util/logon-controller.lua26
-rw-r--r--app/acf-util/logon-model.lua12
-rw-r--r--app/acf-util/password-controller.lua16
-rw-r--r--app/acf-util/password-model.lua20
-rw-r--r--app/acf-util/roles-controller.lua23
-rw-r--r--app/acf-util/roles-model.lua24
-rw-r--r--app/acf-util/skins-controller.lua9
-rw-r--r--app/acf-util/skins-model.lua10
-rw-r--r--app/acf-util/welcome-controller.lua8
-rw-r--r--app/acf_cli-controller.lua14
-rw-r--r--app/acf_www-controller.lua78
11 files changed, 129 insertions, 111 deletions
diff --git a/app/acf-util/logon-controller.lua b/app/acf-util/logon-controller.lua
index 4fa3d20..bd26e10 100644
--- a/app/acf-util/logon-controller.lua
+++ b/app/acf-util/logon-controller.lua
@@ -1,8 +1,8 @@
-- Logon / Logoff functions
-module (..., package.seeall)
+local mymodule = {}
-default_action = "status"
+mymodule.default_action = "status"
-- Logon a new user based upon id and password in clientdata
local check_users = function(self)
@@ -21,14 +21,14 @@ local check_users = function(self)
end
-- Logon a new user based upon id and password in clientdata
-logon = function(self)
- local userid = cfe({ value=clientdata.userid or "", label="User ID", seq=1 })
+mymodule.logon = function(self)
+ local userid = cfe({ value=self.clientdata.userid or "", label="User ID", seq=1 })
local password = cfe({ type="password", label="Password", seq=2 })
- local redir = cfe({ type="hidden", value=clientdata.redir, label="" })
+ local redir = cfe({ type="hidden", value=self.clientdata.redir, label="" })
local cmdresult = cfe({ type="form", value={userid=userid, password=password, redir=redir}, label="Logon", option="Logon" })
- if clientdata.submit then
+ if self.clientdata.submit then
local logonredirect = self.sessiondata.logonredirect
- local logon = self.model:logon(clientdata.userid, clientdata.password, conf.clientip, conf.sessiondir, sessiondata)
+ local logon = self.model:logon(self.clientdata.userid, self.clientdata.password, self.conf.clientip, self.conf.sessiondir, self.sessiondata)
-- If successful logon, redirect to home or welcome page, otherwise try again
if logon.value then
cmdresult.descr = "Logon Successful"
@@ -54,7 +54,7 @@ logon = function(self)
self.sessiondata.logonredirect = logonredirect
end
end
- redirect(self, cmdresult.value.redir.value)
+ self:redirect(cmdresult.value.redir.value)
end
else
if check_users(self) then return end
@@ -64,15 +64,15 @@ logon = function(self)
end
-- Log off current user and go to logon screen
-logoff = function(self)
- local logoff = self.model.logoff(conf.sessiondir, sessiondata)
+mymodule.logoff = function(self)
+ local logoff = self.model.logoff(self.conf.sessiondir, self.sessiondata)
-- We have to redirect so a new session / menu is created
- redirect(self, "logon")
+ self:redirect("logon")
return logoff
end
-- Report the logon status
-status = function(self)
+mymodule.status = function(self)
local name = cfe({ label="User Name" })
local sessionid = cfe({ value=self.sessiondata.id or "", label="Session ID" })
if self.sessiondata.userinfo then
@@ -80,3 +80,5 @@ status = function(self)
end
return cfe({ type="group", value={username=name, sessionid=sessionid}, label="Logon Status" })
end
+
+return mymodule
diff --git a/app/acf-util/logon-model.lua b/app/acf-util/logon-model.lua
index fd67ec2..279e988 100644
--- a/app/acf-util/logon-model.lua
+++ b/app/acf-util/logon-model.lua
@@ -1,6 +1,6 @@
-- Logon / Logoff model functions
-module (..., package.seeall)
+local mymodule = {}
session = require ("session")
html = require ("acf.html")
@@ -9,7 +9,7 @@ roles = require ("roles")
authenticator = require ("authenticator")
-- Logoff the user by deleting session data
-logoff = function (sessiondir, sessiondata)
+mymodule.logoff = function (sessiondir, sessiondata)
-- Unlink / delete the current session
local result = session.unlink_session(sessiondir, sessiondata.id)
local success = (result ~= nil)
@@ -23,7 +23,7 @@ end
-- Log on new user if possible and set up userinfo in session
-- if we fail, we leave the session alone (don't log off)
-logon = function (self, userid, password, ip_addr, sessiondir, sessiondata)
+mymodule.logon = function (self, userid, password, ip_addr, sessiondir, sessiondata)
-- Check to see if we can log on this user id / ip addr
local countevent = session.count_events(sessiondir, userid, session.hash_ip_addr(ip_addr), self.conf.lockouttime, self.conf.lockouteventlimit)
if countevent then
@@ -34,7 +34,7 @@ logon = function (self, userid, password, ip_addr, sessiondir, sessiondata)
if authenticator.authenticate (self, userid, password) then
-- We have a successful logon, change sessiondata
-- for some reason, can't call this function or it skips rest of logon
- -- logoff(sessiondir, sessiondata)
+ -- mymodule.logoff(sessiondir, sessiondata)
---[[ so, do this instead
session.unlink_session(sessiondir, sessiondata.id)
-- Clear the current session data
@@ -57,6 +57,8 @@ logon = function (self, userid, password, ip_addr, sessiondir, sessiondata)
return cfe({ type="boolean", value=false, label="Logon Success" })
end
-list_users = function(self)
+mymodule.list_users = function(self)
return cfe({ type="list", value=authenticator.list_users(self), label="Users" })
end
+
+return mymodule
diff --git a/app/acf-util/password-controller.lua b/app/acf-util/password-controller.lua
index 40ba61b..0715b50 100644
--- a/app/acf-util/password-controller.lua
+++ b/app/acf-util/password-controller.lua
@@ -1,13 +1,13 @@
-module(..., package.seeall)
+local mymodule = {}
roles = require("roles")
-default_action = "editme"
+mymodule.default_action = "editme"
-function status(self)
+function mymodule.status(self)
return self.model.get_users(self)
end
-function editme(self)
+function mymodule.editme(self)
-- just to make sure can't modify any other user from this action
self.clientdata.userid = self.sessiondata.userinfo.userid
return self.handle_form(self, function()
@@ -42,7 +42,7 @@ function editme(self)
end, self.clientdata, "Save", "Edit My Settings", "Saved user")
end
-function edituser(self)
+function mymodule.edituser(self)
return self.handle_form(self, function()
return self.model.read_user(self, self.clientdata.userid)
end, function(self, value)
@@ -63,10 +63,12 @@ function edituser(self)
end, self.clientdata, "Save", "Edit User Settings", "Saved user")
end
-function newuser(self)
+function mymodule.newuser(self)
return self.handle_form(self, function() return self.model.read_user(self) end, self.model.create_user, self.clientdata, "Create", "Create New User", "Created user")
end
-function deleteuser(self)
+function mymodule.deleteuser(self)
return self.handle_form(self, self.model.get_delete_user, self.model.delete_user, self.clientdata, "Delete", "Delete User", "Deleted user")
end
+
+return mymodule
diff --git a/app/acf-util/password-model.lua b/app/acf-util/password-model.lua
index a329c19..3a61983 100644
--- a/app/acf-util/password-model.lua
+++ b/app/acf-util/password-model.lua
@@ -1,4 +1,4 @@
-module(..., package.seeall)
+local mymodule = {}
authenticator = require("authenticator")
roles = require("roles")
@@ -48,11 +48,11 @@ local validate_settings = function(settings)
return true, settings
end
-function create_user(self, settings)
- return update_user(self, settings, true)
+function mymodule.create_user(self, settings)
+ return mymodule.update_user(self, settings, true)
end
-function update_user(self, settings, create)
+function mymodule.update_user(self, settings, create)
local success, settings = validate_settings(settings)
if success then
@@ -86,7 +86,7 @@ function update_user(self, settings, create)
end
-function read_user(self, user)
+function mymodule.read_user(self, user)
local result = {}
result.userid = cfe({ value=user, label="User id", seq=1 })
if user and user ~= "" then
@@ -151,28 +151,30 @@ function read_user(self, user)
return cfe({ type="group", value=result, label="User Config" })
end
-function get_users(self)
+function mymodule.get_users(self)
--List all users and their userinfo
local users = {}
local userlist = authenticator.list_users(self)
table.sort(userlist)
for x,user in pairs(userlist) do
- users[#users+1] = read_user(self, user)
+ users[#users+1] = mymodule.read_user(self, user)
end
return cfe({ type="group", value=users, label="User Configs" })
end
-function get_delete_user(self, clientdata)
+function mymodule.get_delete_user(self, clientdata)
local userid = cfe({ label="User id", value=clientdata.userid or "" })
return cfe({ type="group", value={userid=userid}, label="Delete User" })
end
-function delete_user(self, deleteuser)
+function mymodule.delete_user(self, deleteuser)
deleteuser.errtxt = "Failed to delete user"
if authenticator.delete_user(self, deleteuser.value.userid.value) then
deleteuser.errtxt = nil
end
return deleteuser
end
+
+return mymodule
diff --git a/app/acf-util/roles-controller.lua b/app/acf-util/roles-controller.lua
index c02d693..30cf768 100644
--- a/app/acf-util/roles-controller.lua
+++ b/app/acf-util/roles-controller.lua
@@ -1,11 +1,10 @@
-- Roles/Group functions
-module (..., package.seeall)
+local mymodule = {}
-
-default_action = "read"
+mymodule.default_action = "read"
-- Return your own roles/permissions
-read = function(self)
+mymodule.read = function(self)
userid = cfe({ value=self.sessiondata.userinfo.userid, label="User Id" })
roles = cfe({ type="list", value=self.sessiondata.userinfo.roles, label="Roles" })
permissions = cfe({ type="table", value = self.sessiondata.permissions, label="Permissions" })
@@ -13,7 +12,7 @@ read = function(self)
end
-- Return roles/permissions for specified user
-viewuserroles = function(self)
+mymodule.viewuserroles = function(self)
if not (self.clientdata.userid) then
redirect(self)
end
@@ -24,7 +23,7 @@ viewuserroles = function(self)
end
-- Return permissions for specified role
-viewroleperms = function(self)
+mymodule.viewroleperms = function(self)
if not (self.clientdata.role) then
redirect(self, "getlist")
end
@@ -34,22 +33,24 @@ viewroleperms = function(self)
end
-- Return list of all permissions
-getpermslist = function(self)
+mymodule.getpermslist = function(self)
return cfe({ type="group", value={permissions=self.model.get_perms_list(self)} })
end
-viewroles = function(self)
+mymodule.viewroles = function(self)
return self.model.view_roles(self)
end
-newrole = function(self)
+mymodule.newrole = function(self)
return self.handle_form(self, self.model.getpermissions, self.model.setnewpermissions, self.clientdata, "Create", "Create New Role", "New Role Created")
end
-editrole = function(self)
+mymodule.editrole = function(self)
return self.handle_form(self, self.model.getpermissions, self.model.setpermissions, self.clientdata, "Save", "Edit Role", "Role Saved")
end
-deleterole = function(self)
+mymodule.deleterole = function(self)
return self.handle_form(self, self.model.get_delete_role, self.model.delete_role, self.clientdata, "Delete", "Delete Role", "Role Deleted")
end
+
+return mymodule
diff --git a/app/acf-util/roles-model.lua b/app/acf-util/roles-model.lua
index 4d5d1d3..51c10b1 100644
--- a/app/acf-util/roles-model.lua
+++ b/app/acf-util/roles-model.lua
@@ -1,12 +1,12 @@
-- Roles/Group functions
-module (..., package.seeall)
+local mymodule = {}
modelfunctions = require("modelfunctions")
authenticator = require("authenticator")
roles = require("roles")
-- Return roles/permissions for specified user
-get_user_roles = function(self, userid)
+mymodule.get_user_roles = function(self, userid)
local userinfo = authenticator.get_userinfo(self, userid) or {}
rls = cfe({ type="list", value=userinfo.roles or {}, label="Roles" })
permissions = cfe({ type="table", value=roles.get_roles_perm(self, rls.value), label="Permissions" })
@@ -14,16 +14,16 @@ get_user_roles = function(self, userid)
end
-- Return permissions for specified role
-get_role_perms = function(self, role)
+mymodule.get_role_perms = function(self, role)
return cfe({ type="table", value=roles.get_role_perm(self, role), label="Permissions" })
end
-- Return list of all permissions
-get_perms_list = function(self)
+mymodule.get_perms_list = function(self)
return cfe({ type="table", value=roles.get_all_permissions(self), label="All Permissions" })
end
-view_roles = function(self)
+mymodule.view_roles = function(self)
local defined_roles, default_roles = roles.list_roles(self)
local defined_roles_cfe=cfe({ type="list", value=defined_roles, label="Locally-defined roles" })
local default_roles_cfe=cfe({ type="list", value=default_roles, label="System-defined roles" })
@@ -31,7 +31,7 @@ view_roles = function(self)
return cfe({ type="group", value={defined_roles=defined_roles_cfe, default_roles=default_roles_cfe} })
end
-getpermissions = function(self, clientdata)
+mymodule.getpermissions = function(self, clientdata)
local role_cfe = cfe({ value=clientdata.role or "", label="Role", seq=1 })
local tmp, all_perms = roles.get_all_permissions(self)
@@ -68,11 +68,11 @@ getpermissions = function(self, clientdata)
return cfe({ type="table", value={role=role_cfe, permissions=permissions_cfe} })
end
-setnewpermissions = function(self, permissions, action)
- return setpermissions(self, permissions, action, true)
+mymodule.setnewpermissions = function(self, permissions, action)
+ return mymodule.setpermissions(self, permissions, action, true)
end
-setpermissions = function(self, permissions, action, newrole)
+mymodule.setpermissions = function(self, permissions, action, newrole)
-- Validate entries and create error strings
local result = true
if newrole then
@@ -98,13 +98,13 @@ setpermissions = function(self, permissions, action, newrole)
return permissions
end
-get_delete_role = function(self, clientdata)
+mymodule.get_delete_role = function(self, clientdata)
local defined_roles, default_roles = roles.list_roles(self)
local role = cfe({ type="select", value = clientdata.role or "", label="Role", option=defined_roles })
return cfe({ type="group", value={role=role}, label="Delete Role" })
end
-delete_role = function(self, role)
+mymodule.delete_role = function(self, role)
local result, cmdresult = roles.delete_role(self, role.value.role.value)
if not result then
role.value.role.errtxt = cmdresult
@@ -121,3 +121,5 @@ delete_role = function(self, role)
end
return role
end
+
+return mymodule
diff --git a/app/acf-util/skins-controller.lua b/app/acf-util/skins-controller.lua
index c3d08a0..e6f8fc3 100644
--- a/app/acf-util/skins-controller.lua
+++ b/app/acf-util/skins-controller.lua
@@ -1,14 +1,15 @@
-module (..., package.seeall)
+local mymodule = {}
-- Public methods
-default_action = "read"
+mymodule.default_action = "read"
-read = function (self )
+mymodule.read = function (self )
return self.model.get(self)
end
-update = function (self )
+mymodule.update = function (self )
return self.handle_form(self, self.model.get_update, self.model.update, self.clientdata, "Update", "Update Skin", "Skin updated")
end
+return mymodule
diff --git a/app/acf-util/skins-model.lua b/app/acf-util/skins-model.lua
index e646af9..9016e62 100644
--- a/app/acf-util/skins-model.lua
+++ b/app/acf-util/skins-model.lua
@@ -1,4 +1,4 @@
-module (..., package.seeall)
+local mymodule = {}
modelfunctions = require("modelfunctions")
fs = require("acf.fs")
@@ -31,11 +31,11 @@ local function list_skins(self)
end
-get = function (self)
+mymodule.get = function (self)
return cfe({ type="list", value=list_skins(self), label="Skins" })
end
-get_update = function (self)
+mymodule.get_update = function (self)
local skin = cfe({ type="select", value="", label="Skin", option=list_skins(self) })
if self and self.conf and self.conf.skin then
skin.value = self.conf.skin
@@ -43,7 +43,7 @@ get_update = function (self)
return cfe({ type="group", value={skin=skin}, label="Update Skin" })
end
-update = function (self, newskin)
+mymodule.update = function (self, newskin)
local success = modelfunctions.validateselect(newskin.value.skin)
if success then
set_skins(self, newskin.value.skin.value)
@@ -53,3 +53,5 @@ update = function (self, newskin)
end
return newskin
end
+
+return mymodule
diff --git a/app/acf-util/welcome-controller.lua b/app/acf-util/welcome-controller.lua
index 77735ec..b35266c 100644
--- a/app/acf-util/welcome-controller.lua
+++ b/app/acf-util/welcome-controller.lua
@@ -1,10 +1,10 @@
-- A standin controller for testing
-module (..., package.seeall)
+local mymodule = {}
-default_action = "read"
+mymodule.default_action = "read"
-read = function (self )
+mymodule.read = function (self )
return ( {self = self} )
end
-
+return mymodule
diff --git a/app/acf_cli-controller.lua b/app/acf_cli-controller.lua
index 1828d10..7b706c3 100644
--- a/app/acf_cli-controller.lua
+++ b/app/acf_cli-controller.lua
@@ -1,12 +1,12 @@
-module(..., package.seeall)
+local mymodule = {}
posix = require("posix")
session = require("session")
local parent_exception_handler
-mvc = {}
-mvc.on_load = function (self, parent)
+mymodule.mvc = {}
+mymodule.mvc.on_load = function (self, parent)
-- Make sure we have some kind of sane defaults for libdir
self.conf.libdir = self.conf.libdir or ( string.match(self.conf.appdir, "[^,]+/") .. "/lib/" )
self.conf.script = ""
@@ -22,12 +22,12 @@ mvc.on_load = function (self, parent)
self.session = {}
end
-exception_handler = function (self, message )
+mymodule.exception_handler = function (self, message )
print(session.serialize("exception", message))
parent_exception_handler(self, message)
end
-handle_clientdata = function(form, clientdata, group)
+mymodule.handle_clientdata = function(form, clientdata, group)
clientdata = clientdata or {}
form.errtxt = nil
for n,value in pairs(form.value) do
@@ -35,7 +35,7 @@ handle_clientdata = function(form, clientdata, group)
local name = n
if group then name = group.."."..name end
if value.type == "group" then
- handle_clientdata(value, clientdata, name)
+ mymodule.handle_clientdata(value, clientdata, name)
-- Don't update from the default unless a value exists
elseif value.type == "boolean" and clientdata[name] then
value.value = (clientdata[name] == "true")
@@ -56,3 +56,5 @@ handle_clientdata = function(form, clientdata, group)
end
end
end
+
+return mymodule
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua
index 0391347..eea122b 100644
--- a/app/acf_www-controller.lua
+++ b/app/acf_www-controller.lua
@@ -5,7 +5,7 @@
]]--
-- Required global libraries
-module(..., package.seeall)
+local mymodule = {}
-- This is not in the global namespace, but future
-- require statements shouldn't need to go to the disk lib
@@ -58,7 +58,7 @@ local function build_menus(self)
end
local check_permission = function(self, prefix, controller, action)
- --logevent("Trying "..(prefix or "/")..(controller or "nil").."/"..(action or "nil"))
+ --self.logevent("Trying "..(prefix or "/")..(controller or "nil").."/"..(action or "nil"))
if nil == self.sessiondata.permissions then return false end
if prefix and controller then
if nil == self.sessiondata.permissions[prefix] or nil == self.sessiondata.permissions[prefix][controller] then return false end
@@ -68,7 +68,7 @@ local check_permission = function(self, prefix, controller, action)
end
local check_permission_string = function (self, str)
- local prefix, controller, action = parse_redir_string(str)
+ local prefix, controller, action = self.parse_redir_string(str)
if prefix == "/" then prefix = self.conf.prefix end
if controller == "" then controller = self.conf.controller end
@@ -131,7 +131,7 @@ local dispatch_component = function(self, str, clientdata, suppress_view)
self.clientdata = clientdata or {}
self.clientdata.sessionid = tempclientdata.sessionid
- local prefix, controller, action = parse_redir_string(str)
+ local prefix, controller, action = self.parse_redir_string(str)
if prefix == "/" then prefix = self.conf.prefix end
if controller == "" then controller = self.conf.controller end
local viewtable = self.dispatch(self, prefix, controller, action)
@@ -154,7 +154,7 @@ local has_view = function(self)
end
-- Override the mvc create_helper_library function to add our functions
-create_helper_library = function ( self )
+mymodule.create_helper_library = function ( self )
-- Call the mvc version
local library = parent_create_helper_library(self)
--[[ -- If we have a separate library, here's how we could do it
@@ -171,7 +171,7 @@ create_helper_library = function ( self )
end
-- Our local view resolver called by our dispatch - add the template and skin
-view_resolver = function(self)
+mymodule.view_resolver = function(self)
self.conf.viewtype = self.conf.viewtype or "html"
local viewfunc, viewlibrary, pageinfo = parent_view_resolver(self)
pageinfo.viewfunc = viewfunc
@@ -206,14 +206,14 @@ view_resolver = function(self)
return func, viewlibrary, pageinfo, self.sessiondata
end
-mvc = {}
-mvc.on_load = function (self, parent)
+mymodule.mvc = {}
+mymodule.mvc.on_load = function (self, parent)
-- open the log file
if self.conf.logfile then
self.conf.loghandle = io.open (self.conf.logfile, "a+")
end
- --logevent("acf_www-controller mvc.on_load")
+ --self.logevent("acf_www-controller mvc.on_load")
-- Make sure we have some kind of sane defaults for libdir, wwwdir, and sessiondir
self.conf.libdir = self.conf.libdir or ( string.match(self.conf.appdir, "[^,]+/") .. "/lib/" )
@@ -237,7 +237,7 @@ mvc.on_load = function (self, parent)
self.sessiondata = nil
self.sessiondata = {}
if nil ~= self.clientdata.sessionid then
- --logevent("Found session id = " .. self.clientdata.sessionid)
+ --self.logevent("Found session id = " .. self.clientdata.sessionid)
-- Load existing session data
local timestamp
timestamp, self.sessiondata =
@@ -247,12 +247,12 @@ mvc.on_load = function (self, parent)
-- invalid session id, report event and create new one
sessionlib.record_event(self.conf.sessiondir, nil,
sessionlib.hash_ip_addr(self.conf.clientip))
- --logevent("Didn't find session")
+ --self.logevent("Didn't find session")
else
- --logevent("Found session")
+ --self.logevent("Found session")
-- We read in a valid session, check if it's ok
if self.sessiondata.userinfo and self.sessiondata.userinfo.userid and sessionlib.count_events(self.conf.sessiondir, self.sessiondata.userinfo.userid, sessionlib.hash_ip_addr(self.conf.clientip), self.conf.lockouttime, self.conf.lockouteventlimit) then
- --logevent("Bad session, erasing")
+ --self.logevent("Bad session, erasing")
-- Too many events on this id / ip, kill the session
sessionlib.unlink_session(self.conf.sessiondir, self.clientdata.sessionid)
self.sessiondata.id = nil
@@ -270,34 +270,34 @@ mvc.on_load = function (self, parent)
self.sessiondata.id = sessionlib.random_hash(512)
authenticator = require("authenticator")
self.sessiondata.userinfo = authenticator.get_userinfo(self, ENV.REMOTE_USER)
- logevent("Automatic logon as ENV.REMOTE_USER: "..tostring(ENV.REMOTE_USER))
+ self.logevent("Automatic logon as ENV.REMOTE_USER: "..tostring(ENV.REMOTE_USER))
end
if nil == self.sessiondata.id then
self.sessiondata = {}
self.sessiondata.id = sessionlib.random_hash(512)
- --logevent("New session = " .. self.sessiondata.id)
+ --self.logevent("New session = " .. self.sessiondata.id)
end
if nil == self.sessiondata.permissions or nil == self.sessiondata.menu then
- --logevent("Build menus")
+ --self.logevent("Build menus")
build_menus(self)
end
end
-mvc.on_unload = function (self)
+mymodule.mvc.on_unload = function (self)
sessionlib=require ("session")
if self.sessiondata.id then
sessionlib.save_session(self.conf.sessiondir, self.sessiondata)
end
-- Close the logfile
- --logevent("acf_www-controller mvc.on_unload")
+ --self.logevent("acf_www-controller mvc.on_unload")
if self.conf.loghandle then
self.conf.loghandle:close()
end
end
-- Overload the MVC's exception handler with our own to handle redirection
-exception_handler = function (self, message )
+mymodule.exception_handler = function (self, message )
local html = require ("acf.html")
local viewtable
if type(message) == "table" then
@@ -309,7 +309,7 @@ exception_handler = function (self, message )
self.conf.controller = "dispatcherror"
self.conf.action = ""
elseif message.type == "redir" or message.type == "redir_to_referrer" or message.type == "dispatch" then
- --if self.sessiondata.id then logevent("Redirecting " .. self.sessiondata.id) end
+ --if self.sessiondata.id then self.logevent("Redirecting " .. self.sessiondata.id) end
io.write ("Status: 302 Moved\n")
if message.type == "redir" then
io.write ("Location: " .. ENV["SCRIPT_NAME"] ..
@@ -341,7 +341,7 @@ exception_handler = function (self, message )
parent_exception_handler(self, message)
end
else
- logevent("Exception: "..message)
+ self.logevent("Exception: "..message)
viewtable = {message = message}
self.conf.prefix = "/"
self.conf.controller = "exception"
@@ -351,7 +351,7 @@ exception_handler = function (self, message )
if viewtable then
if not self.conf.suppress_view then
local success, err = xpcall ( function ()
- local viewfunc, p1, p2, p3 = view_resolver(self)
+ local viewfunc, p1, p2, p3 = self.view_resolver(self)
viewfunc (viewtable, p1, p2, p3)
end,
self:soft_traceback()
@@ -368,14 +368,14 @@ end
-- check permissions and redirect if not allowed to see
-- pass more parameters to the view
-- allow display of views without actions
-dispatch = function (self, userprefix, userctlr, useraction)
+mymodule.dispatch = function (self, userprefix, userctlr, useraction)
local controller = nil
local viewtable
local success, err = xpcall ( function ()
if userprefix == nil then
self.conf.prefix, self.conf.controller, self.conf.action =
- parse_path_info(ENV["PATH_INFO"])
+ self.parse_path_info(ENV["PATH_INFO"])
self.conf.wwwprefix = string.gsub(ENV["SCRIPT_NAME"] or "", "/?cgi%-bin/acf.*", "")
else
self.conf.prefix = userprefix or "/"
@@ -404,11 +404,11 @@ dispatch = function (self, userprefix, userctlr, useraction)
for name,value in pairs(self.conf) do origconf[name]=value end
if "" == self.conf.controller and self.sessiondata.userinfo and self.sessiondata.userinfo.home and self.sessiondata.userinfo.home ~= "" then
self.conf.prefix, self.conf.controller, self.conf.action =
- parse_path_info(self.sessiondata.userinfo.home)
+ self.parse_path_info(self.sessiondata.userinfo.home)
end
if "" == self.conf.controller and self.conf.home and self.conf.home ~= "" then
self.conf.prefix, self.conf.controller, self.conf.action =
- parse_path_info(self.conf.home)
+ self.parse_path_info(self.conf.home)
end
if "" == self.conf.controller then
self.conf.prefix = "/acf-util/"
@@ -418,7 +418,7 @@ dispatch = function (self, userprefix, userctlr, useraction)
-- If we have different prefix / controller / action, redirect
if self.conf.prefix ~= origconf.prefix or self.conf.controller ~= origconf.controller or self.conf.action ~= origconf.action then
- redirect(self, self.conf.action) -- controller and prefix already in self.conf
+ self:redirect(self.conf.action) -- controller and prefix already in self.conf
end
if "" ~= self.conf.controller then
@@ -481,7 +481,7 @@ dispatch = function (self, userprefix, userctlr, useraction)
end
if not self.conf.suppress_view then
- local viewfunc, p1, p2, p3 = view_resolver(self)
+ local viewfunc, p1, p2, p3 = self.view_resolver(self)
viewfunc (viewtable, p1, p2, p3)
end
@@ -505,14 +505,14 @@ end
-- Cause a redirect to specified (or default) action
-- We use the self.conf table because it already has prefix,controller,etc
-- The actual redirection is defined in exception_handler above
-redirect = function (self, str, result)
+mymodule.redirect = function (self, str, result)
if self.conf.viewtype ~= "html" then
return
end
if result then
self.sessiondata[self.conf.action.."result"] = result
end
- local prefix, controller, action = parse_redir_string(str)
+ local prefix, controller, action = self.parse_redir_string(str)
if prefix ~= "/" then self.conf.prefix = prefix end
if controller ~= "" then self.conf.controller = controller end
@@ -526,7 +526,7 @@ end
-- If we've done something, cause a redirect to the referring page (assuming it's different)
-- Also handles retrieving the result of a previously redirected action
-redirect_to_referrer = function(self, result)
+mymodule.redirect_to_referrer = function(self, result)
if self.conf.viewtype ~= "html" then
return result
end
@@ -559,7 +559,7 @@ end
-- parse a "URI" like string into a prefix, controller and action
-- this is the same as URI string, but opposite preference
-- if only one is defined, it's assumed to be the action
-parse_redir_string = function( str )
+mymodule.parse_redir_string = function( str )
str = str or ""
str = string.gsub(str, "/+$", "")
local action = string.match(str, "[^/]+$") or ""
@@ -575,16 +575,16 @@ parse_redir_string = function( str )
return prefix, controller, action
end
-logevent = function ( message )
- if conf.loghandle then
- conf.loghandle:write (string.format("%s: %s\n", os.date(), message or ""))
+mymodule.logevent = function ( message )
+ if mymodule.conf.loghandle then
+ mymodule.conf.loghandle:write (string.format("%s: %s\n", os.date(), message or ""))
else
-- call to parent's handler
__index.logevent(message)
end
end
-handle_clientdata = function(form, clientdata)
+mymodule.handle_clientdata = function(form, clientdata)
clientdata = clientdata or {}
form.errtxt = nil
for name,value in pairs(form.value) do
@@ -603,7 +603,7 @@ handle_clientdata = function(form, clientdata)
clientdata[name] = actualval
end
if value.type == "group" then
- handle_clientdata(value, clientdata[name])
+ mymodule.handle_clientdata(value, clientdata[name])
elseif value.type == "boolean" then
--- HTML forms simply don't include checkboxes unless they're checked
value.value = (clientdata[name] ~= nil) and (clientdata[name] ~= "false")
@@ -636,7 +636,7 @@ handle_clientdata = function(form, clientdata)
end
end
-handle_form = function(self, getFunction, setFunction, clientdata, option, label, descr)
+mymodule.handle_form = function(self, getFunction, setFunction, clientdata, option, label, descr)
local form = getFunction(self, clientdata)
if clientdata.submit then
@@ -669,3 +669,5 @@ handle_form = function(self, getFunction, setFunction, clientdata, option, label
return form
end
+
+return mymodule