prod to stage
# Conflicts: # includes/filter_header.php # scripts/cron.php # scripts/cron_certificate_refresher.php # scripts/cron_domain_refresher.php # scripts/cron_mail_queue.php # scripts/cron_ticket_email_parser.php
This commit is contained in:
134
functions.php
134
functions.php
@@ -3,15 +3,6 @@
|
||||
// Role check failed wording
|
||||
DEFINE("WORDING_ROLECHECK_FAILED", "You are not permitted to do that!");
|
||||
|
||||
// PHP Mailer Libs
|
||||
require_once "plugins/PHPMailer/src/Exception.php";
|
||||
require_once "plugins/PHPMailer/src/PHPMailer.php";
|
||||
require_once "plugins/PHPMailer/src/SMTP.php";
|
||||
|
||||
// Initiate PHPMailer
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
// Function to generate both crypto & URL safe random strings
|
||||
function randomString($length = 16) {
|
||||
// Generate some cryptographically safe random bytes
|
||||
@@ -520,7 +511,7 @@ function getDomainRecords($name)
|
||||
$records = array();
|
||||
|
||||
// Only run if we think the domain is valid
|
||||
if (!filter_var($name, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
|
||||
if (!filter_var($name, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) || !checkdnsrr($name, 'SOA')) {
|
||||
$records['a'] = '';
|
||||
$records['ns'] = '';
|
||||
$records['mx'] = '';
|
||||
@@ -688,116 +679,6 @@ function validateAccountantRole() {
|
||||
}
|
||||
}
|
||||
|
||||
// Send a single email to a single recipient
|
||||
function sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port, $from_email, $from_name, $to_email, $to_name, $subject, $body, $ics_str)
|
||||
{
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
if (empty($config_smtp_username)) {
|
||||
$smtp_auth = false;
|
||||
} else {
|
||||
$smtp_auth = true;
|
||||
}
|
||||
|
||||
try {
|
||||
// Mail Server Settings
|
||||
$mail->CharSet = "UTF-8"; // Specify UTF-8 charset to ensure symbols ($/£) load correctly
|
||||
$mail->SMTPDebug = 0; // No Debugging
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = $config_smtp_host; // Specify SMTP server
|
||||
$mail->SMTPAuth = $smtp_auth; // Enable SMTP authentication
|
||||
$mail->Username = $config_smtp_username; // SMTP username
|
||||
$mail->Password = $config_smtp_password; // SMTP password
|
||||
if ($config_smtp_encryption == 'None') {
|
||||
$mail->SMTPOptions = array(
|
||||
'ssl' => array(
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
));
|
||||
$mail->SMTPSecure = false;
|
||||
$mail->SMTPAutoTLS = false;
|
||||
} else {
|
||||
$mail->SMTPSecure = $config_smtp_encryption; // Enable TLS encryption, `ssl` also accepted
|
||||
}
|
||||
$mail->Port = $config_smtp_port; // TCP port to connect to
|
||||
|
||||
//Recipients
|
||||
$mail->setFrom($from_email, $from_name);
|
||||
$mail->addAddress("$to_email", "$to_name"); // Add a recipient
|
||||
|
||||
// Content
|
||||
$mail->isHTML(true); // Set email format to HTML
|
||||
$mail->Subject = "$subject"; // Subject
|
||||
$mail->Body = "<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
color: #333;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.email-container {
|
||||
max-width: 600px;
|
||||
margin: auto;
|
||||
padding: 20px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.header {
|
||||
font-size: 18px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.link-button {
|
||||
display: inline-block;
|
||||
background-color: #007bff;
|
||||
color: #ffffff;
|
||||
padding: 10px 20px;
|
||||
text-decoration: none;
|
||||
border-radius: 5px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.footer {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
margin-top: 20px;
|
||||
border-top: 1px solid #ddd;
|
||||
padding-top: 10px;
|
||||
}
|
||||
.no-reply {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='email-container'>
|
||||
$body
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"; // Content
|
||||
|
||||
// Attachments - todo
|
||||
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
|
||||
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
|
||||
|
||||
if (!empty($ics_str)) {
|
||||
$mail->addStringAttachment($ics_str, 'Scheduled_ticket.ics', 'base64', 'text/calendar');
|
||||
}
|
||||
|
||||
// Send
|
||||
$mail->send();
|
||||
|
||||
// Return true if this was successful
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
// If we couldn't send the message return the error, so we can log it in the database (truncated)
|
||||
error_log("ITFlow - Failed to send email: " . $mail->ErrorInfo);
|
||||
return substr("Mailer Error: $mail->ErrorInfo", 0, 100) . "...";
|
||||
}
|
||||
}
|
||||
|
||||
function roundUpToNearestMultiple($n, $increment = 1000)
|
||||
{
|
||||
return (int) ($increment * ceil($n / $increment));
|
||||
@@ -1297,7 +1178,7 @@ function fetchUpdates() {
|
||||
function getDomainExpirationDate($domain) {
|
||||
// Execute the whois command
|
||||
$result = shell_exec("whois " . escapeshellarg($domain));
|
||||
if (!$result) {
|
||||
if (!$result || !checkdnsrr($domain, 'SOA')) {
|
||||
return null; // Return null if WHOIS query fails
|
||||
}
|
||||
|
||||
@@ -1506,6 +1387,10 @@ function appNotify($type, $details, $action = null, $client_id = 0, $entity_id =
|
||||
$action = "NULL"; // Without quotes for SQL NULL
|
||||
}
|
||||
|
||||
$type = substr($type, 0, 200);
|
||||
$details = substr($details, 0, 1000);
|
||||
$action = substr($action, 0, 250);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT user_id FROM users
|
||||
WHERE user_type = 1 AND user_status = 1 AND user_archived_at IS NULL
|
||||
");
|
||||
@@ -1524,12 +1409,19 @@ function logAction($type, $action, $description, $client_id = 0, $entity_id = 0)
|
||||
$session_user_id = 0;
|
||||
}
|
||||
|
||||
$type = substr($type, 0, 200);
|
||||
$action = substr($action, 0, 255);
|
||||
$description = substr($description, 0, 1000);
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = '$type', log_action = '$action', log_description = '$description', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $entity_id");
|
||||
}
|
||||
|
||||
function logApp($category, $type, $details) {
|
||||
global $mysqli;
|
||||
|
||||
$category = substr($category, 0, 200);
|
||||
$details = substr($details, 0, 1000);
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO app_logs SET app_log_category = '$category', app_log_type = '$type', app_log_details = '$details'");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user