1
0
Fork 0
Manager/app/OpenSim.php

213 lines
6.9 KiB
PHP
Raw Normal View History

2020-06-03 15:31:18 +00:00
<?php
2023-08-27 03:31:32 +00:00
class OpenSim
{
public function isLoginValid($name, $password)
{
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();
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;
}
}
}
$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)
{
global $RUNTIME;
$statementRegion = $RUNTIME['PDO']->prepare("SELECT regionName FROM regions WHERE uuid = ?");
$statementRegion->execute(array($regionID));
if ($rowRegion = $statementRegion->fetch()) {
return $rowRegion['regionName'];
}
return "Unknown Region";
}
public function getPartner($userID)
{
global $RUNTIME;
$statement = $RUNTIME['PDO']->prepare("SELECT profilePartner FROM userprofile WHERE useruuid = ?");
$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;
$statement = $RUNTIME['PDO']->prepare("SELECT imviaemail FROM usersettings WHERE useruuid = ?");
$statement->execute(array($userID));
if ($row = $statement->fetch()) {
return strtoupper($row['imviaemail']);
}
return "FALSE";
}
public function getUserMail($userID)
{
global $RUNTIME;
$statement = $RUNTIME['PDO']->prepare("SELECT Email FROM UserAccounts WHERE PrincipalID = ?");
$statement->execute(array($userID));
if ($row = $statement->fetch()) {
return $row['Email'];
}
return "";
}
public function getUserCount()
{
global $RUNTIME;
$statementUser = $RUNTIME['PDO']->prepare("SELECT COUNT(*) FROM UserAccounts");
$statementUser->execute();
return $statementUser->fetchColumn();
}
public function getRegionCount()
{
global $RUNTIME;
$statementUser = $RUNTIME['PDO']->prepare("SELECT COUNT(*) FROM regions");
$statementUser->execute();
return $statementUser->fetchColumn();
}
public function getOnlineCount()
{
global $RUNTIME;
$statementUser = $RUNTIME['PDO']->prepare("SELECT COUNT(*) FROM Presence");
$statementUser->execute();
return $statementUser->fetchColumn();
}
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
}