1
0
Fork 0
Manager/cron/IARMonitor.php

75 lines
3.6 KiB
PHP
Raw Normal View History

2021-01-08 01:29:46 +00:00
<?php
2021-01-08 01:59:28 +00:00
$statement = $RUNTIME['PDO']->prepare("CREATE TABLE IF NOT EXISTS `iarstates` (`userID` VARCHAR(36) NOT NULL COLLATE 'utf8_unicode_ci', `filesize` INT(11) NOT NULL, `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();
2021-01-08 01:59:28 +00:00
$statement = $RUNTIME['PDO']->prepare("SELECT * FROM iarstates WHERE running = 1 LIMIT 1");
2021-01-08 01:29:46 +00:00
$statement->execute();
2021-01-08 01:59:28 +00:00
if($statement->rowCount() != 0)
2021-01-08 01:29:46 +00:00
{
2021-01-08 01:59:28 +00:00
while($row = $statement->fetch())
2021-01-08 01:29:46 +00:00
{
2021-01-08 01:59:28 +00:00
$email = $RUNTIME['OPENSIM']->getUserMail($row['userID']);
2021-01-08 01:29:46 +00:00
2021-01-08 01:59:28 +00:00
if(file_exists("data/".$row['iarfilename']))
{
$filesize = filesize("data/".$row['iarfilename']);
if($filesize != $row['filesize'])
{
$statementUpdate = $RUNTIME['PDO']->prepare('UPDATE iarstates SET filesize = :filesize WHERE userID = :userID');
$statementUpdate->execute(['filesize' => $filesize, 'userID' => $row['userID']]);
continue;
}else{
$statementUpdate = $RUNTIME['PDO']->prepare('DELETE FROM iarstates WHERE userID = :userID');
$statementUpdate->execute(['userID' => $row['userID']]);
$mail = new PHPMailer(true);
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = $RUNTIME['SMTP']['SERVER'];
$mail->Port = $RUNTIME['SMTP']['PORT'];
$mail->SMTPAuth = false;
$mail->setFrom($RUNTIME['SMTP']['ADRESS'], $RUNTIME['GRID']['NAME']);
$mail->addAddress($email, $RUNTIME['OPENSIM']->getUserName($row['userID']));
$HTMLMESSAGE = 'Deine IAR ist bereit zum Download! <br> Du kannst sie <a href="'.$RUNTIME['IAR']['BASEURL'].$row['iarfilename'].'">hier</a> downloaden.';
$HTML = new HTML();
$HTML->importHTML("style/mail.html");
$HTML->setSeitenInhalt($HTMLMESSAGE);
$HTML->build();
$mail->isHTML(true);
$mail->Subject = "Deine IAR steht nun bereit.";
$mail->Body = $HTML->ausgabe();
$mail->AltBody = strip_tags($HTMLMESSAGE);
$mail->send();
$mail->SmtpClose();
}
}
2021-01-08 01:29:46 +00:00
}else{
2021-01-08 01:59:28 +00:00
$statement = $RUNTIME['PDO']->prepare("SELECT * FROM iarstates WHERE running = 0 LIMIT 1");
$statement->execute();
2021-01-08 01:29:46 +00:00
2021-01-08 01:59:28 +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']]);
2021-01-08 01:29:46 +00:00
2021-01-08 01:59:28 +00:00
$iarname = md5(time().$row['userID'].rand()).".iar";
$name = explode(" ", $RUNTIME['OPENSIM']->getUserName($row['userID']));
2021-01-08 01:29:46 +00:00
2021-01-08 01:59:28 +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/".$iarname);
$APIResult = file_get_contents($APIURL);
}
2021-01-08 01:29:46 +00:00
}
}
?>