2013-10-18 00:07:17 +02:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
|
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
for the specific language governing rights and limitations under the
|
|
|
|
|
License.
|
|
|
|
|
|
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
2023-05-17 20:37:31 +02:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2023
|
2013-10-18 00:07:17 +02:00
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
James Rose <james.o.rose@gmail.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2023-06-15 19:28:23 +02:00
|
|
|
//file or console
|
2024-08-14 20:59:53 +02:00
|
|
|
$output_type = "file";
|
2023-06-15 19:28:23 +02:00
|
|
|
|
|
|
|
|
//only allow command line
|
|
|
|
|
if (!defined('STDIN')) {
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2013-10-18 00:07:17 +02:00
|
|
|
|
2023-06-15 19:28:23 +02:00
|
|
|
//determine if windows is true or false
|
|
|
|
|
$IS_WINDOWS = stristr(PHP_OS, 'WIN') ? true : false;
|
2015-11-23 13:12:55 +01:00
|
|
|
|
2018-02-02 08:06:11 +01:00
|
|
|
if (!function_exists('exec_in_dir')) {
|
2022-05-13 19:44:41 +02:00
|
|
|
function exec_in_dir($dir, $cmd, &$ok) {
|
2015-11-23 13:12:55 +01:00
|
|
|
$args = func_get_args();
|
|
|
|
|
$cwd = getcwd();
|
|
|
|
|
chdir($dir);
|
|
|
|
|
$output = array();
|
|
|
|
|
$ret = 0;
|
|
|
|
|
$result = exec($cmd, $output, $ret);
|
2018-02-02 08:06:11 +01:00
|
|
|
if ($cwd)
|
2015-11-23 13:12:55 +01:00
|
|
|
chdir($cwd);
|
|
|
|
|
$ok = ($ret == 0);
|
2022-05-13 19:44:41 +02:00
|
|
|
return implode("\n", $output);
|
2015-11-23 13:12:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 08:06:11 +01:00
|
|
|
if (!function_exists('correct_path')) {
|
2015-11-23 13:12:55 +01:00
|
|
|
function correct_path($p) {
|
|
|
|
|
global $IS_WINDOWS;
|
|
|
|
|
if ($IS_WINDOWS) {
|
|
|
|
|
return str_replace('/', '\\', $p);
|
|
|
|
|
}
|
|
|
|
|
return $p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 08:06:11 +01:00
|
|
|
if (!function_exists('path_join')) {
|
2015-11-23 13:12:55 +01:00
|
|
|
function path_join() {
|
|
|
|
|
$args = func_get_args();
|
|
|
|
|
$paths = array();
|
|
|
|
|
foreach ($args as $arg) {
|
|
|
|
|
$paths = array_merge($paths, (array)$arg);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-24 11:54:04 +01:00
|
|
|
$prefix = null;
|
|
|
|
|
foreach($paths as &$path) {
|
2023-05-05 18:46:37 +02:00
|
|
|
if ($prefix === null && !empty($path)) {
|
2018-02-02 08:06:11 +01:00
|
|
|
if (substr($path, 0, 1) == '/') $prefix = '/';
|
2015-11-24 11:54:04 +01:00
|
|
|
else $prefix = '';
|
|
|
|
|
}
|
|
|
|
|
$path = trim( $path, '/' );
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 19:44:41 +02:00
|
|
|
if ($prefix === null) {
|
2015-11-24 11:54:04 +01:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-23 13:12:55 +01:00
|
|
|
$paths = array_filter($paths);
|
2022-05-13 19:44:41 +02:00
|
|
|
return $prefix . implode('/', $paths);
|
2015-11-23 13:12:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 08:06:11 +01:00
|
|
|
if (!function_exists('tiff2pdf')) {
|
2022-05-13 19:44:41 +02:00
|
|
|
function tiff2pdf($tiff_file_name) {
|
2015-11-23 13:12:55 +01:00
|
|
|
//convert the tif to a pdf
|
|
|
|
|
//Ubuntu: apt-get install libtiff-tools
|
|
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
global $settings, $IS_WINDOWS;
|
2015-11-23 13:12:55 +01:00
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
if (!file_exists($tiff_file_name) || !is_file($tiff_file_name)) {
|
|
|
|
|
echo "tiff file does not exist\n";
|
|
|
|
|
return false; // "tiff file does not exist";
|
2015-11-23 13:12:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$GS = $IS_WINDOWS ? 'gswin32c' : 'gs';
|
|
|
|
|
$tiff_file = pathinfo($tiff_file_name);
|
|
|
|
|
$dir_fax = $tiff_file['dirname'];
|
|
|
|
|
$fax_file_name = $tiff_file['filename'];
|
2022-05-13 19:44:41 +02:00
|
|
|
$pdf_file_name = path_join($dir_fax, $fax_file_name . '.pdf');
|
2015-11-23 13:12:55 +01:00
|
|
|
|
2022-02-07 23:24:38 +01:00
|
|
|
if (file_exists($pdf_file_name)) {
|
2015-11-23 13:12:55 +01:00
|
|
|
return $pdf_file_name;
|
2022-02-07 23:24:38 +01:00
|
|
|
}
|
2015-11-23 13:12:55 +01:00
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
$dir_fax_temp = $settings->get('server', 'temp', sys_get_temp_dir());
|
2022-05-13 19:44:41 +02:00
|
|
|
if (!$dir_fax_temp) {
|
2015-11-23 13:12:55 +01:00
|
|
|
$dir_fax_temp = path_join(dirname($dir_fax), 'temp');
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 19:44:41 +02:00
|
|
|
if (!file_exists($dir_fax_temp)) {
|
2024-08-14 20:59:53 +02:00
|
|
|
echo "cannot create temporary directory\n";
|
|
|
|
|
return false; //cannot create temporary directory
|
2015-11-23 13:12:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cmd = "tiffinfo " . correct_path($tiff_file_name) . ' | grep "Resolution:"';
|
|
|
|
|
$ok = false;
|
|
|
|
|
$resp = exec_in_dir($dir_fax, $cmd, $ok);
|
2022-05-13 19:44:41 +02:00
|
|
|
if (!$ok) {
|
2024-08-14 20:59:53 +02:00
|
|
|
echo "cannot find fax resoulution\n";
|
|
|
|
|
return false; // "cannot find fax resoulution"
|
2015-11-23 13:12:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ppi_w = 0;
|
|
|
|
|
$ppi_h = 0;
|
|
|
|
|
$tmp = array();
|
2022-05-13 19:44:41 +02:00
|
|
|
if (preg_match('/Resolution.*?(\d+).*?(\d+)/', $resp, $tmp)) {
|
2015-11-23 13:12:55 +01:00
|
|
|
$ppi_w = $tmp[1];
|
|
|
|
|
$ppi_h = $tmp[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cmd = "tiffinfo " . $tiff_file_name . ' | grep "Image Width:"';
|
|
|
|
|
$resp = exec_in_dir($dir_fax, $cmd, $ok);
|
2022-05-13 19:44:41 +02:00
|
|
|
if (!$ok) {
|
2019-08-29 01:53:34 +02:00
|
|
|
echo "can not find fax size";
|
2015-11-23 13:12:55 +01:00
|
|
|
return false; // "can not find fax size"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$pix_w = 0;
|
|
|
|
|
$pix_h = 0;
|
|
|
|
|
$tmp = array();
|
2022-05-13 19:44:41 +02:00
|
|
|
if (preg_match('/Width.*?(\d+).*?Length.*?(\d+)/', $resp, $tmp)) {
|
2015-11-23 13:12:55 +01:00
|
|
|
$pix_w = $tmp[1];
|
|
|
|
|
$pix_h = $tmp[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$page_width = $pix_w / $ppi_w;
|
|
|
|
|
$page_height = $pix_h / $ppi_h;
|
|
|
|
|
$page_size = 'a4';
|
|
|
|
|
|
|
|
|
|
if (($page_width > 8.4) && ($page_height > 13)) {
|
|
|
|
|
$page_width = 8.5;
|
|
|
|
|
$page_height = 14;
|
|
|
|
|
$page_size = 'legal';
|
|
|
|
|
}
|
|
|
|
|
elseif (($page_width > 8.4) && ($page_height < 12)) {
|
|
|
|
|
$page_width = 8.5;
|
|
|
|
|
$page_height = 11;
|
|
|
|
|
$page_size = 'letter';
|
|
|
|
|
}
|
|
|
|
|
elseif (($page_width < 8.4) && ($page_height > 11)) {
|
|
|
|
|
$page_width = 8.3;
|
|
|
|
|
$page_height = 11.7;
|
|
|
|
|
$page_size = 'a4';
|
|
|
|
|
}
|
|
|
|
|
$page_width = sprintf('%.4f', $page_width);
|
|
|
|
|
$page_height = sprintf('%.4f', $page_height);
|
|
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
$cmd = implode(' ', array('tiff2pdf',
|
2015-11-23 13:12:55 +01:00
|
|
|
'-o', correct_path($pdf_file_name),
|
2016-07-28 07:00:33 +02:00
|
|
|
correct_path($tiff_file_name),
|
2022-05-13 19:44:41 +02:00
|
|
|
));
|
2015-11-23 13:12:55 +01:00
|
|
|
|
2018-02-02 08:06:11 +01:00
|
|
|
$resp = exec_in_dir($dir_fax, $cmd, $ok);
|
2015-11-23 13:12:55 +01:00
|
|
|
|
2022-05-13 19:44:41 +02:00
|
|
|
if (!file_exists($pdf_file_name)) {
|
2018-02-02 08:06:11 +01:00
|
|
|
echo "can not create pdf: $resp";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-11-23 13:12:55 +01:00
|
|
|
|
|
|
|
|
return $pdf_file_name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 08:06:11 +01:00
|
|
|
if (!function_exists('fax_split_dtmf')) {
|
2022-05-13 19:44:41 +02:00
|
|
|
function fax_split_dtmf(&$fax_number, &$fax_dtmf) {
|
2015-11-23 13:12:55 +01:00
|
|
|
$tmp = array();
|
|
|
|
|
$fax_dtmf = '';
|
2022-05-13 19:44:41 +02:00
|
|
|
if (preg_match('/^\s*(.*?)\s*\((.*)\)\s*$/', $fax_number, $tmp)) {
|
2015-11-23 13:12:55 +01:00
|
|
|
$fax_number = $tmp[1];
|
|
|
|
|
$fax_dtmf = $tmp[2];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-11 00:35:14 +02:00
|
|
|
//includes files
|
2023-06-15 19:28:23 +02:00
|
|
|
require_once dirname(__DIR__) . "/resources/require.php";
|
2016-04-03 03:23:16 +02:00
|
|
|
include "resources/classes/event_socket.php";
|
2013-10-18 00:07:17 +02:00
|
|
|
include "resources/phpmailer/class.phpmailer.php";
|
|
|
|
|
include "resources/phpmailer/class.smtp.php"; // optional, gets called from within class.phpmailer.php if not already loaded
|
|
|
|
|
|
|
|
|
|
//set php ini values
|
2023-06-10 00:59:09 +02:00
|
|
|
ini_set('max_execution_time', 900); //15 minutes
|
2013-10-18 00:07:17 +02:00
|
|
|
ini_set('memory_limit', '96M');
|
|
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
//add a delimeter to the log
|
|
|
|
|
echo "\n---------------------------------\n";
|
|
|
|
|
|
|
|
|
|
//get the parameters and save them as variables in the request superglobal
|
|
|
|
|
if (empty($_REQUEST)) {
|
|
|
|
|
foreach ($_SERVER['argv'] as $arg) {
|
|
|
|
|
if (strpos($arg, '=') !== false) {
|
|
|
|
|
[$key, $value] = explode('=', $arg, 2);
|
|
|
|
|
$_REQUEST[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//use a foreach loop so order doesn't matter
|
|
|
|
|
foreach ($_REQUEST as $key => $value) {
|
|
|
|
|
if (strpos($value, '=') !== false) {
|
|
|
|
|
$arg = explode('=', $value);
|
|
|
|
|
if (count($arg) > 1) {
|
|
|
|
|
$key = $arg[0];
|
|
|
|
|
$value = $arg[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
switch($key) {
|
|
|
|
|
case 'email':
|
|
|
|
|
$fax_email = $value;
|
|
|
|
|
break;
|
|
|
|
|
case 'extension':
|
|
|
|
|
$fax_extension = $value;
|
|
|
|
|
break;
|
|
|
|
|
case 'name':
|
|
|
|
|
$fax_file = $value;
|
|
|
|
|
break;
|
|
|
|
|
case 'messages':
|
|
|
|
|
$fax_messages = $value;
|
|
|
|
|
break;
|
|
|
|
|
case 'domain':
|
|
|
|
|
//domain_name is global for all functions
|
|
|
|
|
$domain_name = $value;
|
|
|
|
|
break;
|
|
|
|
|
case 'retry':
|
|
|
|
|
$fax_relay = $value;
|
|
|
|
|
break;
|
|
|
|
|
case 'mailfrom_address':
|
|
|
|
|
$mail_from_address = $value;
|
|
|
|
|
break;
|
|
|
|
|
case 'debug':
|
|
|
|
|
$output_type = 'console';
|
|
|
|
|
break;
|
|
|
|
|
case 'config':
|
|
|
|
|
$config_file = $value;
|
|
|
|
|
break;
|
|
|
|
|
case 'caller_id_name':
|
|
|
|
|
case 'caller_id_number':
|
|
|
|
|
case 'fax_relay':
|
|
|
|
|
case 'fax_prefix':
|
|
|
|
|
case 'domain_name':
|
|
|
|
|
case 'mail_from_address':
|
|
|
|
|
case 'output_type':
|
|
|
|
|
case 'fax_extension':
|
|
|
|
|
case 'debug_level':
|
|
|
|
|
case 'config_file':
|
|
|
|
|
//tansform the name of the key into the name of the variable using $$
|
|
|
|
|
$$key = $value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//mark global variables for all functions
|
|
|
|
|
global $output_type, $config, $database, $domain_name, $domains, $settings, $domain_uuid, $debug_level;
|
|
|
|
|
|
|
|
|
|
//run shutdown function on exit
|
|
|
|
|
register_shutdown_function('shutdown');
|
|
|
|
|
|
|
|
|
|
//start to cache the output
|
2016-09-28 21:30:46 +02:00
|
|
|
if ($output_type == "file") {
|
|
|
|
|
ob_end_clean();
|
|
|
|
|
ob_start();
|
|
|
|
|
}
|
2013-10-18 00:07:17 +02:00
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
//find and load the config file
|
|
|
|
|
$config = config::load($config_file ?? ''); //use the config_file option from command line if available
|
2013-10-18 00:07:17 +02:00
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
//stop if no config
|
|
|
|
|
if ($config->is_empty()) {
|
|
|
|
|
exit("Unable to find config file\n");
|
2013-10-18 00:07:17 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
//create a single database object
|
|
|
|
|
$database = database::new(['config' => $config]);
|
|
|
|
|
|
2015-05-12 01:41:11 +02:00
|
|
|
//get the fax file name (only) if a full path
|
2019-08-29 01:53:34 +02:00
|
|
|
$fax_path = pathinfo($fax_file);
|
2015-11-23 13:51:05 +01:00
|
|
|
$fax_file_only = $fax_path['basename'];
|
|
|
|
|
$fax_file_name = $fax_path['filename'];
|
2019-08-29 01:53:34 +02:00
|
|
|
$dir_fax = $fax_path['dirname'];
|
2013-10-18 00:07:17 +02:00
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
//get the enabled domains from the database
|
|
|
|
|
//$domains = domains::fetch($database);
|
|
|
|
|
$domains = [];
|
|
|
|
|
$result = $database->select("select domain_uuid, domain_name from v_domains where domain_enabled = 'true'");
|
2019-08-29 01:53:34 +02:00
|
|
|
if (is_array($result) && @sizeof($result) != 0) {
|
2024-08-14 20:59:53 +02:00
|
|
|
foreach ($result as $row) {
|
2019-08-29 01:53:34 +02:00
|
|
|
//set the domain variables
|
2024-08-14 20:59:53 +02:00
|
|
|
$domains[$row["domain_uuid"]] = $row["domain_name"];
|
2019-08-29 01:53:34 +02:00
|
|
|
}
|
2013-10-18 00:07:17 +02:00
|
|
|
}
|
2024-08-14 20:59:53 +02:00
|
|
|
unset($result, $row);
|
2013-10-18 00:07:17 +02:00
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
//set the global variable domain_uuid using domain_name passed on command line
|
|
|
|
|
$domain_uuid = array_search($domain_name, $domains);
|
|
|
|
|
|
|
|
|
|
//ensure we have a domain_uuid
|
|
|
|
|
if (empty($domain_uuid)) {
|
|
|
|
|
exit("Domain '$domain_name' not found\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//ensure we have a fax extension
|
|
|
|
|
if (empty($fax_extension)) {
|
|
|
|
|
exit("No fax extension set\n");
|
2016-10-31 14:37:32 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
//now that we have the domain_name and uuid, create a settings object for the domain
|
|
|
|
|
$settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid]);
|
|
|
|
|
|
|
|
|
|
//prepare smtp server settings
|
|
|
|
|
$email_from_address = $settings->get('fax','smtp_from', $settings->get('email', 'smtp_from', ''));
|
|
|
|
|
$email_from_name = $settings->get('fax', 'smtp_from_name', $settings->get('email', 'smtp_from_name', $email_from_address));
|
|
|
|
|
|
2022-02-05 00:01:27 +01:00
|
|
|
//get the fax settings from the database
|
2013-10-18 00:07:17 +02:00
|
|
|
$sql = "select * from v_fax ";
|
2019-08-29 01:53:34 +02:00
|
|
|
$sql .= "where domain_uuid = :domain_uuid ";
|
|
|
|
|
$sql .= "and fax_extension = :fax_extension ";
|
2022-05-01 04:39:15 +02:00
|
|
|
$parameters['domain_uuid'] = $domain_uuid;
|
2019-08-29 01:53:34 +02:00
|
|
|
$parameters['fax_extension'] = $fax_extension;
|
|
|
|
|
$row = $database->select($sql, $parameters, 'row');
|
|
|
|
|
if (is_array($row) && @sizeof($row) != 0) {
|
2022-04-23 23:27:29 +02:00
|
|
|
$fax_email = $row["fax_email"];
|
2019-08-29 01:53:34 +02:00
|
|
|
$fax_uuid = $row["fax_uuid"];
|
|
|
|
|
$fax_accountcode = $row["fax_accountcode"];
|
|
|
|
|
$fax_prefix = $row["fax_prefix"];
|
|
|
|
|
$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"];
|
|
|
|
|
$fax_email_inbound_subject_tag = $row['fax_email_inbound_subject_tag'];
|
2022-05-01 07:50:50 +02:00
|
|
|
$mail_to_address = $fax_email;
|
2013-10-18 00:07:17 +02:00
|
|
|
}
|
2019-08-29 01:53:34 +02:00
|
|
|
unset($sql, $parameters, $row);
|
2013-10-18 00:07:17 +02:00
|
|
|
|
|
|
|
|
//set the fax directory
|
2015-11-23 13:51:05 +01:00
|
|
|
if (!file_exists($dir_fax) || !file_exists(path_join($dir_fax, $fax_file_only))) {
|
2024-08-14 20:59:53 +02:00
|
|
|
$switch_dir = $settings->get('switch', 'storage', '/var/lib/freeswitch/storage');
|
|
|
|
|
$dir_fax = "$switch_dir/fax/$domain_name/$fax_extension/inbox";
|
2015-11-23 13:51:05 +01:00
|
|
|
if (!file_exists($dir_fax) || !file_exists(path_join($dir_fax, $fax_file_only))) {
|
2024-08-14 20:59:53 +02:00
|
|
|
$dir_fax = "$switch_dir/fax/$fax_extension/inbox";
|
2013-10-18 00:07:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-11-23 13:51:05 +01:00
|
|
|
$fax_file = path_join($dir_fax, $fax_file_only);
|
|
|
|
|
|
|
|
|
|
//used for debug
|
2017-03-01 20:16:11 +01:00
|
|
|
echo "fax_prefix: $fax_prefix\n";
|
2022-05-01 04:39:15 +02:00
|
|
|
echo "mail_to_adress: $mail_to_address\n";
|
2017-03-01 20:16:11 +01:00
|
|
|
echo "fax_email: $fax_email\n";
|
|
|
|
|
echo "fax_extension: $fax_extension\n";
|
|
|
|
|
echo "fax_name: $fax_file_only\n";
|
|
|
|
|
echo "dir_fax: $dir_fax\n";
|
|
|
|
|
echo "full_path: $fax_file\n";
|
2015-11-23 13:51:05 +01:00
|
|
|
|
2015-11-23 13:12:55 +01:00
|
|
|
$pdf_file = tiff2pdf($fax_file);
|
2017-03-01 20:16:11 +01:00
|
|
|
echo "file: $pdf_file \n";
|
2022-05-13 19:44:41 +02:00
|
|
|
if (!$pdf_file) {
|
2024-08-14 20:59:53 +02:00
|
|
|
$fax_file_warning = "warning: Fax image not available on server.";
|
2013-10-18 00:07:17 +02:00
|
|
|
}
|
2015-11-23 13:51:05 +01:00
|
|
|
else{
|
|
|
|
|
$fax_file_warning = '';
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
echo "fax file warning(s): $fax_file_warning\n";
|
2017-03-01 20:16:11 +01:00
|
|
|
echo "pdf file: $pdf_file\n";
|
2013-10-18 00:07:17 +02:00
|
|
|
|
|
|
|
|
//forward the fax
|
2024-08-14 20:59:53 +02:00
|
|
|
if (file_exists($fax_file) && is_file($fax_file)) {
|
2015-11-23 13:12:55 +01:00
|
|
|
if (strpos($fax_file_name,'#') !== false) {
|
|
|
|
|
$tmp = explode("#",$fax_file_name);
|
2017-03-01 20:16:11 +01:00
|
|
|
$fax_forward_number = $fax_prefix.$tmp[0];
|
2015-11-23 13:12:55 +01:00
|
|
|
}
|
2013-10-18 00:07:17 +02:00
|
|
|
|
2023-05-05 18:46:37 +02:00
|
|
|
if (isset($fax_forward_number) && !empty($fax_forward_number)) {
|
2022-05-01 04:39:15 +02:00
|
|
|
//show info
|
2024-08-14 21:03:03 +02:00
|
|
|
echo "fax_forward_number: $fax_forward_number\n";
|
2022-06-29 18:38:36 +02:00
|
|
|
|
2022-05-01 04:39:15 +02:00
|
|
|
//add fax to the fax queue or send it directly
|
2024-08-14 21:03:03 +02:00
|
|
|
//build an array to add the fax to the queue
|
|
|
|
|
$array['fax_queue'][0]['fax_queue_uuid'] = uuid();
|
|
|
|
|
$array['fax_queue'][0]['domain_uuid'] = $domain_uuid;
|
|
|
|
|
$array['fax_queue'][0]['fax_uuid'] = $fax_uuid;
|
|
|
|
|
$array['fax_queue'][0]['fax_date'] = 'now()';
|
|
|
|
|
$array['fax_queue'][0]['hostname'] = gethostname();
|
|
|
|
|
$array['fax_queue'][0]['fax_caller_id_name'] = $fax_caller_id_name;
|
|
|
|
|
$array['fax_queue'][0]['fax_caller_id_number'] = $fax_caller_id_number;
|
|
|
|
|
$array['fax_queue'][0]['fax_number'] = $fax_forward_number;
|
|
|
|
|
$array['fax_queue'][0]['fax_prefix'] = $fax_prefix;
|
|
|
|
|
$array['fax_queue'][0]['fax_email_address'] = $mail_to_address;
|
|
|
|
|
$array['fax_queue'][0]['fax_file'] = $fax_file;
|
|
|
|
|
$array['fax_queue'][0]['fax_status'] = 'waiting';
|
|
|
|
|
$array['fax_queue'][0]['fax_retry_count'] = 0;
|
|
|
|
|
$array['fax_queue'][0]['fax_accountcode'] = $fax_accountcode;
|
|
|
|
|
|
|
|
|
|
//add temporary permisison
|
|
|
|
|
$p = new permissions;
|
|
|
|
|
$p->add('fax_queue_add', 'temp');
|
|
|
|
|
|
|
|
|
|
//save the data
|
|
|
|
|
$database->app_name = 'fax_queue';
|
|
|
|
|
$database->app_uuid = '3656287f-4b22-4cf1-91f6-00386bf488f4';
|
|
|
|
|
$database->save($array);
|
|
|
|
|
|
|
|
|
|
//remove temporary permisison
|
|
|
|
|
$p->delete('fax_queue_add', 'temp');
|
|
|
|
|
|
|
|
|
|
//add message to show in the browser
|
|
|
|
|
message::add($text['confirm-queued']);
|
2022-05-01 04:39:15 +02:00
|
|
|
|
2013-10-18 00:07:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//send the email
|
2023-05-05 18:46:37 +02:00
|
|
|
if (!empty($fax_email) && file_exists($fax_file)) {
|
2022-02-05 00:01:27 +01:00
|
|
|
|
|
|
|
|
//get the language code
|
2024-08-14 21:03:03 +02:00
|
|
|
$language_code = $settings->get('domain', 'language', 'en-us');
|
2022-02-05 00:01:27 +01:00
|
|
|
|
|
|
|
|
//get the template subcategory
|
2024-08-14 21:03:03 +02:00
|
|
|
if (!empty($fax_relay) && $fax_relay == 'true') {
|
|
|
|
|
$template_subcategory = 'relay';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$template_subcategory = 'inbound';
|
|
|
|
|
}
|
2016-10-31 21:19:41 +01:00
|
|
|
|
2022-02-05 00:01:27 +01:00
|
|
|
//get the email template from the database
|
2024-08-14 21:03:03 +02:00
|
|
|
if (!empty($fax_email) && !empty($domain_uuid)) {
|
|
|
|
|
$sql = "select template_subject, template_body from v_email_templates ";
|
|
|
|
|
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
|
|
|
|
$sql .= "and template_language = :template_language ";
|
|
|
|
|
$sql .= "and template_category = :template_category ";
|
|
|
|
|
$sql .= "and template_subcategory = :template_subcategory ";
|
|
|
|
|
$sql .= "and template_type = :template_type ";
|
|
|
|
|
$sql .= "and template_enabled = 'true' ";
|
|
|
|
|
$parameters['domain_uuid'] = $domain_uuid;
|
|
|
|
|
$parameters['template_language'] = $language_code;
|
|
|
|
|
$parameters['template_category'] = 'fax';
|
|
|
|
|
$parameters['template_subcategory'] = $template_subcategory;
|
|
|
|
|
$parameters['template_type'] = 'html';
|
|
|
|
|
$row = $database->select($sql, $parameters, 'row');
|
|
|
|
|
if (is_array($row)) {
|
|
|
|
|
$email_subject = $row['template_subject'];
|
|
|
|
|
$email_body = $row['template_body'];
|
2016-10-31 21:19:41 +01:00
|
|
|
}
|
2024-08-14 21:03:03 +02:00
|
|
|
unset($sql, $parameters);
|
|
|
|
|
}
|
2016-10-31 21:19:41 +01:00
|
|
|
|
2022-02-05 00:01:27 +01:00
|
|
|
//replace variables in email subject
|
2024-08-14 21:03:03 +02:00
|
|
|
$email_subject = str_replace('${domain_name}', $domain_name, $email_subject);
|
|
|
|
|
$email_subject = str_replace('${fax_file_name}', $fax_file_name, $email_subject);
|
|
|
|
|
$email_subject = str_replace('${fax_extension}', $fax_extension, $email_subject);
|
|
|
|
|
$email_subject = str_replace('${fax_messages}', $fax_messages, $email_subject);
|
|
|
|
|
$email_subject = str_replace('${fax_file_warning}', $fax_file_warning, $email_subject);
|
|
|
|
|
$email_subject = str_replace('${fax_subject_tag}', $fax_email_inbound_subject_tag, $email_subject);
|
2022-02-05 00:01:27 +01:00
|
|
|
|
|
|
|
|
//replace variables in email body
|
2024-08-14 21:03:03 +02:00
|
|
|
$email_body = str_replace('${domain_name}', $domain_name, $email_body);
|
|
|
|
|
$email_body = str_replace('${fax_file_name}', $fax_file_name, $email_body);
|
|
|
|
|
$email_body = str_replace('${fax_extension}', $fax_extension, $email_body);
|
|
|
|
|
$email_body = str_replace('${fax_messages}', $fax_messages, $email_body);
|
|
|
|
|
$email_body = str_replace('${fax_file_warning}', $fax_file_warning, $email_body);
|
|
|
|
|
$email_body = str_replace('${fax_subject_tag}', $fax_email_inbound_subject_tag, $email_body);
|
2022-02-05 00:01:27 +01:00
|
|
|
|
|
|
|
|
//debug info
|
2024-08-14 21:03:03 +02:00
|
|
|
//echo "<hr />\n";
|
|
|
|
|
//echo "email_address ".$fax_email."<br />\n";
|
|
|
|
|
//echo "email_subject ".$email_subject."<br />\n";
|
|
|
|
|
//echo "email_body ".$email_body."<br />\n";
|
|
|
|
|
//echo "<hr />\n";
|
2022-02-05 00:01:27 +01:00
|
|
|
|
|
|
|
|
//send the email
|
2024-08-14 21:03:03 +02:00
|
|
|
if (isset($fax_email) && !empty($fax_email)) {
|
|
|
|
|
//add the attachment
|
|
|
|
|
if (!empty($fax_file_name)) {
|
|
|
|
|
$email_attachments[0]['type'] = 'file';
|
|
|
|
|
if ($pdf_file && file_exists($pdf_file)) {
|
|
|
|
|
$email_attachments[0]['name'] = $fax_file_name.'.pdf';
|
|
|
|
|
$email_attachments[0]['value'] = $pdf_file;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$email_attachments[0]['name'] = $fax_file_name.'.tif';
|
|
|
|
|
$email_attachments[0]['value'] = $fax_file;
|
2022-02-07 23:24:38 +01:00
|
|
|
}
|
2013-10-18 00:07:17 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-14 21:03:03 +02:00
|
|
|
//$email_response = send_email($email_address, $email_subject, $email_body);
|
|
|
|
|
$email = new email;
|
|
|
|
|
$email->recipients = $fax_email;
|
|
|
|
|
$email->subject = $email_subject;
|
|
|
|
|
$email->body = $email_body;
|
|
|
|
|
$email->from_address = $email_from_address;
|
|
|
|
|
$email->from_name = $email_from_name;
|
|
|
|
|
$email->attachments = $email_attachments;
|
|
|
|
|
//$email->debug_level = 3;
|
|
|
|
|
$response = $mail->error;
|
|
|
|
|
$sent = $email->send();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 00:07:17 +02:00
|
|
|
//output to the log
|
2024-08-14 21:03:03 +02:00
|
|
|
echo "email_from_address: ".$email_from_address."\n";
|
|
|
|
|
echo "email_from_name: ".$email_from_address."\n";
|
|
|
|
|
echo "email_subject: $email_subject\n";
|
2013-10-18 00:07:17 +02:00
|
|
|
|
|
|
|
|
//send the email
|
2024-08-14 21:03:03 +02:00
|
|
|
if ($sent) {
|
|
|
|
|
echo "Mailer Error";
|
|
|
|
|
$email_status='failed';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "Message sent!";
|
|
|
|
|
$email_status='ok';
|
|
|
|
|
}
|
2013-10-18 00:07:17 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
//when the exit is called, capture the statements
|
|
|
|
|
function shutdown() {
|
|
|
|
|
//bring variables in to function scope
|
|
|
|
|
global $output_type, $settings, $debug_level;
|
|
|
|
|
|
|
|
|
|
//open the file for writing
|
2016-09-28 21:30:46 +02:00
|
|
|
if ($output_type == "file") {
|
2024-08-14 20:59:53 +02:00
|
|
|
//ensure we can access the settings object
|
|
|
|
|
if (class_exists('settings') && $settings instanceof settings) {
|
|
|
|
|
//temporary directory in default settings or use the system temp directory
|
|
|
|
|
$temp_dir = $settings->get('server', 'temp', sys_get_temp_dir());
|
2024-08-14 21:03:03 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2024-08-14 20:59:53 +02:00
|
|
|
//settings is not available
|
|
|
|
|
$temp_dir = sys_get_temp_dir();
|
|
|
|
|
}
|
2024-08-14 21:03:03 +02:00
|
|
|
|
2016-09-28 21:30:46 +02:00
|
|
|
//open the file
|
2024-08-14 20:59:53 +02:00
|
|
|
$fp = fopen("$temp_dir/fax_to_email.log", "w");
|
2024-08-14 21:03:03 +02:00
|
|
|
|
2016-09-28 21:30:46 +02:00
|
|
|
//get the output from the buffer
|
2024-08-14 20:59:53 +02:00
|
|
|
$content = ob_get_contents();
|
2024-08-14 21:03:03 +02:00
|
|
|
|
2016-09-28 21:30:46 +02:00
|
|
|
//clean the buffer
|
2024-08-14 20:59:53 +02:00
|
|
|
ob_end_clean();
|
2024-08-14 21:03:03 +02:00
|
|
|
|
2016-09-28 21:30:46 +02:00
|
|
|
//write the contents of the buffer
|
2024-08-14 20:59:53 +02:00
|
|
|
fwrite($fp, $content);
|
2024-08-14 21:03:03 +02:00
|
|
|
|
2024-08-14 20:59:53 +02:00
|
|
|
//close the file pointer
|
|
|
|
|
fclose($fp);
|
2024-08-14 21:03:03 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2024-08-14 20:59:53 +02:00
|
|
|
if ($debug_level > 2) {
|
|
|
|
|
var_dump($_REQUEST);
|
|
|
|
|
}
|
2016-09-28 21:30:46 +02:00
|
|
|
}
|
2024-08-14 20:59:53 +02:00
|
|
|
}
|
2017-03-01 20:16:11 +01:00
|
|
|
|
2021-11-20 19:48:22 +01:00
|
|
|
?>
|