1
0
Fork 0
Manager/cron/IARMonitor.php

64 lines
3.5 KiB
PHP
Raw Normal View History

2021-01-08 01:29:46 +00:00
<?php
include '../app/OpenSim.php';
$opensim = new OpenSim();
2021-01-08 02:53:41 +00:00
$statement = $RUNTIME['PDO']->prepare("CREATE TABLE IF NOT EXISTS `iarstates` (`userID` VARCHAR(36) NOT NULL COLLATE 'utf8_unicode_ci', `filesize` BIGINT(20) NOT NULL DEFAULT '0', `iarfilename` VARCHAR(64) NOT NULL COLLATE 'utf8_unicode_ci', `running` INT(1) NOT NULL DEFAULT '0', PRIMARY KEY (`userID`) USING BTREE) COLLATE='utf8_unicode_ci' ENGINE=InnoDB;");
2021-01-08 01:29:46 +00:00
$statement->execute();
2023-08-23 16:16:34 +00:00
$statement = $RUNTIME['PDO']->prepare("SELECT userID,iarfilename,filesize FROM iarstates WHERE running = 1 LIMIT 1");
2021-01-08 01:29:46 +00:00
$statement->execute();
2021-01-08 02:53:41 +00:00
if($row = $statement->fetch())
2021-01-08 01:29:46 +00:00
{
$email = $opensim->getUserMail($row['userID']);
2021-01-08 02:53:41 +00:00
2021-01-08 03:49:21 +00:00
$fullFilePath = "/var/www/html/data/".$row['iarfilename'];
2021-01-08 02:53:41 +00:00
echo "Aktive IAR für ".$opensim->getUserName($row['userID'])." gefunden. File: ".$fullFilePath."\n";
2021-01-08 02:53:41 +00:00
if(file_exists($fullFilePath))
2021-01-08 01:29:46 +00:00
{
2021-01-08 02:53:41 +00:00
$filesize = filesize($fullFilePath);
2021-01-08 01:29:46 +00:00
2021-01-08 02:53:41 +00:00
if($filesize != $row['filesize'])
2021-01-08 01:59:28 +00:00
{
2021-01-08 02:53:41 +00:00
$statementUpdate = $RUNTIME['PDO']->prepare('UPDATE iarstates SET filesize = :filesize WHERE userID = :userID');
$statementUpdate->execute(['filesize' => $filesize, 'userID' => $row['userID']]);
echo "Status der IAR für ".$opensim->getUserName($row['userID']).": Speichert...\n";
2021-01-08 02:53:41 +00:00
}else{
2021-01-08 03:18:42 +00:00
$APIURL = $RUNTIME['SIDOMAN']['URL']."api.php?CONTAINER=".$RUNTIME['SIDOMAN']['CONTAINER']."&KEY=".$RUNTIME['SIDOMAN']['PASSWORD']."&METODE=RESTART";
$APIResult = file_get_contents($APIURL);
echo "Status der IAR für ".$opensim->getUserName($row['userID']).": Sende Mail...\n";
2021-01-08 02:53:41 +00:00
$statementUpdate = $RUNTIME['PDO']->prepare('DELETE FROM iarstates WHERE userID = :userID');
$statementUpdate->execute(['userID' => $row['userID']]);
2021-01-08 03:18:42 +00:00
sendInworldIM("00000000-0000-0000-0000-000000000000", $row['userID'], "Inventory", $RUNTIME['GRID']['HOMEURL'], "Deine IAR ist fertig zum Download: ".$RUNTIME['IAR']['BASEURL'].$row['iarfilename']);
2021-01-08 01:59:28 +00:00
}
2021-01-08 01:29:46 +00:00
}else{
$name = explode(" ", $opensim->getUserName($row['userID']));
2021-01-08 01:29:46 +00:00
2021-01-08 02:53:41 +00:00
$APIURL = $RUNTIME['SIDOMAN']['URL']."api.php?CONTAINER=".$RUNTIME['SIDOMAN']['CONTAINER']."&KEY=".$RUNTIME['SIDOMAN']['PASSWORD']."&METODE=COMMAND&COMMAND=".urlencode("save iar ".$name[0]." ".$name[1]." /* PASSWORD /downloads/".$row['iarfilename']);
$APIResult = file_get_contents($APIURL);
2021-01-08 01:29:46 +00:00
2021-01-08 02:53:41 +00:00
echo "IAR für ".$name[0]." ".$name[1]." wurde gestartet: Status: ".$APIResult."\n";
}
}else{
2023-08-23 16:16:34 +00:00
$statement = $RUNTIME['PDO']->prepare("SELECT userID,iarfilename FROM iarstates WHERE running = 0 LIMIT 1");
2021-01-08 02:53:41 +00:00
$statement->execute();
2021-01-08 01:29:46 +00:00
2021-01-08 02:53:41 +00:00
while($row = $statement->fetch())
{
$statementUpdate = $RUNTIME['PDO']->prepare('UPDATE iarstates SET running = :running WHERE userID = :userID');
$statementUpdate->execute(['running' => 1, 'userID' => $row['userID']]);
$name = explode(" ", $opensim->getUserName($row['userID']));
2021-01-08 02:53:41 +00:00
$APIURL = $RUNTIME['SIDOMAN']['URL']."api.php?CONTAINER=".$RUNTIME['SIDOMAN']['CONTAINER']."&KEY=".$RUNTIME['SIDOMAN']['PASSWORD']."&METODE=COMMAND&COMMAND=".urlencode("save iar ".$name[0]." ".$name[1]." /* PASSWORD /downloads/".$row['iarfilename']);
$APIResult = file_get_contents($APIURL);
echo "IAR für ".$name[0]." ".$name[1]." wurde gestartet: Status: ".$APIResult."\n";
2021-01-08 01:29:46 +00:00
}
}
?>