OpenSim.Robust.HGFriendsSer.../Grid.Friends.php

179 lines
8.9 KiB
PHP
Raw Permalink Normal View History

2020-08-01 00:59:11 +00:00
<? /*<[ Interval = 1800 ]>*/
require("../classes/Framework.php");
set_time_limit(0);
function getDataFromHTTP($URL, $contend = "", $requestTyp = "application/text")
{
try
{
if($contend != "")
{
return file_get_contents($URL, true, stream_context_create(array('http' => array('header' => 'Content-type: '.$requestTyp, 'method' => 'POST', 'timeout' => 2, 'content' => $contend))));
}else{
return file_get_contents($URL);
}
} catch (Exception $e) {
echo "(HTTP REQUEST) error while conntect to remote server. : ".$URL;
dolog("FriendFix", "(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");
}
function getFullGridDomainList()
{
$Domains = array();
$gridUsers = $GLOBALS[MySql]->query("SELECT userID FROM ".$GLOBALS[GridSettings]["robustdb"].".griduser", array($LocalUserUUID));
while($UserData = $gridUsers->fetch())
{
$found = FALSE;
$data = explode(";", $UserData[userID]);
$userDomain = strtolower(trim($data[1]));
foreach($Domains as $domain)
if($userDomain == $domain)
{
$found = TRUE;
continue;
}
if($found == FALSE && $userDomain != "")
array_push($Domains, $userDomain);
}
return $Domains;
}
function getUserInfo($homeURI, $UUID)
{
try
{
$homeURIParts = parse_url($homeURI);
$HTTPUSerInfo = new SimpleXMLElement(getDataFromHTTP("http://".$homeURIParts['host'].":".$homeURIParts['port'], "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>get_user_info</methodName><params><param><value><struct><member><name>userID</name><value><string>".$UUID."</string></value></member></struct></value></param></params></methodCall>", "application/xml"));
$HTTPUSerInfo = $HTTPUSerInfo->params->param->value->struct->member;
$UserInfoData = array();
foreach($HTTPUSerInfo as $userRequestElement)
{
if($userRequestElement->value->string->__toString() != "")
$UserInfoData[strtoupper($userRequestElement->name->__toString())] = $userRequestElement->value->string->__toString();
if($userRequestElement->value->i4->__toString() != "")
$UserInfoData[strtoupper($userRequestElement->name->__toString())] = $userRequestElement->value->i4->__toString();
}
return $UserInfoData;
} catch (Exception $e) {
echo "(getUserInfo) error while getting data";
dolog("FriendFix", "(getUserInfo) error while getting data");
}
$UserInfoData = array();
$UserInfoData['RESULT'] = "failure";
return $UserInfoData;
}
function tryToGetUserDataFromHomeURIList($homeURLs, $UUID)
{
foreach($homeURLs as $url)
{
$tempUserData = getUserInfo($url, $UUID);
$tempUserData['HOMEURL'] = $url;
if($tempUserData['RESULT'] != "failure")
{
return $tempUserData;
}
}
return array();
}
$AllGrids = HTTP_Request($GLOBALS[Sqlite]->setting("SMTP.ORIGIN")."/opensim/triggers", "pass=".$GLOBALS[Sqlite]->setting("MANAGER.AUTH.PASS"), "", 3, "application/x-www-form-urlencoded");
if (empty($AllGrids))
{
dolog("FriendFix", "Grids konnten nicht abgerufen werden!");
die("Grids konnten nicht abgerufen werden!");
}
$AllGrids = json_decode($AllGrids, true);
dolog("FriendFix", count($AllGrids)." Grids gefunden...");
for ($z = 0; $z < count($AllGrids); ++$z)
{
RequestGridSpecificData($GLOBALS[Sqlite]->setting("SMTP.ORIGIN"), $AllGrids[$z]);
if ($GLOBALS[GridSettings]["hasrobust"] == "1")
{
if(is_file(dirname($GLOBALS[GridSettings]["osbasepath"])."/friends.txt"))
{
$FriendFixFile = explode("\n", file_get_contents(dirname($GLOBALS[GridSettings]["osbasepath"])."/friends.txt"));
foreach ($FriendFixFile as $rawLine)
{
$DataLine = trim($rawLine);
$LineData = explode(";", $DataLine);
if(count($LineData) == 5)
{
$LocalUserUUID = $LineData[1];
$RemoteUserUUID = $LineData[0];
$LocalAvatarName = "Unknown User";
$AvatarData = $GLOBALS[MySql]->query("SELECT * FROM ".$GLOBALS[GridSettings]["robustdb"].".useraccounts WHERE PrincipalID = '{0}' LIMIT 1", array($LocalUserUUID))->fetch();
$RemoteUserData = $GLOBALS[MySql]->query("SELECT * FROM ".$GLOBALS[GridSettings]["robustdb"].".griduser WHERE userID LIKE '{0}' LIMIT 1", array($RemoteUserUUID."%"))->fetch();
if(!empty($AvatarData))
$LocalAvatarName = $AvatarData[FirstName]." ".$AvatarData[LastName];
if (!empty($RemoteUserData))
{
$DBUserData = explode(";", $RemoteUserData[UserID]);
if(count($DBUserData) == 3)
{
$RemoteUserString = $LineData[0].";".$DBUserData[1].";".$DBUserData[2].";".$LineData[4];
$FriendData = $GLOBALS[MySql]->query("SELECT * FROM ".$GLOBALS[GridSettings]["robustdb"].".friends WHERE Friend LIKE '{0}' LIMIT 1", array($RemoteUserUUID."%"))->fetch();
if(empty($FriendData))
{
echo "Generiere freundschaft für ".$LocalUserUUID."(".$LocalAvatarName.")<->".$RemoteUserUUID."(".$DBUserData[2]."@".$DBUserData[1].").\n";
dolog("FriendFix", "Generiere freundschaft für ".$LocalUserUUID."(".$LocalAvatarName.")<->".$RemoteUserUUID."(".$DBUserData[2]."@".$DBUserData[1].").");
sendInworldIM("00000000-0000-0000-0000-000000000000", $LocalUserUUID, "GRID SERVICE", $GLOBALS[GridSettings][robust], "Es wurde eine Freundschaft für '".$DBUserData[2]." @ ".$DBUserData[1]."' generiert.");
$GLOBALS[MySql]->query("INSERT INTO ".$GLOBALS[GridSettings]["robustdb"].".friends (PrincipalID, Friend) VALUES ('{0}', '{1}')", array($LocalUserUUID, $RemoteUserString));
$GLOBALS[MySql]->query("INSERT INTO ".$GLOBALS[GridSettings]["robustdb"].".friends (PrincipalID, Friend) VALUES ('{0}', '{1}')", array($RemoteUserString, $LocalUserUUID));
}
}
}else{
echo "Kann User ".$RemoteUserUUID." für ".$LocalUserUUID."(".$LocalAvatarName.")<->".$RemoteUserUUID." nicht in der DB finden.\n";
dolog("FriendFix", "Kann User ".$RemoteUserUUID." für ".$LocalUserUUID."(".$LocalAvatarName.")<->".$RemoteUserUUID." nicht in der DB finden.");
$userData = tryToGetUserDataFromHomeURIList(getFullGridDomainList(), $RemoteUserUUID);
if(count($userData) != 0)
{
echo "Erfolgreich Remotedaten zu User ".$RemoteUserUUID." abrufen: ".str_replace("\r", "", str_replace("\n", "", print_r($userData, true)))."\n";
dolog("FriendFix", "Erfolgreich Remotedaten zu User ".$RemoteUserUUID." abrufen: ".str_replace("\r", "", str_replace("\n", "", print_r($userData, true))));
//echo $RemoteUserUUID.";".$userData['HOMEURL'].";".$userData['USER_FIRSTNAME']." ".$userData['USER_LASTNAME'];
$GLOBALS[MySql]->query("INSERT INTO ".$GLOBALS[GridSettings]["robustdb"].".griduser (UserID) VALUES ('{0}')", array($RemoteUserUUID.";".$userData['HOMEURL'].";".$userData['USER_FIRSTNAME']." ".$userData['USER_LASTNAME']));
}else{
echo "Kann keine Remotedaten für User ".$RemoteUserUUID." abrufen. Dieser User ist keinem Grid bekannt.\n";
dolog("FriendFix", "Kann keine Remotedaten für User ".$RemoteUserUUID." abrufen. Dieser User ist keinem Grid bekannt.");
}
}
}
}
}else{
echo "Konnte keine Daten für das Grid '".$AllGrids[$z]."' finden.";
dolog("FriendFix", "Konnte keine Daten für das Grid '".$AllGrids[$z]."' finden.");
}
}
}
?>