From 95e965b108d385291128fe19fe150fdc2a7fc4e5 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Sat, 9 May 2015 05:22:29 +0000 Subject: [PATCH] Fax: Upgrade script to generate and store meta-data from existing fax files, fix Lua script to insert correct fax file path into db, JavaScript prompt corrections, adjust redirect after send to use new interface, fix delete so files on file system are removed (using path from db), fix paging and sorting on Inbox and Sent, fix TIF to PDF conversion for viewing sent/received faxes (if PDF version not present). --- app/fax/app_languages.php | 22 +- app/fax/fax.php | 12 +- app/fax/fax_box.php | 478 ------------------ app/fax/fax_delete.php | 2 +- app/fax/fax_edit.php | 4 +- app/fax/fax_file_delete.php | 80 ++- app/fax/fax_files.php | 237 +++++---- ...ax_box_remote.php => fax_files_remote.php} | 29 +- app/fax/fax_send.php | 11 +- resources/install/scripts/fax_retry.lua | 1 + 10 files changed, 219 insertions(+), 657 deletions(-) delete mode 100644 app/fax/fax_box.php rename app/fax/{fax_box_remote.php => fax_files_remote.php} (82%) diff --git a/app/fax/app_languages.php b/app/fax/app_languages.php index c4733beca3..185eb77b62 100644 --- a/app/fax/app_languages.php +++ b/app/fax/app_languages.php @@ -160,13 +160,13 @@ $text['message-delete']['pt-br'] = "Remoção Efetuada"; $text['message-delete']['pl'] = "Usunięto poprawnie"; $text['message-delete']['sv-se'] = "Borttagning Klar"; -$text['message-confirm-delete']['en-us'] = "Are you sure you want to delete this?"; -$text['message-confirm-delete']['es-cl'] = "¿Realmente desea eliminar esto?"; -$text['message-confirm-delete']['pt-pt'] = "Tem a certeza que deseja remover?"; -$text['message-confirm-delete']['fr-fr'] = "Voulez-vous vraiment supprimer cela?"; -$text['message-confirm-delete']['pt-br'] = "Deseja realmente remover isto?"; -$text['message-confirm-delete']['pl'] = "Czy na pewno chcesz to usunąć?"; -$text['message-confirm-delete']['sv-se'] = "Vill du verkligen radera detta?"; +$text['confirm-delete']['en-us'] = "Are you sure you want to delete this?"; +$text['confirm-delete']['es-cl'] = "¿Realmente desea eliminar esto?"; +$text['confirm-delete']['pt-pt'] = "Tem a certeza que deseja remover?"; +$text['confirm-delete']['fr-fr'] = "Voulez-vous vraiment supprimer cela?"; +$text['confirm-delete']['pt-br'] = "Deseja realmente remover isto?"; +$text['confirm-delete']['pl'] = "Czy na pewno chcesz to usunąć?"; +$text['confirm-delete']['sv-se'] = "Vill du verkligen radera detta?"; $text['message-cannot_connect']['en-us'] = "Connection Failed"; $text['message-cannot_connect']['es-cl'] = "Error de Conexión"; @@ -1352,14 +1352,6 @@ $text['confirm-ext']['pl'] = "Proszę wprowadzić numer wewnętrzny"; $text['confirm-ext']['sv-se'] = "Por favor indique: Extensión "; $text['confirm-ext']['es-cl'] = ""; -$text['confirm-delete']['en-us'] = "Delete Complete"; -$text['confirm-delete']['es-cl'] = "Eliminación Completada"; -$text['confirm-delete']['pt-pt'] = "Remoção Efectuada"; -$text['confirm-delete']['fr-fr'] = "Supprimé"; -$text['confirm-delete']['pt-br'] = "Deseja realmente remover isto?"; -$text['confirm-delete']['pl'] = "Czy na pewno chcesz to usunąć?"; -$text['confirm-delete']['sv-se'] = "Borttagning slutförd"; - $text['confirm-copy-info']['en-us'] = "Do you really want to copy this?"; $text['confirm-copy-info']['es-cl'] = "¿Desea realmente copiar esto?"; $text['confirm-copy-info']['pt-pt'] = "Deseja realmente copiar isto?"; diff --git a/app/fax/fax.php b/app/fax/fax.php index 516720ebaa..6f6db6e935 100644 --- a/app/fax/fax.php +++ b/app/fax/fax.php @@ -152,8 +152,14 @@ require_once "resources/paging.php"; echo " ".$text['label-new']."  "; } if (permission_exists('fax_inbox_view')) { - $file = ($row['fax_email_connection_host'] != '' && $row['fax_email_connection_mailbox'] != '') ? "fax_box_remote.php" : "fax_files.php"; - $box = ($row['fax_email_connection_host'] != '' && $row['fax_email_connection_mailbox'] != '') ? $row['fax_email_connection_mailbox'] : 'inbox'; + if ($row['fax_email_connection_host'] != '') { + $file = "fax_box_remote.php"; + $box = $row['fax_email_connection_mailbox']; + } + else { + $file = "fax_files.php"; + $box = 'inbox'; + } echo " ".$text['label-inbox']."  "; } if (permission_exists('fax_sent_view')) { @@ -169,7 +175,7 @@ require_once "resources/paging.php"; echo "$v_link_label_edit"; } if (permission_exists('fax_extension_delete')) { - echo "$v_link_label_delete"; + echo "$v_link_label_delete"; } echo " \n"; echo "\n"; diff --git a/app/fax/fax_box.php b/app/fax/fax_box.php deleted file mode 100644 index b3927db3b5..0000000000 --- a/app/fax/fax_box.php +++ /dev/null @@ -1,478 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2015 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane - James Rose -*/ -include "root.php"; -require_once "resources/require.php"; -require_once "resources/check_auth.php"; -if (permission_exists('fax_extension_view')) { - //access granted -} -else { - echo "access denied"; - exit; -} - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//get the fax_extension and save it as a variable - if (strlen($_REQUEST["fax_extension"]) > 0) { - $fax_extension = check_str($_REQUEST["fax_extension"]); - } - -//get fax extension - if (strlen($_GET['id']) > 0) { - //get the key - $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_name = $row["fax_name"]; - $fax_extension = $row["fax_extension"]; - //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); - -//delete a fax - if ($_GET['a'] == "del") { - $file_name = substr(check_str($_GET['filename']), 0, -4); - $file_ext = substr(check_str($_GET['filename']), -3); - if ($_GET['type'] == "fax_inbox" && permission_exists('fax_inbox_delete')) { - unlink($fax_dir.'/'.$fax_extension.'/inbox/'.$file_name.".tif"); - unlink($fax_dir.'/'.$fax_extension.'/inbox/'.$file_name.".pdf"); - $box = 'inbox'; - } - if ($_GET['type'] == "fax_sent" && permission_exists('fax_sent_delete')) { - unlink($fax_dir.'/'.$fax_extension.'/sent/'.$file_name.".tif"); - unlink($fax_dir.'/'.$fax_extension.'/sent/'.$file_name.".pdf"); - $box = 'sent'; - } - unset($file_name); - unset($file_ext); - - $_SESSION["message"] = $text['confirm-delete']; - header("Location: fax_box.php?id=".$fax_uuid."&box=".$box); - exit; - } - -//download the fax - if ($_GET['a'] == "download") { - session_cache_limiter('public'); - //test to see if it is in the inbox or sent directory. - if ($_GET['type'] == "fax_inbox") { - if (file_exists($fax_dir.'/'.check_str($_GET['ext']).'/inbox/'.check_str($_GET['filename']))) { - $tmp_faxdownload_file = $fax_dir.'/'.check_str($_GET['ext']).'/inbox/'.check_str($_GET['filename']); - } - } - else if ($_GET['type'] == "fax_sent") { - if (file_exists($fax_dir.'/'.check_str($_GET['ext']).'/sent/'.check_str($_GET['filename']))) { - $tmp_faxdownload_file = $fax_dir.'/'.check_str($_GET['ext']).'/sent/'.check_str($_GET['filename']); - } - } - //let's see if we found it. - if (strlen($tmp_faxdownload_file) > 0) { - $fd = fopen($tmp_faxdownload_file, "rb"); - if ($_GET['t'] == "bin") { - header("Content-Type: application/force-download"); - header("Content-Type: application/octet-stream"); - header("Content-Description: File Transfer"); - header('Content-Disposition: attachment; filename="'.check_str($_GET['filename']).'"'); - } - else { - $file_ext = substr(check_str($_GET['filename']), -3); - if ($file_ext == "tif") { - header("Content-Type: image/tiff"); - } - else if ($file_ext == "png") { - header("Content-Type: image/png"); - } - else if ($file_ext == "jpg") { - header('Content-Type: image/jpeg'); - } - else if ($file_ext == "pdf") { - header("Content-Type: application/pdf"); - } - } - header('Accept-Ranges: bytes'); - header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 - header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // date in the past - header("Content-Length: " . filesize($tmp_faxdownload_file)); - fpassthru($fd); - } - else { - echo "".$text['label-file'].""; - } - exit; - } - -//get the fax extension - if (strlen($fax_extension) > 0) { - //set the fax directories. example /usr/local/freeswitch/storage/fax/329/inbox - $dir_fax_inbox = $fax_dir.'/'.$fax_extension.'/inbox'; - $dir_fax_sent = $fax_dir.'/'.$fax_extension.'/sent'; - $dir_fax_temp = $fax_dir.'/'.$fax_extension.'/temp'; - - //make sure the directories exist - if (!is_dir($_SESSION['switch']['storage']['dir'])) { - mkdir($_SESSION['switch']['storage']['dir']); - chmod($dir_fax_sent,0774); - } - if (!is_dir($fax_dir.'/'.$fax_extension)) { - mkdir($fax_dir.'/'.$fax_extension,0774,true); - chmod($fax_dir.'/'.$fax_extension,0774); - } - if (!is_dir($dir_fax_inbox)) { - mkdir($dir_fax_inbox,0774,true); - chmod($dir_fax_inbox,0774); - } - if (!is_dir($dir_fax_sent)) { - mkdir($dir_fax_sent,0774,true); - chmod($dir_fax_sent,0774); - } - if (!is_dir($dir_fax_temp)) { - mkdir($dir_fax_temp,0774,true); - chmod($dir_fax_temp,0774); - } - } - -//show the header - require_once "resources/header.php"; - -//show the inbox - if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) { - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['header-inbox'].": ".$fax_name." (".$fax_extension.")\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; - - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " "; - - if ($handle = opendir($dir_fax_inbox)) { - //build an array of the files in the inbox - $i = 0; - $files = array(); - while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != ".." && is_file($dir_fax_inbox.'/'.$file)) { - $file_path = $dir_fax_inbox.'/'.$file; - $modified = filemtime($file_path); - $index = $modified.$file; - $files[$index]['file'] = $file; - $files[$index]['name'] = substr($file, 0, -4); - $files[$index]['ext'] = substr($file, -3); - //$files[$index]['path'] = $file_path; - $files[$index]['size'] = filesize($file_path); - $files[$index]['size_bytes'] = byte_convert(filesize($file_path)); - $files[$index]['modified'] = filemtime($file_path); - $file_name_array[$i++] = $index; - } - } - closedir($handle); - //order the index array - sort($file_name_array,SORT_STRING); - - //loop through the file array - foreach($file_name_array as $i) { - if (strtolower($files[$i]['ext']) == "tif") { - $file = $files[$i]['file']; - $file_name = $files[$i]['name']; - $file_ext = $files[$i]['ext']; - $file_modified = $files[$i]['modified']; - $file_size_bytes = byte_convert($files[$i]['size']); - if (!file_exists($dir_fax_inbox.'/'.$file_name.".pdf")) { - //convert the tif to pdf - chdir($dir_fax_inbox); - if (is_file("/usr/local/bin/tiff2pdf")) { - exec("/usr/local/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_inbox.'/'.$file_name.".tif"); - } - if (is_file("/usr/bin/tiff2pdf")) { - exec("/usr/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_inbox.'/'.$file_name.".tif"); - } - } - //if (!file_exists($dir_fax_inbox.'/'.$file_name.".jpg")) { - // //convert the tif to jpg - // chdir($dir_fax_inbox); - // if (is_file("/usr/local/bin/tiff2rgba")) { - // exec("/usr/local/bin/tiff2rgba ".$file_name.".tif ".$dir_fax_inbox.'/'.$file_name.".jpg"); - // } - // if (is_file("/usr/bin/tiff2rgba")) { - // exec("/usr/bin/tiff2rgba ".$file_name.".tif ".$dir_fax_inbox.'/'.$file_name.".jpg"); - // } - //} - echo "\n"; - echo " \n"; - - echo " \n"; - - //echo " \n"; - - echo " \n"; - - echo " \n"; - - echo " \n"; - echo "\n"; - $c = ($c) ? 0 : 1; - } - } - } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
".$text['table-file']."".$text['table-view']."".$text['table-modified']."".$text['table-size']."
\n"; - echo " \n"; - echo " $file_name"; - echo " "; - echo " \n"; - if (file_exists($dir_fax_inbox.'/'.$file_name.".pdf")) { - echo " \n"; - echo " PDF"; - echo " "; - } - else { - echo " \n"; - } - echo " \n"; - //if (file_exists($dir_fax_inbox.'/'.$file_name.".jpg")) { - // echo " \n"; - // echo " jpg"; - // echo " "; - //} - //else { - // echo " \n"; - //} - //echo "  \n"; - echo " ".date("F d Y H:i:s", $file_modified); - echo " \n"; - echo " ".$file_size_bytes; - echo " \n"; - echo " \n"; - echo " \n"; - if (permission_exists('fax_inbox_delete')) { - echo " \n"; - } - echo " \n"; - echo "
$v_link_label_delete
\n"; - echo "
\n"; - echo "


\n"; - if (if_group('superadmin')) { - echo "".$text['label-location'].":  ".$dir_fax_inbox; - } - echo "

\n"; - } - -//show the sent box - if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) { - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['header-sent'].": ".$fax_name." (".$fax_extension.")\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - echo "\n"; - echo " \n"; - echo " "; - - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; - - if ($handle = opendir($dir_fax_sent)) { - //build an array of the files in the sent box - $i = 0; - $files = array(); - while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != ".." && is_file($dir_fax_sent.'/'.$file)) { - $file_path = $dir_fax_sent.'/'.$file; - $modified = filemtime($file_path); - $index = $modified.$file; - $files[$index]['file'] = $file; - $files[$index]['name'] = substr($file, 0, -4); - $files[$index]['ext'] = substr($file, -3); - //$files[$index]['path'] = $file_path; - $files[$index]['size'] = filesize($file_path); - $files[$index]['size_bytes'] = byte_convert(filesize($file_path)); - $files[$index]['modified'] = filemtime($file_path); - $file_name_array[$i++] = $index; - } - } - closedir($handle); - //order the index array - rsort($file_name_array,SORT_STRING); - - //loop through the file array - foreach($file_name_array as $i) { - if (strtolower($files[$i]['ext']) == "tif") { - $file = $files[$i]['file']; - $file_name = $files[$i]['name']; - $file_ext = $files[$i]['ext']; - $file_modified = $files[$i]['modified']; - $file_size_bytes = byte_convert($files[$i]['size']); - - if (!file_exists($dir_fax_sent.'/'.$file_name.".pdf")) { - //convert the tif to pdf - chdir($dir_fax_sent); - if (is_file("/usr/local/bin/tiff2pdf")) { - exec("/usr/local/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_sent.'/'.$file_name.".tif"); - } - if (is_file("/usr/bin/tiff2pdf")) { - exec("/usr/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_sent.'/'.$file_name.".tif"); - } - } - if (!file_exists($dir_fax_sent.'/'.$file_name.".jpg")) { - //convert the tif to jpg - //chdir($dir_fax_sent); - //if (is_file("/usr/local/bin/tiff2rgba")) { - // exec("/usr/local/bin/tiff2rgba -c jpeg -n ".$file_name.".tif ".$dir_fax_sent.'/'.$file_name.".jpg"); - //} - //if (is_file("/usr/bin/tiff2rgba")) { - // exec("/usr/bin/tiff2rgba -c lzw -n ".$file_name.".tif ".$dir_fax_sent.'/'.$file_name.".jpg"); - //} - } - echo "\n"; - echo " \n"; - echo " \n"; - //echo " \n"; - echo " \n"; - - echo " \n"; - - echo " \n"; - echo "\n"; - $c = ($c) ? 0 : 1; - } //check if the file is a .tif file - } - } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
".$text['table-file']."\n"; - echo " ".$text['table-view']."\n"; - echo " ".$text['table-modified']."\n"; - echo " ".$text['table-size']."\n"; - echo "
\n"; - echo " \n"; - echo " $file"; - echo " "; - echo " \n"; - if (file_exists($dir_fax_sent.'/'.$file_name.".pdf")) { - echo " \n"; - echo " PDF"; - echo " "; - } - else { - echo " \n"; - } - echo " \n"; - //if (file_exists($dir_fax_sent.'/'.$file_name.".jpg")) { - // echo " \n"; - // echo " jpg"; - // echo " "; - //} - //else { - // echo " \n"; - //} - //echo " \n"; - echo " ".date("F d Y H:i:s", $file_modified); - echo " \n"; - echo " ".$file_size_bytes; - echo " \n"; - echo " \n"; - echo " \n"; - if (permission_exists('fax_sent_delete')) { - echo " \n"; - } - echo " \n"; - echo "
$v_link_label_delete
\n"; - echo "
\n"; - echo "


\n"; - if (if_group('superadmin')) { - echo "".$text['label-location'].":  ".$dir_fax_sent; - } - echo "

\n"; - } - echo " "; - echo " "; - echo ""; - -//show the footer - require_once "resources/footer.php"; -?> \ No newline at end of file diff --git a/app/fax/fax_delete.php b/app/fax/fax_delete.php index a9d3d73674..406cbc8cf3 100644 --- a/app/fax/fax_delete.php +++ b/app/fax/fax_delete.php @@ -91,7 +91,7 @@ else { } //redirect the user - $_SESSION["message"] = $text['confirm-delete']; + $_SESSION["message"] = $text['message-delete']; header("Location: fax.php"); return; diff --git a/app/fax/fax_edit.php b/app/fax/fax_edit.php index 4461951f72..80dc609758 100644 --- a/app/fax/fax_edit.php +++ b/app/fax/fax_edit.php @@ -151,7 +151,7 @@ else { $db->exec(check_sql($sql)); //redirect the browser - $_SESSION["message"] = $text['confirm-delete']; + $_SESSION["message"] = $text['message-delete']; header("Location: fax_edit.php?id=".$fax_uuid); return; } @@ -767,7 +767,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo " \n"; echo " ".$field['username']."\n"; echo " \n"; - echo " $v_link_label_delete\n"; + echo " $v_link_label_delete\n"; echo " \n"; echo " \n"; $assigned_user_uuids[] = $field['user_uuid']; diff --git a/app/fax/fax_file_delete.php b/app/fax/fax_file_delete.php index d1e2c502b7..6f70a3fc4d 100644 --- a/app/fax/fax_file_delete.php +++ b/app/fax/fax_file_delete.php @@ -42,20 +42,19 @@ else { //get the id if (isset($_REQUEST["id"])) { - $id = check_str($_REQUEST["id"]); + $fax_file_uuid = check_str($_REQUEST["id"]); } //validate the id - if (strlen($id) > 0) { + if (strlen($fax_file_uuid) > 0) { //get the fax file data $sql = "select * from v_fax_files "; - $sql .= "where fax_file_uuid = '$id' "; - //echo $sql."\n"; + $sql .= "where fax_file_uuid = '".$fax_file_uuid."' "; + $sql .= "and domain_uuid = '".$_SESSION['domain_uuid']."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { - $domain_uuid = $row["domain_uuid"]; $fax_uuid = $row["fax_uuid"]; $fax_mode = $row["fax_mode"]; $fax_file_path = $row["fax_file_path"]; @@ -63,57 +62,42 @@ else { } unset($prep_statement); - //get the fax file data - $sql = "select * from v_fax_files "; - $sql .= "where fax_uuid = '$fax_uuid' "; - $sql .= "and domain_uuid = '$domain_uuid' "; - //echo $sql."\n"; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $fax_extension = $row["fax_extension"]; - } - unset($prep_statement); - - //delete fax_file - $sql = "delete from v_fax_files "; - $sql .= "where fax_file_uuid = '$id' "; - $sql .= "and domain_uuid = '$domain_uuid' "; - //echo $sql."\n"; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - unset($prep_statement); - //set the type - if ($fax_mode == 'rx') { - $type = 'inbox'; + if ($fax_mode == 'rx') { $type = 'inbox'; } + if ($fax_mode == 'tx') { $type = 'sent'; } + + //delete fax file(s) + if (substr_count($fax_file_path, '/temp/') > 0) { + $fax_file_path = str_replace('/temp/', '/'.$type.'/', $fax_file_path); } - if ($fax_mode == 'tx') { - $type = 'sent'; + if (file_exists($fax_file_path)) { + @unlink($fax_file_path); + } + if ($fax_file_type == 'tif') { + $fax_file_path = str_replace('.tif', '.pdf', $fax_file_path); + if (file_exists($fax_file_path)) { + @unlink($fax_file_path); + } + } + else if ($fax_file_type == 'pdf') { + $fax_file_path = str_replace('.pdf', '.tif', $fax_file_path); + if (file_exists($fax_file_path)) { + @unlink($fax_file_path); + } } - //set the fax directory - $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null); - $file = basename($row['fax_file_path']); - $file_ext = substr($file, -3); - $dir_fax = $fax_dir.'/'.$fax_extension.'/'.$type; - if (strtolower(substr($file, -3)) == "tif" || strtolower(substr($file, -3)) == "pdf") { - $file_name = substr($file, 0, (strlen($file) -4)); - } + //delete fax file record + $sql = "delete from v_fax_files "; + $sql .= "where fax_file_uuid = '".$fax_file_uuid."' "; + $sql .= "and domain_uuid = '".$_SESSION['domain_uuid']."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + unset($prep_statement); - //if the file does not exist then remove temp/ out of the path - if (!file_exists($fax_file_path)) { - $file = str_replace("temp/", $type."/", $file); - } - - //delete the files - unlink($dir_fax.'/'.$file_name.'.tif'); - unlink($dir_fax.'/'.$file_name.'.pdf'); + $_SESSION['message'] = $text['message-delete']; } //redirect the user - $_SESSION['message'] = $text['message-delete']; header('Location: fax_files.php?id='.$fax_uuid.'&box='.$type); ?> \ No newline at end of file diff --git a/app/fax/fax_files.php b/app/fax/fax_files.php index f3110d9907..b79431d31f 100644 --- a/app/fax/fax_files.php +++ b/app/fax/fax_files.php @@ -51,13 +51,13 @@ else { } if (if_group("superadmin") || if_group("admin")) { //show all fax extensions - $sql = "select * from v_fax "; + $sql = "select fax_name, fax_extension 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 = "select fax_name, fax_extension 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' "; @@ -88,6 +88,56 @@ else { //set the fax directory $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null); +//download the fax + if ($_GET['a'] == "download") { + session_cache_limiter('public'); + //test to see if it is in the inbox or sent directory. + if ($_GET['type'] == "fax_inbox") { + if (file_exists($fax_dir.'/'.check_str($_GET['ext']).'/inbox/'.check_str($_GET['filename']))) { + $tmp_faxdownload_file = $fax_dir.'/'.check_str($_GET['ext']).'/inbox/'.check_str($_GET['filename']); + } + } + else if ($_GET['type'] == "fax_sent") { + if (file_exists($fax_dir.'/'.check_str($_GET['ext']).'/sent/'.check_str($_GET['filename']))) { + $tmp_faxdownload_file = $fax_dir.'/'.check_str($_GET['ext']).'/sent/'.check_str($_GET['filename']); + } + } + //let's see if we found it. + if (strlen($tmp_faxdownload_file) > 0) { + $fd = fopen($tmp_faxdownload_file, "rb"); + if ($_GET['t'] == "bin") { + header("Content-Type: application/force-download"); + header("Content-Type: application/octet-stream"); + header("Content-Description: File Transfer"); + header('Content-Disposition: attachment; filename="'.check_str($_GET['filename']).'"'); + } + else { + $file_ext = substr(check_str($_GET['filename']), -3); + if ($file_ext == "tif") { + header("Content-Type: image/tiff"); + } + else if ($file_ext == "png") { + header("Content-Type: image/png"); + } + else if ($file_ext == "jpg") { + header('Content-Type: image/jpeg'); + } + else if ($file_ext == "pdf") { + header("Content-Type: application/pdf"); + } + } + header('Accept-Ranges: bytes'); + header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 + header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // date in the past + header("Content-Length: " . filesize($tmp_faxdownload_file)); + fpassthru($fd); + } + else { + echo "".$text['label-file'].""; + } + exit; + } + //get the fax extension if (strlen($fax_extension) > 0) { //set the fax directories. example /usr/local/freeswitch/storage/fax/329/inbox @@ -122,17 +172,8 @@ else { require_once "resources/header.php"; require_once "resources/paging.php"; -//show the content - echo "
"; - echo "\n"; - echo "\n"; - echo "
\n"; - echo "
"; - //show the header - //$text['title-fax_files'] - //$text['description-fax_file'] - echo "\n"; + echo "
\n"; echo " \n"; echo " "; - echo ""; - echo "
\n"; if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) { @@ -159,7 +200,6 @@ else { if ($_REQUEST['box'] == 'sent') { $sql .= "and fax_mode = 'tx' "; } - if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } $prep_statement = $db->prepare($sql); if ($prep_statement) { $prep_statement->execute(); @@ -173,12 +213,12 @@ else { } //prepare to page the results - $rows_per_page = 10; - $param = ""; + $rows_per_page = 50; + $param = "&id=".$_GET['id']."&box=".$_GET['box']."&order_by=".$_GET['order_by']."&order=".$_GET['order']; $page = $_GET['page']; - if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } - list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page); - $offset = $rows_per_page * $page; + if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } + list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page); + $offset = $rows_per_page * $page; //get the list $sql = "select * from v_fax_files "; @@ -190,7 +230,7 @@ else { if ($_REQUEST['box'] == 'sent') { $sql .= "and fax_mode = 'tx' "; } - if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $sql .= "order by ".((strlen($order_by) > 0) ? $order_by.' '.$order : "fax_date desc")." "; $sql .= "limit $rows_per_page offset $offset "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); @@ -203,21 +243,18 @@ else { $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; - echo "
\n"; echo "\n"; echo "\n"; + echo th_order_by('fax_caller_id_name', $text['label-fax_caller_id_name'], $order_by, $order, "&id=".$_GET['id']."&box=".$_GET['box']."&page=".$_GET['page']); + echo th_order_by('fax_caller_id_number', $text['label-fax_caller_id_number'], $order_by, $order, "&id=".$_GET['id']."&box=".$_GET['box']."&page=".$_GET['page']); + if ($_REQUEST['box'] == 'sent') { + echo th_order_by('fax_destination', $text['label-fax_destination'], $order_by, $order, "&id=".$_GET['id']."&box=".$_GET['box']."&page=".$_GET['page']); + } echo "\n"; echo "\n"; - echo th_order_by('fax_number', $text['label-fax_number'], $order_by, $order); - //echo th_order_by('fax_file_type', $text['label-fax_file_type'], $order_by, $order); - //echo th_order_by('fax_file_path', $text['label-fax_file_path'], $order_by, $order); - echo th_order_by('fax_caller_id_name', $text['label-fax_caller_id_name'], $order_by, $order); - echo th_order_by('fax_caller_id_number', $text['label-fax_caller_id_number'], $order_by, $order); - echo th_order_by('fax_date', $text['label-fax_date'], $order_by, $order); - //echo th_order_by('fax_epoch', $text['label-fax_epoch'], $order_by, $order); - //echo th_order_by('fax_base64', $text['label-fax_base64'], $order_by, $order); - echo "\n"; - echo "\n"; + echo th_order_by('fax_date', $text['label-fax_date'], $order_by, $order, "&id=".$_GET['id']."&box=".$_GET['box']."&page=".$_GET['page']); + echo "\n"; + echo "\n"; if ($result_count > 0) { foreach($result as $row) { $file = basename($row['fax_file_path']); @@ -239,43 +276,85 @@ else { file_put_contents($dir_fax_sent.'/'.$file, base64_decode($row['fax_base64'])); } } - - } - //convert the tif to pdf - if (!file_exists($dir_fax_inbox.'/'.$file_name.".pdf")) { - if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) { - chdir($dir_fax_inbox); - if (is_file("/usr/local/bin/tiff2pdf")) { - exec("/usr/local/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_inbox.'/'.$file_name.".tif"); - } - if (is_file("/usr/bin/tiff2pdf")) { - exec("/usr/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_inbox.'/'.$file_name.".tif"); - } - } - if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) { - chdir($dir_fax_sent); - if (is_file("/usr/local/bin/tiff2pdf")) { - exec("/usr/local/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_sent.'/'.$file_name.".tif"); - } - if (is_file("/usr/bin/tiff2pdf")) { - exec("/usr/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_sent.'/'.$file_name.".tif"); - } - } } - echo "\n"; - echo "\n"; - echo " "; + echo "\n"; + echo " \n"; + echo " \n"; + if ($_REQUEST['box'] == 'sent') { + echo " \n"; + } + echo " \n"; - echo " \n"; - //echo " \n"; - //echo " \n"; - echo " \n"; - //echo " \n"; - echo " \n"; - echo " \n"; echo " \n"; - //echo " \n"; - //echo " \n"; - echo " \n"; echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } + $c = ($c) ? 0 : 1; } //end foreach unset($sql, $result, $row_count); } //end if results //show the paging controls - echo "\n"; - echo "\n"; - echo "\n"; - echo "
".$text['table-file']."".$text['table-view']." 
 
\n"; + //convert the tif to pdf + unset($dir_fax); if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) { - echo " \n"; + if (!file_exists($dir_fax_inbox.'/'.$file_name.".pdf")) { + $dir_fax = $dir_fax_inbox; + } } if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) { - echo " \n"; + if (!file_exists($dir_fax_sent.'/'.$file_name.".pdf")) { + $dir_fax = $dir_fax_sent; + } + } + if ($dir_fax != '') { + chdir($dir_fax); + //get fax resolution (ppi, W & H) + $resp = exec("tiffinfo ".$file_name.".tif | grep 'Resolution:'"); + $resp_array = explode(' ', trim($resp)); + $ppi_w = (int) $resp_array[1]; + $ppi_h = (int) $resp_array[2]; + unset($resp_array); + $gs_r = $ppi_w.'x'.$ppi_h; //used by ghostscript + //get page dimensions/size (pixels/inches, W & H) + $resp = exec("tiffinfo ".$file_name.".tif | grep 'Image Width:'"); + $resp_array = explode(' ', trim($resp)); + $pix_w = $resp_array[2]; + $pix_h = $resp_array[5]; + unset($resp_array); + $gs_g = $pix_w.'x'.$pix_h; //used by ghostscript + $page_width = $pix_w / $ppi_w; + $page_height = $pix_h / $ppi_h; + if ($page_width > 8.4 && $page_height > 13) { + $page_width = 8.5; + $page_height = 14; + $page_size = 'legal'; + } + else if ($page_width > 8.4 && $page_height < 12) { + $page_width = 8.5; + $page_height = 11; + $page_size = 'letter'; + } + else if ($page_width < 8.4 && $page_height > 11) { + $page_width = 8.3; + $page_height = 11.7; + $page_size = 'a4'; + } + //generate pdf (a work around, as tiff2pdf improperly inverts the colors) + $cmd_tif2pdf = "tiff2pdf -i -u i -p ".$page_size." -w ".$page_width." -l ".$page_height." -f -o ".$dir_fax_temp.'/'.$file_name.".pdf ".$dir_fax.'/'.$file_name.".tif"; + //echo $cmd_tif2pdf."
"; + exec($cmd_tif2pdf); + chdir($dir_fax_temp); + $cmd_pdf2tif = "gs -q -sDEVICE=tiffg3 -r".$gs_r." -g".$gs_g." -dNOPAUSE -sOutputFile=".$file_name."_temp.tif -- ".$file_name.".pdf -c quit"; + //echo $cmd_pdf2tif."
"; + exec($cmd_pdf2tif); //convert pdf to tif + @unlink($dir_fax_temp.'/'.$file_name.".pdf"); + $cmd_tif2pdf = "tiff2pdf -i -u i -p ".$page_size." -w ".$page_width." -l ".$page_height." -f -o ".$dir_fax.'/'.$file_name.".pdf ".$dir_fax_temp.'/'.$file_name."_temp.tif"; + //echo $cmd_tif2pdf."
"; + exec($cmd_tif2pdf); + @unlink($dir_fax_temp.'/'.$file_name."_temp.tif"); + } + echo "
".$row['fax_caller_id_name']." ".format_phone($row['fax_caller_id_number'])." ".format_phone($row['fax_destination'])." \n"; + if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) { + echo " \n"; + } + if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) { + echo " \n"; } echo " $file_name"; echo " "; echo " \n"; + echo " \n"; if ($_REQUEST['box'] == 'inbox') { $dir_fax = $dir_fax_inbox; } @@ -284,65 +363,33 @@ else { } if (file_exists($dir_fax.'/'.$file_name.".pdf")) { if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) { - echo " \n"; + echo " PDF\n"; } if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) { - echo " \n"; + echo " PDF\n"; } - echo " PDF"; - echo " "; } else { echo " \n"; } echo " ".basename($row['fax_file_path'])." PDF ".$row['fax_number']." ".$row['fax_file_type']." ".$row['fax_caller_id_name']." ".$row['fax_caller_id_number']." ".date("F d Y H:i:s", strtotime($row['fax_date']))." ".$row['fax_epoch']." ".$row['fax_base64']." "; - //if (permission_exists('fax_file_edit')) { - // echo "$v_link_label_edit"; - //} + echo " "; if (permission_exists('fax_file_delete')) { echo "$v_link_label_delete"; } echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
 $paging_controls"; - echo " "; - echo "
\n"; - echo "
"; - echo "
"; echo "

"; -//close the table and div - echo "
"; - echo ""; + echo "
".$paging_controls."
\n"; echo "

"; //include the footer diff --git a/app/fax/fax_box_remote.php b/app/fax/fax_files_remote.php similarity index 82% rename from app/fax/fax_box_remote.php rename to app/fax/fax_files_remote.php index 95a6dd5c78..ddc87a7dca 100644 --- a/app/fax/fax_box_remote.php +++ b/app/fax/fax_files_remote.php @@ -187,11 +187,13 @@ else { echo "\n"; echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; if (permission_exists('fax_inbox_delete')) { - echo " \n"; + echo " \n"; } echo " "; @@ -202,19 +204,24 @@ else { foreach ($emails as $email_id) { $metadata = object_to_array(imap_fetch_overview($connection, $email_id, FT_UID)); $attachment = parse_attachments($connection, $email_id, FT_UID); - - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; + $file_name = $attachment[0]['filename']; + $caller_id_name = substr($file_name, 0, strpos($file_name, '-')); + $caller_id_number = (is_numeric($caller_id_name)) ? format_phone((int) $caller_id_name) : null; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; if (permission_exists('fax_inbox_delete')) { - echo " \n"; + echo " \n"; } - echo "\n"; + echo " \n"; // $fax_message = imap_fetchbody($connection, $email_id, '1.1', FT_UID); // if ($fax_message == '') { // $fax_message = imap_fetchbody($connection, $email_id, '1', FT_UID); // } + $c = ($c) ? 0 : 1; } } diff --git a/app/fax/fax_send.php b/app/fax/fax_send.php index d8ac802913..f2e10fb9c4 100644 --- a/app/fax/fax_send.php +++ b/app/fax/fax_send.php @@ -196,14 +196,17 @@ if (!$included) { //set resolution switch ($fax_resolution) { case 'fine': - $gs_r = '204x196'; $gs_g = ((int) ($page_width * 204)).'x'.((int) ($page_height * 196)); + $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)); + $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)); + $gs_r = '204x98'; + $gs_g = ((int) ($page_width * 204)).'x'.((int) ($page_height * 98)); break; } @@ -573,7 +576,7 @@ if (!$included) { if (!$included) { //redirect the browser $_SESSION["message"] = $response; - header("Location: fax_box.php?id=".$fax_uuid."&box=sent"); + header("Location: fax_files.php?id=".$fax_uuid."&box=sent"); exit; } diff --git a/resources/install/scripts/fax_retry.lua b/resources/install/scripts/fax_retry.lua index 2d9be611e7..c9d5d99f19 100644 --- a/resources/install/scripts/fax_retry.lua +++ b/resources/install/scripts/fax_retry.lua @@ -340,6 +340,7 @@ table.insert(sql, "'" .. sip_to_user .. "', "); end table.insert(sql, "'tif', "); + fax_file = string.gsub(fax_file, '/temp/', '/sent/'); table.insert(sql, "'" .. fax_file .. "', "); table.insert(sql, "'" .. origination_caller_id_name .. "', "); table.insert(sql, "'" .. origination_caller_id_number .. "', ");
".$text['label-email_received']."".$text['label-email-fax']."".$text['label-email_size']."".$text['label-fax_caller_id_name']."".$text['label-fax_caller_id_number']."".$text['table-file']."".$text['label-email_size']."".$text['label-email_received']."  
".$metadata[0]['date']."".$attachment[0]['filename']."".byte_convert(strlen($attachment[0]['attachment']))."
".$caller_id_name."".$caller_id_number."".$file_name."".byte_convert(strlen($attachment[0]['attachment']))."".$metadata[0]['date']."$v_link_label_delete".$v_link_label_delete."