diff --git a/app/fax/app_config.php b/app/fax/app_config.php
index 894353ff06..d5d499ed2f 100644
--- a/app/fax/app_config.php
+++ b/app/fax/app_config.php
@@ -235,7 +235,19 @@
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_email_connection_mailbox";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
- $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Mailbox folder to read.";
+ $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Mailbox folder to monitor.";
+ $z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_email_inbound_subject_tag";
+ $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+ $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Subject tag to detect inbound faxes.";
+ $z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_email_outbound_subject_tag";
+ $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+ $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Subject tag to detect outbound faxes.";
+ $z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_email_outbound_authorized_senders";
+ $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+ $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Authorized email-to-fax sender addresses.";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_pin_number";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
diff --git a/app/fax/app_languages.php b/app/fax/app_languages.php
index 67ddc2d43a..920c6913d4 100644
--- a/app/fax/app_languages.php
+++ b/app/fax/app_languages.php
@@ -248,10 +248,10 @@
$text['label-email_connection_validate']['pt-pt'] = "Validar Certificado";
$text['label-email_connection_validate']['fr-fr'] = "Valider le Certificat";
- $text['description-email_connection_validate']['en-us'] = "Enable server certificate validation (select 'False' for self-signed certificates).";
- $text['description-email_connection_validate']['es-cl'] = "Activar la validación del certificado del servidor (seleccione 'Falso' para certificados con firma).";
- $text['description-email_connection_validate']['pt-pt'] = "Habilitar a validação do certificado do servidor (selecione 'Não' para os certificados auto-assinados).";
- $text['description-email_connection_validate']['fr-fr'] = "Activer la validation du certificat du serveur (sélectionner 'Non' pour les certificats auto-signés).";
+ $text['description-email_connection_validate']['en-us'] = "Enable server certificate validation.
(Select 'False' for self-signed certificates.)";
+ $text['description-email_connection_validate']['es-cl'] = "Activar la validación del certificado del servidor.
(Seleccione 'Falso' para certificados con firma.)";
+ $text['description-email_connection_validate']['pt-pt'] = "Habilitar a validação do certificado do servidor.
(Selecione 'Não' para os certificados auto-assinados.)";
+ $text['description-email_connection_validate']['fr-fr'] = "Activer la validation du certificat du serveur.
(Sélectionner 'Non' pour les certificats auto-signés.)";
$text['label-email_connection_username']['en-us'] = "Username";
$text['label-email_connection_username']['es-cl'] = "Nombre de usuario";
@@ -278,10 +278,65 @@
$text['label-email_connection_mailbox']['pt-pt'] = "Pasta Caixa";
$text['label-email_connection_mailbox']['fr-fr'] = "Dossier Boîte aux Lettres";
- $text['description-email_connection_mailbox']['en-us'] = "Enter the remote folder name to view.";
- $text['description-email_connection_mailbox']['es-cl'] = "Escriba el nombre de la carpeta a distancia para ver.";
- $text['description-email_connection_mailbox']['pt-pt'] = "Digite o nome da pasta remota para ver.";
- $text['description-email_connection_mailbox']['fr-fr'] = "Entrez le nom du dossier à distance pour voir.";
+ $text['description-email_connection_mailbox']['en-us'] = "Enter the remote folder name to monitor.";
+ $text['description-email_connection_mailbox']['es-cl'] = "Escriba el nombre de la carpeta remota para monitorear.";
+ $text['description-email_connection_mailbox']['pt-pt'] = "Digite o nome da pasta remoto para monitorar.";
+ $text['description-email_connection_mailbox']['fr-fr'] = "Entrez le nom du dossier à distance pour surveiller.";
+
+ $text['label-advanced_settings']['en-us'] = "Advanced Settings";
+ $text['label-advanced_settings']['es-cl'] = "Configuración Avanzada";
+ $text['label-advanced_settings']['pt-pt'] = "Configurações Avançadas";
+ $text['label-advanced_settings']['fr-fr'] = "Paramètres Avancés";
+
+ $text['description-advanced_settings']['en-us'] = "Configure the settings below to enable Remote Inbox and Email-to-Fax functionality.";
+ $text['description-advanced_settings']['es-cl'] = "Configure las opciones de abajo para permitir que la bandeja de entrada remota y funcionalidad-Email-a-Fax.";
+ $text['description-advanced_settings']['pt-pt'] = "Defina as configurações abaixo para permitir Inbox remoto e funcionalidade Email-to-Fax.";
+ $text['description-advanced_settings']['fr-fr'] = "Configurez les paramètres ci-dessous pour activer la boîte de réception à distance et la fonctionnalité Email-à-Fax.";
+
+ $text['label-email_account_connection']['en-us'] = "Account Connection";
+ $text['label-email_account_connection']['es-cl'] = "Conexión Cuenta";
+ $text['label-email_account_connection']['pt-pt'] = "Connection Conta";
+ $text['label-email_account_connection']['fr-fr'] = "Compte Connexion";
+
+ $text['label-email_remote_inbox']['en-us'] = "Remote Inbox";
+ $text['label-email_remote_inbox']['es-cl'] = "Bandeja de Entrada Remota";
+ $text['label-email_remote_inbox']['pt-pt'] = "Inbox Remoto";
+ $text['label-email_remote_inbox']['fr-fr'] = "Boîte de Réception à Distance";
+
+ $text['label-email_inbound_subject_tag']['en-us'] = "Subject Tag";
+ $text['label-email_inbound_subject_tag']['es-cl'] = "Asunto Tag";
+ $text['label-email_inbound_subject_tag']['pt-pt'] = "Assunto Tag";
+ $text['label-email_inbound_subject_tag']['fr-fr'] = "Tag Sujet";
+
+ $text['description-email_inbound_subject_tag']['en-us'] = "Set the email subject tag for inbound faxes.";
+ $text['description-email_inbound_subject_tag']['es-cl'] = "Ajuste la etiqueta de asunto del correo electrónico para los faxes entrantes.";
+ $text['description-email_inbound_subject_tag']['pt-pt'] = "Defina a tag e-mail assunto para faxes recebidos.";
+ $text['description-email_inbound_subject_tag']['fr-fr'] = "Réglez le tag objet du courriel pour les fax entrants.";
+
+ $text['label-email_email-to-fax']['en-us'] = "Email-to-Fax";
+ $text['label-email_email-to-fax']['es-cl'] = "Email-a-Fax";
+ $text['label-email_email-to-fax']['pt-pt'] = "Email-to-Fax";
+ $text['label-email_email-to-fax']['fr-fr'] = "Email-à-Fax";
+
+ $text['label-email_outbound_subject_tag']['en-us'] = "Subject Tag";
+ $text['label-email_outbound_subject_tag']['es-cl'] = "Asunto Tag";
+ $text['label-email_outbound_subject_tag']['pt-pt'] = "Assunto Tag";
+ $text['label-email_outbound_subject_tag']['fr-fr'] = "Tag Sujet";
+
+ $text['description-email_outbound_subject_tag']['en-us'] = "Set the email subject tag for outbound faxes.";
+ $text['description-email_outbound_subject_tag']['es-cl'] = "Ajuste la etiqueta de asunto del correo electrónico para los faxes salientes.";
+ $text['description-email_outbound_subject_tag']['pt-pt'] = "Defina a tag e-mail assunto para faxes de saída.";
+ $text['description-email_outbound_subject_tag']['fr-fr'] = "Réglez le tag objet du courriel pour les fax sortants.";
+
+ $text['label-email_outbound_authorized_senders']['en-us'] = "Authorized Senders";
+ $text['label-email_outbound_authorized_senders']['es-cl'] = "Los Remitentes Autorizados";
+ $text['label-email_outbound_authorized_senders']['pt-pt'] = "Remetentes Autorizados";
+ $text['label-email_outbound_authorized_senders']['fr-fr'] = "Expéditeurs Autorisés";
+
+ $text['description-email_outbound_authorized_senders']['en-us'] = "Define the email address(es) allowed to send faxes through this server.";
+ $text['description-email_outbound_authorized_senders']['es-cl'] = "Definir la dirección de correo electrónico(es) pueden enviar faxes a través de este servidor.";
+ $text['description-email_outbound_authorized_senders']['pt-pt'] = "Defina o endereço de e-mail(s) permissão para enviar faxes através deste servidor.";
+ $text['description-email_outbound_authorized_senders']['fr-fr'] = "Définir l'adresse e-mail(s) autorisé à envoyer des télécopies via ce serveur.";
$text['option-true']['en-us'] = "True";
$text['option-true']['es-cl'] = "Verdadero";
@@ -408,10 +463,10 @@
$text['label-fax-number']['pt-pt'] = "Número de Fax";
$text['label-fax-number']['fr-fr'] = "Numéro de Fax";
- $text['description-fax-number']['en-us'] = "Enter the recipient's fax number.";
- $text['description-fax-number']['es-cl'] = "Ingrese el número aquí.";
- $text['description-fax-number']['pt-pt'] = "Introduza aqui o número.";
- $text['description-fax-number']['fr-fr'] = "Entrez le numéro de fax du destinataire.";
+ $text['description-fax-number']['en-us'] = "Enter the recipient fax number(s).";
+ $text['description-fax-number']['es-cl'] = "Introduzca el número(s) de fax del destinatario.";
+ $text['description-fax-number']['pt-pt'] = "Digite o número do(s) de fax do destinatário.";
+ $text['description-fax-number']['fr-fr'] = "Entrez le numéro(s) de fax du destinataire.";
$text['label-fax-subject']['en-us'] = "Subject";
$text['label-fax-subject']['es-cl'] = "Asunto";
diff --git a/app/fax/fax_box_remote.php b/app/fax/fax_box_remote.php
index 0ca41526ba..6063eafa11 100644
--- a/app/fax/fax_box_remote.php
+++ b/app/fax/fax_box_remote.php
@@ -27,6 +27,8 @@
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
+require_once "resources/functions/object_to_array.php";
+require_once "resources/functions/parse_attachments.php";
if (permission_exists('fax_inbox_view')) {
//access granted
}
@@ -79,6 +81,7 @@ else {
$fax_email_connection_username = $row["fax_email_connection_username"];
$fax_email_connection_password = $row["fax_email_connection_password"];
$fax_email_connection_mailbox = $row["fax_email_connection_mailbox"];
+ $fax_email_inbound_subject_tag = $row["fax_email_inbound_subject_tag"];
break;
}
unset ($prep_statement);
@@ -88,7 +91,7 @@ else {
$fax_email_connection .= ($fax_email_connection_security != '') ? "/".$fax_email_connection_security : "/notls";
$fax_email_connection .= "/".(($fax_email_connection_validate == 'false') ? "no" : null)."validate-cert";
$fax_email_connection .= "}".$fax_email_connection_mailbox;
- if (!$mailbox = imap_open($fax_email_connection, $fax_email_connection_username, $fax_email_connection_password)) {
+ if (!$connection = imap_open($fax_email_connection, $fax_email_connection_username, $fax_email_connection_password)) {
$_SESSION["message_mood"] = 'negative';
$_SESSION["message"] = $text['message-cannot_connect']."(".imap_last_error().")";
header("Location: fax.php");
@@ -107,7 +110,7 @@ else {
//download attachment
if (isset($_GET['download'])) {
- $attachment = get_attachments($mailbox, $email_id, FT_UID);
+ $attachment = parse_attachments($connection, $email_id, FT_UID);
$file_type = pathinfo($attachment[0]['filename'], PATHINFO_EXTENSION);
switch ($file_type) {
case "pdf" : header("Content-Type: application/pdf"); break;
@@ -130,9 +133,9 @@ else {
//delete email
if (isset($_GET['delete']) && permission_exists('fax_inbox_delete')) {
- $attachment = get_attachments($mailbox, $email_id, FT_UID);
- if (imap_delete($mailbox, $email_id, FT_UID)) {
- if (imap_expunge($mailbox)) {
+ $attachment = parse_attachments($connection, $email_id, FT_UID);
+ if (imap_delete($connection, $email_id, FT_UID)) {
+ if (imap_expunge($connection)) {
//clean up local inbox copy
$fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null);
@unlink($fax_dir.'/'.$fax_extension.'/inbox/'.$attachment[0]['filename']);
@@ -161,7 +164,7 @@ else {
}
//get emails
- $emails = imap_search($mailbox, 'SUBJECT "Fax"', SE_UID);
+ $emails = imap_search($connection, "SUBJECT \"".$fax_email_inbound_subject_tag."\"", SE_UID);
//show the header
require_once "resources/header.php";
@@ -199,8 +202,8 @@ else {
rsort($emails); // most recent on top
foreach ($emails as $email_id) {
- $metadata = object_to_array(imap_fetch_overview($mailbox, $email_id, FT_UID));
- $attachment = get_attachments($mailbox, $email_id, FT_UID);
+ $metadata = object_to_array(imap_fetch_overview($connection, $email_id, FT_UID));
+ $attachment = parse_attachments($connection, $email_id, FT_UID);
echo "
\n";
echo " | ".$metadata[0]['date']." | \n";
@@ -210,8 +213,10 @@ else {
echo " $v_link_label_delete | \n";
}
echo "
\n";
- //$message = imap_fetchbody($mailbox, $email_id, 2, FT_UID);
- //echo $message;
+// $fax_message = imap_fetchbody($connection, $email_id, '1.1', FT_UID);
+// if ($fax_message == '') {
+// $fax_message = imap_fetchbody($connection, $email_id, '1', FT_UID);
+// }
}
}
@@ -230,57 +235,4 @@ imap_close($inbox);
//show the footer
require_once "resources/footer.php";
-
-
-
-//functions used above
-function object_to_array($obj) {
- if (!is_object($obj) && !is_array($obj)) { return $obj; }
- if (is_object($obj)) { $obj = get_object_vars($obj); }
- return array_map('object_to_array', $obj);
-}
-
-function get_attachments($connection, $message_number, $option = '') {
- $attachments = array();
- $structure = imap_fetchstructure($connection, $message_number, $option);
-
- if(isset($structure->parts) && count($structure->parts)) {
-
- for($i = 0; $i < count($structure->parts); $i++) {
-
- if($structure->parts[$i]->ifdparameters) {
- foreach($structure->parts[$i]->dparameters as $object) {
- if(strtolower($object->attribute) == 'filename') {
- $attachments[$i]['is_attachment'] = true;
- $attachments[$i]['filename'] = $object->value;
- }
- }
- }
-
- if($structure->parts[$i]->ifparameters) {
- foreach($structure->parts[$i]->parameters as $object) {
- if(strtolower($object->attribute) == 'name') {
- $attachments[$i]['is_attachment'] = true;
- $attachments[$i]['name'] = $object->value;
- }
- }
- }
-
- if($attachments[$i]['is_attachment']) {
- $attachments[$i]['attachment'] = imap_fetchbody($connection, $message_number, $i+1, $option);
- if($structure->parts[$i]->encoding == 3) { // 3 = BASE64
- $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
- }
- elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
- $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
- }
- }
-
- unset($attachments[$i]['is_attachment']);
- }
-
- }
- return array_values($attachments); //reindex
-}
-
?>
\ No newline at end of file
diff --git a/app/fax/fax_edit.php b/app/fax/fax_edit.php
index b977632854..c3981e095f 100644
--- a/app/fax/fax_edit.php
+++ b/app/fax/fax_edit.php
@@ -107,6 +107,9 @@ else {
$fax_email_connection_username = check_str($_POST["fax_email_connection_username"]);
$fax_email_connection_password = check_str($_POST["fax_email_connection_password"]);
$fax_email_connection_mailbox = check_str($_POST["fax_email_connection_mailbox"]);
+ $fax_email_inbound_subject_tag = check_str($_POST["fax_email_inbound_subject_tag"]);
+ $fax_email_outbound_subject_tag = check_str($_POST["fax_email_outbound_subject_tag"]);
+ $fax_email_outbound_authorized_senders = $_POST["fax_email_outbound_authorized_senders"];
//$fax_pin_number = check_str($_POST["fax_pin_number"]);
$fax_caller_id_name = check_str($_POST["fax_caller_id_name"]);
$fax_caller_id_number = check_str($_POST["fax_caller_id_number"]);
@@ -221,6 +224,16 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
//add or update the database
if ($_POST["persistformvar"] != "true") {
+
+ //prep authorized senders
+ if (sizeof($fax_email_outbound_authorized_senders) > 0) {
+ foreach ($fax_email_outbound_authorized_senders as $sender_num => $sender) {
+ $sender = check_str($sender);
+ if ($sender == '' || !valid_email($sender)) { unset($fax_email_outbound_authorized_senders[$sender_num]); }
+ }
+ $fax_email_outbound_authorized_senders = implode(',', $fax_email_outbound_authorized_senders);
+ }
+
if ($action == "add" && permission_exists('fax_extension_add')) {
//prepare the unique identifiers
$fax_uuid = uuid();
@@ -244,6 +257,9 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$sql .= "fax_email_connection_username, ";
$sql .= "fax_email_connection_password, ";
$sql .= "fax_email_connection_mailbox, ";
+ $sql .= "fax_email_inbound_subject_tag, ";
+ $sql .= "fax_email_outbound_subject_tag, ";
+ $sql .= "fax_email_outbound_authorized_senders, ";
//$sql .= "fax_pin_number, ";
$sql .= "fax_caller_id_name, ";
$sql .= "fax_caller_id_number, ";
@@ -269,6 +285,9 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$sql .= "'$fax_email_connection_username', ";
$sql .= "'$fax_email_connection_password', ";
$sql .= "'$fax_email_connection_mailbox', ";
+ $sql .= "'$fax_email_inbound_subject_tag', ";
+ $sql .= "'$fax_email_outbound_subject_tag', ";
+ $sql .= "'$fax_email_outbound_authorized_senders', ";
//$sql .= "'$fax_pin_number', ";
$sql .= "'$fax_caller_id_name', ";
$sql .= "'$fax_caller_id_number', ";
@@ -303,6 +322,9 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$sql .= "fax_email_connection_username = '$fax_email_connection_username', ";
$sql .= "fax_email_connection_password = '$fax_email_connection_password', ";
$sql .= "fax_email_connection_mailbox = '$fax_email_connection_mailbox', ";
+ $sql .= "fax_email_inbound_subject_tag = '$fax_email_inbound_subject_tag', ";
+ $sql .= "fax_email_outbound_subject_tag = '$fax_email_outbound_subject_tag', ";
+ $sql .= "fax_email_outbound_authorized_senders = '$fax_email_outbound_authorized_senders', ";
//$sql .= "fax_pin_number = '$fax_pin_number', ";
$sql .= "fax_caller_id_name = '$fax_caller_id_name', ";
$sql .= "fax_caller_id_number = '$fax_caller_id_number', ";
@@ -540,6 +562,9 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$fax_email_connection_username = $row["fax_email_connection_username"];
$fax_email_connection_password = $row["fax_email_connection_password"];
$fax_email_connection_mailbox = $row["fax_email_connection_mailbox"];
+ $fax_email_inbound_subject_tag = $row["fax_email_inbound_subject_tag"];
+ $fax_email_outbound_subject_tag = $row["fax_email_outbound_subject_tag"];
+ $fax_email_outbound_authorized_senders = $row["fax_email_outbound_authorized_senders"];
//$fax_pin_number = $row["fax_pin_number"];
$fax_caller_id_name = $row["fax_caller_id_name"];
$fax_caller_id_number = $row["fax_caller_id_number"];
@@ -562,23 +587,32 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
//advanced button js
echo "\n";
//fax extension form
echo "";
-
echo "
\n";
+ if (function_exists("imap_open") && file_exists("fax_box_remote.php")) {
+
+ echo "\n";
+
+ echo "
".$text['label-advanced_settings']."";
+ echo $text['description-advanced_settings']."
";
+
+ echo "
";
+ echo "
";
+ echo "
\n";
+
+ }
+
+ echo "";
+
//show the footer
require_once "resources/footer.php";
?>
\ No newline at end of file
diff --git a/app/fax/fax_send.php b/app/fax/fax_send.php
index ffd24e29ed..df46e670d9 100644
--- a/app/fax/fax_send.php
+++ b/app/fax/fax_send.php
@@ -24,81 +24,77 @@
Mark J Crane
James Rose
*/
-include "root.php";
-require_once "resources/require.php";
-require_once "resources/check_auth.php";
-if (permission_exists('fax_send')) {
- //access granted
-}
-else {
- echo "access denied";
- exit;
-}
-//add multi-lingual support
- require_once "app_languages.php";
- foreach($text as $key => $value) {
- $text[$key] = $value[$_SESSION['domain']['language']['code']];
- }
+if (!$included) {
-//get the fax_extension and save it as a variable
- if (strlen($_REQUEST["fax_extension"]) > 0) {
- $fax_extension = check_str($_REQUEST["fax_extension"]);
- }
-
-//pre-populate the form
- if (strlen($_REQUEST['id']) > 0 && $_POST["persistformvar"] != "true") {
- $fax_uuid = check_str($_REQUEST["id"]);
- if (if_group("superadmin") || if_group("admin")) {
- //show all fax extensions
- $sql = "select * from v_fax ";
- $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
- $sql .= "and fax_uuid = '$fax_uuid' ";
- }
- else {
- //show only assigned fax extensions
- $sql = "select * from v_fax as f, v_fax_users as u ";
- $sql .= "where f.fax_uuid = u.fax_uuid ";
- $sql .= "and f.domain_uuid = '".$_SESSION['domain_uuid']."' ";
- $sql .= "and f.fax_uuid = '$fax_uuid' ";
- $sql .= "and u.user_uuid = '".$_SESSION['user_uuid']."' ";
- }
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- if (count($result) == 0) {
- if (if_group("superadmin") || if_group("admin")) {
- //allow access
- }
- else {
- echo "access denied";
- exit;
- }
- }
- foreach ($result as &$row) {
- //set database fields as variables
- $fax_extension = $row["fax_extension"];
- $fax_name = $row["fax_name"];
- $fax_email = $row["fax_email"];
- $fax_pin_number = $row["fax_pin_number"];
- $fax_caller_id_name = $row["fax_caller_id_name"];
- $fax_caller_id_number = $row["fax_caller_id_number"];
- $fax_forward_number = $row["fax_forward_number"];
- $fax_description = $row["fax_description"];
- //limit to one row
- break;
- }
- unset ($prep_statement);
- }
-
-//set the fax directory
- if (count($_SESSION["domains"]) > 1) {
- $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'];
+ include "root.php";
+ require_once "resources/require.php";
+ require_once "resources/check_auth.php";
+ if (permission_exists('fax_send')) {
+ //access granted
}
else {
- $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax';
+ echo "access denied";
+ exit;
}
+ //add multi-lingual support
+ require_once "app_languages.php";
+ foreach($text as $key => $value) {
+ $text[$key] = $value[$_SESSION['domain']['language']['code']];
+ }
+
+ //get the fax_extension and save it as a variable
+ if (strlen($_REQUEST["fax_extension"]) > 0) {
+ $fax_extension = check_str($_REQUEST["fax_extension"]);
+ }
+
+ //pre-populate the form
+ if (strlen($_REQUEST['id']) > 0 && $_POST["persistformvar"] != "true") {
+ $fax_uuid = check_str($_REQUEST["id"]);
+ if (if_group("superadmin") || if_group("admin")) {
+ //show all fax extensions
+ $sql = "select * from v_fax ";
+ $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+ $sql .= "and fax_uuid = '$fax_uuid' ";
+ }
+ else {
+ //show only assigned fax extensions
+ $sql = "select * from v_fax as f, v_fax_users as u ";
+ $sql .= "where f.fax_uuid = u.fax_uuid ";
+ $sql .= "and f.domain_uuid = '".$_SESSION['domain_uuid']."' ";
+ $sql .= "and f.fax_uuid = '$fax_uuid' ";
+ $sql .= "and u.user_uuid = '".$_SESSION['user_uuid']."' ";
+ }
+ $prep_statement = $db->prepare(check_sql($sql));
+ $prep_statement->execute();
+ $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+ if (count($result) == 0) {
+ if (if_group("superadmin") || if_group("admin")) {
+ //allow access
+ }
+ else {
+ echo "access denied";
+ exit;
+ }
+ }
+ foreach ($result as &$row) {
+ //set database fields as variables
+ $fax_extension = $row["fax_extension"];
+ $fax_caller_id_name = $row["fax_caller_id_name"];
+ $fax_caller_id_number = $row["fax_caller_id_number"];
+ //limit to one row
+ break;
+ }
+ unset ($prep_statement);
+ }
+
+ //set the fax directory
+ $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null);
+
+}
+
+
//get the fax extension
if (strlen($fax_extension) > 0) {
//set the fax directories. example /usr/local/freeswitch/storage/fax/329/inbox
@@ -129,59 +125,47 @@ else {
}
}
-//set the action as an add or an update
- if (isset($_REQUEST["id"])) {
- $action = "update";
- $fax_uuid = check_str($_REQUEST["id"]);
- }
- else {
- $action = "add";
- }
-
-//get the http post values and set them as php variables
- if (count($_POST)>0) {
- $fax_name = check_str($_POST["fax_name"]);
- $fax_email = check_str($_POST["fax_email"]);
- $fax_pin_number = check_str($_POST["fax_pin_number"]);
- $fax_caller_id_name = check_str($_POST["fax_caller_id_name"]);
- $fax_caller_id_number = check_str($_POST["fax_caller_id_number"]);
- $fax_forward_number = check_str($_POST["fax_forward_number"]);
- if (strlen($fax_forward_number) > 0) {
- $fax_forward_number = preg_replace("~[^0-9]~", "",$fax_forward_number);
- }
- $fax_description = check_str($_POST["fax_description"]);
- }
-
//clear file status cache
clearstatcache();
-//upload (if necessary) and send the fax
- if (($_POST['action'] == "send")) {
- $fax_number = check_str($_POST['fax_number']);
- if (strlen($fax_number) > 0) {
- $fax_number = preg_replace("~[^0-9]~", "",$fax_number);
+//send the fax
+ $continue = false;
+
+ if (!$included) {
+ if (($_POST['action'] == "send")) {
+
+ $fax_numbers = $_POST['fax_numbers'];
+ if (sizeof($fax_numbers) > 0) {
+ foreach ($fax_numbers as $index => $fax_number) {
+ $fax_numbers[$index] = preg_replace("~[^0-9]~", "", $fax_number);
+ if ($fax_numbers[$index] == '') { unset($fax_numbers[$index]); }
+ }
+ sort($fax_numbers);
+ }
+
+ $fax_uuid = check_str($_POST["id"]);
+ $fax_caller_id_name = check_str($_POST['fax_caller_id_name']);
+ $fax_caller_id_number = check_str($_POST['fax_caller_id_number']);
+ $fax_header = check_str($_POST['fax_header']);
+ $fax_sender = check_str($_POST['fax_sender']);
+ $fax_recipient = check_str($_POST['fax_recipient']);
+ $fax_subject = check_str($_POST['fax_subject']);
+ $fax_message = check_str($_POST['fax_message']);
+ $fax_resolution = check_str($_POST['fax_resolution']);
+ $fax_page_size = check_str($_POST['fax_page_size']);
+ $fax_footer = check_str($_POST['fax_footer']);
+
+ $continue = true;
}
+ }
+ else {
+ //all necessary local and session variables should
+ //be already set by now by file including this one
+ $continue = true;
+ }
- $provider_type = check_str($_POST['provider_type']);
- $fax_uuid = check_str($_POST["id"]);
-
- $fax_caller_id_name = check_str($_POST['fax_caller_id_name']);
- $fax_caller_id_number = check_str($_POST['fax_caller_id_number']);
- $fax_forward_number = check_str($_POST['fax_forward_number']);
- if (strlen($fax_forward_number) > 0) {
- $fax_forward_number = preg_replace("~[^0-9]~", "",$fax_forward_number);
- }
-
- $fax_header = check_str($_POST['fax_header']);
- $fax_sender = check_str($_POST['fax_sender']);
- $fax_recipient = check_str($_POST['fax_recipient']);
- $fax_subject = check_str($_POST['fax_subject']);
- $fax_message = check_str($_POST['fax_message']);
- $fax_resolution = check_str($_POST['fax_resolution']);
- $fax_page_size = check_str($_POST['fax_page_size']);
- $fax_footer = check_str($_POST['fax_footer']);
-
+ if ($continue) {
//determine page size
switch ($fax_page_size) {
case 'a4' :
@@ -200,52 +184,33 @@ else {
//set resolution
switch ($fax_resolution) {
- case 'normal':
- $gs_r = '204x98'; $gs_g = ((int) ($page_width * 204)).'x'.((int) ($page_height * 98));
- break;
case 'fine':
$gs_r = '204x196'; $gs_g = ((int) ($page_width * 204)).'x'.((int) ($page_height * 196));
break;
case 'superfine':
$gs_r = '408x391'; $gs_g = ((int) ($page_width * 408)).'x'.((int) ($page_height * 391));
break;
+ case 'normal':
+ default:
+ $gs_r = '204x98'; $gs_g = ((int) ($page_width * 204)).'x'.((int) ($page_height * 98));
+ break;
}
- // process uploaded files, if any
+ // process uploaded or emailed files (if any)
$fax_page_count = 0;
- foreach ($_FILES['fax_files']['tmp_name'] as $index => $fax_tmp_name) {
- if (
- is_uploaded_file($fax_tmp_name)
- && $_FILES['fax_files']['error'][$index] == 0
- && $_FILES['fax_files']['size'][$index] > 0
- ) {
-
+ $_files = (!$included) ? $_FILES['fax_files'] : $emailed_files;
+ foreach ($_files['tmp_name'] as $index => $fax_tmp_name) {
+ $uploaded_file = (!$included) ? is_uploaded_file($fax_tmp_name) : true;
+ if ( $uploaded_file && $_files['error'][$index] == 0 && $_files['size'][$index] > 0 ) {
//get the file extension
- $fax_file_extension = strtolower(pathinfo($_FILES['fax_files']['name'][$index], PATHINFO_EXTENSION));
+ $fax_file_extension = strtolower(pathinfo($_files['name'][$index], PATHINFO_EXTENSION));
if ($fax_file_extension == "tiff") { $fax_file_extension = "tif"; }
//block unauthorized files
- if (
- $fax_file_extension == 'sh' ||
- $fax_file_extension == 'ssh' ||
- $fax_file_extension == 'so' ||
- $fax_file_extension == 'dll' ||
- $fax_file_extension == 'exe' ||
- $fax_file_extension == 'bat' ||
- $fax_file_extension == 'vbs' ||
- $fax_file_extension == 'zip' ||
- $fax_file_extension == 'rar' ||
- $fax_file_extension == 'z' ||
- $fax_file_extension == 'tar' ||
- $fax_file_extension == 'tbz' ||
- $fax_file_extension == 'tgz' ||
- $fax_file_extension == 'gz' ||
- $fax_file_extension == ''
- ) {
- continue;
- }
+ $disallowed_file_extensions = explode(',','sh,ssh,so,dll,exe,bat,vbs,zip,rar,z,tar,tbz,tgz,gz');
+ if (in_array($fax_file_extension, $disallowed_file_extensions) || $fax_file_extension == '') { continue; }
- $fax_name = $_FILES['fax_files']['name'][$index];
+ $fax_name = $_files['name'][$index];
$fax_name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $fax_name);
$fax_name = str_replace(" ", "_", $fax_name);
@@ -267,8 +232,10 @@ else {
$fax_name = str_replace("+", "_", $fax_name);
$fax_name = str_replace("=", "_", $fax_name);
- //move uploaded file
- move_uploaded_file($_FILES['fax_files']['tmp_name'][$index], $dir_fax_temp.'/'.$fax_name.'.'.$fax_file_extension);
+ if (!$included) {
+ //move uploaded file
+ move_uploaded_file($_files['tmp_name'][$index], $dir_fax_temp.'/'.$fax_name.'.'.$fax_file_extension);
+ }
//convert uploaded file to pdf, if necessary
if ($fax_file_extension != "pdf" && $fax_file_extension != "tif") {
@@ -362,7 +329,7 @@ else {
}
//header
- if (isset($_SESSION['fax']['cover_header']['text'])) {
+ if ($fax_header != '') {
$pdf -> SetLeftMargin(0.5);
$pdf -> SetFont("times", "", 10);
$pdf -> Write(0.3, $fax_header);
@@ -381,7 +348,7 @@ else {
//field labels
$pdf -> SetFont("times", "B", 12);
- if ($fax_recipient != '' || $fax_number != '') {
+ if ($fax_recipient != '' || sizeof($fax_numbers) > 0) {
$pdf -> Text($x + 0.5, $y + 2.0, strtoupper($text['label-fax-recipient']).":");
}
if ($fax_sender != '' || $fax_caller_id_number != '') {
@@ -399,14 +366,19 @@ else {
$pdf -> SetXY($x + 2.0, $y + 1.95);
if ($fax_recipient != '') {
$pdf -> Write(0.3, $fax_recipient);
- if ($fax_number != '') {
- $pdf -> Write(0.3, ' ('.format_phone($fax_number).')');
- }
}
- else {
- if ($fax_number != '') {
- $pdf -> Write(0.3, format_phone($fax_number));
+ if (sizeof($fax_numbers) > 0) {
+ $fax_number_string = ($fax_recipient != '') ? ' (' : null;
+ $fax_number_string .= format_phone($fax_numbers[0]);
+ if (sizeof($fax_numbers) > 1) {
+ for ($n = 1; $n <= sizeof($fax_numbers); $n++) {
+ if ($n == 4) { break; }
+ $fax_number_string .= ', '.format_phone($fax_numbers[$n]);
+ }
}
+ $fax_number_string .= (sizeof($fax_numbers) > 4) ? ', +'.(sizeof($fax_numbers) - 4) : null;
+ $fax_number_string .= ($fax_recipient != '') ? ')' : null;
+ $pdf -> Write(0.3, $fax_number_string);
}
$pdf -> SetXY($x + 2.0, $y + 2.25);
if ($fax_sender != '') {
@@ -479,11 +451,13 @@ else {
@unlink($dir_fax_temp.'/'.$fax_instance_uuid."_temp.tif");
}
else {
- //nothing to send, redirect the browser
- $_SESSION['message_mood'] = 'negative';
- $_SESSION["message"] = $text['message-invalid-fax'];
- header("Location: fax_send.php?id=".$fax_uuid);
- exit;
+ if (!$included) {
+ //nothing to send, redirect the browser
+ $_SESSION['message_mood'] = 'negative';
+ $_SESSION["message"] = $text['message-invalid-fax'];
+ header("Location: fax_send.php?id=".$fax_uuid);
+ exit;
+ }
}
//preview, if requested
@@ -519,12 +493,7 @@ else {
}
//get some more info to send the fax
- if (isset($_SESSION['fax']['smtp_from']['var'])) {
- $mailfrom_address = $_SESSION['fax']['smtp_from']['var'];
- }
- else {
- $mailfrom_address = $_SESSION['email']['smtp_from']['var'];
- }
+ $mailfrom_address = (isset($_SESSION['fax']['smtp_from']['var'])) ? $_SESSION['fax']['smtp_from']['var'] : $_SESSION['email']['smtp_from']['var'];
$sql = "select fax_email from v_fax where fax_uuid = '".$fax_uuid."'; ";
$prep_statement = $db->prepare(check_sql($sql));
@@ -532,18 +501,23 @@ else {
$result = $prep_statement->fetch(PDO::FETCH_NAMED);
$mailto_address_fax = $result["fax_email"];
- $sql = "select contact_uuid from v_users where user_uuid = '".$_SESSION['user_uuid']."'; ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetch(PDO::FETCH_NAMED);
+ if (!included) {
+ $sql = "select contact_uuid from v_users where user_uuid = '".$_SESSION['user_uuid']."'; ";
+ $prep_statement = $db->prepare(check_sql($sql));
+ $prep_statement->execute();
+ $result = $prep_statement->fetch(PDO::FETCH_NAMED);
- $sql = "select contact_email from v_contacts where contact_uuid = '".$result["contact_uuid"]."'; ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetch(PDO::FETCH_NAMED);
- $mailto_address_user = $result["contact_email"];
+ $sql = "select contact_email from v_contacts where contact_uuid = '".$result["contact_uuid"]."'; ";
+ $prep_statement = $db->prepare(check_sql($sql));
+ $prep_statement->execute();
+ $result = $prep_statement->fetch(PDO::FETCH_NAMED);
+ $mailto_address_user = $result["contact_email"];
+ }
+ else {
+ //use email-to-fax from address
+ }
- if ($mailto_address_user != $mailto_address_fax) {
+ if ($mailto_address_fax != '' && $mailto_address_user != $mailto_address_fax) {
$mailto_address = "'".$mailto_address_fax."\,".$mailto_address_user."'";
}
else {
@@ -551,27 +525,29 @@ else {
}
//send the fax
- $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
- if ($fp) {
- //prepare the fax command
- $route_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $fax_number);
- $fax_file = $dir_fax_temp."/".$fax_instance_uuid.".tif";
- if (count($route_array) == 0) {
- //send the internal call to the registered extension
+ foreach ($fax_numbers as $fax_number) {
+ $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
+ if ($fp) {
+ //prepare the fax command
+ $route_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $fax_number);
+ $fax_file = $dir_fax_temp."/".$fax_instance_uuid.".tif";
+ if (count($route_array) == 0) {
+ //send the internal call to the registered extension
$fax_uri = "user/".$fax_number."@".$_SESSION['domain_name'];
$t38 = "";
- }
- else {
- //send the external call
+ }
+ else {
+ //send the external call
$fax_uri = $route_array[0];
$t38 = "fax_enable_t38=true,fax_enable_t38_request=true,";
+ }
+ $cmd = "api originate {domain_uuid=".$_SESSION["domain_uuid"].",domain_name=".$_SESSION["domain_name"].",mailto_address='".$mailto_address."',mailfrom_address='".$mailfrom_address."',origination_caller_id_name='".$fax_caller_id_name."',origination_caller_id_number='".$fax_caller_id_number."',fax_ident='".$fax_caller_id_number."',fax_header='".$fax_caller_id_name."',fax_uri=".$fax_uri.",fax_file='".$fax_file."',fax_retry_attempts=1,fax_retry_limit=20,fax_retry_sleep=180,fax_verbose=true,fax_use_ecm=off,".$t38."api_hangup_hook='lua fax_retry.lua'}".$fax_uri." &txfax('".$fax_file."')";
+ //send the command to event socket
+ $response = event_socket_request($fp, $cmd);
+ $response = str_replace("\n", "", $response);
+ $uuid = str_replace("+OK ", "", $response);
+ fclose($fp);
}
- $cmd = "api originate {domain_uuid=".$_SESSION["domain_uuid"].",domain_name=".$_SESSION["domain_name"].",mailto_address='".$mailto_address."',mailfrom_address='".$mailfrom_address."',origination_caller_id_name='".$fax_caller_id_name."',origination_caller_id_number='".$fax_caller_id_number."',fax_ident='".$fax_caller_id_number."',fax_header='".$fax_caller_id_name."',fax_uri=".$fax_uri.",fax_file='".$fax_file."',fax_retry_attempts=1,fax_retry_limit=20,fax_retry_sleep=180,fax_verbose=true,fax_use_ecm=off,".$t38."api_hangup_hook='lua fax_retry.lua'}".$fax_uri." &txfax('".$fax_file."')";
- //send the command to event socket
- $response = event_socket_request($fp, $cmd);
- $response = str_replace("\n", "", $response);
- $uuid = str_replace("+OK ", "", $response);
- fclose($fp);
}
//wait for a few seconds
@@ -583,311 +559,333 @@ else {
exec("cp ".$dir_fax_temp.'/'.$fax_instance_uuid.".pdf ".$dir_fax_sent.'/'.$fax_instance_uuid.".pdf");
}
- //redirect the browser
- $_SESSION["message"] = $response;
- header("Location: fax_box.php?id=".$fax_uuid."&box=sent");
- exit;
+ if (!$included) {
+ //redirect the browser
+ $_SESSION["message"] = $response;
+ header("Location: fax_box.php?id=".$fax_uuid."&box=sent");
+ exit;
+ }
} //end upload and send fax
-//show the header
- require_once "resources/header.php";
-//javascript to toggle input/select boxes
- echo "\n";
- echo "\n";
+ echo "";
+ echo " function contact_load(obj_sel) {";
+ echo " obj_sel.style.display='none';";
+ echo " document.getElementById('fax_recipient').style.display='';";
+ echo " var selected_option_value = obj_sel.options[obj_sel.selectedIndex].value;";
+ echo " var selected_option_values = selected_option_value.split('|', 2);";
+ echo " document.getElementById('fax_recipient').value = selected_option_values[1];";
+ echo " document.getElementById('fax_number').value = selected_option_values[0];";
+ echo " $('#fax_recipient').css({width: '50%'});";
+ echo " $('#fax_number').css({width: '120px'});";
+ echo " }";
-//fax extension form
- echo "\n";
-
-//show the footer
- require_once "resources/footer.php";
-
-// used by pdf generation
- function showgrid($pdf) {
- // generate a grid for placement
- for ($x=0; $x<=8.5; $x+=0.1) {
- for ($y=0; $y<=11; $y+=0.1) {
- $pdf -> SetTextColor(0,0,0);
- $pdf -> SetFont("courier", "", 3);
- $pdf -> Text($x-0.01,$y-0.01,".");
- }
- }
- for ($x=0; $x<=9; $x+=1) {
- for ($y=0; $y<=11; $y+=1) {
- $pdf -> SetTextColor(255,0,0);
- $pdf -> SetFont("times", "", 10);
- $pdf -> Text($x-.02,$y-.01,".");
- $pdf -> SetFont("courier", "", 4);
- $pdf -> Text($x+0.01,$y+0.035,$x.",".$y);
- }
+// used for initial element alignment during pdf generation
+/*
+function showgrid($pdf) {
+ // generate a grid for placement
+ for ($x=0; $x<=8.5; $x+=0.1) {
+ for ($y=0; $y<=11; $y+=0.1) {
+ $pdf -> SetTextColor(0,0,0);
+ $pdf -> SetFont("courier", "", 3);
+ $pdf -> Text($x-0.01,$y-0.01,".");
}
}
-
+ for ($x=0; $x<=9; $x+=1) {
+ for ($y=0; $y<=11; $y+=1) {
+ $pdf -> SetTextColor(255,0,0);
+ $pdf -> SetFont("times", "", 10);
+ $pdf -> Text($x-.02,$y-.01,".");
+ $pdf -> SetFont("courier", "", 4);
+ $pdf -> Text($x+0.01,$y+0.035,$x.",".$y);
+ }
+ }
+}
+*/
?>
\ No newline at end of file
diff --git a/app/fax/resources/functions/object_to_array.php b/app/fax/resources/functions/object_to_array.php
new file mode 100644
index 0000000000..45e8c2a1b7
--- /dev/null
+++ b/app/fax/resources/functions/object_to_array.php
@@ -0,0 +1,9 @@
+
\ No newline at end of file
diff --git a/app/fax/resources/functions/parse_attachments.php b/app/fax/resources/functions/parse_attachments.php
new file mode 100644
index 0000000000..9999660636
--- /dev/null
+++ b/app/fax/resources/functions/parse_attachments.php
@@ -0,0 +1,48 @@
+parts) && count($structure->parts)) {
+
+ for($i = 0; $i < count($structure->parts); $i++) {
+
+ if($structure->parts[$i]->ifdparameters) {
+ foreach($structure->parts[$i]->dparameters as $object) {
+ if(strtolower($object->attribute) == 'filename') {
+ $attachments[$i]['is_attachment'] = true;
+ $attachments[$i]['filename'] = $object->value;
+ }
+ }
+ }
+
+ if($structure->parts[$i]->ifparameters) {
+ foreach($structure->parts[$i]->parameters as $object) {
+ if(strtolower($object->attribute) == 'name') {
+ $attachments[$i]['is_attachment'] = true;
+ $attachments[$i]['name'] = $object->value;
+ }
+ }
+ }
+
+ if($attachments[$i]['is_attachment']) {
+ $attachments[$i]['attachment'] = imap_fetchbody($connection, $message_number, $i+1, $option);
+ if($structure->parts[$i]->encoding == 3) { // 3 = BASE64
+ $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
+ $attachments[$i]['size'] = strlen($attachments[$i]['attachment']);
+ }
+ elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
+ $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
+ $attachments[$i]['size'] = strlen($attachments[$i]['attachment']);
+ }
+ }
+
+ unset($attachments[$i]['is_attachment']);
+ }
+
+ }
+ return array_values($attachments); //reindex
+}
+
+?>
\ No newline at end of file