1
0
Fork 0
Manager/app/OpenSim.php

230 lines
5.8 KiB
PHP
Raw Normal View History

2020-06-03 15:31:18 +00:00
<?php
class OpenSim
{
public function isLoginValid($name, $password)
{
global $RUNTIME;
2023-08-23 16:16:34 +00:00
$statementUser = $RUNTIME['PDO']->prepare("SELECT PrincipalID FROM UserAccounts WHERE FirstName = ? AND LastName = ? LIMIT 1");
2020-06-03 15:31:18 +00:00
$statementUser->execute(explode(" ", trim($name)));
while($rowUser = $statementUser->fetch())
{
2023-08-23 16:16:34 +00:00
$statementAuth = $RUNTIME['PDO']->prepare("SELECT passwordHash,passwordSalt FROM auth WHERE UUID = ? LIMIT 1");
2020-06-03 15:31:18 +00:00
$statementAuth->execute(array($rowUser['PrincipalID']));
while($rowAuth = $statementAuth->fetch())
{
$passwordCorrect = false;
if(strlen($rowAuth['passwordHash']) == 32) {
if(md5(md5($password).":".$rowAuth['passwordSalt']) == $rowAuth['passwordHash']) {
$passwordCorrect = true;
$newHash = password_hash($password, PASSWORD_ARGON2ID);
$updateHash = $RUNTIME['PDO']->prepare("UPDATE auth SET passwordHash = ?, passwordSalt = ? WHERE UUID = ?");
$updateHash->execute(array($newHash, '', $rowUser['PrincipalID']));
}
2020-06-03 15:31:18 +00:00
}
else {
$passwordCorrect = password_verify($password, $rowAuth['passwordHash']);
}
return $passwordCorrect;
2020-06-03 15:31:18 +00:00
}
}
return false;
}
public function getUserName($userID)
{
global $RUNTIME;
2021-01-06 14:16:43 +00:00
if($userID == "00000000-0000-0000-0000-000000000000")
return "Unknown User";
2020-06-03 15:31:18 +00:00
if(isset($RUNTIME['CACHE']['USERNAME'][$userID]))
return $RUNTIME['CACHE']['USERNAME'][$userID];
2023-08-23 16:16:34 +00:00
$statementUser = $RUNTIME['PDO']->prepare("SELECT FirstName,LastName FROM UserAccounts WHERE PrincipalID = ?");
2020-06-03 15:31:18 +00:00
$statementUser->execute(array($userID));
while($rowUser = $statementUser->fetch())
{
$RUNTIME['CACHE']['USERNAME'][$userID] = $rowUser['FirstName']." ".$rowUser['LastName'];
return $rowUser['FirstName']." ".$rowUser['LastName'];
}
2023-08-23 16:16:34 +00:00
$statementGridUser = $RUNTIME['PDO']->prepare("SELECT UserID FROM GridUser");
2020-08-06 01:15:07 +00:00
$statementGridUser->execute(array($userID));
while($rowGridUser = $statementGridUser->fetch())
{
$UserData = explode(";", $rowGridUser['UserID']);
if(count($UserData) >= 3)
{
$DBUserID = $UserData[0];
$DBUserName = $UserData[2];
$RUNTIME['CACHE']['USERNAME'][$userID] = $DBUserName;
if($DBUserID == $userID)
return $DBUserName;
}
}
2023-08-23 16:16:34 +00:00
$statementFriends = $RUNTIME['PDO']->prepare("SELECT PrincipalID FROM Friends");
2020-08-06 01:15:07 +00:00
$statementFriends->execute(array($userID));
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;
}
}
2020-06-03 15:31:18 +00:00
return "Unknown User";
}
public function getUserUUID($UserName)
{
global $RUNTIME;
2023-08-23 16:16:34 +00:00
$statementUser = $RUNTIME['PDO']->prepare("SELECT PrincipalID,FirstName,LastName FROM UserAccounts");
2020-06-03 15:31:18 +00:00
$statementUser->execute();
while($rowUser = $statementUser->fetch())
{
$SQLUserName = $rowUser['FirstName']." ".$rowUser['LastName'];
if($SQLUserName == $UserName)
{
return $rowUser['PrincipalID'];
}
}
return null;
}
public function getRegionName($regionID)
{
global $RUNTIME;
2023-08-23 16:16:34 +00:00
$statementRegion = $RUNTIME['PDO']->prepare("SELECT regionName FROM regions WHERE uuid = ?");
2020-06-03 15:31:18 +00:00
$statementRegion->execute(array($regionID));
while($rowRegion = $statementRegion->fetch())
{
return $rowRegion['regionName'];
}
return "Unknown Region";
}
public function getPartner($userID)
{
global $RUNTIME;
2023-08-23 16:16:34 +00:00
$statement = $RUNTIME['PDO']->prepare("SELECT profilePartner FROM userprofile WHERE useruuid = ?");
2020-06-03 15:31:18 +00:00
$statement->execute(array($userID));
while($row = $statement->fetch())
{
if($row['profilePartner'] != "00000000-0000-0000-0000-000000000000")
return $row['profilePartner'];
}
return null;
}
public function allowOfflineIM($userID)
{
global $RUNTIME;
2023-08-23 16:16:34 +00:00
$statement = $RUNTIME['PDO']->prepare("SELECT imviaemail FROM usersettings WHERE useruuid = ?");
2020-06-03 15:31:18 +00:00
$statement->execute(array($userID));
while($row = $statement->fetch())
{
return strtoupper($row['imviaemail']);
}
return "FALSE";
}
public function getUserMail($userID)
{
global $RUNTIME;
2023-08-23 16:16:34 +00:00
$statement = $RUNTIME['PDO']->prepare("SELECT Email FROM UserAccounts WHERE PrincipalID = ?");
2020-06-03 15:31:18 +00:00
$statement->execute(array($userID));
while($row = $statement->fetch())
{
return $row['Email'];
}
return "";
}
public function getUserCount()
{
global $RUNTIME;
2023-08-23 16:16:34 +00:00
$statementUser = $RUNTIME['PDO']->prepare("SELECT COUNT(*) FROM UserAccounts");
2020-06-03 15:31:18 +00:00
$statementUser->execute();
2023-08-23 16:16:34 +00:00
return $statementUser->fetchColumn();
2020-06-03 15:31:18 +00:00
}
public function getRegionCount()
{
global $RUNTIME;
2023-08-23 16:16:34 +00:00
$statementUser = $RUNTIME['PDO']->prepare("SELECT COUNT(*) FROM regions");
2020-06-03 15:31:18 +00:00
$statementUser->execute();
2023-08-23 16:16:34 +00:00
return $statementUser->fetchColumn();
2020-06-03 15:31:18 +00:00
}
public function getOnlineCount()
{
global $RUNTIME;
2023-08-23 16:16:34 +00:00
$statementUser = $RUNTIME['PDO']->prepare("SELECT COUNT(*) FROM Presence");
2020-06-03 15:31:18 +00:00
$statementUser->execute();
2023-08-23 16:16:34 +00:00
return $statementUser->fetchColumn();
2020-06-03 15:31:18 +00:00
}
2020-08-02 05:22:25 +00:00
public function gen_uuid()
{
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand( 0, 0x0fff ) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand( 0, 0x3fff ) | 0x8000,
// 48 bits for "node"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
2020-06-03 15:31:18 +00:00
}
?>