2020-06-03 15:31:18 +00:00
|
|
|
<?php
|
2023-08-23 16:16:36 +00:00
|
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
|
2020-06-03 15:31:18 +00:00
|
|
|
function fillString($string, $targetlength)
|
|
|
|
{
|
|
|
|
while(strlen($string) < $targetlength)
|
|
|
|
{
|
|
|
|
$string = "0".$string;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function left($str, $length)
|
|
|
|
{
|
|
|
|
return substr($str, 0, $length);
|
|
|
|
}
|
|
|
|
|
|
|
|
function right($str, $length)
|
|
|
|
{
|
|
|
|
return substr($str, -$length);
|
|
|
|
}
|
|
|
|
|
2023-08-23 16:16:36 +00:00
|
|
|
function generateToken($length): string {
|
|
|
|
$chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
$res = "";
|
|
|
|
for($i = 0; $i < $length; $i++) {
|
|
|
|
$index = random_int(0, strlen($chars) - 1);
|
|
|
|
$res = $res.substr($chars, $index, 1);
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function htmlToPlain($message): string {
|
|
|
|
$messageNew = str_replace('<br/>', "\n", $message);
|
|
|
|
$messageNew = preg_replace('/<a href="(.*)">(.*)<\\/a>/', "$2: $1", $messageNew);
|
|
|
|
return $messageNew;
|
|
|
|
}
|
|
|
|
|
2023-08-23 16:16:36 +00:00
|
|
|
function sendMail($email, $message, $subject, $title, $preheader): bool {
|
|
|
|
include_once('lib/phpmailer/Exception.php');
|
|
|
|
include_once('lib/phpmailer/PHPMailer.php');
|
|
|
|
include_once('lib/phpmailer/SMTP.php');
|
2023-08-23 16:16:36 +00:00
|
|
|
include_once('app/HTML.php');
|
|
|
|
global $RUNTIME;
|
|
|
|
|
|
|
|
$mailer = new PHPMailer(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$mailer->isSMTP();
|
|
|
|
$mailer->Host = $RUNTIME['SMTP']['SERVER'];
|
|
|
|
$mailer->Port = $RUNTIME['SMTP']['PORT'];
|
|
|
|
$mailer->Username = $RUNTIME['SMTP']['ADDRESS'];
|
|
|
|
$mailer->Password = $RUNTIME['SMTP']['PASS'];
|
2023-08-23 16:16:36 +00:00
|
|
|
$mailer->SMTPAuth = true;
|
2023-08-23 16:16:36 +00:00
|
|
|
$mailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
|
|
|
|
|
|
|
$mailer->setFrom($RUNTIME['SMTP']['ADDRESS'], $RUNTIME['SMTP']['NAME']);
|
|
|
|
$mailer->addAddress($email);
|
|
|
|
|
|
|
|
$mailer->isHTML(true);
|
|
|
|
$mailer->Subject = $subject;
|
|
|
|
$mailHtml = new HTML();
|
2023-08-23 16:16:36 +00:00
|
|
|
$mailHtml->importHTML("mail.html");
|
2023-08-23 16:16:36 +00:00
|
|
|
$mailHtml->setHTMLTitle($title);
|
|
|
|
$mailHtml->ReplaceLayoutInhalt('%%MESSAGE%%', $message);
|
|
|
|
$mailHtml->ReplaceLayoutInhalt('%%PREHEADER%%', $preheader);
|
|
|
|
$mailHtml->build();
|
|
|
|
$mailer->Body = $mailHtml->ausgabe();
|
|
|
|
$mailer->AltBody = htmlToPlain($message);
|
|
|
|
|
|
|
|
$mailer->send();
|
|
|
|
return true;
|
|
|
|
} catch(Exception $e) {
|
|
|
|
error_log('Could not send email: '.$mailer->ErrorInfo);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 15:31:18 +00:00
|
|
|
function getDataFromHTTP($URL, $contend = "", $requestTyp = "application/text")
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if($contend != "")
|
|
|
|
{
|
2023-08-23 16:16:35 +00:00
|
|
|
return file_get_contents($URL, true, stream_context_create(array('http' => array('header' => 'Content-type: '.$requestTyp, 'method' => 'POST', 'timeout' => 0.5, 'content' => $contend))));
|
2020-06-03 15:31:18 +00:00
|
|
|
}else{
|
2023-08-23 16:16:35 +00:00
|
|
|
return file_get_contents($URL);
|
2020-06-03 15:31:18 +00:00
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo "(HTTP REQUEST) error while conntect to remote server. : ".$URL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendInworldIM($fromUUID, $toUUID, $fromName, $targetURL, $text)
|
|
|
|
{
|
|
|
|
$rawXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>grid_instant_message</methodName><params><param><value><struct><member><name>position_x</name><value><string>0</string></value></member><member><name>position_y</name><value><string>0</string></value></member><member><name>position_z</name><value><string>0</string></value></member><member><name>to_agent_id</name><value><string>".$toUUID."</string></value></member><member><name>from_agent_session</name><value><string>00000000-0000-0000-0000-000000000000</string></value></member><member><name>im_session_id</name><value><string>".$fromUUID."</string></value></member><member><name>from_agent_name</name><value><string>".$fromName."</string></value></member><member><name>from_agent_id</name><value><string>".$fromUUID."</string></value></member><member><name>binary_bucket</name><value><string>AA==</string></value></member><member><name>region_handle</name><value><i4>0</i4></value></member><member><name>region_id</name><value><string>00000000-0000-0000-0000-000000000000</string></value></member><member><name>parent_estate_id</name><value><string>1</string></value></member><member><name>timestamp</name><value><string>".time()."</string></value></member><member><name>dialog</name><value><string>AA==</string></value></member><member><name>offline</name><value><string>AA==</string></value></member><member><name>from_group</name><value><string>FALSE</string></value></member><member><name>message</name><value><string>".$text."</string></value></member></struct></value></param></params></methodCall>";
|
|
|
|
getDataFromHTTP($targetURL, $rawXML, "text/xml");
|
|
|
|
}
|
|
|
|
?>
|