Commit 52313309 authored by Ted Trask's avatar Ted Trask

Remove all calls to 'module' in preparation for move to Lua 5.2

Use mymodule parameter for module definition.
This was also helpful in revealing places where the code relied on the global environment.
parent 42aaaede
-- Copy of authenticator-plaintext, plus added authentication from voicemail DB
module (..., package.seeall)
local mymodule = {}
authenticator = require("authenticator")
md5 = require("md5")
list_fields = function(self, tabl)
mymodule.list_fields = function(self, tabl)
return nil
end
read_field = function(self, tabl, field)
mymodule.read_field = function(self, tabl, field)
return nil
end
delete_field = function(self, tabl, field)
mymodule.delete_field = function(self, tabl, field)
return false
end
write_entry = function(self, tabl, field, id, entry)
mymodule.write_entry = function(self, tabl, field, id, entry)
return false
end
read_entry = function(self, tabl, field, id)
mymodule.read_entry = function(self, tabl, field, id)
local result
if tabl == authenticator.usertable and field == "" then
-- authenticator is reading one user
......@@ -33,6 +34,8 @@ read_entry = function(self, tabl, field, id)
return result
end
delete_entry = function (self, tabl, field, id)
mymodule.delete_entry = function (self, tabl, field, id)
return false
end
return mymodule
module (..., package.seeall)
local mymodule = {}
default_action = "listmessages"
mymodule.default_action = "listmessages"
listfolders = function( self )
mymodule.listfolders = function( self )
return self.model.list_folders()
end
listusers = function( self )
mymodule.listusers = function( self )
return self.model.list_users()
end
editusers = function( self )
mymodule.editusers = function( self )
return self.model.list_users()
end
deleteuser = function( self )
mymodule.deleteuser = function( self )
return self.handle_form(self, self.model.get_delete_user, self.model.set_delete_user, self.clientdata, "Delete", "Delete User", "User Deleted")
end
listmessages = function( self )
mymodule.listmessages = function( self )
return self.model.list_messages(self.clientdata.username)
end
listmymessages = function( self )
mymodule.listmymessages = function( self )
return self.model.list_messages(self.sessiondata.userinfo.userid)
end
downloadmessage = function( self )
mymodule.downloadmessage = function( self )
return self.model.get_message(self.clientdata.message)
end
downloadmymessage = function( self )
mymodule.downloadmymessage = function( self )
return self.model.get_message(self.clientdata.message, self.sessiondata.userinfo.userid)
end
deletemessage = function( self )
mymodule.deletemessage = function( self )
return self.handle_form(self, self.model.get_delete_message, self.model.set_delete_message, self.clientdata, "Delete", "Delete Message", "Message Deleted")
end
deletemymessage = function( self )
mymodule.deletemymessage = function( self )
self.clientdata.username = nil
if self.sessiondata.userinfo then
self.clientdata.username = self.sessiondata.userinfo.userid
......@@ -46,11 +46,11 @@ deletemymessage = function( self )
return self.handle_form(self, self.model.get_delete_message, self.model.set_delete_message, self.clientdata, "Delete", "Delete Message", "Message Deleted")
end
forwardmessage = function( self )
mymodule.forwardmessage = function( self )
return self.handle_form(self, self.model.get_forward_message, self.model.forward_message, self.clientdata, "Forward", "Forward Message", "Message Forwarded")
end
forwardmymessage = function( self )
mymodule.forwardmymessage = function( self )
self.clientdata.username = nil
if self.sessiondata.userinfo then
self.clientdata.username = self.sessiondata.userinfo.userid
......@@ -58,11 +58,11 @@ forwardmymessage = function( self )
return self.handle_form(self, self.model.get_forward_message, self.model.forward_message, self.clientdata, "Forward", "Forward Message", "Message Forwarded")
end
emailmessage = function( self )
mymodule.emailmessage = function( self )
return self.handle_form(self, self.model.get_email_message, self.model.email_message, self.clientdata, "Email", "Email Message")
end
emailmymessage = function( self )
mymodule.emailmymessage = function( self )
self.clientdata.username = nil
if self.sessiondata.userinfo then
self.clientdata.username = self.sessiondata.userinfo.userid
......@@ -70,11 +70,11 @@ emailmymessage = function( self )
return self.handle_form(self, self.model.get_email_message, self.model.email_message, self.clientdata, "Email", "Email Message")
end
movemessage = function( self )
mymodule.movemessage = function( self )
return self.handle_form(self, self.model.get_move_message, self.model.move_message, self.clientdata, "Move")
end
movemymessage = function( self )
mymodule.movemymessage = function( self )
self.clientdata.username = nil
if self.sessiondata.userinfo then
self.clientdata.username = self.sessiondata.userinfo.userid
......@@ -82,11 +82,11 @@ movemymessage = function( self )
return self.handle_form(self, self.model.get_move_message, self.model.move_message, self.clientdata, "Move")
end
callbackmessage = function( self )
mymodule.callbackmessage = function( self )
return self.handle_form(self, self.model.get_callback_message, self.model.callback_message, self.clientdata, "Callme")
end
callbackmymessage = function( self )
mymodule.callbackmymessage = function( self )
self.clientdata.username = nil
if self.sessiondata.userinfo then
self.clientdata.username = self.sessiondata.userinfo.userid
......@@ -94,11 +94,11 @@ callbackmymessage = function( self )
return self.handle_form(self, self.model.get_callback_message, self.model.callback_message, self.clientdata, "Callme")
end
editusersettings = function( self )
mymodule.editusersettings = function( self )
return self.handle_form(self, self.model.get_usersettings, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
end
editmyusersettings = function( self )
mymodule.editmyusersettings = function( self )
self.clientdata.username = nil
if self.sessiondata.userinfo then
self.clientdata.username = self.sessiondata.userinfo.userid
......@@ -106,20 +106,22 @@ editmyusersettings = function( self )
return self.handle_form(self, self.model.get_usersettings, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
end
createuser = function( self )
mymodule.createuser = function( self )
return self.handle_form(self, self.model.get_usersettings, self.model.create_usersettings, self.clientdata, "Create", "Create User", "User Created")
end
processdialplanxml = function( self )
mymodule.processdialplanxml = function( self )
self.conf.viewtype = "xml"
return self.model.process_dialplan_xml_request(self.clientdata)
end
processdirectoryxml = function( self )
mymodule.processdirectoryxml = function( self )
self.conf.viewtype = "xml"
return self.model.process_directory_xml_request(self.clientdata)
end
editconfig = function( self )
mymodule.editconfig = function( self )
return self.handle_form(self, self.model.get_config, self.model.update_config, self.clientdata, "Save", "Update Config", "Config Saved")
end
return mymodule
module (..., package.seeall)
local mymodule = {}
-- Load libraries
modelfunctions = require("modelfunctions")
......@@ -300,7 +300,7 @@ local delete_user = function(username)
return false, "User does not exist"
else
-- Delete all of the user's voicemails
local messages = list_messages(username)
local messages = mymodule.list_messages(username)
if #messages.value then
for i,m in ipairs(messages.value) do
delete_message(m.uuid)
......@@ -325,7 +325,7 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
get_config = function()
mymodule.get_config = function()
local result = {}
result.domain = cfe({ value=config.domain, label="Domain" })
result.database = cfe({ value=config.database, label="Database" })
......@@ -336,7 +336,7 @@ get_config = function()
return cfe({ type="group", value=result, label="Voicemail Config" })
end
update_config = function(self, newconfig)
mymodule.update_config = function(self, newconfig)
local success = validateconfig(newconfig)
if success then
for name,val in pairs(newconfig.value) do
......@@ -352,7 +352,7 @@ update_config = function(self, newconfig)
return newconfig
end
list_messages = function(username)
mymodule.list_messages = function(username)
local retval = {}
local errtxt
local res, err = pcall(function()
......@@ -369,7 +369,7 @@ list_messages = function(username)
return cfe({ type="structure", value=retval, label="List of Messages", errtxt=errtxt })
end
get_message = function(message, username)
mymodule.get_message = function(message, username)
local retval = cfe({ type="raw", label="error", option="audio/x-wav" })
local res, err = pcall(function()
local connected = vmaildb.databaseconnect()
......@@ -392,14 +392,14 @@ get_message = function(message, username)
return retval
end
get_delete_message = function(self, clientdata)
mymodule.get_delete_message = function(self, clientdata)
local result = {}
result.message = cfe({ value=clientdata.message or "", label="Message" })
result.username = cfe({ value=clientdata.username or "", label="User Name" })
return cfe({ type="group", value=result, label="Delete Message" })
end
set_delete_message = function(self, deleterequest)
mymodule.set_delete_message = function(self, deleterequest)
if not deleterequest.value.message.value or deleterequest.value.message.value == "" then
deleterequest.errtxt = "Failed to delete message - message not found"
return deleterequest
......@@ -423,7 +423,7 @@ set_delete_message = function(self, deleterequest)
return deleterequest
end
get_forward_message = function(self, clientdata)
mymodule.get_forward_message = function(self, clientdata)
local result = {}
result.message = cfe({ value=clientdata.message or "", label="Message" })
result.username = cfe({ value=clientdata.username or "", label="User Name" })
......@@ -431,7 +431,7 @@ get_forward_message = function(self, clientdata)
return cfe({ type="group", value=result, label="Forward Message" })
end
forward_message = function(self, forwardrequest)
mymodule.forward_message = function(self, forwardrequest)
local messages = format.string_to_table(forwardrequest.value.message.value, "%s*,%s*")
local res, err = pcall(function()
local connected = vmaildb.databaseconnect()
......@@ -466,7 +466,7 @@ forward_message = function(self, forwardrequest)
return forwardrequest
end
get_email_message = function(self, clientdata)
mymodule.get_email_message = function(self, clientdata)
local result = {}
result.message = cfe({ value=clientdata.message or "", label="Message" })
result.address = cfe({ value=clientdata.newuser or "", label="Address" })
......@@ -474,7 +474,7 @@ get_email_message = function(self, clientdata)
return cfe({ type="group", value=result, label="Email Message" })
end
email_message = function(self, emailrequest)
mymodule.email_message = function(self, emailrequest)
local messages = format.string_to_table(emailrequest.value.message.value, "%s*,%s*")
if emailrequest.value.address.value == "" or string.find(emailrequest.value.address.value, "%s") or not string.find(emailrequest.value.address.value, "@") then
emailrequest.errtxt = "Failed to e-mail message - invalid address"
......@@ -490,7 +490,7 @@ email_message = function(self, emailrequest)
while validuser(newuser) do
newuser = "tempuser"..session.random_hash(128)
end
local settings = get_usersettings(self, {username=newuser})
local settings = mymodule.get_usersettings(self, {username=newuser})
if settings.value["vm-mailto"] and settings.value["vm-email-all-messages"] and settings.value["vm-attach-file"] and settings.value["vm-keep-local-after-email"] then
settings.value["vm-mailto"].value = emailrequest.value.address.value
settings.value["vm-email-all-messages"].value = true
......@@ -498,7 +498,7 @@ email_message = function(self, emailrequest)
settings.value["vm-keep-local-after-email"].value = false
if settings.value["vm-password"] then settings.value["vm-password"].value = "1234" end
if settings.value["vm-password-confirm"] then settings.value["vm-password-confirm"].value = "1234" end
settings = create_usersettings(self, settings)
settings = mymodule.create_usersettings(self, settings)
if not settings.errtxt then
for i,m in ipairs(mess) do
-- E-mail message using mod_voicemail API
......@@ -531,7 +531,7 @@ email_message = function(self, emailrequest)
return emailrequest
end
get_move_message = function(self, clientdata)
mymodule.get_move_message = function(self, clientdata)
local result = {}
result.message = cfe({ value=clientdata.message or "", label="Message" })
result.newfolder = cfe({ value=clientdata.newfolder or "", label="New Folder" })
......@@ -539,7 +539,7 @@ get_move_message = function(self, clientdata)
return cfe({ type="group", value=result, label="Move Message" })
end
move_message = function(self, moverequest)
mymodule.move_message = function(self, moverequest)
local messages = format.string_to_table(moverequest.value.message.value, "%s*,%s*")
local res, err = pcall(function()
local connected = vmaildb.databaseconnect()
......@@ -580,7 +580,7 @@ move_message = function(self, moverequest)
return moverequest
end
get_callback_message = function(self, clientdata)
mymodule.get_callback_message = function(self, clientdata)
local result = {}
result.message = cfe({ value=clientdata.message or "", label="Message" })
result.extension = cfe({ value=clientdata.extension or "", label="Extension" })
......@@ -588,7 +588,7 @@ get_callback_message = function(self, clientdata)
return cfe({ type="group", value=result, label="Callback Message" })
end
callback_message = function(self, callbackrequest)
mymodule.callback_message = function(self, callbackrequest)
if string.find(callbackrequest.value.message.value, ",") then
callbackrequest.errtxt = "Failed to callback message - can only callback one message at a time"
elseif callbackrequest.value.extension.value == "" or string.find(callbackrequest.value.extension.value, "[%s@]") then
......@@ -618,7 +618,7 @@ callback_message = function(self, callbackrequest)
return callbackrequest
end
list_folders = function()
mymodule.list_folders = function()
local errtxt
local folders = {}
local res, err = pcall(function()
......@@ -633,7 +633,7 @@ list_folders = function()
return cfe({ type="structure", value=folders, label="Voicemail Folders", errtxt=errtxt })
end
list_passwords = function(username)
mymodule.list_passwords = function(username)
local errtxt
local users = {}
local res, err = pcall(function()
......@@ -649,7 +649,7 @@ list_passwords = function(username)
return cfe({ type="structure", value=users, label="Voicemail User Passwords", errtxt=errtxt })
end
list_users = function()
mymodule.list_users = function()
local errtxt
local users = {}
local res, err = pcall(function()
......@@ -666,13 +666,13 @@ list_users = function()
return cfe({ type="structure", value=users, label="Voicemail Users", errtxt=errtxt })
end
get_delete_user = function(self, clientdata)
mymodule.get_delete_user = function(self, clientdata)
local result = {}
result.username = cfe({ value=clientdata.username or "", label="User Name" })
return cfe({ type="group", value=result, label="Delete User" })
end
set_delete_user = function(self, deleterequest)
mymodule.set_delete_user = function(self, deleterequest)
local result = ""
local success = true
if not deleterequest.value.username.value == "" then
......@@ -695,7 +695,7 @@ set_delete_user = function(self, deleterequest)
return deleterequest
end
get_usersettings = function(self, clientdata)
mymodule.get_usersettings = function(self, clientdata)
local retval = {}
local errtxt
local res, err = pcall(function()
......@@ -711,11 +711,11 @@ get_usersettings = function(self, clientdata)
return cfe({ type="group", value=retval, label="Voicemail User Settings", errtxt=errtxt })
end
create_usersettings = function(self, usersettings, action)
return update_usersettings(self, usersettings, action, true)
mymodule.create_usersettings = function(self, usersettings, action)
return mymodule.update_usersettings(self, usersettings, action, true)
end
update_usersettings = function(self, usersettings, action, create)
mymodule.update_usersettings = function(self, usersettings, action, create)
local success = true
local errtxt
-- Validate the settings
......@@ -761,7 +761,7 @@ update_usersettings = function(self, usersettings, action, create)
return usersettings
end
process_directory_xml_request = function(input)
mymodule.process_directory_xml_request = function(input)
local output = {}
local errtxt
local res, err = pcall(function()
......@@ -781,7 +781,7 @@ process_directory_xml_request = function(input)
return cfe({ type="group", value=output, label="Directory Data", errtxt=errtxt })
end
process_dialplan_xml_request = function(input)
mymodule.process_dialplan_xml_request = function(input)
local output = {}
local errtxt
local res, err = pcall(function()
......@@ -799,3 +799,5 @@ process_dialplan_xml_request = function(input)
end
return cfe({ type="group", value=output, label="Dialplan Data", errtxt=errtxt })
end
return mymodule
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment