Merge branch 'master' of https://github.com/fusionpbx/fusionpbx
This commit is contained in:
commit
dc873eee43
|
|
@ -4,7 +4,6 @@ require "resources.functions.sleep"
|
||||||
local log = require "resources.functions.log".next_fax_task
|
local log = require "resources.functions.log".next_fax_task
|
||||||
local Tasks = require "app.fax.resources.scripts.queue.tasks"
|
local Tasks = require "app.fax.resources.scripts.queue.tasks"
|
||||||
local Esl = require "resources.functions.esl"
|
local Esl = require "resources.functions.esl"
|
||||||
local send_mail = require "resources.functions.send_mail"
|
|
||||||
|
|
||||||
local FAX_OPTIONS = {
|
local FAX_OPTIONS = {
|
||||||
"fax_use_ecm=false,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=default";
|
"fax_use_ecm=false,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=default";
|
||||||
|
|
@ -15,22 +14,16 @@ local FAX_OPTIONS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local function task_send_mail(task)
|
local function task_send_mail(task)
|
||||||
local mail_x_headers = {
|
|
||||||
["X-FusionPBX-Domain-UUID"] = task.domain_uuid;
|
|
||||||
["X-FusionPBX-Domain-Name"] = task.domain_name;
|
|
||||||
["X-FusionPBX-Email-Type"] = 'email2fax';
|
|
||||||
}
|
|
||||||
local number_dialed = task.uri:match("/([^/]-)%s*$")
|
local number_dialed = task.uri:match("/([^/]-)%s*$")
|
||||||
if task.reply_address and #task.reply_address > 0 then
|
|
||||||
send_mail(mail_x_headers, task.reply_address, {
|
Tasks.send_mail_task(task, {
|
||||||
"Fax to: " .. number_dialed .. " FAILED",
|
"Fax to: " .. number_dialed .. " FAILED",
|
||||||
table.concat{
|
table.concat{
|
||||||
"We are sorry the fax failed to go through. ",
|
"We are sorry the fax failed to go through. ",
|
||||||
"It has been attached. Please check the number "..number_dialed..", ",
|
"It has been attached. Please check the number " .. number_dialed .. ", ",
|
||||||
"and if it was correct you might consider emailing it instead.",
|
"and if it was correct you might consider emailing it instead.",
|
||||||
}
|
}}
|
||||||
})
|
)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function next_task()
|
local function next_task()
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@
|
||||||
local send_mail = require "resources.functions.send_mail"
|
local send_mail = require "resources.functions.send_mail"
|
||||||
|
|
||||||
local fax_task_uuid = env:getHeader('fax_task_uuid')
|
local fax_task_uuid = env:getHeader('fax_task_uuid')
|
||||||
|
if not fax_task_uuid then
|
||||||
|
log.warning("No [fax_task_uuid] channel variable")
|
||||||
|
return
|
||||||
|
end
|
||||||
local task = Tasks.select_task(fax_task_uuid)
|
local task = Tasks.select_task(fax_task_uuid)
|
||||||
if not task then
|
if not task then
|
||||||
log.warningf("Can not find fax task: %q", tostring(fax_task_uuid))
|
log.warningf("Can not find fax task: %q", tostring(fax_task_uuid))
|
||||||
|
|
@ -31,7 +35,7 @@
|
||||||
local domain_name = env:getHeader("domain_name") or task.domain_name
|
local domain_name = env:getHeader("domain_name") or task.domain_name
|
||||||
local origination_caller_id_name = env:getHeader("origination_caller_id_name") or '000000000000000'
|
local origination_caller_id_name = env:getHeader("origination_caller_id_name") or '000000000000000'
|
||||||
local origination_caller_id_number = env:getHeader("origination_caller_id_number") or '000000000000000'
|
local origination_caller_id_number = env:getHeader("origination_caller_id_number") or '000000000000000'
|
||||||
local accountcode = env:getHeader("accountcode")
|
local accountcode = env:getHeader("accountcode") or domain_name
|
||||||
local duration = tonumber(env:getHeader("billmsec")) or 0
|
local duration = tonumber(env:getHeader("billmsec")) or 0
|
||||||
local sip_to_user = env:getHeader("sip_to_user")
|
local sip_to_user = env:getHeader("sip_to_user")
|
||||||
local bridge_hangup_cause = env:getHeader("bridge_hangup_cause")
|
local bridge_hangup_cause = env:getHeader("bridge_hangup_cause")
|
||||||
|
|
@ -142,39 +146,29 @@
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
--get the values from the fax file
|
log.debug([[<<< DEBUG >>>
|
||||||
if not (fax_uuid and domain_name) then
|
domain_name = '%s'
|
||||||
local array = split(fax_file, "[\\/]+")
|
domain_uuid = '%s'
|
||||||
domain_name = domain_name or array[#array - 3]
|
task.domain_name = '%s'
|
||||||
local fax_extension = fax_extension or array[#array - 2]
|
task.domain_uuid = '%s'
|
||||||
|
]],
|
||||||
|
tostring(domain_name ),
|
||||||
|
tostring(domain_uuid ),
|
||||||
|
tostring(task.domain_name ),
|
||||||
|
tostring(task.domain_uuid )
|
||||||
|
)
|
||||||
|
|
||||||
if not fax_uuid then
|
assert(fax_uuid, 'no fax server uuid')
|
||||||
local sql = "SELECT fax_uuid FROM v_fax "
|
assert(domain_name, 'no domain name')
|
||||||
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .. "' "
|
assert(domain_uuid, 'no domain uuid')
|
||||||
sql = sql .. "AND fax_extension = '" .. fax_extension .. "' "
|
assert(domain_uuid:lower() == task.domain_uuid:lower(), 'invalid domain uuid')
|
||||||
fax_uuid = dbh:first_value(sql);
|
assert(domain_name:lower() == task.domain_name:lower(), 'invalid domain name')
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--get the domain_uuid using the domain name required for multi-tenant
|
|
||||||
if domain_name and not domain_uuid then
|
|
||||||
local sql = "SELECT domain_uuid FROM v_domains ";
|
|
||||||
sql = sql .. "WHERE domain_name = '" .. domain_name .. "' "
|
|
||||||
domain_uuid = dbh:first_value(sql)
|
|
||||||
end
|
|
||||||
|
|
||||||
assert(domain_name and domain_uuid)
|
|
||||||
|
|
||||||
--settings
|
--settings
|
||||||
local settings = Settings.new(dbh, domain_name, domain_uuid)
|
local settings = Settings.new(dbh, domain_name, domain_uuid)
|
||||||
local keep_local = settings:get('fax', 'keep_local','boolean')
|
local keep_local = settings:get('fax', 'keep_local','boolean')
|
||||||
local storage_type = (keep_local == "false") and "" or settings:get('fax', 'storage_type', 'text')
|
local storage_type = (keep_local == "false") and "" or settings:get('fax', 'storage_type', 'text')
|
||||||
|
|
||||||
--be sure accountcode is not empty
|
|
||||||
if (accountcode == nil) then
|
|
||||||
accountcode = domain_name
|
|
||||||
end
|
|
||||||
|
|
||||||
local function opt(v, default)
|
local function opt(v, default)
|
||||||
if v then return "'" .. v .. "'" end
|
if v then return "'" .. v .. "'" end
|
||||||
return default or 'NULL'
|
return default or 'NULL'
|
||||||
|
|
@ -244,14 +238,6 @@
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
end
|
end
|
||||||
|
|
||||||
--prepare the headers
|
|
||||||
local mail_x_headers = {
|
|
||||||
["X-FusionPBX-Domain-UUID"] = domain_uuid;
|
|
||||||
["X-FusionPBX-Domain-Name"] = domain_name;
|
|
||||||
["X-FusionPBX-Call-UUID"] = uuid;
|
|
||||||
["X-FusionPBX-Email-Type"] = 'email2fax';
|
|
||||||
}
|
|
||||||
|
|
||||||
-- add the fax files
|
-- add the fax files
|
||||||
if fax_success == "1" then
|
if fax_success == "1" then
|
||||||
|
|
||||||
|
|
@ -331,16 +317,13 @@
|
||||||
end
|
end
|
||||||
|
|
||||||
Tasks.remove_task(task)
|
Tasks.remove_task(task)
|
||||||
|
Tasks.send_mail_task(task, {
|
||||||
if task.reply_address and #task.reply_address > 0 then
|
"Fax to: " .. number_dialed .. " SENT",
|
||||||
send_mail(mail_x_headers, task.reply_address, {
|
table.concat{
|
||||||
"Fax to: " .. number_dialed .. " SENT",
|
"We are happy to report the fax was sent successfully.",
|
||||||
table.concat{
|
"It has been attached for your records.",
|
||||||
"We are happy to report the fax was sent successfully.",
|
}}, uuid
|
||||||
"It has been attached for your records.",
|
)
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if fax_success ~= "1" then
|
if fax_success ~= "1" then
|
||||||
|
|
@ -362,16 +345,14 @@
|
||||||
Tasks.wait_task(task, answered, hangup_cause_q850)
|
Tasks.wait_task(task, answered, hangup_cause_q850)
|
||||||
if task.status ~= 0 then
|
if task.status ~= 0 then
|
||||||
Tasks.remove_task(task)
|
Tasks.remove_task(task)
|
||||||
if task.reply_address and #task.reply_address > 0 then
|
Tasks.send_mail_task(task, {
|
||||||
send_mail(mail_x_headers, task.reply_address, {
|
"Fax to: " .. number_dialed .. " FAILED",
|
||||||
"Fax to: " .. number_dialed .. " FAILED",
|
table.concat{
|
||||||
table.concat{
|
"We are sorry the fax failed to go through. ",
|
||||||
"We are sorry the fax failed to go through. ",
|
"It has been attached. Please check the number "..number_dialed..", ",
|
||||||
"It has been attached. Please check the number "..number_dialed..", ",
|
"and if it was correct you might consider emailing it instead.",
|
||||||
"and if it was correct you might consider emailing it instead.",
|
}}, uuid
|
||||||
}
|
)
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
local Database = require "resources.functions.database"
|
local Database = require "resources.functions.database"
|
||||||
local Settings = require "resources.functions.lazy_settings"
|
local Settings = require "resources.functions.lazy_settings"
|
||||||
|
local send_mail = require "resources.functions.send_mail"
|
||||||
|
|
||||||
local db
|
local db
|
||||||
|
|
||||||
|
|
@ -244,6 +245,21 @@ local function cleanup_tasks()
|
||||||
db:query(remove_finished_tasks_sql)
|
db:query(remove_finished_tasks_sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function send_mail_task(task, message, call_uuid)
|
||||||
|
if not task.reply_address or #task.reply_address == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local mail_x_headers = {
|
||||||
|
["X-FusionPBX-Domain-UUID"] = task.domain_uuid;
|
||||||
|
["X-FusionPBX-Domain-Name"] = task.domain_name;
|
||||||
|
["X-FusionPBX-Call-UUID"] = call_uuid;
|
||||||
|
["X-FusionPBX-Email-Type"] = 'email2fax';
|
||||||
|
}
|
||||||
|
|
||||||
|
return send_mail(mail_x_headers, task.reply_address, message)
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
release_db = function()
|
release_db = function()
|
||||||
if db then
|
if db then
|
||||||
|
|
@ -251,10 +267,11 @@ return {
|
||||||
db = nil
|
db = nil
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
next_task = next_task;
|
next_task = next_task;
|
||||||
wait_task = wait_task;
|
wait_task = wait_task;
|
||||||
select_task = select_task;
|
select_task = select_task;
|
||||||
remove_task = remove_task;
|
remove_task = remove_task;
|
||||||
release_task = release_task;
|
release_task = release_task;
|
||||||
cleanup_tasks = cleanup_tasks;
|
cleanup_tasks = cleanup_tasks;
|
||||||
|
send_mail_task = send_mail_task;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ function Settings:_load(category, subcategory, name)
|
||||||
local found = false
|
local found = false
|
||||||
--get the domain settings
|
--get the domain settings
|
||||||
if domain_uuid then
|
if domain_uuid then
|
||||||
sql = "SELECT domain_setting_uuid,domain_setting_category,domain_setting_subcategory,domain_setting_name,domain_setting_value "
|
local sql = "SELECT domain_setting_uuid,domain_setting_category,domain_setting_subcategory,domain_setting_name,domain_setting_value "
|
||||||
sql = sql .. "FROM v_domain_settings ";
|
sql = sql .. "FROM v_domain_settings ";
|
||||||
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .. "'";
|
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .. "'";
|
||||||
sql = sql .. "AND domain_setting_enabled = 'true' ";
|
sql = sql .. "AND domain_setting_enabled = 'true' ";
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ local LEVELS = {
|
||||||
'warning',
|
'warning',
|
||||||
'notice',
|
'notice',
|
||||||
'info',
|
'info',
|
||||||
|
'debug',
|
||||||
}
|
}
|
||||||
|
|
||||||
local TRACE_LEVEL = 'notice'
|
local TRACE_LEVEL = 'notice'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue