1
0
Fork 0

add crone

This commit is contained in:
Christopher 2021-11-05 03:01:38 +01:00
parent a43554a753
commit 431a6035f1
8 changed files with 33 additions and 113 deletions

View File

View File

@ -1,85 +1,5 @@
<?php
function getServerURI($homeURL, $userID)
{
$xml = '<?xml version="1.0" encoding="utf-8"?><methodCall><methodName>get_server_urls</methodName><params><param><value><struct><member><name>userID</name><value><string>'.$userID.'</string></value></member></struct></value></param></params></methodCall>';
$optionen = stream_context_create(array('http' => array('timeout' => 1, 'method' => 'POST', 'header' => 'Content-Type: application/xml', 'content' => $xml)));
$result = file_get_contents($homeURL, false, $optionen);
$servers = new SimpleXMLElement($result);
foreach ($servers->params->param->value->struct[0] as $serverEntry)
{
if($serverEntry->name == 'SRV_AssetServerURI')
return $serverEntry->value->string->__toString();
}
}
function getAssetData($assetServer, $assetUUID)
{
global $DATA;
chdir("/var/www/html");
if(!is_file('./data/RegionImages/'.$assetUUID.'.png'))
{
$DATA['WGETCMD'] = '/usr/bin/wget '.$assetServer.'assets/'.$assetUUID.'/data -O /tmp/'.$assetUUID;
$DATA['MPEGCMD'] = '/usr/bin/ffmpeg -i /tmp/'.$assetUUID.' ./data/RegionImages/'.$assetUUID.'.png';
$DATA['WGET'] = shell_exec($DATA['WGETCMD']);
$DATA['FFMPEG'] = shell_exec($DATA['MPEGCMD']);
}
return $assetUUID.'.png';
}
function getRegionStats($regionHostName)
{
$optionen = stream_context_create(array('http' => array('timeout' => 1)));
$result = file_get_contents("http://".$regionHostName."/jsonSimStats", false, $optionen);
if($result != "")
{
return json_decode($result);
}
}
if(isset($_SERVER['HTTP_X_SECONDLIFE_SHARD']) && isset($_SERVER['HTTP_X_SECONDLIFE_REGION']))
{
$DATA = array();
$DATA['RegionData'] = explode("(", $_SERVER['HTTP_X_SECONDLIFE_REGION']);
$DATA['RegionName'] = trim($DATA['RegionData'][0]);
$DATA['RegionID'] = md5($_SERVER['HTTP_X_SECONDLIFE_REGION'].$_REQUEST['grid']);
$DATA['Position'] = trim(str_replace(" ", "", str_replace(")", "", str_replace("(", "", $_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION']))));
$DATA['PositionData'] = explode(",", $DATA['Position']);
$DATA['PositionData'][0] = explode(".", $DATA['PositionData'][0])[0];
$DATA['PositionData'][1] = explode(".", $DATA['PositionData'][1])[0];
$DATA['PositionData'][2] = explode(".", $DATA['PositionData'][2])[0];
$DATA['GridHomeURI'] = $_REQUEST['GridHomeURI'];
$DATA['Link'] = "hop://".str_replace("http://", "", $DATA['GridHomeURI']).":".$DATA['RegionName']."/".$DATA['PositionData'][0]."/".$DATA['PositionData'][1]."/".$DATA['PositionData'][2];
$DATA['AgentCount'] = $_REQUEST['AgentCount'];
$DATA['Beschreibung'] = file_get_contents("php://input");
$DATA['AssetServer'] = getServerURI($DATA['GridHomeURI'], $_SERVER['HTTP_X_SECONDLIFE_OWNER_KEY']);
$DATA['AssetPath'] = getAssetData($DATA['AssetServer'], $_REQUEST['RegionImageTexture']);
$DATA['GridName'] = $_REQUEST['GridName'];
if(!isset($DATA['RegionName']) || @$DATA['RegionName'] == "")die("ERROR: RegionName");
if(!isset($DATA['Beschreibung']) || @$DATA['Beschreibung'] == "")die("ERROR: Beschreibung");
if(!isset($DATA['GridHomeURI']) || @$DATA['GridHomeURI'] == "")die("ERROR: GridHomeURI");
if(!isset($DATA['AgentCount']) || @$DATA['AgentCount'] == "")die("ERROR: AgentCount");
if(!isset($DATA['GridName']) || @$DATA['GridName'] == "")die("ERROR: GridName");
$MYSQLDATA = array('RegionID' => $DATA['RegionID'], 'RegionName' => $DATA['RegionName'], 'RegionBeschreibung' => $DATA['Beschreibung'], 'RegionLink' => $DATA['Link'],'PositionX' => $DATA['PositionData'][0], 'PositionY' => $DATA['PositionData'][1], 'PositionZ' => $DATA['PositionData'][2], 'GridName' => $DATA['GridName'], 'ImageName' => $DATA['AssetPath'], 'LastSeen' => time(), 'OnlineUser' => $DATA['AgentCount']);
$statementSend = $RUNTIME['PDO']->prepare('REPLACE INTO Regions (RegionID, RegionName, RegionBeschreibung, RegionLink, PositionX, PositionY, PositionZ, GridName, ImageName, LastSeen, OnlineUser) VALUES (:RegionID, :RegionName, :RegionBeschreibung, :RegionLink, :PositionX, :PositionY, :PositionZ, :GridName, :ImageName, :LastSeen, :OnlineUser)');
$statementSend->execute($MYSQLDATA);
echo "OK";
}else{
die("ERROR: LSL");
}
//file_put_contents("debug-".time().".txt", print_r($GLOBALS, true));
$data = json_decode(file_get_contents('php://input'), true);
file_put_contents("debug_".time().".txt", print_r($data, true));
?>

View File

@ -38,10 +38,7 @@
{
global $RUNTIME;
$removeRegionStatement = $RUNTIME['PDO']->prepare("DELETE FROM regions WHERE RegionUUID = ?");
$removeRegionStatement->execute(array($uuid));
$removeRegionStatement = $RUNTIME['PDO']->prepare("DELETE FROM onlinetimes WHERE RegionUUID = ?");
$removeRegionStatement = $RUNTIME['PDO']->prepare("DELETE regions, onlinetimes FROM regions INNER JOIN onlinetimes ON regions.RegionUUID = onlinetimes.RegionUUID WHERE regions.RegionUUID = ?");
$removeRegionStatement->execute(array($uuid));
}
}

View File

@ -86,10 +86,10 @@ function getAssetImage($assetServer, $assetUUID)
global $DATA;
chdir("/var/www/html");
if(!is_file('./data/RegionImages/'.$assetUUID.'.png'))
if(!is_file('./data/RegionImages/'.$assetUUID.'.jpg'))
{
$DATA['WGETCMD'] = '/usr/bin/wget '.$assetServer.'assets/'.$assetUUID.'/data -O /tmp/'.$assetUUID;
$DATA['MPEGCMD'] = '/usr/bin/ffmpeg -i /tmp/'.$assetUUID.' ./data/RegionImages/'.$assetUUID.'.png';
$DATA['MPEGCMD'] = '/usr/bin/ffmpeg -i /tmp/'.$assetUUID.' ./data/RegionImages/'.$assetUUID.'.jpg';
$DATA['WGET'] = shell_exec($DATA['WGETCMD']);
$DATA['FFMPEG'] = shell_exec($DATA['MPEGCMD']);
@ -116,25 +116,25 @@ function getTopRegionHTML($row)
if(!isset($row['Image']))
return;
if(!file_exists("./data/RegionImages/".$row['Image']))
$row['Image'] = "notFound.jpg";
if(!file_exists("./data/RegionImages/".$row['Image'].".jpg"))
$row['Image'] = "notFound";
if(!isset($row['Description']))
$row['Description'] = "(Es wurde noch keine Beschreibung hinterlegt.)";
return '<section id="banner"><div class="content"><header><h1>'.substr($row['Name'], 0, 50).'</h1><p>Online: '.$row['OnlineCount'].'</p></header><p>'.substr($row['Description'], 0, 800).'</p><ul class="actions"><a href="info/'.$row['UUID'].'.html" class="button big html5lightbox">Menr Infos</a></ul></div>
<span class="image object"><img src="./data/RegionImages/'.$row['Image'].'" alt="Region Image '.substr($row['Name'], 0, 50).'" /></span></section>';
<span class="image object"><img style="min-height: 450px; max-height: 45px;" src="./data/RegionImages/'.$row['Image'].'.jpg" alt="Region Image '.substr($row['Name'], 0, 50).'" /></span></section>';
}
function getRegionHTML($row)
{
if(!file_exists("./data/RegionImages/".$row['Image']))
$row['Image'] = "notFound.jpg";
if(!file_exists("./data/RegionImages/".$row['Image']."jpg"))
$row['Image'] = "notFound";
if(!isset($row['Description']))
$row['Description'] = "(Es wurde noch keine Beschreibung hinterlegt.)";
return '<article><a href="index.php?page=regionInfo&id='.$row['UUID'].'" class="image"><img src="./data/RegionImages/'.$row['Image'].'" alt="Region Image '.substr($row['Name'], 0, 50).'" /></a>
return '<article><a href="index.php?page=regionInfo&id='.$row['UUID'].'" class="image"><img src="./data/RegionImages/'.$row['Image'].'.jpg" alt="Region Image '.substr($row['Name'], 0, 50).'" /></a>
<h3>'.substr($row['Name'], 0, 50).'</h3><p>Online: '.$row['OnlineCount'].'</p><p>'.substr($row['Description'], 0, 300).'</p><ul class="actions"><li><a href="info/'.$row['UUID'].'.html" class="button html5lightbox">Menr Infos</a></li></ul></article>';
}
?>

View File

@ -1,16 +0,0 @@
<?php
$topRegionStatement = $RUNTIME['PDO']->prepare("SELECT regions.RegionName AS Name, regions.RegionUUID AS UUID, regions.RegionImage AS Image, regions.RegionOwner AS OwnerID, users.UserName AS OwnerName, onlinetimes.RegionLastSeen AS LastSeen, onlinetimes.RegionOnlineUser AS OnlineCount, regions.RegionVersion AS RegionVersion, regions.RegionHostname AS Hostname, regions.RegionPort AS Port FROM regions INNER JOIN onlinetimes ON regions.RegionUUID = onlinetimes.RegionUUID INNER JOIN users ON regions.RegionOwner = users.UserUUID WHERE onlinetimes.RegionLastSeen < ? ORDER BY LastSeen ASC");
$topRegionStatement->execute(array(time() - 600));
while($row = $topRegionStatement->fetch())
{
if(ping($row['Hostname'], $row['Port']))
{
RegionManager::setOnlineTime($row['UUID']);
continue;
}
RegionManager::removeRegion($row['UUID']);
}
?>

View File

@ -0,0 +1,20 @@
<?php
$QueueStatement = $RUNTIME['PDO']->prepare("SELECT * FROM queue WHERE QueueType = 'regionImageDownload'");
$QueueStatement->execute(array());
while($row = $QueueStatement->fetch())
{
$queueData = json_decode($row['QueueData']);
if(!is_file('./data/RegionImages/'.$queueData->TargetAssetUUID.'.jpg'))
{
$rawImage = getDataFromHTTP($queueData->URL, "");
file_put_contents("./data/RegionImages/".$queueData->TargetAssetUUID.".jpg", $rawImage);
}
$removeQueueStatement = $RUNTIME['PDO']->prepare("DELETE FROM queue WHERE QueueID = ?");
$removeQueueStatement->execute(array($row['QueueID']));
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -4,7 +4,7 @@
$HTML->importHTML("style/default/start.html");
$RegionManager = new RegionManager(0, 28);
$HTML->ReplaceLayoutInhalt("%%TopRegion%%", getTopRegionHTML($RegionManager->getNextRegion()));
while($region = $RegionManager->getNextRegion())
@ -12,7 +12,6 @@
$HTML->ReplaceLayoutInhalt("%%RegionList%%", @$RUNTIME['RegionList']);
$HTML->build();
echo $HTML->ausgabe();
?>