diff --git a/app/emails/app_languages.php b/app/emails/app_languages.php index 5c08ca3825..c373cd8ce5 100644 --- a/app/emails/app_languages.php +++ b/app/emails/app_languages.php @@ -72,6 +72,15 @@ $text['label-type_voicemail']['pl'] = "Poczta głosowa"; $text['label-type_voicemail']['sv-se'] = "Röstbrevlåda"; $text['label-type_voicemail']['de-at'] = "Mailbox"; +$text['label-type_email2fax']['en-us'] = "Email to fax report"; +$text['label-type_email2fax']['es-cl'] = ""; +$text['label-type_email2fax']['pt-pt'] = ""; +$text['label-type_email2fax']['fr-fr'] = ""; +$text['label-type_email2fax']['pt-br'] = ""; +$text['label-type_email2fax']['pl'] = ""; +$text['label-type_email2fax']['sv-se'] = ""; +$text['label-type_email2fax']['de-at'] = ""; + $text['label-type']['en-us'] = "Type"; $text['label-type']['es-cl'] = "Tipo"; $text['label-type']['pt-pt'] = "Tipo"; diff --git a/app/fax/app_config.php b/app/fax/app_config.php index fe63326d1d..83fe88019d 100644 --- a/app/fax/app_config.php +++ b/app/fax/app_config.php @@ -554,6 +554,10 @@ $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_reply_address'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_interrupted'; $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; diff --git a/app/fax/fax_send.php b/app/fax/fax_send.php index 362dbaf46c..b5491287a0 100644 --- a/app/fax/fax_send.php +++ b/app/fax/fax_send.php @@ -131,7 +131,7 @@ if(!function_exists('gs_cmd')) { } if(!function_exists('fax_enqueue')) { - function fax_enqueue($fax_uuid, $fax_file, $wav_file, $fax_uri, $fax_dtmf, $dial_string){ + function fax_enqueue($fax_uuid, $fax_file, $wav_file, $reply_address, $fax_uri, $fax_dtmf, $dial_string){ global $db, $db_type; $fax_task_uuid = uuid(); @@ -151,12 +151,12 @@ INSERT INTO v_fax_tasks( fax_task_uuid, fax_uuid, task_next_time, task_lock_time, task_fax_file, task_wav_file, task_uri, task_dial_string, task_dtmf, task_interrupted, task_status, task_no_answer_counter, task_no_answer_retry_counter, task_retry_counter, - task_description) + task_reply_address, task_description) VALUES (?, ?, $date_utc_now_sql, NULL, ?, ?, ?, ?, ?, 'false', 0, 0, 0, 0, - ?); + ?, ?); HERE; $stmt = $db->prepare($sql); $i = 0; @@ -167,6 +167,7 @@ HERE; $stmt->bindValue(++$i, $fax_uri); $stmt->bindValue(++$i, $dial_string); $stmt->bindValue(++$i, $fax_dtmf); + $stmt->bindValue(++$i, $reply_address); $stmt->bindValue(++$i, $description); if ($stmt->execute()) { $response = 'Enqueued'; @@ -694,8 +695,6 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){ $common_dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',"; $common_dial_string .= "domain_uuid=" . $_SESSION["domain_uuid"] . ","; $common_dial_string .= "domain_name=" . $_SESSION["domain_name"] . ","; - $common_dial_string .= "mailto_address='" . $mailto_address . "',"; - $common_dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; $common_dial_string .= "origination_caller_id_name='" . $fax_caller_id_name . "',"; $common_dial_string .= "origination_caller_id_number='" . $fax_caller_id_number . "',"; $common_dial_string .= "fax_ident='" . $fax_caller_id_number . "',"; @@ -722,6 +721,8 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){ if ($fax_send_mode != 'queue') { $dial_string .= $t38; + $dial_string .= "mailto_address='" . $mailto_address . "',"; + $dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; $dial_string .= "fax_uri=" . $fax_uri . ","; $dial_string .= "fax_retry_attempts=1" . ","; $dial_string .= "fax_retry_limit=20" . ","; @@ -744,7 +745,7 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){ } else{ // enqueue $wav_file = ''; //! @todo add custom message - $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $fax_uri, $fax_dtmf, $dial_string); + $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $mailto_address, $fax_uri, $fax_dtmf, $dial_string); } } diff --git a/core/install/resources/classes/install_fusionpbx.php b/core/install/resources/classes/install_fusionpbx.php index f0e4ca1597..c891f96daa 100644 --- a/core/install/resources/classes/install_fusionpbx.php +++ b/core/install/resources/classes/install_fusionpbx.php @@ -275,9 +275,9 @@ include "root.php"; try { if (strlen($this->db_port) == 0) { $this->db_port = "5432"; } if (strlen($this->db_host) > 0) { - $this->dbh = new PDO("pgsql:host={$this->db_host} port={$this->db_port} user={".$this->db_create_username."} password={".$this->db_create_password."} dbname=template1"); + $this->dbh = new PDO("pgsql:host={$this->db_host} port={$this->db_port} user={$this->db_create_username} password={$this->db_create_password} dbname=template1"); } else { - $this->dbh = new PDO("pgsql:host=localhost port={$this->db_port} user={".$this->db_create_username."} password={".$this->db_create_password."} dbname=template1"); + $this->dbh = new PDO("pgsql:host=localhost port={$this->db_port} user={$this->db_create_username} password={$this->db_create_password} dbname=template1"); } } catch (PDOException $error) { throw new Exception("error connecting to database: " . $error->getMessage()); diff --git a/resources/install/scripts/app/fax/resources/scripts/queue/next.lua b/resources/install/scripts/app/fax/resources/scripts/queue/next.lua index bb5607f5ca..fb0df5c1cd 100644 --- a/resources/install/scripts/app/fax/resources/scripts/queue/next.lua +++ b/resources/install/scripts/app/fax/resources/scripts/queue/next.lua @@ -4,6 +4,7 @@ require "resources.functions.sleep" local log = require "resources.functions.log".next_fax_task local Tasks = require "app.fax.resources.scripts.queue.tasks" local Esl = require "resources.functions.esl" +local send_mail = require "resources.functions.send_mail" local FAX_OPTIONS = { "fax_use_ecm=false,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=default"; @@ -13,6 +14,25 @@ local FAX_OPTIONS = { "fax_use_ecm=false,fax_enable_t38=false,fax_enable_t38_request=false,fax_disable_v17=false"; } +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*$") + if task.reply_address and #task.reply_address > 0 then + send_mail(mail_x_headers, task.reply_address, { + "Fax to: " .. number_dialed .. " FAILED", + table.concat{ + "We are sorry the fax failed to go through. ", + "It has been attached. Please check the number "..number_dialed..", ", + "and if it was correct you might consider emailing it instead.", + } + }) + end +end + local function next_task() local task, err = Tasks.next_task() @@ -43,6 +63,7 @@ local function next_task() Tasks.wait_task(task, false, info) if task.status ~= 0 then Tasks.remove_task(task) + task_send_mail(task) end log.noticef('Can not originate to `%s` cause: %s: %s ', task.uri, tostring(status), tostring(info)) else diff --git a/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua b/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua index feb8f6ef4f..32ef3fac07 100644 --- a/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua +++ b/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua @@ -4,10 +4,11 @@ require "resources.functions.split"; require "resources.functions.count"; - local log = require "resources.functions.log".fax_retry - local Database = require "resources.functions.database" - local Settings = require "resources.functions.lazy_settings" - local Tasks = require "app.fax.resources.scripts.queue.tasks" + local log = require "resources.functions.log".fax_retry + local Database = require "resources.functions.database" + local Settings = require "resources.functions.lazy_settings" + local Tasks = require "app.fax.resources.scripts.queue.tasks" + local send_mail = require "resources.functions.send_mail" local fax_task_uuid = env:getHeader('fax_task_uuid') local task = Tasks.select_task(fax_task_uuid) @@ -69,11 +70,7 @@ local fax_uuid = task.fax_uuid -- Email variables - local email_address = env:getHeader("mailto_address") - local from_address = env:getHeader("mailfrom_address") or email_address local number_dialed = fax_uri:match("/([^/]-)%s*$") - local email_message_fail = "We are sorry the fax failed to go through. It has been attached. Please check the number "..number_dialed..", and if it was correct you might consider emailing it instead." - local email_message_success = "We are happy to report the fax was sent successfully. It has been attached for your records." log.noticef([[<<< CALL RESULT >>> uuid: = '%s' @@ -86,7 +83,6 @@ accountcode: = '%s' origination_caller_id_name: = '%s' origination_caller_id_number: = '%s' - mailfrom_address: = '%s' mailto_address: = '%s' hangup_cause_q850: = '%s' fax_options = '%s' @@ -101,8 +97,7 @@ tostring(accountcode) , tostring(origination_caller_id_name) , tostring(origination_caller_id_number) , - tostring(from_address) , - tostring(email_address) , + tostring(task.reply_address) , tostring(hangup_cause_q850) , fax_options ) @@ -249,6 +244,14 @@ dbh:query(sql); 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 if fax_success == "1" then @@ -328,6 +331,16 @@ end Tasks.remove_task(task) + + if task.reply_address and #task.reply_address > 0 then + send_mail(mail_x_headers, task.reply_address, { + "Fax to: " .. number_dialed .. " SENT", + table.concat{ + "We are happy to report the fax was sent successfully.", + "It has been attached for your records.", + } + }) + end end if fax_success ~= "1" then @@ -349,6 +362,16 @@ Tasks.wait_task(task, answered, hangup_cause_q850) if task.status ~= 0 then Tasks.remove_task(task) + if task.reply_address and #task.reply_address > 0 then + send_mail(mail_x_headers, task.reply_address, { + "Fax to: " .. number_dialed .. " FAILED", + table.concat{ + "We are sorry the fax failed to go through. ", + "It has been attached. Please check the number "..number_dialed..", ", + "and if it was correct you might consider emailing it instead.", + } + }) + end end end end diff --git a/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua b/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua index 96f6d612bf..dd049fd8ef 100644 --- a/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua +++ b/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua @@ -43,6 +43,7 @@ select t1.task_dtmf as dtmf, t1.task_fax_file as fax_file, t1.task_wav_file as wav_file, + t1.task_reply_address as reply_address, t1.task_no_answer_counter as no_answer_counter, t1.task_no_answer_retry_counter as no_answer_retry_counter, t1.task_retry_counter as retry_counter, diff --git a/resources/install/scripts/app/voicemail/app_languages.lua b/resources/install/scripts/app/voicemail/app_languages.lua index 0c2daed73b..57dc356a16 100644 --- a/resources/install/scripts/app/voicemail/app_languages.lua +++ b/resources/install/scripts/app/voicemail/app_languages.lua @@ -1,4 +1,4 @@ -text = {}; +text = text or {}; text['label-download'] = {}; text['label-download']['en-us'] = "Download"; @@ -24,3 +24,4 @@ text['label-attached']['fr-fr'] = "Attaché"; text['label-attached']['de-de'] = "im Anhang"; text['label-attached']['de-at'] = "im Anhang"; +return text \ No newline at end of file diff --git a/resources/install/scripts/app/voicemail/resources/functions/send_email.lua b/resources/install/scripts/app/voicemail/resources/functions/send_email.lua index 0cb437c19e..0480f8c9dd 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/send_email.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/send_email.lua @@ -25,10 +25,6 @@ local send_mail = require 'resources.functions.send_mail' - local function T(str) - return text[str][default_language..'-'..default_dialect] or text[str]['en-us'] - end - --define a function to send email function send_email(id, uuid) --get voicemail message details @@ -58,7 +54,8 @@ --require the email address to send the email if (string.len(voicemail_mail_to) > 2) then --include languages file - require "app.voicemail.app_languages"; + local Text = require "resources.functions.text" + local text = Text.new("app.voicemail.app_languages") --get voicemail message details sql = [[SELECT * FROM v_voicemail_messages @@ -142,11 +139,11 @@ body = body:gsub("${sip_to_user}", id); body = body:gsub("${dialed_user}", id); if (voicemail_file == "attach") then - body = body:gsub("${message}", T'label-attached'); + body = body:gsub("${message}", text['label-attached']); elseif (voicemail_file == "link") then - body = body:gsub("${message}", ""..T'label-download'..""); + body = body:gsub("${message}", ""..text['label-download']..""); else - body = body:gsub("${message}", ""..T'label-listen'..""); + body = body:gsub("${message}", ""..text['label-listen']..""); end body = body:gsub(" ", " "); body = body:gsub("%s+", ""); diff --git a/resources/install/scripts/resources/functions/text.lua b/resources/install/scripts/resources/functions/text.lua new file mode 100644 index 0000000000..11bf0933a2 --- /dev/null +++ b/resources/install/scripts/resources/functions/text.lua @@ -0,0 +1,71 @@ +--- +-- @tparam table dict Dictionary +-- @tparam[opt='en'] string language default language +-- @tparam[opt='us'] string dialect default language +-- @return[1] nil if key is unknown +-- @return[2] empty string if language/dialect unknown or there no appropriate value for default language/dialect +-- @return[3] translated value accordint dictionary/language/dialect +-- +-- @usage +-- local dict = { +-- ['label-text'] = { +-- ['en-us'] = 'text'; +-- ['ru-ru'] = 'текст'; +-- } +-- } +-- local text = Text.new(dict) +-- -- use global `default_language` and `default_dialect` to resolve language +-- var = text['label-attached'] +-- -- use prefix form +-- var = text'label-attached' +-- -- Implicit specify language +-- var = text('label-attached', 'ru', 'ru') +-- -- set global variables(you can set them even after ctor call) +-- default_language, default_dialect = 'ru', 'ru' +-- var = text['label-attached'] +local function make_text(dict, language, dialect) + if not (language and dialect) then + language, dialect = 'en', 'us' + end + + if type(dict) == 'string' then + dict = require(dict) + end + + local default = (language .. '-' .. dialect):lower() + + local function index(_, k) + local t = dict[k] + if not t then return end + + local lang + if default_language and default_dialect then + lang = (default_language .. '-' .. default_dialect):lower() + end + if not lang then lang = default end + return t[lang] or t[default] or '' + end + + local function call(self, k, language, dialect) + if language and dialect then + local t = dict[k] + if not t then return end + local lang = (language .. '-' .. dialect):lower() + local v = t[lang] + if v then return v end + end + return self[k] + end + + return setmetatable({},{ + __newindex = function() + error('Can not add field to proxy') + end; + __index = index; + __call = call; + }) +end + +return { + new = make_text; +} \ No newline at end of file diff --git a/secure/fax_to_email.php b/secure/fax_to_email.php index a0576756c0..3005595d6b 100644 --- a/secure/fax_to_email.php +++ b/secure/fax_to_email.php @@ -236,7 +236,7 @@ if(!function_exists('tiff2pdf')) { } if(!function_exists('fax_enqueue')) { - function fax_enqueue($fax_uuid, $fax_file, $wav_file, $fax_uri, $fax_dtmf, $dial_string){ + function fax_enqueue($fax_uuid, $fax_file, $wav_file, $reply_address, $fax_uri, $fax_dtmf, $dial_string){ global $db, $db_type; $fax_task_uuid = uuid(); @@ -256,12 +256,12 @@ INSERT INTO v_fax_tasks( fax_task_uuid, fax_uuid, task_next_time, task_lock_time, task_fax_file, task_wav_file, task_uri, task_dial_string, task_dtmf, task_interrupted, task_status, task_no_answer_counter, task_no_answer_retry_counter, task_retry_counter, - task_description) + task_reply_address, task_description) VALUES (?, ?, $date_utc_now_sql, NULL, ?, ?, ?, ?, ?, 'false', 0, 0, 0, 0, - ?); + ?, ?); HERE; $stmt = $db->prepare($sql); $i = 0; @@ -272,6 +272,7 @@ HERE; $stmt->bindValue(++$i, $fax_uri); $stmt->bindValue(++$i, $dial_string); $stmt->bindValue(++$i, $fax_dtmf); + $stmt->bindValue(++$i, $reply_address); $stmt->bindValue(++$i, $description); if ($stmt->execute()) { $response = 'Enqueued'; @@ -479,8 +480,6 @@ if(!function_exists('fax_split_dtmf')) { $common_dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',"; $common_dial_string .= "domain_uuid=" . $_SESSION["domain_uuid"] . ","; $common_dial_string .= "domain_name=" . $_SESSION["domain_name"] . ","; - $common_dial_string .= "mailto_address='" . $mailto_address . "',"; - $common_dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; $common_dial_string .= "origination_caller_id_name='" . $fax_caller_id_name . "',"; $common_dial_string .= "origination_caller_id_number='" . $fax_caller_id_number . "',"; $common_dial_string .= "fax_ident='" . $fax_caller_id_number . "',"; @@ -489,6 +488,8 @@ if(!function_exists('fax_split_dtmf')) { if ($fax_send_mode != 'queue') { $dial_string .= $t38; + $dial_string .= "mailto_address='" . $mailto_address . "',"; + $dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; $dial_string .= "fax_uri=" . $fax_uri . ","; $dial_string .= "fax_retry_attempts=1" . ","; $dial_string .= "fax_retry_limit=20" . ","; @@ -533,7 +534,7 @@ if(!function_exists('fax_split_dtmf')) { } else{ $wav_file = ''; - $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $fax_uri, $fax_dtmf, $dial_string); + $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $mailto_address, $fax_uri, $fax_dtmf, $dial_string); } } } diff --git a/secure/v_mailto.php b/secure/v_mailto.php index e81de0c6b1..5a7566a081 100644 --- a/secure/v_mailto.php +++ b/secure/v_mailto.php @@ -292,11 +292,14 @@ $mailer_error = $mail->ErrorInfo; echo "Mailer Error: ".$mailer_error."\n\n"; + $call_uuid = $headers["X-FusionPBX-Call-UUID"]; // log/store message in database for review $email_uuid = uuid(); $sql = "insert into v_emails ( "; $sql .= "email_uuid, "; - $sql .= "call_uuid, "; + if ($call_uuid) { + $sql .= "call_uuid, "; + } $sql .= "domain_uuid, "; $sql .= "sent_date, "; $sql .= "type, "; @@ -304,7 +307,9 @@ $sql .= "email "; $sql .= ") values ( "; $sql .= "'".$email_uuid."', "; - $sql .= "'".$headers["X-FusionPBX-Call-UUID"]."', "; + if ($call_uuid) { + $sql .= "'".$call_uuid."', "; + } $sql .= "'".$headers["X-FusionPBX-Domain-UUID"]."', "; $sql .= "now(),"; $sql .= "'".$headers["X-FusionPBX-Email-Type"]."', "; diff --git a/themes/enhanced/template.php b/themes/enhanced/template.php index fd0c9da8ad..23aadd820a 100644 --- a/themes/enhanced/template.php +++ b/themes/enhanced/template.php @@ -1434,7 +1434,7 @@ if (strlen($_SESSION['message']) > 0) {