2022-04-22 21:00:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
//check the permission
|
|
|
|
|
if (defined('STDIN')) {
|
2023-06-17 06:49:09 +02:00
|
|
|
//includes files
|
|
|
|
|
require_once dirname(__DIR__, 4) . "/resources/require.php";
|
2022-04-22 21:00:38 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-23 07:52:01 +02:00
|
|
|
//includes files
|
|
|
|
|
require_once "resources/pdo.php";
|
2023-01-13 22:23:27 +01:00
|
|
|
require $_SERVER['DOCUMENT_ROOT']."/app/email_queue/resources/functions/transcribe.php";
|
2022-10-23 07:52:01 +02:00
|
|
|
|
2022-04-22 21:00:38 +02:00
|
|
|
//increase limits
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
ini_set('max_execution_time', 0);
|
|
|
|
|
ini_set('memory_limit', '512M');
|
|
|
|
|
|
|
|
|
|
//save the arguments to variables
|
|
|
|
|
$script_name = $argv[0];
|
|
|
|
|
if (!empty($argv[1])) {
|
|
|
|
|
parse_str($argv[1], $_GET);
|
|
|
|
|
}
|
|
|
|
|
//print_r($_GET);
|
|
|
|
|
|
|
|
|
|
//set the variables
|
|
|
|
|
if (isset($_GET['hostname'])) {
|
|
|
|
|
$hostname = urldecode($_GET['hostname']);
|
|
|
|
|
}
|
|
|
|
|
if (isset($_GET['debug'])) {
|
|
|
|
|
$debug = $_GET['debug'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//define the process id file
|
|
|
|
|
$pid_file = "/var/run/fusionpbx/".basename( $argv[0], ".php") .".pid";
|
|
|
|
|
//echo "pid_file: ".$pid_file."\n";
|
|
|
|
|
|
|
|
|
|
//function to check if the process exists
|
|
|
|
|
function process_exists($file = false) {
|
|
|
|
|
|
|
|
|
|
//set the default exists to false
|
|
|
|
|
$exists = false;
|
|
|
|
|
|
|
|
|
|
//check to see if the process is running
|
|
|
|
|
if (file_exists($file)) {
|
|
|
|
|
$pid = file_get_contents($file);
|
|
|
|
|
if (posix_getsid($pid) === false) {
|
|
|
|
|
//process is not running
|
|
|
|
|
$exists = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//process is running
|
|
|
|
|
$exists = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//return the result
|
|
|
|
|
return $exists;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//check to see if the process exists
|
|
|
|
|
$pid_exists = process_exists($pid_file);
|
|
|
|
|
|
|
|
|
|
//prevent the process running more than once
|
|
|
|
|
if ($pid_exists) {
|
|
|
|
|
echo "Cannot lock pid file {$pid_file}\n";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 00:10:13 +02:00
|
|
|
//get the email queue settings
|
|
|
|
|
$setting = new settings(["category" => "email_queue"]);
|
|
|
|
|
|
2022-04-22 21:00:38 +02:00
|
|
|
//email queue enabled
|
2023-09-15 00:10:13 +02:00
|
|
|
if ($setting->get('email_queue', 'enabled') != 'true') {
|
2022-04-22 21:00:38 +02:00
|
|
|
echo "Email Queue is disabled in Default Settings\n";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//make sure the /var/run/fusionpbx directory exists
|
|
|
|
|
if (!file_exists('/var/run/fusionpbx')) {
|
|
|
|
|
$result = mkdir('/var/run/fusionpbx', 0777, true);
|
|
|
|
|
if (!$result) {
|
|
|
|
|
die('Failed to create /var/run/fusionpbx');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//create the process id file if the process doesn't exist
|
|
|
|
|
if (!$pid_exists) {
|
|
|
|
|
//remove the old pid file
|
|
|
|
|
if (file_exists($file)) {
|
|
|
|
|
unlink($pid_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//show the details to the user
|
|
|
|
|
//echo "The process id is ".getmypid()."\n";
|
|
|
|
|
//echo "pid_file: ".$pid_file."\n";
|
|
|
|
|
|
|
|
|
|
//save the pid file
|
|
|
|
|
file_put_contents($pid_file, getmypid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the call center settings
|
2023-09-15 00:10:13 +02:00
|
|
|
$interval = $setting->get('email_queue', 'interval');
|
2022-04-22 21:00:38 +02:00
|
|
|
|
|
|
|
|
//set the defaults
|
|
|
|
|
if (!is_numeric($interval)) { $interval = 30; }
|
|
|
|
|
|
|
|
|
|
//set the email queue limit
|
2023-09-15 00:10:13 +02:00
|
|
|
if (!empty($setting->get('email_queue', 'limit'))) {
|
|
|
|
|
$email_queue_limit = $setting->get('email_queue', 'limit');
|
2022-04-22 21:00:38 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$email_queue_limit = '30';
|
|
|
|
|
}
|
2023-09-15 00:10:13 +02:00
|
|
|
if (!empty($setting->get('email_queue', 'debug'))) {
|
|
|
|
|
$debug = $setting->get('email_queue', 'debug');
|
2022-04-22 21:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the messages waiting in the email queue
|
|
|
|
|
$sql = "select * from v_email_queue ";
|
|
|
|
|
$sql .= "where (email_status = 'waiting' or email_status = 'trying') ";
|
|
|
|
|
$sql .= "and hostname = :hostname ";
|
|
|
|
|
$sql .= "order by domain_uuid asc ";
|
|
|
|
|
$sql .= "limit :limit ";
|
|
|
|
|
if (isset($hostname)) {
|
|
|
|
|
$parameters['hostname'] = $hostname;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$parameters['hostname'] = gethostname();
|
|
|
|
|
}
|
|
|
|
|
$parameters['limit'] = $email_queue_limit;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$email_queue = $database->select($sql, $parameters, 'all');
|
|
|
|
|
unset($parameters);
|
|
|
|
|
|
|
|
|
|
//process the messages
|
|
|
|
|
if (is_array($email_queue) && @sizeof($email_queue) != 0) {
|
|
|
|
|
foreach($email_queue as $row) {
|
2024-12-03 01:55:35 +01:00
|
|
|
$command = PHP_BINARY." ".$_SERVER['DOCUMENT_ROOT']."/app/email_queue/resources/jobs/email_send.php ";
|
2022-04-22 21:00:38 +02:00
|
|
|
$command .= "'action=send&email_queue_uuid=".$row["email_queue_uuid"]."&hostname=".$hostname."'";
|
|
|
|
|
if (isset($debug)) {
|
|
|
|
|
//run process inline to see debug info
|
|
|
|
|
echo $command."\n";
|
|
|
|
|
$result = system($command);
|
|
|
|
|
echo $result."\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//starts process rapidly doesn't wait for previous process to finish (used for production)
|
|
|
|
|
$handle = popen($command." > /dev/null &", 'r');
|
|
|
|
|
echo "'$handle'; " . gettype($handle) . "\n";
|
|
|
|
|
$read = fread($handle, 2096);
|
|
|
|
|
echo $read;
|
|
|
|
|
pclose($handle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//remove the old pid file
|
2022-04-24 08:19:57 +02:00
|
|
|
if (file_exists($pid_file)) {
|
2022-04-22 21:00:38 +02:00
|
|
|
unlink($pid_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//save output to
|
|
|
|
|
//$fp = fopen(sys_get_temp_dir()."/mailer-app.log", "a");
|
|
|
|
|
|
|
|
|
|
//prepare the output buffers
|
|
|
|
|
//ob_end_clean();
|
|
|
|
|
//ob_start();
|
|
|
|
|
|
|
|
|
|
//message divider for log file
|
|
|
|
|
//echo "\n\n=============================================================================================================================================\n\n";
|
|
|
|
|
|
|
|
|
|
//get and save the output from the buffer
|
|
|
|
|
//$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);
|
|
|
|
|
|
|
|
|
|
//notes
|
|
|
|
|
//echo __line__."\n";
|
|
|
|
|
// if not keeping the email then need to delete it after the voicemail is emailed
|
|
|
|
|
|
|
|
|
|
//how to use this feature
|
|
|
|
|
// cd /var/www/fusionpbx; /usr/bin/php /var/www/fusionpbx/app/email_queue/resources/send.php
|
|
|
|
|
|
|
|
|
|
?>
|