1
0
Fork 0

fix bug in cron

master
Chris 2021-01-08 03:53:41 +01:00
parent dc40431e84
commit aebdb4d673
2 changed files with 67 additions and 57 deletions

View File

@ -1,74 +1,84 @@
<?php <?php
$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;"); $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;");
$statement->execute(); $statement->execute();
$statement = $RUNTIME['PDO']->prepare("SELECT * FROM iarstates WHERE running = 1 LIMIT 1"); $statement = $RUNTIME['PDO']->prepare("SELECT * FROM iarstates WHERE running = 1 LIMIT 1");
$statement->execute(); $statement->execute();
if($statement->rowCount() != 0) if($row = $statement->fetch())
{ {
while($row = $statement->fetch()) $email = $RUNTIME['OPENSIM']->getUserMail($row['userID']);
$fullFilePath = $_SERVER['PWD']."/data/".$row['iarfilename'];
echo "Aktive IAR für ".$RUNTIME['OPENSIM']->getUserName($row['userID'])." gefunden. File: ".$fullFilePath."\n";
if(file_exists($fullFilePath))
{ {
$email = $RUNTIME['OPENSIM']->getUserMail($row['userID']); $filesize = filesize($fullFilePath);
if(file_exists("data/".$row['iarfilename'])) if($filesize != $row['filesize'])
{ {
$filesize = filesize("data/".$row['iarfilename']); $statementUpdate = $RUNTIME['PDO']->prepare('UPDATE iarstates SET filesize = :filesize WHERE userID = :userID');
$statementUpdate->execute(['filesize' => $filesize, 'userID' => $row['userID']]);
if($filesize != $row['filesize']) echo "Status der IAR für ".$RUNTIME['OPENSIM']->getUserName($row['userID']).": Speichert...\n";
{ }else{
$statementUpdate = $RUNTIME['PDO']->prepare('UPDATE iarstates SET filesize = :filesize WHERE userID = :userID'); echo "Status der IAR für ".$RUNTIME['OPENSIM']->getUserName($row['userID']).": Sende Mail...\n";
$statementUpdate->execute(['filesize' => $filesize, 'userID' => $row['userID']]); $statementUpdate = $RUNTIME['PDO']->prepare('DELETE FROM iarstates WHERE userID = :userID');
$statementUpdate->execute(['userID' => $row['userID']]);
continue; $email = $RUNTIME['OPENSIM']->getUserMail($row['PrincipalID']);
}else{
$statementUpdate = $RUNTIME['PDO']->prepare('DELETE FROM iarstates WHERE userID = :userID'); $mail = new PHPMailer(true);
$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->SMTPDebug = SMTP::DEBUG_SERVER; $mail->setFrom($RUNTIME['SMTP']['ADRESS'], $RUNTIME['GRID']['NAME']);
$mail->isSMTP(); $mail->addAddress($email, $RUNTIME['OPENSIM']->getUserName($row['userID']));
$mail->Host = $RUNTIME['SMTP']['SERVER'];
$mail->Port = $RUNTIME['SMTP']['PORT'];
$mail->SMTPAuth = false;
$HTMLMESSAGE = 'Deine IAR ist bereit zum Download! <br> Du kannst sie <a href="'.$RUNTIME['IAR']['BASEURL'].$row['iarfilename'].'">hier</a> downloaden.';
$mail->setFrom($RUNTIME['SMTP']['ADRESS'], $RUNTIME['GRID']['NAME']); $HTML = new HTML();
$mail->addAddress($email, $RUNTIME['OPENSIM']->getUserName($row['userID'])); $HTML->importHTML("style/mail.html");
$HTML->setSeitenInhalt($HTMLMESSAGE);
$HTML->build();
$HTMLMESSAGE = 'Deine IAR ist bereit zum Download! <br> Du kannst sie <a href="'.$RUNTIME['IAR']['BASEURL'].$row['iarfilename'].'">hier</a> downloaden.'; $mail->isHTML(true);
$mail->Subject = "Deine IAR steht nun bereit.";
$mail->Body = $HTML->ausgabe();
$mail->AltBody = strip_tags($HTMLMESSAGE);
$HTML = new HTML(); $mail->send();
$HTML->importHTML("style/mail.html"); $mail->SmtpClose();
$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();
}
} }
}else{ }else{
$statement = $RUNTIME['PDO']->prepare("SELECT * FROM iarstates WHERE running = 0 LIMIT 1"); $name = explode(" ", $RUNTIME['OPENSIM']->getUserName($row['userID']));
$statement->execute();
while($row = $statement->fetch()) $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);
$statementUpdate = $RUNTIME['PDO']->prepare('UPDATE iarstates SET running = :running WHERE userID = :userID');
$statementUpdate->execute(['running' => 1, 'userID' => $row['userID']]);
$iarname = md5(time().$row['userID'].rand()).".iar"; echo "IAR für ".$name[0]." ".$name[1]." wurde gestartet: Status: ".$APIResult."\n";
$name = explode(" ", $RUNTIME['OPENSIM']->getUserName($row['userID'])); }
}else{
$statement = $RUNTIME['PDO']->prepare("SELECT * FROM iarstates WHERE running = 0 LIMIT 1");
$statement->execute();
$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); while($row = $statement->fetch())
$APIResult = file_get_contents($APIURL); {
} $statementUpdate = $RUNTIME['PDO']->prepare('UPDATE iarstates SET running = :running WHERE userID = :userID');
$statementUpdate->execute(['running' => 1, 'userID' => $row['userID']]);
$name = explode(" ", $RUNTIME['OPENSIM']->getUserName($row['userID']));
$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";
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
$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;"); $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;");
$statement->execute(); $statement->execute();
$HTML->setHTMLTitle("Dein Profile"); $HTML->setHTMLTitle("Dein Profile");