summaryrefslogtreecommitdiffstats
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
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.
-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
-rw-r--r--lib/authenticator-plaintext.lua20
-rw-r--r--lib/authenticator.lua38
-rw-r--r--lib/htmlviewfunctions.lua44
-rw-r--r--lib/menubuilder.lua6
-rw-r--r--lib/modelfunctions.lua30
-rw-r--r--lib/roles.lua50
-rw-r--r--lib/session.lua33
-rwxr-xr-xlua/mvc.lua50
19 files changed, 269 insertions, 242 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
diff --git a/lib/authenticator-plaintext.lua b/lib/authenticator-plaintext.lua
index caa6748..ecfca03 100644
--- a/lib/authenticator-plaintext.lua
+++ b/lib/authenticator-plaintext.lua
@@ -7,12 +7,12 @@ create a different file for each field.
]]--
-module (..., package.seeall)
+local mymodule = {}
fs = require("acf.fs")
posix = require("posix")
-list_fields = function(self, tabl)
+mymodule.list_fields = function(self, tabl)
if not self or not tabl or tabl == "" then
return {}
end
@@ -27,7 +27,7 @@ list_fields = function(self, tabl)
return fields
end
-read_field = function(self, tabl, field)
+mymodule.read_field = function(self, tabl, field)
if not self or not tabl or tabl == "" or not field then
return nil
end
@@ -53,7 +53,7 @@ read_field = function(self, tabl, field)
end
end
-delete_field = function(self, tabl, field)
+mymodule.delete_field = function(self, tabl, field)
if not self or not tabl or tabl == "" or not field then
return false
end
@@ -62,7 +62,7 @@ delete_field = function(self, tabl, field)
return true
end
-write_entry = function(self, tabl, field, id, entry)
+mymodule.write_entry = function(self, tabl, field, id, entry)
if not self or not tabl or tabl == "" or not field or not id or not entry then
return false
end
@@ -83,7 +83,7 @@ write_entry = function(self, tabl, field, id, entry)
return true
end
-read_entry = function(self, tabl, field, id)
+mymodule.read_entry = function(self, tabl, field, id)
if not self or not tabl or tabl == "" or not field or not id then
return nil
end
@@ -99,7 +99,7 @@ read_entry = function(self, tabl, field, id)
return nil
end
-delete_entry = function (self, tabl, field, id)
+mymodule.delete_entry = function (self, tabl, field, id)
if not self or not tabl or tabl == "" or not field or not id then
return false
end
@@ -123,11 +123,13 @@ delete_entry = function (self, tabl, field, id)
-- If deleting the main field, delete all other fields also
if field == "" then
- local fields = list_fields(self, tabl)
+ local fields = mymodule.list_fields(self, tabl)
for i,fld in ipairs(fields) do
- delete_entry(self, tabl, fld, id)
+ mymodule.delete_entry(self, tabl, fld, id)
end
end
return result
end
+
+return mymodule
diff --git a/lib/authenticator.lua b/lib/authenticator.lua
index 789ecde..975d0e6 100644
--- a/lib/authenticator.lua
+++ b/lib/authenticator.lua
@@ -1,7 +1,7 @@
-- ACF Authenticator - does validation and loads sub-authenticator to read/write database
-- We store the logon info in the passwd table, "" field. It looks like
-- password:username:ROLE1[,ROLE2...]
-module (..., package.seeall)
+local mymodule = {}
modelfunctions = require("modelfunctions")
format = require("acf.format")
@@ -92,8 +92,8 @@ auth.delete_entry = function (self, tabl, field, id)
end
-- Publicly define the pre-defined tables
-usertable = "passwd"
-roletable = "roles"
+mymodule.usertable = "passwd"
+mymodule.roletable = "roles"
-- This will hold the auth structure from the database
local authstruct = {}
@@ -120,7 +120,7 @@ end
local load_database = function(self)
if not complete then
- local authtable = auth.read_field(self, usertable, "") or {}
+ local authtable = auth.read_field(self, mymodule.usertable, "") or {}
authstruct = {}
for i,value in ipairs(authtable) do
parse_entry(value.id, value.entry)
@@ -131,7 +131,7 @@ end
local get_id = function(self, userid)
if not authstruct[userid] then
- parse_entry(userid, auth.read_entry(self, usertable, "", userid))
+ parse_entry(userid, auth.read_entry(self, mymodule.usertable, "", userid))
end
return authstruct[userid]
end
@@ -184,7 +184,7 @@ end
--- public methods
-get_subauth = function(self)
+mymodule.get_subauth = function(self)
if not auth.subauths then
auth.subauths = {}
if self and self.conf and self.conf.authenticator and self.conf.authenticator ~= "" then
@@ -200,8 +200,8 @@ end
-- This function returns true or false, and
-- if false: the reason for failure
-authenticate = function(self, userid, password)
- auth = get_subauth(self)
+mymodule.authenticate = function(self, userid, password)
+ auth = mymodule.get_subauth(self)
local errtxt
if not userid or not password then
@@ -220,8 +220,8 @@ authenticate = function(self, userid, password)
end
-- This function returns the username, roles, ...
-get_userinfo = function(self, userid)
- auth = get_subauth(self)
+mymodule.get_userinfo = function(self, userid)
+ auth = mymodule.get_subauth(self)
local id = get_id(self, userid)
if id then
-- Make a copy so roles don't get changed in the authstruct
@@ -239,8 +239,8 @@ get_userinfo = function(self, userid)
return nil
end
-write_userinfo = function(self, userinfo)
- auth = get_subauth(self)
+mymodule.write_userinfo = function(self, userinfo)
+ auth = mymodule.get_subauth(self)
if not userinfo or not userinfo.userid or userinfo.userid == "" then
return false
end
@@ -253,7 +253,7 @@ write_userinfo = function(self, userinfo)
if userinfo.skin then id.skin = userinfo.skin end
if userinfo.home then id.home = userinfo.home end
- local success = auth.write_entry(self, usertable, "", id.userid, (id.password or "")..":"..(id.username or "")..":"..(id.roles or "")..":"..(id.skin or "")..":"..(id.home or ""))
+ local success = auth.write_entry(self, mymodule.usertable, "", id.userid, (id.password or "")..":"..(id.username or "")..":"..(id.roles or "")..":"..(id.skin or "")..":"..(id.home or ""))
authstruct[userinfo.userid] = nil
get_id(self, id.userid)
@@ -276,8 +276,8 @@ write_userinfo = function(self, userinfo)
return success
end
-list_users = function (self)
- auth = get_subauth(self)
+mymodule.list_users = function (self)
+ auth = mymodule.get_subauth(self)
load_database(self)
local output = {}
for k in pairs(authstruct) do
@@ -286,8 +286,10 @@ list_users = function (self)
return output
end
-delete_user = function (self, userid)
- auth = get_subauth(self)
+mymodule.delete_user = function (self, userid)
+ auth = mymodule.get_subauth(self)
authstruct[userid] = nil
- return auth.delete_entry(self, usertable, "", userid)
+ return auth.delete_entry(self, mymodule.usertable, "", userid)
end
+
+return mymodule
diff --git a/lib/htmlviewfunctions.lua b/lib/htmlviewfunctions.lua
index 6f7512a..35d4ca4 100644
--- a/lib/htmlviewfunctions.lua
+++ b/lib/htmlviewfunctions.lua
@@ -1,4 +1,4 @@
-module(..., package.seeall)
+local mymodule = {}
html = require("acf.html")
session = require("session")
@@ -22,12 +22,12 @@ local function getlabel(myitem, value)
return tostring(value)
end
-function displayitem(myitem, header_level, page_info)
+function mymodule.displayitem(myitem, header_level, page_info)
if not myitem then return end
if myitem.type == "form" then
header_level = header_level or 1
io.write("<H"..tostring(header_level)..">"..html.html_escape(myitem.label).."</H"..tostring(header_level)..">")
- displayform(myitem, nil, nil, page_info, header_level)
+ mymodule.displayform(myitem, nil, nil, page_info, header_level)
elseif myitem.type == "group" then
header_level = header_level or 1
io.write("<H"..tostring(header_level)..">"..html.html_escape(myitem.label).."</H"..tostring(header_level)..">")
@@ -49,7 +49,7 @@ function displayitem(myitem, header_level, page_info)
end
for x,name in ipairs(order) do
if myitem.value[name] then
- displayitem(myitem.value[name], tonumber(header_level)+1)
+ mymodule.displayitem(myitem.value[name], tonumber(header_level)+1)
end
end
elseif myitem.type ~= "hidden" then
@@ -67,7 +67,7 @@ function displayitem(myitem, header_level, page_info)
end
end
-function displayformitem(myitem, name, viewtype, header_level, group)
+function mymodule.displayformitem(myitem, name, viewtype, header_level, group)
if not myitem then return end
if name then myitem.name = name end
if group and group ~= "" then myitem.name = group.."."..myitem.name end
@@ -88,7 +88,7 @@ function displayformitem(myitem, name, viewtype, header_level, group)
io.write("<H"..tostring(header_level)..">"..html.html_escape(myitem.label).."</H"..tostring(header_level)..">")
if myitem.descr then io.write('<P CLASS="descr">' .. string.gsub(html.html_escape(myitem.descr), "\n", "<BR>") .. "</P>\n") end
if myitem.errtxt then io.write('<P CLASS="error">' .. string.gsub(html.html_escape(myitem.errtxt), "\n", "<BR>") .. "</P>\n") end
- displayformcontents(myitem, nil, nil, tonumber(header_level)+1, myitem.name)
+ mymodule.displayformcontents(myitem, nil, nil, tonumber(header_level)+1, myitem.name)
elseif myitem.type == "multi" then
-- FIXME multiple select doesn't work in haserl, so use series of checkboxes
--myitem.type = "select"
@@ -156,7 +156,7 @@ function displayformitem(myitem, name, viewtype, header_level, group)
end
end
-function displayformstart(myform, page_info)
+function mymodule.displayformstart(myform, page_info)
if not myform then return end
if not myform.action and page_info then
myform.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action
@@ -170,11 +170,11 @@ function displayformstart(myform, page_info)
end
io.write('method="POST">\n')
if myform.value.redir then
- displayformitem(myform.value.redir, "redir")
+ mymodule.displayformitem(myform.value.redir, "redir")
end
end
-function displayformcontents(myform, order, finishingorder, header_level, group)
+function mymodule.displayformcontents(myform, order, finishingorder, header_level, group)
if not myform then return end
if not order and not finishingorder then
tmporder = {}
@@ -197,7 +197,7 @@ function displayformcontents(myform, order, finishingorder, header_level, group)
reverseorder[name] = x
if myform.value[name] then
myform.value[name].name = name
- displayformitem(myform.value[name], nil, nil, header_level, group)
+ mymodule.displayformitem(myform.value[name], nil, nil, header_level, group)
end
end
end
@@ -210,20 +210,20 @@ function displayformcontents(myform, order, finishingorder, header_level, group)
for name,item in pairs(myform.value) do
if nil == reverseorder[name] and nil == reversefinishingorder[name] then
item.name = name
- displayformitem(item, nil, nil, header_level, group)
+ mymodule.displayformitem(item, nil, nil, header_level, group)
end
end
if finishingorder then
for x,name in ipairs(finishingorder) do
if myform.value[name] then
myform.value[name].name = name
- displayformitem(myform.value[name], nil, nil, header_level, group)
+ mymodule.displayformitem(myform.value[name], nil, nil, header_level, group)
end
end
end
end
-function displayformend(myform)
+function mymodule.displayformend(myform)
if not myform then return end
local option = myform.submit or myform.option
io.write('<DT></DT><DD>')
@@ -239,14 +239,14 @@ function displayformend(myform)
io.write('</DL>\n')
end
-function displayform(myform, order, finishingorder, page_info, header_level)
+function mymodule.displayform(myform, order, finishingorder, page_info, header_level)
if not myform then return end
- displayformstart(myform, page_info)
- displayformcontents(myform, order, finishingorder, header_level)
- displayformend(myform)
+ mymodule.displayformstart(myform, page_info)
+ mymodule.displayformcontents(myform, order, finishingorder, header_level)
+ mymodule.displayformend(myform)
end
-function displaycommandresults(commands, session, preserveerrors)
+function mymodule.displaycommandresults(commands, session, preserveerrors)
local cmdresult = {}
for i,cmd in ipairs(commands) do
if session[cmd.."result"] then
@@ -269,7 +269,7 @@ end
-- Divide up data into pages of size pagesize
-- clientdata can be a page number or a table where clientdata.page is the page number
-function paginate(data, clientdata, pagesize)
+function mymodule.paginate(data, clientdata, pagesize)
local subset = data
local page_data = { numpages=1, page=1, pagesize=pagesize, num=#data }
if #data > pagesize then
@@ -294,7 +294,7 @@ function paginate(data, clientdata, pagesize)
return subset, page_data
end
-function displaypagination(page_data, page_info)
+function mymodule.displaypagination(page_data, page_info)
local min, max
if page_data.page == 0 then
min = 1
@@ -363,10 +363,12 @@ end
-- give a cfe and get back a string of what is inside
-- great for troubleshooting and seeing what is really being passed to the view
-function cfe_unpack ( a )
+function mymodule.cfe_unpack ( a )
if type(a) == "table" then
value = session.serialize("cfe", a)
value = "<pre>" .. html.html_escape(value) .. "</pre>"
return value
end
end
+
+return mymodule
diff --git a/lib/menubuilder.lua b/lib/menubuilder.lua
index b40348a..6bb981f 100644
--- a/lib/menubuilder.lua
+++ b/lib/menubuilder.lua
@@ -3,7 +3,7 @@
Copyright (C) 2007 Nathan Angelacos
Licensed under the terms of GPL2
]]--
-module(..., package.seeall)
+local mymodule = {}
posix = require("posix")
format = require("acf.format")
@@ -60,7 +60,7 @@ local prio_compare = function(x,y)
end
-- returns a table of all the menu items found, sorted by priority
-get_menuitems = function (self)
+mymodule.get_menuitems = function (self)
local cats = {}
local reversecats = {}
local foundcontrollers = {}
@@ -193,4 +193,4 @@ get_menuitems = function (self)
return cats
end
-
+return mymodule
diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua
index fb85102..2819911 100644
--- a/lib/modelfunctions.lua
+++ b/lib/modelfunctions.lua
@@ -1,4 +1,4 @@
-module(..., package.seeall)
+local mymodule = {}
-- Load libraries
fs = require("acf.fs")
@@ -7,7 +7,7 @@ processinfo = require("acf.processinfo")
posix = require("posix")
subprocess = require("subprocess")
-function getenabled(servicename)
+function mymodule.getenabled(servicename)
local result = cfe({ label = "Program status", name=servicename })
result.value, result.errtxt = processinfo.daemoncontrol(servicename, "status")
if string.find(result.value, ": not found") then
@@ -20,7 +20,7 @@ function getenabled(servicename)
return result
end
-function get_startstop(servicename)
+function mymodule.get_startstop(servicename)
local service = cfe({ type="hidden", value=servicename, label="Service Name" })
local actions, descr = processinfo.daemon_actions(servicename)
local errtxt
@@ -34,7 +34,7 @@ function get_startstop(servicename)
return cfe({ type="group", label="Management", value={servicename=service}, option=actions, errtxt=errtxt })
end
-function startstop_service(startstop, action)
+function mymodule.startstop_service(startstop, action)
if not action then
startstop.errtxt = "Invalid Action"
else
@@ -51,7 +51,7 @@ function startstop_service(startstop, action)
return startstop
end
-function getstatus(servicename, packagename, label)
+function mymodule.getstatus(servicename, packagename, label)
local status = {}
if packagename then
@@ -65,7 +65,7 @@ function getstatus(servicename, packagename, label)
end
if servicename then
- status.status = getenabled(servicename)
+ status.status = mymodule.getenabled(servicename)
local autostart_value, autostart_errtxt = processinfo.process_autostart(servicename)
status.autostart = cfe({
@@ -79,7 +79,7 @@ function getstatus(servicename, packagename, label)
return cfe({ type="group", value=status, label=label })
end
-function getfiledetails(file, validatefilename, validatefiledetails)
+function mymodule.getfiledetails(file, validatefilename, validatefiledetails)
local filename = cfe({ value=file or "", label="File name" })
local filecontent = cfe({ type="longtext", label="File content" })
local filesize = cfe({ value="0", label="File size" })
@@ -117,7 +117,7 @@ function getfiledetails(file, validatefilename, validatefiledetails)
return filedetails
end
-function setfiledetails(self, filedetails, validatefilename, validatefiledetails)
+function mymodule.setfiledetails(self, filedetails, validatefilename, validatefiledetails)
filedetails.value.filecontent.value = string.gsub(format.dostounix(filedetails.value.filecontent.value), "\n+$", "")
local success = true
if type(validatefilename) == "function" then
@@ -140,8 +140,8 @@ function setfiledetails(self, filedetails, validatefilename, validatefiledetails
end
if success then
--fs.write_file(filedetails.value.filename.value, filedetails.value.filecontent.value)
- write_file_with_audit(self, filedetails.value.filename.value, filedetails.value.filecontent.value)
- filedetails = getfiledetails(filedetails.value.filename.value)
+ mymodule.write_file_with_audit(self, filedetails.value.filename.value, filedetails.value.filecontent.value)
+ filedetails = mymodule.getfiledetails(filedetails.value.filename.value)
else
filedetails.errtxt = "Failed to set file"
end
@@ -149,7 +149,7 @@ function setfiledetails(self, filedetails, validatefilename, validatefiledetails
return filedetails
end
-function validateselect(select)
+function mymodule.validateselect(select)
for i,option in ipairs(select.option) do
if type(option) == "string" and option == select.value then
return true
@@ -161,7 +161,7 @@ function validateselect(select)
return false
end
-function validatemulti(multi)
+function mymodule.validatemulti(multi)
local reverseoption = {}
for i,option in ipairs(multi.option) do
if type(option) == "string" then
@@ -179,7 +179,7 @@ function validatemulti(multi)
return true
end
-function write_file_with_audit (self, path, str)
+function mymodule.write_file_with_audit (self, path, str)
if self then
local pre = ""
local post = ""
@@ -240,7 +240,7 @@ end
-- output will never be nil
-- errtxt will be nil for success and non-nil for failure
-- if include_err, then stderr will be prepended to stdout (if executable doesn't fail)
-run_executable = function(args, include_err, input)
+mymodule.run_executable = function(args, include_err, input)
local output = ""
local errtxt
local res, err = pcall(function()
@@ -291,3 +291,5 @@ run_executable = function(args, include_err, input)
end
return output, errtxt
end
+
+return mymodule
diff --git a/lib/roles.lua b/lib/roles.lua
index 5cc293d..eb64305 100644
--- a/lib/roles.lua
+++ b/lib/roles.lua
@@ -4,9 +4,9 @@ authenticator = require ("authenticator")
fs = require ("acf.fs")
format = require ("acf.format")
-module (..., package.seeall)
+local mymodule = {}
-guest_role = "GUEST"
+mymodule.guest_role = "GUEST"
-- Global variables so we don't have to figure out all the roles multiple times
local defined_roles, default_roles, reverseroles, roles_candidates, role_table, table_perm, array_perm
@@ -27,7 +27,7 @@ local get_roles_candidates = function(self)
end
-- Return a list of *controller.lua files
-list_controllers = function(self)
+mymodule.list_controllers = function(self)
local list = {}
for p in string.gmatch(self.conf.appdir, "[^,]+") do
for file in fs.find(".*controller%.lua", p, true) do
@@ -41,9 +41,9 @@ list_controllers = function(self)
end
-- Return information about all or specified controller files
-get_controllers = function(self,pre,controller)
+mymodule.get_controllers = function(self,pre,controller)
--we get all the controllers
- local list = list_controllers(self)
+ local list = mymodule.list_controllers(self)
--we need to grab the directory and name of file
local temp = {}
for k,v in pairs(list) do
@@ -64,7 +64,7 @@ get_controllers = function(self,pre,controller)
end
-- Find all public functions in a controller
-get_controllers_func = function(self,controller_info)
+mymodule.get_controllers_func = function(self,controller_info)
if controller_info == nil then
return "Could not be processed"
else
@@ -91,7 +91,7 @@ get_controllers_func = function(self,controller_info)
end
-- Find all views for a controller
-get_controllers_view = function(self,controller_info)
+mymodule.get_controllers_view = function(self,controller_info)
local temp = {}
for file in fs.find(controller_info.sname.."%-[^%.]+%-html%.lsp", controller_info.path) do
temp[#temp + 1] = string.match(file, controller_info.sname.."%-([^%./]+)%-html%.lsp")
@@ -99,10 +99,10 @@ get_controllers_view = function(self,controller_info)
return temp
end
-get_all_permissions = function(self)
+mymodule.get_all_permissions = function(self)
if not table_perm or not array_perm then
-- need to get a list of all the controllers
- controllers = get_controllers(self)
+ controllers = mymodule.get_controllers(self)
table_perm = {}
array_perm = {}
for a,b in pairs(controllers) do
@@ -112,12 +112,12 @@ get_all_permissions = function(self)
if nil == table_perm[b.prefix][b.sname] then
table_perm[b.prefix][b.sname] = {}
end
- local temp = get_controllers_func(self,b)
+ local temp = mymodule.get_controllers_func(self,b)
for x,y in ipairs(temp) do
table_perm[b.prefix][b.sname][y] = {}
array_perm[#array_perm + 1] = b.prefix .. b.sname .. "/" .. y
end
- temp = get_controllers_view(self,b)
+ temp = mymodule.get_controllers_view(self,b)
for x,y in ipairs(temp) do
if not table_perm[b.prefix][b.sname][y] then
table_perm[b.prefix][b.sname][y] = {}
@@ -130,7 +130,7 @@ get_all_permissions = function(self)
return table_perm, array_perm
end
-list_default_roles = function(self)
+mymodule.list_default_roles = function(self)
if not default_roles then
default_roles = {}
reverseroles = {}
@@ -174,7 +174,7 @@ list_default_roles = function(self)
return default_roles, reverseroles
end
-list_defined_roles = function(self)
+mymodule.list_defined_roles = function(self)
if not defined_roles then
local auth = authenticator.get_subauth(self)
-- Open the roles file and parse for defined roles
@@ -191,15 +191,15 @@ list_defined_roles = function(self)
return defined_roles
end
-list_roles = function(self)
- local default_roles = list_default_roles(self)
- local defined_roles = list_defined_roles(self)
+mymodule.list_roles = function(self)
+ local default_roles = mymodule.list_default_roles(self)
+ local defined_roles = mymodule.list_defined_roles(self)
return defined_roles, default_roles
end
-list_all_roles = function(self)
- local defined_roles, default_roles = list_roles(self)
+mymodule.list_all_roles = function(self)
+ local defined_roles, default_roles = mymodule.list_roles(self)
-- put the defined roles first
for x,role in ipairs(default_roles) do
defined_roles[#defined_roles + 1] = role
@@ -270,7 +270,7 @@ local determine_perms = function(self,roles)
temp = format.string_to_table(entry.entry, ",")
for z,perm in pairs(temp) do
local prefix,control,action = self.parse_path_info(perm)
- if control then
+ if control and "" ~= control then
if nil == permissions[prefix] then
permissions[prefix] = {}
end
@@ -290,18 +290,18 @@ local determine_perms = function(self,roles)
end
-- Go through the roles files and determine the permissions for the specified list of roles (including guest)
-get_roles_perm = function(self,roles)
- roles[#roles+1] = guest_role
+mymodule.get_roles_perm = function(self,roles)
+ roles[#roles+1] = mymodule.guest_role
return determine_perms(self, roles)
end
-- Go through the roles files and determine the permissions for the specified role
-get_role_perm = function(self,role)
+mymodule.get_role_perm = function(self,role)
return determine_perms(self, {role})
end
-- Delete a role from role file
-delete_role = function(self, role)
+mymodule.delete_role = function(self, role)
local auth = authenticator.get_subauth(self)
local result = auth.delete_entry(self, authenticator.roletable, "", role)
local cmdresult = "Role entry not found"
@@ -311,7 +311,7 @@ delete_role = function(self, role)
end
-- Set permissions for a role in role file
-set_role_perm = function(self, role, permissions, permissions_array)
+mymodule.set_role_perm = function(self, role, permissions, permissions_array)
if role==nil or role=="" then
return false, "Invalid Role"
end
@@ -332,3 +332,5 @@ set_role_perm = function(self, role, permissions, permissions_array)
local auth = authenticator.get_subauth(self)
return auth.write_entry(self, authenticator.roletable, "", role, table.concat(permissions_array or {},","))
end
+
+return mymodule
diff --git a/lib/session.lua b/lib/session.lua
index 12f0c28..34b9789 100644
--- a/lib/session.lua
+++ b/lib/session.lua
@@ -1,7 +1,6 @@
-- Session handling routines - written for acf
-- Copyright (C) 2007 N. Angelacos - GPL2 License
-
--[[ Note that in this library, we use empty (0 byte) files
-- everwhere we can, as they only take up dir entries, not inodes
-- as the tmpfs blocksize is 4K, and under denial of service
@@ -10,7 +9,7 @@
-- not take this precaution.
-- ]]--
-module (..., package.seeall)
+local mymodule = {}
posix = require("posix")
@@ -23,7 +22,7 @@ cached_content=nil
local b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
-- Return a sessionid of at least size bits length
-random_hash = function (size)
+mymodule.random_hash = function (size)
local file = io.open("/dev/urandom")
local str = ""
if file == nil then return nil end
@@ -36,8 +35,7 @@ random_hash = function (size)
end
-- FIXME: only hashes ipv4
-
-hash_ip_addr = function (string)
+mymodule.hash_ip_addr = function (string)
local str = ""
for i in string.gmatch(string, "%d+") do
str = str .. string.format("%02x", i )
@@ -45,7 +43,7 @@ hash_ip_addr = function (string)
return str
end
-ip_addr_from_hash = function (string)
+mymodule.ip_addr_from_hash = function (string)
local str = ""
for i in string.gmatch(string, "..") do
str = str .. string.format("%d", "0x" .. i) .. "."
@@ -53,7 +51,6 @@ ip_addr_from_hash = function (string)
return string.sub(str, 1, string.len(str)-1)
end
-
--[[
These functions serialize a table, including nested tables.
The code based on code in PiL 2nd edition p113
@@ -66,8 +63,7 @@ local function basicSerialize (o)
end
end
-
-function serialize (name, value, saved, output )
+mymodule.serialize = function(name, value, saved, output )
local need_to_concat = (output == nil)
output = output or {}
saved = saved or {}
@@ -82,7 +78,7 @@ function serialize (name, value, saved, output )
table.insert(output, str .. "{}")
for k,v in pairs(value) do
local fieldname = string.format("%s[%s]", name, basicSerialize(k))
- serialize (fieldname, v, saved, output)
+ mymodule.serialize (fieldname, v, saved, output)
end
end
elseif type(value) == "boolean" then
@@ -99,7 +95,7 @@ end
-- Save the session (unless all it contains is the id)
-- return true or false for success
-save_session = function( sessionpath, sessiontable)
+mymodule.save_session = function( sessionpath, sessiontable)
if nil == sessiontable or nil == sessiontable.id then return false end
-- clear the id key, don't need to store that
@@ -110,7 +106,7 @@ save_session = function( sessionpath, sessiontable)
if #sessiontable then
local output = {}
output[#output+1] = "-- This is an ACF session table."
- output[#output+1] = "local " .. serialize("s", sessiontable)
+ output[#output+1] = "local " .. mymodule.serialize("s", sessiontable)
output[#output+1] = "return s"
local content = table.concat(output, "\n") .. "\n"
@@ -132,11 +128,10 @@ save_session = function( sessionpath, sessiontable)
return true
end
-
-- Loads a session
-- Returns a timestamp (when the session data was saved) and the session table.
-- Insert the session into the "id" field
-load_session = function ( sessionpath, session )
+mymodule.load_session = function ( sessionpath, session )
if type(session) ~= "string" then return nil, {} end
local s = {}
-- session can only have b64 characters in it
@@ -171,7 +166,7 @@ end
-- Unlinks a session (deletes the session file)
-- return nil for failure, ?? for success
-unlink_session = function (sessionpath, session)
+mymodule.unlink_session = function (sessionpath, session)
if type(session) ~= "string" then return nil end
local s = string.gsub (session, "[^" .. b64 .. "]", "")
if s ~= session then
@@ -185,7 +180,7 @@ end
-- Record an invalid logon event
-- ID would typically be an ip address or username
-- the format is lockevent.id.datetime.processid
-record_event = function( sessionpath, id_u, id_ip )
+mymodule.record_event = function( sessionpath, id_u, id_ip )
local x = io.open (string.format ("%s/lockevent.%s.%s.%s.%s",
sessionpath or "/", id_u or "", id_ip or "", os.time(),
(posix.getpid("pid")) or "" ), "w")
@@ -195,7 +190,7 @@ end
-- Check how many invalid logon events
-- have happened for this id in the last n minutes
-- this will only effect the lockevent files
-count_events = function (sessionpath, id_user, ipaddr, minutes, limit)
+mymodule.count_events = function (sessionpath, id_user, ipaddr, minutes, limit)
--we need to have the counts added up? deny off any and or all
local now = os.time()
local minutes_ago = now - ((minutes or minutes_count_events) * 60)
@@ -225,7 +220,7 @@ count_events = function (sessionpath, id_user, ipaddr, minutes, limit)
end
-- Clear events that are older than n minutes
-expired_events = function (sessionpath, minutes)
+mymodule.expired_events = function (sessionpath, minutes)
--current os time in seconds
local now = os.time()
--take minutes and convert to seconds
@@ -252,3 +247,5 @@ expired_events = function (sessionpath, minutes)
end
return 0
end
+
+return mymodule
diff --git a/lua/mvc.lua b/lua/mvc.lua
index a9619ae..b698bd5 100755
--- a/lua/mvc.lua
+++ b/lua/mvc.lua
@@ -4,7 +4,7 @@
Copyright (C) 2007 Nathan Angelacos
Licensed under the terms of GPL2
]]--
-module(..., package.seeall)
+local mymodule = {}
posix = require("posix")
subprocess = require("subprocess")
@@ -13,7 +13,7 @@ format = require("acf.format")
-- For security, set the path
posix.setenv("PATH", "/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin")
-mvc = {}
+mymodule.mvc = {}
-- the constructor
--[[ Builds a new MVC object. If "module" is given, then tries to load
@@ -27,7 +27,7 @@ mvc = {}
appname - the name of the application
]]
-new = function (self, modname)
+mymodule.new = function (self, modname)
local model_loaded = true
local worker_loaded = true
local c = {}
@@ -107,7 +107,7 @@ new = function (self, modname)
return c, worker_loaded, model_loaded
end
-destroy = function (self)
+mymodule.destroy = function (self)
if type(rawget(self.worker.mvc, "on_unload")) == "function" then
self.worker.mvc.on_unload(self)
self.worker.mvc.on_unload = nil
@@ -129,7 +129,7 @@ destroy = function (self)
end
-- This is a sample front controller/dispatch.
-dispatch = function (self, userprefix, userctlr, useraction, clientdata)
+mymodule.dispatch = function (self, userprefix, userctlr, useraction, clientdata)
local controller = nil
local success, err = xpcall ( function ()
self.conf.prefix = userprefix or "/"
@@ -204,7 +204,7 @@ dispatch = function (self, userprefix, userctlr, useraction, clientdata)
controller = nil
end
if nil == handler then
- handler = self.worker or mvc
+ handler = self.worker or self.mvc
handler:exception_handler(err)
end
end
@@ -212,7 +212,7 @@ end
-- Tries to see if name exists in the self.conf.appdir, and if so, it loads it.
-- otherwise, returns nil, but no error
-soft_require = function (self, name )
+mymodule.soft_require = function (self, name )
local filename, file
for p in string.gmatch(self.conf.appdir, "[^,]+") do
filename = p .. name .. ".lua"
@@ -239,7 +239,7 @@ soft_require = function (self, name )
end
-- look in various places for a config file, and store it in self.conf
-read_config = function( self, appname, home )
+mymodule.read_config = function( self, appname, home )
appname = appname or self.conf.appname
self.conf.appname = self.conf.appname or appname
@@ -286,7 +286,7 @@ end
-- parse a "URI" like string into a prefix, controller and action
-- return them (or blank strings)
-parse_path_info = function( str )
+mymodule.parse_path_info = function( str )
str = str or ""
local words = {}
str = string.gsub(str, "/+$", "")
@@ -304,7 +304,7 @@ end
-- look for a view
-- ctlr-action-view, then ctlr-view
-find_view = function ( appdir, prefix, controller, action, viewtype )
+mymodule.find_view = function ( appdir, prefix, controller, action, viewtype )
if not viewtype then return nil end
for p in string.gmatch(appdir, "[^,]+") do
local names = { p .. prefix .. controller .. "-" ..
@@ -324,7 +324,7 @@ find_view = function ( appdir, prefix, controller, action, viewtype )
return nil
end
-create_helper_library = function ( self )
+mymodule.create_helper_library = function ( self )
local library = {}
--[[ -- If we have a separate library, here's how we could do it
local library = require("library_name")
@@ -338,7 +338,7 @@ create_helper_library = function ( self )
end
-- The view of last resort
-auto_view = function(viewtable, viewlibrary, pageinfo, session)
+mymodule.auto_view = function(viewtable, viewlibrary, pageinfo, session)
if pageinfo.viewtype == "html" then
local htmlviewfunctions = require("htmlviewfunctions")
htmlviewfunctions.displayitem(viewtable, 1, pageinfo)
@@ -354,7 +354,7 @@ auto_view = function(viewtable, viewlibrary, pageinfo, session)
end
-- The view resolver of last resort.
-view_resolver = function(self)
+mymodule.view_resolver = function(self)
local viewname, viewlibrary
-- search for view
@@ -385,7 +385,7 @@ view_resolver = function(self)
end
-- Generates a debug.traceback if called with no arguments
-soft_traceback = function (self, message )
+mymodule.soft_traceback = function (self, message )
if message then
return message
else
@@ -394,17 +394,17 @@ soft_traceback = function (self, message )
end
-- The exception hander of last resort
-exception_handler = function (self, message )
+mymodule.exception_handler = function (self, message )
self.logevent ("The following unhandled application error occured:\n\n")
if (type(message) == "table" ) then
if (message.type == "dispatch") then
- logevent ('controller: "' .. message.controller .. '" does not have a "' .. message.action .. '" action.')
+ self.logevent ('controller: "' .. message.controller .. '" does not have a "' .. message.action .. '" action.')
else
- logevent ("An error of type: '" .. (tostring(message.type) or "nil") .. "' was raised." )
+ self.logevent ("An error of type: '" .. (tostring(message.type) or "nil") .. "' was raised." )
end
else
- logevent (tostring(message))
+ self.logevent (tostring(message))
end
-- Pass the exception to the calling function
@@ -413,7 +413,7 @@ end
-- create a Configuration Framework Entity (cfe)
-- returns a table with at least "value", "type", and "label"
-cfe = function ( optiontable )
+mymodule.cfe = function ( optiontable )
optiontable = optiontable or {}
me = { value="",
type="text",
@@ -423,26 +423,26 @@ cfe = function ( optiontable )
end
return me
end
-_G.cfe = cfe
+_G.cfe = mymodule.cfe
-logevent = function ( message )
+mymodule.logevent = function ( message )
subprocess.call({"logger", "ACF: " .. (message or "")})
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
value.errtxt = nil
if value.type == "group" then
- handle_clientdata(value, clientdata[name])
+ mymodule.handle_clientdata(value, clientdata[name])
else
value.value = clientdata[name] or value.value
end
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
@@ -460,3 +460,5 @@ handle_form = function(self, getFunction, setFunction, clientdata, option, label
return form
end
+
+return mymodule