summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach LeBar <zach@zachlebar.com>2012-02-28 18:47:59 +0000
committerZach LeBar <zach@zachlebar.com>2012-02-28 18:47:59 +0000
commite5e9fc6fe1bb44cde346a6ae7c01ac98ec4c0ddf (patch)
tree6a9e4717fca0532c371cfe95eba0b15adae1192f
parent774acc0d56664daa4074690c0b5158a8b4f3ec68 (diff)
downloadacf-freeswitch-vmail-e5e9fc6fe1bb44cde346a6ae7c01ac98ec4c0ddf.tar.bz2
acf-freeswitch-vmail-e5e9fc6fe1bb44cde346a6ae7c01ac98ec4c0ddf.tar.xz
Change vmail-controller.lua to use new handle_form() functions found in acf_www-controller.lua instead of the controllerfunctions.lua version and also instead of redirect_to_referrer(). Made corresponding changes to vmail-model.lua to make everything work.HEADmaster
-rw-r--r--vmail-controller.lua52
-rw-r--r--vmail-listmessages-html.lsp6
-rw-r--r--vmail-model.lua213
3 files changed, 172 insertions, 99 deletions
diff --git a/vmail-controller.lua b/vmail-controller.lua
index d087833..9a883de 100644
--- a/vmail-controller.lua
+++ b/vmail-controller.lua
@@ -1,7 +1,5 @@
module (..., package.seeall)
-require("controllerfunctions")
-
default_action = "listmessages"
listfolders = function( self )
@@ -17,7 +15,7 @@ editusers = function( self )
end
deleteuser = function( self )
- return controllerfunctions.handle_form(self, self.model.get_delete_user, self.model.set_delete_user, self.clientdata, "Delete", "Delete User", "User Deleted")
+ 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 )
@@ -39,47 +37,67 @@ downloadmymessage = function( self )
end
deletemessage = function( self )
- return self:redirect_to_referrer(self.model.delete_message(self.clientdata.message))
+ 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 )
- return self:redirect_to_referrer(self.model.delete_message(self.clientdata.message, self.sessiondata.userinfo.userid))
+ self.clientdata.username = nil
+ if self.sessiondata.userinfo then
+ self.clientdata.username = self.sessiondata.userinfo.userid
+ end
+ 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 )
- return self:redirect_to_referrer(self.model.forward_message(self.clientdata.message, self.clientdata.newuser))
+ 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 )
- return self:redirect_to_referrer(self.model.forward_message(self.clientdata.message, self.clientdata.newuser, self.sessiondata.userinfo.userid))
+ self.clientdata.username = nil
+ if self.sessiondata.userinfo then
+ self.clientdata.username = self.sessiondata.userinfo.userid
+ end
+ 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 )
- return self:redirect_to_referrer(self.model.email_message(self.clientdata.message, self.clientdata.address))
+ return self.handle_form(self, self.model.get_email_message, self.model.email_message, self.clientdata, "Email", "Email Message", "Message Emailed")
end
emailmymessage = function( self )
- return self:redirect_to_referrer(self.model.email_message(self.clientdata.message, self.clientdata.address, self.sessiondata.userinfo.userid))
+ self.clientdata.username = nil
+ if self.sessiondata.userinfo then
+ self.clientdata.username = self.sessiondata.userinfo.userid
+ end
+ return self.handle_form(self, self.model.get_email_message, self.model.email_message, self.clientdata, "Email", "Email Message", "Message Emailed")
end
movemessage = function( self )
- return self:redirect_to_referrer(self.model.move_message(self.clientdata.message, self.clientdata.newfolder))
+ return self.handle_form(self, self.model.get_move_message, self.model.move_message, self.clientdata)
end
movemymessage = function( self )
- return self:redirect_to_referrer(self.model.move_message(self.clientdata.message, self.clientdata.newfolder, self.sessiondata.userinfo.userid))
+ self.clientdata.username = nil
+ if self.sessiondata.userinfo then
+ self.clientdata.username = self.sessiondata.userinfo.userid
+ end
+ return self.handle_form(self, self.model.get_move_message, self.model.move_message, self.clientdata)
end
callbackmessage = function( self )
- return self:redirect_to_referrer(self.model.callback_message(self.clientdata.message, self.clientdata.extension))
+ return self.handle_form(self, self.model.get_callback_message, self.model.callback_message, self.clientdata)
end
callbackmymessage = function( self )
- return self:redirect_to_referrer(self.model.callback_message(self.clientdata.message, self.clientdata.extension, self.sessiondata.userinfo.userid))
+ self.clientdata.username = nil
+ if self.sessiondata.userinfo then
+ self.clientdata.username = self.sessiondata.userinfo.userid
+ end
+ return self.handle_form(self, self.model.get_callback_message, self.model.callback_message, self.clientdata)
end
editusersettings = function( self )
- return controllerfunctions.handle_form(self, self.model.get_usersettings, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
+ return self.handle_form(self, self.model.get_usersettings, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
end
editmyusersettings = function( self )
@@ -87,11 +105,11 @@ editmyusersettings = function( self )
if self.sessiondata.userinfo then
self.clientdata.username = self.sessiondata.userinfo.userid
end
- return controllerfunctions.handle_form(self, self.model.get_usersettings, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
+ return self.handle_form(self, self.model.get_usersettings, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
end
createuser = function( self )
- return controllerfunctions.handle_form(self, self.model.get_usersettings, self.model.create_usersettings, self.clientdata, "Create", "Create User", "User Created")
+ return self.handle_form(self, self.model.get_usersettings, self.model.create_usersettings, self.clientdata, "Create", "Create User", "User Created")
end
processdialplanxml = function( self )
@@ -105,5 +123,5 @@ processdirectoryxml = function( self )
end
editconfig = function( self )
- return controllerfunctions.handle_form(self, self.model.get_config, self.model.update_config, self.clientdata, "Save", "Update Config", "Config Saved")
+ return self.handle_form(self, self.model.get_config, self.model.update_config, self.clientdata, "Save", "Update Config", "Config Saved")
end
diff --git a/vmail-listmessages-html.lsp b/vmail-listmessages-html.lsp
index 9ed9b56..23e6379 100644
--- a/vmail-listmessages-html.lsp
+++ b/vmail-listmessages-html.lsp
@@ -217,7 +217,7 @@ end
" method="POST">
<input class="hidden" type="hidden" name="redir" value="<%= html.html_escape(page_info.orig_action) %>" >
<input class="hidden" type="hidden" name="message" value="" >
- <input class="submit" type="submit" value="Delete">
+ <input class="submit" type="submit" name="submit" value="Delete">
</form>
<% end %>
<% if viewlibrary.check_permission("forwardmessage") or viewlibrary.check_permission("forwardmymessage") then %>
@@ -226,7 +226,7 @@ end
" method="POST">
<input class="hidden" type="hidden" name="redir" value="<%= html.html_escape(page_info.orig_action) %>" >
<input class="hidden" type="hidden" name="message" value="" >
- <input class="submit" type="submit" value="Forward">
+ <input class="submit" type="submit" name="submit" value="Forward">
<select name="newuser" style="width:auto;"><%= (useroptions or "") %></select>
</form>
<% end %>
@@ -236,7 +236,7 @@ end
" method="POST">
<input class="hidden" type="hidden" name="redir" value="<%= html.html_escape(page_info.orig_action) %>" >
<input class="hidden" type="hidden" name="message" value="" >
- <input class="submit" type="submit" value="E-mail">
+ <input class="submit" type="submit" name="submit" value="E-mail">
<input class="text" type="text" name="address" value="" style="width:auto;">
</form>
<% end %>
diff --git a/vmail-model.lua b/vmail-model.lua
index 0148916..683aa77 100644
--- a/vmail-model.lua
+++ b/vmail-model.lua
@@ -43,7 +43,7 @@ local table_creation_scripts = {
"INSERT INTO voicemail_params VALUES(null, 'vm-password-confirm', 'password', 'Enter again to confirm', '', '', '5')",
"INSERT INTO voicemail_params VALUES(null, 'vm-mailto', 'text', 'Email Address', 'Email a notification, including audio file if enabled', '', '6')",
"INSERT INTO voicemail_params VALUES(null, 'vm-email-all-messages', 'boolean', 'Email Enable', '', 'false', '7')",
- "INSERT INTO voicemail_params VALUES(null, 'vm-attach-file', 'boolean', 'Attach voicemail to email', 'Option to attach audio file to email', 'false', '8')",
+ "INSERT INTO voicemail_params VALUES(null, 'vm-attach-file', 'boolean', 'Attach voicemail to email', 'Option to attach audio file to emaie', 'false', '8')",
"INSERT INTO voicemail_params VALUES(null, 'vm-keep-local-after-email', 'boolean', 'Keep voicemail', 'When disabled, the message will be deleted from the voicemailbox after any notification email is sent (whether or not email is enabled). This allows receiving voicemail via email alone, rather than having the voicemail available from the Web interface or by telephone. CAUTION: \"Email Address\" must be valid and \"Email Enable\" and \"Attach voicemail to email\" must be enabled, OTHERWISE YOUR MESSAGES WILL BE LOST FOREVER.', 'true', '9')",
"INSERT INTO voicemail_params VALUES(null, 'vm-notify-mailto', 'text', 'Pager Email Address', 'Email a short notification', '', '10')",
"INSERT INTO voicemail_params VALUES(null, 'vm-notify-email-all-messages', 'boolean', 'Pager Email Enable', '', 'false', '11')",
@@ -362,6 +362,39 @@ local function validateconfig(newconfig)
return success, newconfig
end
+local delete_message = function(messages, username)
+ local retval = ""
+
+ local sql = "SELECT * FROM voicemail_msgs"
+ sql = sql .. generatewhereclause(username, messages)
+ local tmp = getselectresponse(sql)
+ if #tmp == #messages then
+ sql = "DELETE FROM voicemail_msgs" .. generatewhereclause(username, messages)
+ runsqlcommand(sql)
+ for i,t in ipairs(tmp) do
+ os.remove(t.file_path)
+ end
+ if #messages == 1 then
+ retval = "Deleted message"
+ else
+ retval = "Deleted "..#messages.." messages"
+ end
+ if username then
+ voicemail_update(username, config.domain)
+ else
+ for i,m in ipairs(tmp) do
+ voicemail_update(m.username, m.domain)
+ end
+ end
+ end
+
+ if not res and err then
+ return false, err
+ end
+
+ return retval
+end
+
local delete_user = function(username)
local users = listusers(username)
if #users == 0 then
@@ -460,50 +493,51 @@ get_message = function(message, username)
return retval
end
-delete_message = function(message, username)
- local retval = cfe({ label="Delete message result", errtxt="Failed to delete message - message not found" })
- local messages = format.string_to_table(message, "%s*,%s*")
- local res, err = pcall(function()
+get_delete_message = function(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(deleterequest)
+ if not deleterequest.value.message.value or deleterequest.value.message.value == "" then
+ deleterequest.errtxt = "Failed to delete message - message not found"
+ return deleterequest
+ end
+ local messages = format.string_to_table(deleterequest.value.message.value, "%s*,%s*")
+
+ local res, err = pcall(function()
local connected = databaseconnect()
- local sql = "SELECT * FROM voicemail_msgs"
- sql = sql .. generatewhereclause(username, messages)
- local tmp = getselectresponse(sql)
- if #tmp == #messages then
- sql = "DELETE FROM voicemail_msgs" .. generatewhereclause(username, messages)
- runsqlcommand(sql)
- for i,t in ipairs(tmp) do
- os.remove(t.file_path)
- end
- if #messages == 1 then
- retval.value = "Deleted message"
- else
- retval.value = "Deleted "..#messages.." messages"
- end
- retval.errtxt = nil
- if username then
- voicemail_update(username, config.domain)
- else
- for i,m in ipairs(tmp) do
- voicemail_update(m.username, m.domain)
- end
- end
- end
+ res, err = delete_message(messages, deleterequest.value.username.value)
if connected then databasedisconnect() end
end)
+
+ if res then
+ deleterequest.descr = res
+ end
+
if not res and err then
- retval.errtxt = err
+ deleterequest.errtxt = err
end
+
+ return deleterequest
+end
- return retval
+get_forward_message = function(clientdata)
+ local result = {}
+ result.message = cfe({ value=clientdata.message or "", label="Message" })
+ result.username = cfe({ value=clientdata.username or "", label="User Name" })
+ result.newuser = cfe({ value=clientdata.newuser or "", label="New User" })
+ return cfe({ type="group", value=result, label="Forward Message" })
end
-forward_message = function(message, newuser, username)
- local retval = cfe({ label="Forward message result" })
- local messages = format.string_to_table(message, "%s*,%s*")
+forward_message = function(forwardrequest)
+ local messages = format.string_to_table(forwardrequest.value.message.value, "%s*,%s*")
local res, err = pcall(function()
local connected = databaseconnect()
-- Check if message exists
- local sql = "SELECT * FROM voicemail_msgs" .. generatewhereclause(username, messages)
+ local sql = "SELECT * FROM voicemail_msgs" .. generatewhereclause(forwardrequest.value.username.value, messages)
local mess = getselectresponse(sql)
if #mess == #messages then
-- Check if newuser exists
@@ -511,38 +545,45 @@ forward_message = function(message, newuser, username)
for i,m in ipairs(mess) do
-- Forward message using mod_voicemail API
-- doesn't seem like there's any way to tell whether or not it worked
- voicemail_inject(newuser, config.domain, m.file_path, m.cid_number, m.cid_name)
+ voicemail_inject(forwardrequest.value.newuser.value, config.domain, m.file_path, m.cid_number, m.cid_name)
end
if #mess == 1 then
- retval.value = "Forwarded message"
+ forwardrequest.descr = "Forwarded message"
else
- retval.value = "Forwarded "..#mess.." messages"
+ forwardrequest.descr = "Forwarded "..#mess.." messages"
end
else
- retval.errtxt = "Failed to forward message - invalid user"
+ forwardrequest.errtxt = "Failed to forward message - invalid user"
end
else
- retval.errtxt = "Failed to forward message - message not found"
+ forwardrequest.errtxt = "Failed to forward message - message not found"
end
if connected then databasedisconnect() end
end)
if not res and err then
- retval.errtxt = err
+ forwardrequest.errtxt = err
end
- return retval
+ return forwardrequest
+end
+
+get_email_message = function(clientdata)
+ local result = {}
+ result.message = cfe({ value=clientdata.message or "", label="Message" })
+ result.address = cfe({ value=clientdata.newuser or "", label="Address" })
+ result.username = cfe({ value=clientdata.username or "", label="User Name" })
+ return cfe({ type="group", value=result, label="Email Message" })
end
-email_message = function(message, address, username)
- local retval = cfe({ label="E-mail message result" })
- local messages = format.string_to_table(message, "%s*,%s*")
- if address == "" or string.find(address, "%s") or not string.find(address, "@") then
- retval.errtxt = "Failed to e-mail message - invalid address"
+email_message = function(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"
else
local res, err = pcall(function()
local connected = databaseconnect()
-- Check if message exists
- local sql = "SELECT * FROM voicemail_msgs" .. generatewhereclause(username, messages)
+ local sql = "SELECT * FROM voicemail_msgs" .. generatewhereclause(emailrequest.value.username.value, messages)
local mess = getselectresponse(sql)
if #mess == #messages then
-- Create a temporary user and settings
@@ -552,7 +593,7 @@ email_message = function(message, address, username)
end
local settings = get_usersettings(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 = address
+ settings.value["vm-mailto"].value = emailrequest.value.address.value
settings.value["vm-email-all-messages"].value = true
settings.value["vm-attach-file"].value = true
settings.value["vm-keep-local-after-email"].value = false
@@ -573,95 +614,109 @@ email_message = function(message, address, username)
-- Now, delete the temporary user
delete_user(newuser)
else
- retval.errtxt = "Failed to e-mail message - "..settings.errtxt
+ emailrequest.errtxt = "Failed to e-mail message - "..settings.errtxt
end
else
- retval.errtxt = "Failed to e-mail message - unsupported"
+ emailrequest.errtxt = "Failed to e-mail message - unsupported"
end
else
- retval.errtxt = "Failed to e-mail message - message not found"
+ emailrequest.errtxt = "Failed to e-mail message - message not found"
end
if connected then databasedisconnect() end
end)
if not res and err then
- retval.errtxt = err
+ emailrequest.errtxt = err
end
end
- return retval
+ return emailrequest
+end
+
+get_move_message = function(clientdata)
+ local result = {}
+ result.message = cfe({ value=clientdata.message or "", label="Message" })
+ result.newfolder = cfe({ value=clientdata.newfolder or "", label="New Folder" })
+ result.username = cfe({ value=clientdata.username or "", label="User Name" })
+ return cfe({ type="group", value=result, label="Move Message" })
end
-move_message = function(message, newfolder, username)
- local retval = cfe({ label="Move message result" })
- local messages = format.string_to_table(message, "%s*,%s*")
+move_message = function(moverequest)
+ local messages = format.string_to_table(moverequest.value.message.value, "%s*,%s*")
local res, err = pcall(function()
local connected = databaseconnect()
-- Check if message exists
- local sql = "SELECT * FROM voicemail_msgs" .. generatewhereclause(username, messages)
+ local sql = "SELECT * FROM voicemail_msgs" .. generatewhereclause(moverequest.value.username.value, messages)
local mess = getselectresponse(sql)
if #mess == #messages then
-- Check if newfolder exists
if validfolder(newfolder) then
for i,m in ipairs(mess) do
- local sql = "UPDATE voicemail_msgs SET in_folder='"..newfolder.."'" .. generatewhereclause(username, messages)
+ local sql = "UPDATE voicemail_msgs SET in_folder='"..moverequest.value.newfolder.value.."'" .. generatewhereclause(moverequest.value.username.value, messages)
runsqlcommand(sql)
end
if #mess == 1 then
- retval.value = "Moved message"
+ moverequest.descr = "Moved message"
else
- retval.value = "Moved "..#mess.." messages"
+ moverequest.value = "Moved "..#mess.." messages"
end
- if username then
- voicemail_update(username, config.domain)
+ if moverequest.value.username.value then
+ voicemail_update(moverequest.value.username.value, config.domain)
else
for i,m in ipairs(mess) do
voicemail_update(m.username, m.domain)
end
end
else
- retval.errtxt = "Failed to move message - invalid folder"
+ moverequest.errtxt = "Failed to move message - invalid folder"
end
else
- retval.errtxt = "Failed to move message - message not found"
+ moverequest.errtxt = "Failed to move message - message not found"
end
if connected then databasedisconnect() end
end)
if not res and err then
- retval.errtxt = err
+ moverequest.errtxt = err
end
- return retval
+ return moverequest
end
-callback_message = function(message, extension, username)
- local retval = cfe({ label="Callback message result" })
- if string.find(message, ",") then
- retval.errtxt = "Failed to callback message - can only callback one message at a time"
- elseif extension == "" or string.find(extension, "[%s@]") then
- retval.errtxt = "Failed to callback message - invalid extension"
+get_callback_message = function(clientdata)
+ local result = {}
+ result.message = cfe({ value=clientdata.message or "", label="Message" })
+ result.extension = cfe({ value=clientdata.extension or "", label="Extension" })
+ result.username = cfe({ value=clientdata.username or "", label="User Name" })
+ return cfe({ type="group", value=result, label="Callback Message" })
+end
+
+callback_message = function(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
+ callbackrequest.errtxt = "Failed to callback message - invalid extension"
else
local res, err = pcall(function()
local connected = databaseconnect()
-- Check if message exists
- local sql = "SELECT * FROM voicemail_msgs" .. generatewhereclause(username, message)
+ local sql = "SELECT * FROM voicemail_msgs" .. generatewhereclause(callbackrequest.value.username.value, callbackrequest.value.message.value)
local mess = getselectresponse(sql)
if #mess == 1 then
-- Mark the message as read
- voicemail_read(mess[1].username, config.domain, message)
+ voicemail_read(mess[1].username, config.domain, callbackrequest.value.message.value)
-- Initiate the call to the extension
- voicemail_callback(extension, mess[1].file_path, mess[1].username)
- retval.value = "Initiated callback"
+ voicemail_callback(callbackrequest.value.extension.value, mess[1].file_path, mess[1].username)
+ callbackrequest.descr = "Initiated callback"
else
- retval.errtxt = "Failed to callback message - message not found"
+ callbackrequest.errtxt = "Failed to callback message - message not found"
end
if connected then databasedisconnect() end
end)
if not res and err then
- retval.errtxt = err
+ callbackrequest.errtxt = err
end
end
- return retval
+ return callbackrequest
end
list_folders = function()