mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Misc: Database class integration.
This commit is contained in:
@@ -39,7 +39,7 @@ if (defined('STDIN')) {
|
||||
//echo "$document_root is document_root\n";
|
||||
}
|
||||
|
||||
if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; }
|
||||
$IS_WINDOWS = stristr(PHP_OS, 'WIN') ? true : false;
|
||||
|
||||
if (!function_exists('exec_in_dir')) {
|
||||
function exec_in_dir($dir, $cmd, &$ok){
|
||||
@@ -119,7 +119,7 @@ if (!function_exists('tiff2pdf')) {
|
||||
}
|
||||
|
||||
if (!file_exists($dir_fax_temp)){
|
||||
echo"can not create temporary directory";
|
||||
echo "can not create temporary directory";
|
||||
return false; //
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ if (!function_exists('tiff2pdf')) {
|
||||
$ok = false;
|
||||
$resp = exec_in_dir($dir_fax, $cmd, $ok);
|
||||
if (!$ok){
|
||||
echo"can not find fax resoulution";
|
||||
echo "can not find fax resoulution";
|
||||
return false; // "can not find fax resoulution"
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ if (!function_exists('tiff2pdf')) {
|
||||
$cmd = "tiffinfo " . $tiff_file_name . ' | grep "Image Width:"';
|
||||
$resp = exec_in_dir($dir_fax, $cmd, $ok);
|
||||
if (!$ok){
|
||||
echo"can not find fax size";
|
||||
echo "can not find fax size";
|
||||
return false; // "can not find fax size"
|
||||
}
|
||||
|
||||
@@ -193,11 +193,11 @@ if (!function_exists('tiff2pdf')) {
|
||||
}
|
||||
|
||||
if (!function_exists('fax_enqueue')) {
|
||||
function fax_enqueue($fax_uuid, $fax_file, $wav_file, $reply_address, $fax_uri, $fax_dtmf, $dial_string){
|
||||
global $db, $db_type;
|
||||
function fax_enqueue($fax_uuid, $fax_file, $wav_file, $reply_address, $fax_uri, $fax_dtmf, $dial_string) {
|
||||
global $db_type;
|
||||
|
||||
$fax_task_uuid = uuid();
|
||||
$dial_string .= "fax_task_uuid='" . $fax_task_uuid . "',";
|
||||
$dial_string .= "fax_task_uuid='".$fax_task_uuid."',";
|
||||
$description = ''; //! @todo add description
|
||||
if ($db_type == "pgsql") {
|
||||
$date_utc_now_sql = "NOW() at time zone 'utc'";
|
||||
@@ -209,38 +209,64 @@ if (!function_exists('fax_enqueue')) {
|
||||
$date_utc_now_sql = "datetime('now')";
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO v_fax_tasks (fax_task_uuid, fax_uuid, ";
|
||||
$sql .= " task_next_time, task_lock_time, ";
|
||||
$sql .= " task_fax_file, task_wav_file, task_uri, task_dial_string, task_dtmf, ";
|
||||
$sql .= " task_interrupted, task_status, task_no_answer_counter, task_no_answer_retry_counter, task_retry_counter, ";
|
||||
$sql .= " task_reply_address, task_description) ";
|
||||
$sql .= "VALUES ( ";
|
||||
$sql .= " :fax_task_uuid, :fax_uuid, ";
|
||||
$sql .= " ".$date_utc_now_sql.", NULL, ";
|
||||
$sql .= " :fax_file, :wav_file, :fax_uri, :dial_string, :fax_dtmf, ";
|
||||
$sql .= " 'false', 0, 0, 0, 0, ";
|
||||
$sql .= " :reply_address, :description, ";
|
||||
$sql .= "); ";
|
||||
$statement = $db->prepare($sql);
|
||||
$statement->bindParam(':fax_task_uuid', $fax_task_uuid);
|
||||
$statement->bindParam(':fax_uuid', $fax_uuid);
|
||||
$statement->bindParam(':fax_file', $fax_file);
|
||||
$statement->bindParam(':wav_file', $wav_file);
|
||||
$statement->bindParam(':fax_uri', $fax_uri);
|
||||
$statement->bindParam(':dial_string', $dial_string);
|
||||
$statement->bindParam(':fax_dtmf', $fax_dtmf);
|
||||
$statement->bindParam(':reply_address', $reply_address);
|
||||
$statement->bindParam(':description', $description);
|
||||
if ($statement->execute()) {
|
||||
$response = 'Success';
|
||||
$sql = "insert into v_fax_tasks";
|
||||
$sql .= "( ";
|
||||
$sql .= "fax_task_uuid, ";
|
||||
$sql .= "fax_uuid, ";
|
||||
$sql .= "task_next_time, ";
|
||||
$sql .= "task_lock_time, ";
|
||||
$sql .= "task_fax_file, ";
|
||||
$sql .= "task_wav_file, ";
|
||||
$sql .= "task_uri, ";
|
||||
$sql .= "task_dial_string, ";
|
||||
$sql .= "task_dtmf, ";
|
||||
$sql .= "task_interrupted, ";
|
||||
$sql .= "task_status, ";
|
||||
$sql .= "task_no_answer_counter, ";
|
||||
$sql .= "task_no_answer_retry_counter,";
|
||||
$sql .= "task_retry_counter, ";
|
||||
$sql .= "task_reply_address, ";
|
||||
$sql .= "task_description ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ( ";
|
||||
$sql .= ":fax_task_uuid, ";
|
||||
$sql .= ":fax_uuid, ";
|
||||
$sql .= $date_utc_now_sql.", ";
|
||||
$sql .= "null, ";
|
||||
$sql .= ":fax_file, ";
|
||||
$sql .= ":wav_file, ";
|
||||
$sql .= ":fax_uri, ";
|
||||
$sql .= ":dial_string, ";
|
||||
$sql .= ":fax_dtmf, ";
|
||||
$sql .= "'false', ";
|
||||
$sql .= "0, ";
|
||||
$sql .= "0, ";
|
||||
$sql .= "0, ";
|
||||
$sql .= "0, ";
|
||||
$sql .= ":reply_address, ";
|
||||
$sql .= ":description ";
|
||||
$sql .= ") ";
|
||||
$parameters['fax_task_uuid'] = $fax_task_uuid;
|
||||
$parameters['fax_uuid'] = $fax_uuid;
|
||||
$parameters['fax_file'] = $fax_file;
|
||||
$parameters['wav_file'] = $wav_file;
|
||||
$parameters['fax_uri'] = $fax_uri;
|
||||
$parameters['dial_string'] = $dial_string;
|
||||
$parameters['fax_dtmf'] = $fax_dtmf;
|
||||
$parameters['reply_address'] = $reply_address;
|
||||
$parameters['description'] = $description;
|
||||
$database = new database;
|
||||
$database->execute($sql, $parameters);
|
||||
$response = $database->message();
|
||||
if ($response['message'] == 'OK' && $response['code'] == '200') {
|
||||
return 'Success';
|
||||
}
|
||||
else{
|
||||
//! @todo log error
|
||||
$response = 'Failed';
|
||||
var_dump($db->errorInfo());
|
||||
view_array($response);
|
||||
return 'Failed';
|
||||
}
|
||||
unset($statement);
|
||||
return $response;
|
||||
unset($sql, $parameters, $response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,41 +362,44 @@ if (!function_exists('fax_split_dtmf')) {
|
||||
$mailto_address = $fax_email;
|
||||
|
||||
//get the fax file name (only) if a full path
|
||||
$fax_path = pathinfo($fax_file);
|
||||
$fax_path = pathinfo($fax_file);
|
||||
$fax_file_only = $fax_path['basename'];
|
||||
$fax_file_name = $fax_path['filename'];
|
||||
$dir_fax = $fax_path['dirname'];
|
||||
$dir_fax = $fax_path['dirname'];
|
||||
|
||||
//get the domain_uuid from the database
|
||||
$sql = "select * from v_domains ";
|
||||
$sql .= "where domain_name = '".$domain_name."' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach ($result as &$row) {
|
||||
//set the domain variables
|
||||
$domain_uuid = $row["domain_uuid"];
|
||||
$_SESSION["domain_uuid"] = $row["domain_uuid"];
|
||||
$_SESSION["domain_name"] = $domain_name;
|
||||
//set the setting arrays
|
||||
$domain = new domains();
|
||||
$domain->db = $db;
|
||||
$domain->set();
|
||||
$sql .= "where domain_name = :domain_name ";
|
||||
$parameters['domain_name'] = $domain_name;
|
||||
$database = new database;
|
||||
$result = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as &$row) {
|
||||
//set the domain variables
|
||||
$domain_uuid = $row["domain_uuid"];
|
||||
$_SESSION["domain_uuid"] = $row["domain_uuid"];
|
||||
$_SESSION["domain_name"] = $domain_name;
|
||||
//set the setting arrays
|
||||
$domain = new domains();
|
||||
$domain->db = $db;
|
||||
$domain->set();
|
||||
}
|
||||
}
|
||||
unset ($prep_statement);
|
||||
unset($sql, $parameters, $result);
|
||||
|
||||
//prepare smtp server settings
|
||||
// load default smtp settings
|
||||
$smtp['method'] = $_SESSION['email']['smtp_method']['text'];
|
||||
$smtp['host'] = (strlen($_SESSION['email']['smtp_host']['text'])?$_SESSION['email']['smtp_host']['text']:'127.0.0.1');
|
||||
$smtp['method'] = $_SESSION['email']['smtp_method']['text'];
|
||||
$smtp['host'] = (strlen($_SESSION['email']['smtp_host']['text'])?$_SESSION['email']['smtp_host']['text']:'127.0.0.1');
|
||||
if (isset($_SESSION['email']['smtp_port'])) {
|
||||
$smtp['port'] = (int)$_SESSION['email']['smtp_port']['numeric'];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$smtp['port'] = 0;
|
||||
}
|
||||
|
||||
$smtp['secure'] = $_SESSION['email']['smtp_secure']['text'];
|
||||
$smtp['auth'] = $_SESSION['email']['smtp_auth']['text'];
|
||||
$smtp['secure'] = $_SESSION['email']['smtp_secure']['text'];
|
||||
$smtp['auth'] = $_SESSION['email']['smtp_auth']['text'];
|
||||
$smtp['username'] = $_SESSION['email']['smtp_username']['text'];
|
||||
$smtp['password'] = $_SESSION['email']['smtp_password']['text'];
|
||||
$smtp['from'] = $_SESSION['email']['smtp_from']['text'];
|
||||
@@ -384,55 +413,59 @@ if (!function_exists('fax_split_dtmf')) {
|
||||
}
|
||||
|
||||
// overwrite with domain-specific smtp server settings, if any
|
||||
if ($domain_uuid != '') {
|
||||
$sql = "select domain_setting_subcategory, domain_setting_value ";
|
||||
if (is_uuid($domain_uuid)) {
|
||||
$sql = "select ";
|
||||
$sql .= "domain_setting_subcategory, ";
|
||||
$sql .= "domain_setting_value ";
|
||||
$sql .= "from v_domain_settings ";
|
||||
$sql .= "where domain_uuid = '".$domain_uuid."' ";
|
||||
$sql .= "and (domain_setting_category = 'email' ";
|
||||
$sql .= "or domain_setting_category = 'fax') ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ( ";
|
||||
$sql .= "domain_setting_category = 'email' ";
|
||||
$sql .= "or domain_setting_category = 'fax' ";
|
||||
$sql .= ") ";
|
||||
$sql .= "and domain_setting_name = 'text' ";
|
||||
$sql .= "and domain_setting_enabled = 'true' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
$parameters['domain_name'] = $domain_name;
|
||||
$database = new database;
|
||||
$result = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as $row) {
|
||||
if ($row['domain_setting_value'] != '') {
|
||||
$smtp[str_replace('smtp_','',$row["domain_setting_subcategory"])] = $row['domain_setting_value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($sql, $prep_statement);
|
||||
unset($sql, $parameters, $result, $row);
|
||||
}
|
||||
|
||||
// value adjustments
|
||||
$smtp['method'] = ($smtp['method'] == '') ? 'smtp' : $smtp['method'];
|
||||
$smtp['auth'] = ($smtp['auth'] == "true") ? true : false;
|
||||
$smtp['password'] = ($smtp['password'] != '') ? $smtp['password'] : null;
|
||||
$smtp['secure'] = ($smtp['secure'] != "none") ? $smtp['secure'] : null;
|
||||
$smtp['username'] = ($smtp['username'] != '') ? $smtp['username'] : null;
|
||||
$smtp['method'] = ($smtp['method'] == '') ? 'smtp' : $smtp['method'];
|
||||
$smtp['auth'] = ($smtp['auth'] == "true") ? true : false;
|
||||
$smtp['password'] = ($smtp['password'] != '') ? $smtp['password'] : null;
|
||||
$smtp['secure'] = ($smtp['secure'] != "none") ? $smtp['secure'] : null;
|
||||
$smtp['username'] = ($smtp['username'] != '') ? $smtp['username'] : null;
|
||||
|
||||
//get the fax details from the database
|
||||
$sql = "select * from v_fax ";
|
||||
$sql .= "where domain_uuid = '".$_SESSION["domain_uuid"]."' ";
|
||||
$sql .= "and fax_extension = '$fax_extension' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach ($result as &$row) {
|
||||
//set database fields as variables
|
||||
//$fax_email = $row["fax_email"];
|
||||
$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'];
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and fax_extension = :fax_extension ";
|
||||
$parameters['domain_uuid'] = $_SESSION["domain_uuid"];
|
||||
$parameters['fax_extension'] = $fax_extension;
|
||||
$database = new database;
|
||||
$row = $database->select($sql, $parameters, 'row');
|
||||
if (is_array($row) && @sizeof($row) != 0) {
|
||||
//$fax_email = $row["fax_email"];
|
||||
$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'];
|
||||
}
|
||||
unset ($prep_statement);
|
||||
unset($sql, $parameters, $row);
|
||||
|
||||
//set the fax directory
|
||||
if (!file_exists($dir_fax) || !file_exists(path_join($dir_fax, $fax_file_only))) {
|
||||
@@ -461,7 +494,6 @@ if (!function_exists('fax_split_dtmf')) {
|
||||
$fax_file_warning = '';
|
||||
}
|
||||
|
||||
//used for debug
|
||||
echo "pdf file: $pdf_file\n";
|
||||
|
||||
//forward the fax
|
||||
@@ -495,7 +527,7 @@ if (!function_exists('fax_split_dtmf')) {
|
||||
}
|
||||
}
|
||||
|
||||
$dial_string = "absolute_codec_string='PCMU,PCMA',";
|
||||
$dial_string = "absolute_codec_string='PCMU,PCMA',";
|
||||
$dial_string .= "accountcode='" . $fax_accountcode . "',";
|
||||
$dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',";
|
||||
$dial_string .= "domain_uuid=" . $_SESSION["domain_uuid"] . ",";
|
||||
@@ -517,19 +549,18 @@ if (!function_exists('fax_split_dtmf')) {
|
||||
$dial_string .= "fax_verbose=true" . ",";
|
||||
$dial_string .= "fax_use_ecm=off" . ",";
|
||||
$dial_string .= "api_hangup_hook='lua fax_retry.lua'";
|
||||
$dial_string = "{" . $dial_string . "}" . $fax_uri." &txfax('".$fax_file."')";
|
||||
$dial_string = "{" . $dial_string . "}" . $fax_uri." &txfax('".$fax_file."')";
|
||||
|
||||
//get the event socket information
|
||||
$sql = "select * from v_settings ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach ($result as &$row) {
|
||||
$database = new database;
|
||||
$row = $database->select($sql, $parameters, 'row');
|
||||
if (is_array($row) && @sizeof($row) != 0) {
|
||||
$event_socket_ip_address = $row["event_socket_ip_address"];
|
||||
$event_socket_port = $row["event_socket_port"];
|
||||
$event_socket_password = $row["event_socket_password"];
|
||||
break;
|
||||
}
|
||||
unset($sql);
|
||||
|
||||
//create the event socket connection
|
||||
$fp = event_socket_create($event_socket_ip_address, $event_socket_port, $event_socket_password);
|
||||
@@ -537,7 +568,7 @@ if (!function_exists('fax_split_dtmf')) {
|
||||
//send the command with event socket
|
||||
if ($fp) {
|
||||
//prepare the fax originate command
|
||||
$cmd = "api originate " . $dial_string;
|
||||
$cmd = "api originate ".$dial_string;
|
||||
//send info to the log
|
||||
echo "fax forward\n";
|
||||
echo $cmd."\n";
|
||||
@@ -683,16 +714,17 @@ if (!function_exists('fax_split_dtmf')) {
|
||||
else {
|
||||
$fax_to_email_queue_dir = $_SESSION['switch']['storage']['dir']."/fax";
|
||||
if ($email_status == 'ok') {
|
||||
// log the success
|
||||
//log the success
|
||||
$fp = fopen($fax_to_email_queue_dir."/emailed_faxes.log", "a");
|
||||
fwrite($fp, $fax_file_name." received on ".$fax_extension." emailed to ".$fax_email." ".$fax_messages."\n");
|
||||
fclose($fp);
|
||||
} else {
|
||||
// create an instruction log to email messages once the connection to the mail server has been restored
|
||||
}
|
||||
else {
|
||||
//create an instruction log to email messages once the connection to the mail server has been restored
|
||||
$fp = fopen($fax_to_email_queue_dir."/failed_fax_emails.log", "a");
|
||||
fwrite($fp, PHP_BINDIR."/php ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/secure/fax_to_email.php email='".$fax_email."' extension=".$fax_extension." name='".$fax_file."' messages='".$fax_messages."' domain=".$domain_name." caller_id_name='".$caller_id_name."' caller_id_number=".$caller_id_number." retry=true\n");
|
||||
fclose($fp);
|
||||
// create a script to do the delayed mailing
|
||||
//create a script to do the delayed mailing
|
||||
$fp = fopen($_SESSION['server']['temp']['dir']."/failed_fax_emails.sh", "w");
|
||||
fwrite($fp, "rm ".$_SESSION['server']['temp']['dir']."/fax_email_retry.sh\n");
|
||||
fwrite($fp, "mv ".$fax_to_email_queue_dir."/failed_fax_emails.log ".$_SESSION['server']['temp']['dir']."/fax_email_retry.sh\n");
|
||||
@@ -700,7 +732,7 @@ if (!function_exists('fax_split_dtmf')) {
|
||||
fwrite($fp, $_SESSION['server']['temp']['dir']."/fax_email_retry.sh\n");
|
||||
fclose($fp);
|
||||
$tmp_response = exec("chmod 777 ".$_SESSION['server']['temp']['dir']."/failed_fax_emails.sh");
|
||||
// note we use batch in order to execute when system load is low. Alternatively this could be replaced with AT.
|
||||
//note we use batch in order to execute when system load is low. Alternatively this could be replaced with AT.
|
||||
$tmp_response = exec("at -f ".$_SESSION['server']['temp']['dir']."/failed_fax_emails.sh now + 3 minutes");
|
||||
}
|
||||
}
|
||||
@@ -719,4 +751,4 @@ if (!function_exists('fax_split_dtmf')) {
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2018
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2019
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
@@ -82,23 +82,23 @@
|
||||
}
|
||||
|
||||
//parse the email message
|
||||
$mime=new mime_parser_class;
|
||||
$mime = new mime_parser_class;
|
||||
$mime->decode_bodies = 1;
|
||||
$parameters=array(
|
||||
$parameters = array(
|
||||
//'File'=>$message_file,
|
||||
|
||||
// Read a message from a string instead of a file
|
||||
'Data'=>$msg,
|
||||
'Data' => $msg,
|
||||
|
||||
// Save the message body parts to a directory
|
||||
// 'SaveBody'=>'/tmp',
|
||||
// 'SaveBody' => '/tmp',
|
||||
|
||||
// Do not retrieve or save message body parts
|
||||
// 'SkipBody'=>1,
|
||||
// 'SkipBody' => 1,
|
||||
);
|
||||
$success=$mime->Decode($parameters, $decoded);
|
||||
$success = $mime->Decode($parameters, $decoded);
|
||||
|
||||
if(!$success) {
|
||||
if (!$success) {
|
||||
echo "MIME message decoding error: ".HtmlSpecialChars($mime->error)."\n";
|
||||
}
|
||||
else {
|
||||
@@ -118,7 +118,7 @@
|
||||
$body = '';
|
||||
$content_type = $decoded[0]['Headers']['content-type:'];
|
||||
if (substr($content_type, 0, 15) == "multipart/mixed" || substr($content_type, 0, 21) == "multipart/alternative") {
|
||||
foreach($decoded[0]["Parts"] as $row) {
|
||||
foreach ($decoded[0]["Parts"] as $row) {
|
||||
$body_content_type = $row["Headers"]["content-type:"];
|
||||
if (substr($body_content_type, 0, 9) == "text/html") { $body = $row["Body"]; }
|
||||
if (substr($body_content_type, 0, 10) == "text/plain") { $body_plain = $row["Body"]; $body = $body_plain; }
|
||||
@@ -141,7 +141,8 @@
|
||||
$smtp['host'] = (strlen($_SESSION['email']['smtp_host']['text'])?$_SESSION['email']['smtp_host']['text']:'127.0.0.1');
|
||||
if (isset($_SESSION['email']['smtp_port'])) {
|
||||
$smtp['port'] = (int)$_SESSION['email']['smtp_port']['numeric'];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$smtp['port'] = 0;
|
||||
}
|
||||
$smtp['secure'] = $_SESSION['email']['smtp_secure']['text'];
|
||||
@@ -162,21 +163,21 @@
|
||||
if ($headers["X-FusionPBX-Domain-UUID"] != '') {
|
||||
$sql = "select domain_setting_subcategory, domain_setting_value ";
|
||||
$sql .= "from v_domain_settings ";
|
||||
$sql .= "where domain_uuid = '".$headers["X-FusionPBX-Domain-UUID"]."' ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and (domain_setting_category = 'email' or domain_setting_category = 'voicemail') ";
|
||||
$sql .= "and domain_setting_name = 'text' ";
|
||||
$sql .= "and domain_setting_enabled = 'true' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
$parameters['domain_uuid'] = $headers["X-FusionPBX-Domain-UUID"];
|
||||
$database = new database;
|
||||
$result = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as $row) {
|
||||
if ($row['domain_setting_value'] != '') {
|
||||
$smtp[str_replace('smtp_','',$row["domain_setting_subcategory"])] = $row['domain_setting_value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($sql, $prep_statement);
|
||||
unset($sql, $parameters, $result, $row);
|
||||
}
|
||||
// value adjustments
|
||||
$smtp['auth'] = ($smtp['auth'] == "true") ? true : false;
|
||||
@@ -195,7 +196,10 @@
|
||||
case 'mail': $mail->IsMail(); break;
|
||||
default: $mail->IsSMTP(); break;
|
||||
}
|
||||
} else $mail->IsSMTP();
|
||||
}
|
||||
else {
|
||||
$mail->IsSMTP();
|
||||
}
|
||||
|
||||
// optional bypass TLS certificate check e.g. for self-signed certificates
|
||||
if (isset($_SESSION['email']['smtp_validate_certificate'])) {
|
||||
@@ -257,7 +261,7 @@
|
||||
$mail->AddAddress($to);
|
||||
}
|
||||
else {
|
||||
foreach($to_array as $to_row) {
|
||||
foreach ($to_array as $to_row) {
|
||||
if (strlen($to_row) > 0) {
|
||||
echo "Add Address: $to_row\n";
|
||||
$mail->AddAddress(trim($to_row));
|
||||
@@ -266,7 +270,7 @@
|
||||
}
|
||||
|
||||
//get the attachments and add to the email
|
||||
if($success) {
|
||||
if ($success) {
|
||||
foreach ($decoded[0][Parts] as &$parts_array) {
|
||||
$content_type = $parts_array["Parts"][0]["Headers"]["content-type:"];
|
||||
//image/tiff;name="testfax.tif"
|
||||
@@ -325,7 +329,7 @@
|
||||
//add the body to the email
|
||||
$body_plain = remove_tags($body);
|
||||
//echo "body_plain = $body_plain\n";
|
||||
if ((substr($body, 0, 5) == "<html") || (substr($body, 0, 9) == "<!doctype")) {
|
||||
if ((substr($body, 0, 5) == "<html") || (substr($body, 0, 9) == "<!doctype")) {
|
||||
$mail->ContentType = "text/html";
|
||||
$mail->Body = $body."<br><br>".nl2br($transcription);
|
||||
$mail->AltBody = $body_plain."\n\n$transcription";
|
||||
@@ -340,40 +344,40 @@
|
||||
$mail->CharSet = "utf-8";
|
||||
|
||||
//send the email
|
||||
if(!$mail->Send()) {
|
||||
if (!$mail->Send()) {
|
||||
$mailer_error = $mail->ErrorInfo;
|
||||
echo "Mailer Error: ".$mailer_error."\n\n";
|
||||
|
||||
$call_uuid = $headers["X-FusionPBX-Call-UUID"];
|
||||
if ($resend == true) {
|
||||
echo "Retained in v_email_logs \n";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// log/store message in database for review
|
||||
if (!isset($email_log_uuid)) {
|
||||
$email_log_uuid = uuid();
|
||||
$sql = "insert into v_email_logs ( ";
|
||||
$sql .= "email_log_uuid, ";
|
||||
if ($call_uuid) {
|
||||
$sql .= "call_uuid, ";
|
||||
}
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "sent_date, ";
|
||||
$sql .= "type, ";
|
||||
$sql .= "status, ";
|
||||
$sql .= "email ";
|
||||
$sql .= ") values ( ";
|
||||
$sql .= "'".$email_log_uuid."', ";
|
||||
if ($call_uuid) {
|
||||
$sql .= "'".$call_uuid."', ";
|
||||
}
|
||||
$sql .= "'".$headers["X-FusionPBX-Domain-UUID"]."', ";
|
||||
$sql .= "now(),";
|
||||
$sql .= "'".$headers["X-FusionPBX-Email-Type"]."', ";
|
||||
$sql .= "'failed', ";
|
||||
$sql .= "'".str_replace("'", "''", $msg)."' ";
|
||||
$sql .= ") ";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
//build insert array
|
||||
$email_log_uuid = uuid();
|
||||
$array['email_logs'][0]['email_log_uuid'] = $email_log_uuid;
|
||||
if (is_uuid($call_uuid)) {
|
||||
$array['email_logs'][0]['call_uuid'] = $call_uuid;
|
||||
}
|
||||
$array['email_logs'][0]['domain_uuid'] = $headers["X-FusionPBX-Domain-UUID"];
|
||||
$array['email_logs'][0]['sent_date'] = 'now()';
|
||||
$array['email_logs'][0]['type'] = $headers["X-FusionPBX-Email-Type"];
|
||||
$array['email_logs'][0]['status'] = 'failed';
|
||||
$array['email_logs'][0]['email'] = str_replace("'", "''", $msg);
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('email_log_add', 'temp');
|
||||
//execute insert
|
||||
$database = new database;
|
||||
$database->app_name = 'v_mailto';
|
||||
$database->app_uuid = 'ba41954e-9d21-4b10-bbc2-fa5ceabeb184';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p = new permissions;
|
||||
$p->delete('email_log_add', 'temp');
|
||||
}
|
||||
|
||||
echo "Retained in v_email_logs as email_log_uuid = ".$email_log_uuid."\n";
|
||||
@@ -394,31 +398,25 @@
|
||||
fclose($fp);
|
||||
|
||||
/*
|
||||
// save in /tmp as eml file
|
||||
//save in /tmp as eml file
|
||||
$fp = fopen(sys_get_temp_dir()."/email.eml", "w");
|
||||
ob_end_clean();
|
||||
ob_start();
|
||||
|
||||
$fp = fopen(sys_get_temp_dir()."/email.eml", "w");
|
||||
ob_end_clean();
|
||||
ob_start();
|
||||
$sql = "select email from v_email_logs where email_log_uuid = :email_log_uuid ";
|
||||
$parameters['email_log_uuid'] = $email_log_uuid;
|
||||
$database = new database;
|
||||
$email = $database->select($sql, $parameters, 'column');
|
||||
echo $email;
|
||||
unset($sql, $parameters, $email);
|
||||
|
||||
$sql = "select email from v_email_logs where email_log_uuid = '".$email_log_uuid."'";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
foreach ($result as &$row) {
|
||||
echo $row["email"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($sql, $prep_statement, $result);
|
||||
$content = ob_get_contents(); //get the output from the buffer
|
||||
$content = str_replace("<br />", "", $content);
|
||||
|
||||
$content = ob_get_contents(); //get the output from the buffer
|
||||
$content = str_replace("<br />", "", $content);
|
||||
|
||||
ob_end_clean(); //clean the buffer
|
||||
|
||||
fwrite($fp, $content);
|
||||
fclose($fp);
|
||||
ob_end_clean(); //clean the buffer
|
||||
|
||||
fwrite($fp, $content);
|
||||
fclose($fp);
|
||||
*/
|
||||
?>
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user