Adapt existing classes to new structure and PSR-12
parent
cc240f47a2
commit
686e991266
|
@ -1,4 +1,8 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mcp;
|
||||
|
||||
class FormValidator {
|
||||
|
||||
private array $fieldValidation;
|
||||
|
|
260
app/OpenSim.php
260
app/OpenSim.php
|
@ -1,61 +1,35 @@
|
|||
<?php
|
||||
class OpenSim
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mcp;
|
||||
|
||||
use Exception;
|
||||
use PDO;
|
||||
|
||||
class OpenSim
|
||||
{
|
||||
|
||||
private PDO $pdo;
|
||||
private $cache = array();
|
||||
|
||||
public function __construct(PDO $pdo)
|
||||
{
|
||||
public function isLoginValid($name, $password)
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
private function getUserNameFromGridData($userID, $table, $row): ?string
|
||||
{
|
||||
global $RUNTIME;
|
||||
|
||||
$nameParts = explode(" ", trim($name));
|
||||
if(count($nameParts) != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$statementUser = $RUNTIME['PDO']->prepare("SELECT PrincipalID FROM UserAccounts WHERE FirstName = ? AND LastName = ? LIMIT 1");
|
||||
$statementUser->execute($nameParts);
|
||||
|
||||
while($rowUser = $statementUser->fetch()) {
|
||||
$statementAuth = $RUNTIME['PDO']->prepare("SELECT passwordHash,passwordSalt FROM auth WHERE UUID = ? LIMIT 1");
|
||||
$statementAuth->execute(array($rowUser['PrincipalID']));
|
||||
|
||||
if ($rowAuth = $statementAuth->fetch()) {
|
||||
return md5(md5($_POST['password']).":".$rowAuth['passwordSalt']) == $rowAuth['passwordHash'];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getUserName($userID)
|
||||
{
|
||||
global $RUNTIME;
|
||||
|
||||
if ($userID == "00000000-0000-0000-0000-000000000000") {
|
||||
return "Unknown User";
|
||||
}
|
||||
|
||||
if (isset($RUNTIME['CACHE']['USERNAME'][$userID])) {
|
||||
return $RUNTIME['CACHE']['USERNAME'][$userID];
|
||||
}
|
||||
|
||||
$statementUser = $RUNTIME['PDO']->prepare("SELECT FirstName,LastName FROM UserAccounts WHERE PrincipalID = ?");
|
||||
$statementUser->execute(array($userID));
|
||||
|
||||
if ($rowUser = $statementUser->fetch()) {
|
||||
$RUNTIME['CACHE']['USERNAME'][$userID] = $rowUser['FirstName']." ".$rowUser['LastName'];
|
||||
return $rowUser['FirstName']." ".$rowUser['LastName'];
|
||||
}
|
||||
|
||||
$statementGridUser = $RUNTIME['PDO']->prepare("SELECT UserID FROM GridUser");
|
||||
$statementGridUser->execute();
|
||||
$statementGridUser = $this->pdo->prepare('SELECT '.$row.' FROM '.$table.' WHERE '.$row.' LIKE ?');
|
||||
$statementGridUser->execute(array($userID.';%'));
|
||||
|
||||
while ($rowGridUser = $statementGridUser->fetch()) {
|
||||
$userData = explode(";", $rowGridUser['UserID']);
|
||||
$userData = explode(";", $rowGridUser[$row]);
|
||||
|
||||
if (count($userData) >= 3) {
|
||||
$dbUserID = $userData[0];
|
||||
$dbUserName = $userData[2];
|
||||
|
||||
$RUNTIME['CACHE']['USERNAME'][$userID] = $dbUserName;
|
||||
$this->cache['USERNAME'][$userID] = $dbUserName;
|
||||
|
||||
if ($dbUserID == $userID) {
|
||||
return $dbUserName;
|
||||
|
@ -63,50 +37,50 @@
|
|||
}
|
||||
}
|
||||
|
||||
$statementFriends = $RUNTIME['PDO']->prepare("SELECT PrincipalID FROM Friends");
|
||||
$statementFriends->execute();
|
||||
|
||||
while ($rowFriends = $statementFriends->fetch()) {
|
||||
$userData = explode(";", $rowFriends['PrincipalID']);
|
||||
|
||||
if (count($userData) == 4) {
|
||||
$dbUserID = $userData[0];
|
||||
$dbUserName = $userData[2];
|
||||
|
||||
$RUNTIME['CACHE']['USERNAME'][$userID] = $dbUserName;
|
||||
|
||||
if ($dbUserID == $userID) {
|
||||
return $dbUserName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "Unknown User";
|
||||
}
|
||||
|
||||
public function getUserUUID($userName)
|
||||
{
|
||||
global $RUNTIME;
|
||||
|
||||
$statementUser = $RUNTIME['PDO']->prepare("SELECT PrincipalID,FirstName,LastName FROM UserAccounts");
|
||||
$statementUser->execute();
|
||||
|
||||
while ($rowUser = $statementUser->fetch()) {
|
||||
$sqlUserName = $rowUser['FirstName']." ".$rowUser['LastName'];
|
||||
|
||||
if ($sqlUserName == $userName) {
|
||||
return $rowUser['PrincipalID'];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRegionName($regionID)
|
||||
public function getUserName($userID): string
|
||||
{
|
||||
global $RUNTIME;
|
||||
if ($userID == "00000000-0000-0000-0000-000000000000") {
|
||||
return "Unknown User";
|
||||
}
|
||||
|
||||
$statementRegion = $RUNTIME['PDO']->prepare("SELECT regionName FROM regions WHERE uuid = ?");
|
||||
if (isset($this->cache['USERNAME'][$userID])) {
|
||||
return $this->cache['USERNAME'][$userID];
|
||||
}
|
||||
|
||||
$statementUser = $this->pdo->prepare('SELECT FirstName,LastName FROM UserAccounts WHERE PrincipalID = ?');
|
||||
$statementUser->execute(array($userID));
|
||||
|
||||
if ($rowUser = $statementUser->fetch()) {
|
||||
$this->cache['USERNAME'][$userID] = $rowUser['FirstName'].' '.$rowUser['LastName'];
|
||||
return $this->cache['USERNAME'][$userID];
|
||||
}
|
||||
|
||||
$res = $this->getUserNameFromGridData($this->pdo, $userID, 'GridUser', 'UserID');
|
||||
if ($res == null) {
|
||||
$res = $this->getUserNameFromGridData($this->pdo, $userID, 'Friends', 'PrincipalID');
|
||||
}
|
||||
|
||||
return $res == null ? "Unknown User" : $res;
|
||||
}
|
||||
|
||||
public function getUserUUID($userName): ?string
|
||||
{
|
||||
$statementUser = $this->pdo->prepare('SELECT PrincipalID,FirstName,LastName FROM UserAccounts WHERE FirstName = ? AND LastName = ?');
|
||||
$statementUser->execute(explode(' ', $userName));
|
||||
|
||||
if ($rowUser = $statementUser->fetch()) {
|
||||
return $rowUser['PrincipalID'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRegionName($regionID): string
|
||||
{
|
||||
$statementRegion = $this->pdo->prepare("SELECT regionName FROM regions WHERE uuid = ?");
|
||||
$statementRegion->execute(array($regionID));
|
||||
|
||||
if ($rowRegion = $statementRegion->fetch()) {
|
||||
|
@ -116,11 +90,9 @@
|
|||
return "Unknown Region";
|
||||
}
|
||||
|
||||
public function getPartner($userID)
|
||||
public function getPartner($userID): string
|
||||
{
|
||||
global $RUNTIME;
|
||||
|
||||
$statement = $RUNTIME['PDO']->prepare("SELECT profilePartner FROM userprofile WHERE useruuid = ?");
|
||||
$statement = $this->pdo->prepare("SELECT profilePartner FROM userprofile WHERE useruuid = ?");
|
||||
$statement->execute(array($userID));
|
||||
|
||||
while ($row = $statement->fetch()) {
|
||||
|
@ -129,14 +101,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
|
||||
public function allowOfflineIM($userID)
|
||||
public function allowOfflineIM($userID): string
|
||||
{
|
||||
global $RUNTIME;
|
||||
|
||||
$statement = $RUNTIME['PDO']->prepare("SELECT imviaemail FROM usersettings WHERE useruuid = ?");
|
||||
$statement = $this->pdo->prepare("SELECT imviaemail FROM usersettings WHERE useruuid = ?");
|
||||
$statement->execute(array($userID));
|
||||
|
||||
if ($row = $statement->fetch()) {
|
||||
|
@ -146,11 +116,9 @@
|
|||
return "FALSE";
|
||||
}
|
||||
|
||||
public function getUserMail($userID)
|
||||
public function getUserMail($userID): string
|
||||
{
|
||||
global $RUNTIME;
|
||||
|
||||
$statement = $RUNTIME['PDO']->prepare("SELECT Email FROM UserAccounts WHERE PrincipalID = ?");
|
||||
$statement = $this->pdo->prepare("SELECT Email FROM UserAccounts WHERE PrincipalID = ?");
|
||||
$statement->execute(array($userID));
|
||||
|
||||
if ($row = $statement->fetch()) {
|
||||
|
@ -160,108 +128,104 @@
|
|||
return "";
|
||||
}
|
||||
|
||||
public function getUserCount()
|
||||
private function getEntryCount($table): int
|
||||
{
|
||||
global $RUNTIME;
|
||||
|
||||
$statementUser = $RUNTIME['PDO']->prepare("SELECT COUNT(*) FROM UserAccounts");
|
||||
$statementUser->execute();
|
||||
return $statementUser->fetchColumn();
|
||||
$statementCount = $this->pdo->prepare('SELECT COUNT(*) AS Count FROM '.$table);
|
||||
$statementCount->execute();
|
||||
if ($row = $statementCount->fetch()) {
|
||||
return $row['Count'];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getRegionCount()
|
||||
public function getUserCount(): int
|
||||
{
|
||||
global $RUNTIME;
|
||||
|
||||
$statementUser = $RUNTIME['PDO']->prepare("SELECT COUNT(*) FROM regions");
|
||||
$statementUser->execute();
|
||||
return $statementUser->fetchColumn();
|
||||
return $this->getEntryCount('UserAccounts');
|
||||
}
|
||||
|
||||
public function getOnlineCount()
|
||||
public function getRegionCount(): int
|
||||
{
|
||||
global $RUNTIME;
|
||||
return $this->getEntryCount('regions');
|
||||
}
|
||||
|
||||
$statementUser = $RUNTIME['PDO']->prepare("SELECT COUNT(*) FROM Presence");
|
||||
$statementUser->execute();
|
||||
return $statementUser->fetchColumn();
|
||||
public function getOnlineCount(): int
|
||||
{
|
||||
return $this->getEntryCount('Presence');
|
||||
}
|
||||
|
||||
public function deleteUser($uuid): bool
|
||||
{
|
||||
global $RUNTIME;
|
||||
|
||||
try {
|
||||
$RUNTIME['PDO']->beginTransaction();
|
||||
$this->pdo->beginTransaction();
|
||||
|
||||
$statementAuth = $RUNTIME['PDO']->prepare('DELETE FROM auth WHERE UUID = ?');
|
||||
$statementAuth = $this->pdo->prepare('DELETE FROM auth WHERE UUID = ?');
|
||||
$statementAuth->execute([$uuid]);
|
||||
|
||||
$statementAgentPrefs = $RUNTIME['PDO']->prepare('DELETE FROM AgentPrefs WHERE PrincipalID = ?');
|
||||
$statementAgentPrefs = $this->pdo->prepare('DELETE FROM AgentPrefs WHERE PrincipalID = ?');
|
||||
$statementAgentPrefs->execute([$uuid]);
|
||||
|
||||
$statementAvatars = $RUNTIME['PDO']->prepare('DELETE FROM Avatars WHERE PrincipalID = ?');
|
||||
$statementAvatars = $this->pdo->prepare('DELETE FROM Avatars WHERE PrincipalID = ?');
|
||||
$statementAvatars->execute([$uuid]);
|
||||
|
||||
$statementGridUser = $RUNTIME['PDO']->prepare('DELETE FROM GridUser WHERE UserID = ?');
|
||||
$statementGridUser = $this->pdo->prepare('DELETE FROM GridUser WHERE UserID = ?');
|
||||
$statementGridUser->execute([$uuid]);
|
||||
|
||||
$statementEstateUser = $RUNTIME['PDO']->prepare('DELETE FROM estate_users WHERE uuid = ?');
|
||||
$statementEstateUser = $this->pdo->prepare('DELETE FROM estate_users WHERE uuid = ?');
|
||||
$statementEstateUser->execute([$uuid]);
|
||||
|
||||
$statementEstateBan = $RUNTIME['PDO']->prepare('DELETE FROM estateban WHERE bannedUUID = ?');
|
||||
$statementEstateBan = $this->pdo->prepare('DELETE FROM estateban WHERE bannedUUID = ?');
|
||||
$statementEstateBan->execute([$uuid]);
|
||||
|
||||
$statementHgTraveling = $RUNTIME['PDO']->prepare('DELETE FROM hg_traveling_data WHERE UserID = ?');
|
||||
$statementHgTraveling = $this->pdo->prepare('DELETE FROM hg_traveling_data WHERE UserID = ?');
|
||||
$statementHgTraveling->execute([$uuid]);
|
||||
|
||||
$statementUserIdentitys = $RUNTIME['PDO']->prepare('DELETE FROM UserIdentitys WHERE PrincipalID = ?');
|
||||
$statementUserIdentitys = $this->pdo->prepare('DELETE FROM UserIdentitys WHERE PrincipalID = ?');
|
||||
$statementUserIdentitys->execute([$uuid]);
|
||||
|
||||
$statementFriends = $RUNTIME['PDO']->prepare('DELETE FROM Friends WHERE PrincipalID = ? OR Friend = ?');
|
||||
$statementFriends = $this->pdo->prepare('DELETE FROM Friends WHERE PrincipalID = ? OR Friend = ?');
|
||||
$statementFriends->execute([$uuid, $uuid]);
|
||||
|
||||
$statementImOffline = $RUNTIME['PDO']->prepare('DELETE FROM im_offline WHERE PrincipalID = ?');
|
||||
$statementImOffline = $this->pdo->prepare('DELETE FROM im_offline WHERE PrincipalID = ?');
|
||||
$statementImOffline->execute([$uuid]);
|
||||
|
||||
$statementInventoryFolders = $RUNTIME['PDO']->prepare('DELETE FROM inventoryfolders WHERE agentID = ?');
|
||||
$statementInventoryFolders = $this->pdo->prepare('DELETE FROM inventoryfolders WHERE agentID = ?');
|
||||
$statementInventoryFolders->execute([$uuid]);
|
||||
|
||||
$statementInventoryItems = $RUNTIME['PDO']->prepare('DELETE FROM inventoryitems WHERE avatarID = ?');
|
||||
$statementInventoryItems = $this->pdo->prepare('DELETE FROM inventoryitems WHERE avatarID = ?');
|
||||
$statementInventoryItems->execute([$uuid]);
|
||||
|
||||
$statementGroupMembership = $RUNTIME['PDO']->prepare('DELETE FROM os_groups_membership WHERE PrincipalID = ?');
|
||||
$statementGroupMembership = $this->pdo->prepare('DELETE FROM os_groups_membership WHERE PrincipalID = ?');
|
||||
$statementGroupMembership->execute([$uuid]);
|
||||
|
||||
$statementGroupRoles = $RUNTIME['PDO']->prepare('DELETE FROM os_groups_rolemembership WHERE PrincipalID = ?');
|
||||
$statementGroupRoles = $this->pdo->prepare('DELETE FROM os_groups_rolemembership WHERE PrincipalID = ?');
|
||||
$statementGroupRoles->execute([$uuid]);
|
||||
|
||||
$statementGroupRoles = $RUNTIME['PDO']->prepare('DELETE FROM Presence WHERE UserID = ?');
|
||||
$statementGroupRoles = $this->pdo->prepare('DELETE FROM Presence WHERE UserID = ?');
|
||||
$statementGroupRoles->execute([$uuid]);
|
||||
|
||||
$statementMute = $RUNTIME['PDO']->prepare('DELETE FROM MuteList WHERE AgentID = ? OR MuteID = ?');
|
||||
$statementMute = $this->pdo->prepare('DELETE FROM MuteList WHERE AgentID = ? OR MuteID = ?');
|
||||
$statementMute->execute([$uuid, $uuid]);
|
||||
|
||||
$statementUserAccounts = $RUNTIME['PDO']->prepare('DELETE FROM UserAccounts WHERE PrincipalID = ?');
|
||||
$statementUserAccounts = $this->pdo->prepare('DELETE FROM UserAccounts WHERE PrincipalID = ?');
|
||||
$statementUserAccounts->execute([$uuid]);
|
||||
|
||||
$statementUserData = $RUNTIME['PDO']->prepare('DELETE FROM userdata WHERE UserId = ?');
|
||||
$statementUserData = $this->pdo->prepare('DELETE FROM userdata WHERE UserId = ?');
|
||||
$statementUserData->execute([$uuid]);
|
||||
|
||||
$statementUserNotes = $RUNTIME['PDO']->prepare('DELETE FROM usernotes WHERE targetuuid = ?');
|
||||
$statementUserNotes = $this->pdo->prepare('DELETE FROM usernotes WHERE targetuuid = ?');
|
||||
$statementUserNotes->execute([$uuid]);
|
||||
|
||||
$statementUserProfile = $RUNTIME['PDO']->prepare('DELETE FROM userprofile WHERE useruuid = ?');
|
||||
$statementUserProfile = $this->pdo->prepare('DELETE FROM userprofile WHERE useruuid = ?');
|
||||
$statementUserProfile->execute([$uuid]);
|
||||
|
||||
$statementUserSettings = $RUNTIME['PDO']->prepare('DELETE FROM usersettings WHERE useruuid = ?');
|
||||
$statementUserSettings = $this->pdo->prepare('DELETE FROM usersettings WHERE useruuid = ?');
|
||||
$statementUserSettings->execute([$uuid]);
|
||||
|
||||
$RUNTIME['PDO']->commit();
|
||||
$this->pdo->commit();
|
||||
|
||||
return true;
|
||||
} catch (Exception $pdoException) {
|
||||
$RUNTIME['PDO']->rollBack();
|
||||
$this->pdo->rollBack();
|
||||
error_log('Could not delete account '.$uuid.': '.$pdoException->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
@ -269,13 +233,11 @@
|
|||
|
||||
public function deleteIdentity($uuid, $identId): bool
|
||||
{
|
||||
global $RUNTIME;
|
||||
|
||||
$statementValidate = $RUNTIME['PDO']->prepare('SELECT 1 FROM UserIdentitys WHERE PrincipalID = ? AND IdentityID = ?');
|
||||
$statementValidate = $this->pdo->prepare('SELECT 1 FROM UserIdentitys WHERE PrincipalID = ? AND IdentityID = ?');
|
||||
$statementValidate->execute([$uuid, $identId]);
|
||||
|
||||
if($statementValidate->fetch()) {
|
||||
$statementDelete = $RUNTIME['PDO']->prepare('DELETE FROM UserAccounts WHERE PrincipalID = ?');
|
||||
$statementDelete = $this->pdo->prepare('DELETE FROM UserAccounts WHERE PrincipalID = ?');
|
||||
$statementDelete->execute([$identId]);
|
||||
|
||||
return true;
|
||||
|
@ -284,7 +246,7 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
public function gen_uuid()
|
||||
public function generateUuid(): string
|
||||
{
|
||||
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||
// 32 bits for "time_low"
|
||||
|
@ -306,4 +268,4 @@
|
|||
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<?php
|
||||
function sendMessageToWebhook($webhook, $title, $message)
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mcp\Util;
|
||||
|
||||
class DiscordUtil
|
||||
{
|
||||
public static function sendMessageToWebhook($webhook, $title, $message): void
|
||||
{
|
||||
$rawMessage = file_get_contents("style/discordMessage.json");
|
||||
$rawMessage = str_replace("%%message%%", $message, $rawMessage);
|
||||
|
@ -16,3 +22,4 @@
|
|||
|
||||
file_get_contents($webhook, false, stream_context_create($options));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mcp\Util;
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use Exception;
|
||||
use Mcp\TemplateBuilder;
|
||||
|
||||
class SmtpClient
|
||||
{
|
||||
|
||||
private PHPMailer $mailer;
|
||||
|
||||
public function __construct(string $host, int $port, string $username, string $password)
|
||||
{
|
||||
$mailer = new PHPMailer(true);
|
||||
$mailer->isSMTP();
|
||||
$mailer->Host = $host;
|
||||
$mailer->Port = $port;
|
||||
$mailer->Username = $username;
|
||||
$mailer->Password = $password;
|
||||
$mailer->SMTPAuth = true;
|
||||
$mailer->SMTPSecure = $port == 465 ? PHPMailer::ENCRYPTION_SMTPS : PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$this->mailer = $mailer;
|
||||
}
|
||||
|
||||
public function sendHtml(string $fromAddr, string $fromName, string $to, string $subject, TemplateBuilder $tpl): bool
|
||||
{
|
||||
try {
|
||||
$this->mailer->setFrom($fromAddr, $fromName);
|
||||
$this->mailer->addAddress($to);
|
||||
} catch (Exception $e) {
|
||||
error_log('Failed to prepare mail client (from: '.$fromAddr.', to: '.$to.')');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->mailer->isHTML(true);
|
||||
$this->mailer->Subject = $subject;
|
||||
ob_start();
|
||||
$tpl->render();
|
||||
$tplOut = ob_end_clean();
|
||||
$this->mailer->Body = $tplOut;
|
||||
$this->mailer->AltBody = $this::htmlToPlain($tplOut);
|
||||
|
||||
try {
|
||||
$this->mailer->send();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
error_log('Could not send email: '.$this->mailer->ErrorInfo);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static function htmlToPlain($message): string
|
||||
{
|
||||
$messageNew = str_replace('<br/>', "\n", $message);
|
||||
$messageNew = preg_replace('/<a href="(.*)">(.*)<\\/a>/', "$2: $1", $messageNew);
|
||||
return $messageNew;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mcp\Util;
|
||||
|
||||
use Exception;
|
||||
|
||||
class Util
|
||||
{
|
||||
public static function fillString($string, $targetlength)
|
||||
{
|
||||
while(strlen($string) < $targetlength)
|
||||
{
|
||||
$string = "0".$string;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function left($str, $length)
|
||||
{
|
||||
return substr($str, 0, $length);
|
||||
}
|
||||
|
||||
public static function right($str, $length)
|
||||
{
|
||||
return substr($str, -$length);
|
||||
}
|
||||
|
||||
public static 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;
|
||||
}
|
||||
|
||||
public static function getDataFromHTTP($url, $content = "", $requestTyp = "application/text")
|
||||
{
|
||||
try {
|
||||
if ($content != "") {
|
||||
return file_get_contents($url, true, stream_context_create(array('http' => array('header' => 'Content-type: '.$requestTyp, 'method' => 'POST', 'timeout' => 0.5, 'content' => $content))));
|
||||
} else {
|
||||
return file_get_contents($url);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "(HTTP REQUEST) error while conntect to remote server. : ".$url;
|
||||
}
|
||||
}
|
||||
|
||||
public static 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>";
|
||||
Util::getDataFromHTTP($targetURL, $rawXML, "text/xml");
|
||||
}
|
||||
}
|
101
app/utils.php
101
app/utils.php
|
@ -1,101 +0,0 @@
|
|||
<?php
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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';
|
||||
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'];
|
||||
$mailer->SMTPAuth = true;
|
||||
$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();
|
||||
$mailHtml->importHTML("mail.html");
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
function getDataFromHTTP($url, $content = "", $requestTyp = "application/text")
|
||||
{
|
||||
try {
|
||||
if ($content != "") {
|
||||
return file_get_contents($url, true, stream_context_create(array('http' => array('header' => 'Content-type: '.$requestTyp, 'method' => 'POST', 'timeout' => 0.5, 'content' => $content))));
|
||||
} else {
|
||||
return file_get_contents($url);
|
||||
}
|
||||
} 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");
|
||||
}
|
Loading…
Reference in New Issue