diff --git a/cron/IARMonitor.php b/cron/IARMonitor.php index a273367..569e94c 100644 --- a/cron/IARMonitor.php +++ b/cron/IARMonitor.php @@ -1,55 +1,75 @@ 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', 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` 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->execute(); - $statement = $RUNTIME['PDO']->prepare("SELECT * FROM iarstates"); + $statement = $RUNTIME['PDO']->prepare("SELECT * FROM iarstates WHERE running = 1 LIMIT 1"); $statement->execute(); - while($row = $statement->fetch()) + if($statement->rowCount() != 0) { - $email = $RUNTIME['OPENSIM']->getUserMail($row['userID']); - $filesize = filesize("data/".$row['iarfilename']); - - if($filesize != $row['filesize']) + while($row = $statement->fetch()) { - $statementUpdate = $RUNTIME['PDO']->prepare('UPDATE iarstates SET filesize = :filesize WHERE userID = :userID'); - $statementUpdate->execute(['filesize' => $filesize, 'userID' => $row['userID']]); + $email = $RUNTIME['OPENSIM']->getUserMail($row['userID']); - continue; + 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!
Du kannst sie hier 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(); + } + } }else{ - - $statementUpdate = $RUNTIME['PDO']->prepare('DELETE FROM iarstates WHERE userID = :userID'); - $statementUpdate->execute(['userID' => $row['userID']]); + $statement = $RUNTIME['PDO']->prepare("SELECT * FROM iarstates WHERE running = 0 LIMIT 1"); + $statement->execute(); - $mail = new PHPMailer(true); + while($row = $statement->fetch()) + { + $statementUpdate = $RUNTIME['PDO']->prepare('UPDATE iarstates SET running = :running WHERE userID = :userID'); + $statementUpdate->execute(['running' => 1, 'userID' => $row['userID']]); - $mail->SMTPDebug = SMTP::DEBUG_SERVER; - $mail->isSMTP(); - $mail->Host = $RUNTIME['SMTP']['SERVER']; - $mail->Port = $RUNTIME['SMTP']['PORT']; - $mail->SMTPAuth = false; - + $iarname = md5(time().$row['userID'].rand()).".iar"; + $name = explode(" ", $RUNTIME['OPENSIM']->getUserName($row['userID'])); - $mail->setFrom($RUNTIME['SMTP']['ADRESS'], $RUNTIME['GRID']['NAME']); - $mail->addAddress($email, $RUNTIME['OPENSIM']->getUserName($row['userID'])); - - $HTMLMESSAGE = 'Deine IAR ist bereit zum Download!
Du kannst sie hier 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(); + $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); + } } } - ?> \ No newline at end of file diff --git a/pages/HTML/profile.html b/pages/HTML/profile.html index 8e354a9..166878d 100644 --- a/pages/HTML/profile.html +++ b/pages/HTML/profile.html @@ -98,7 +98,7 @@

IAR Sicherung

%%IARINFOMESSAGE%%
Hier kannst du eine IAR deines Inventars erstellen.
- Dies wird einige Zeit dauern. Deswegen bekommst du einen Downloadlink per E-Mail zugeschickt, sobald die IAR fertig gestellt wurde. Stelle also sicher das du links eine gültige E-Mail Adresse eingetragen hast. + Dies wird einige Zeit dauern. Du bekommst eine E-Mail mit einem Downloadlink sobald deine IAR fertig erstellt wurde. Stelle also sicher das du Links eine gültige E-Mail Adresse eingetragen hast.
diff --git a/pages/profile.php b/pages/profile.php index a415b62..c9ac5e6 100644 --- a/pages/profile.php +++ b/pages/profile.php @@ -1,5 +1,5 @@ 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', 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` 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->execute(); $HTML->setHTMLTitle("Dein Profile"); @@ -22,20 +22,11 @@ if($IARRUNNING == FALSE) { $iarname = md5(time().$_SESSION['UUID'] . rand()).".iar"; - - $APIURL = $RUNTIME['SIDOMAN']['URL']."api.php?CONTAINER=".$RUNTIME['SIDOMAN']['CONTAINER']."&KEY=".$RUNTIME['SIDOMAN']['PASSWORD']."&METODE=COMMAND&COMMAND=".urlencode("save iar ".$_SESSION['FIRSTNAME']." ".$_SESSION['LASTNAME']." /* PASSWORD /downloads/".$iarname); - $APIResult = file_get_contents($APIURL); - if(trim($APIResult) == "DONE") - { - $HTML->ReplaceSeitenInhalt("%%IARINFOMESSAGE%%", ''); + $HTML->ReplaceSeitenInhalt("%%IARINFOMESSAGE%%", ''); - $statementIARSTART = $RUNTIME['PDO']->prepare('INSERT INTO iarstates (userID, filesize, iarfilename) VALUES (:userID, :filesize, :iarfilename)'); - $statementIARSTART->execute(['userID' => $_SESSION['UUID'], 'filesize' => 0, 'iarfilename' => $iarname]); - }else{ - $HTML->ReplaceSeitenInhalt("%%IARINFOMESSAGE%%", ''); - - } + $statementIARSTART = $RUNTIME['PDO']->prepare('INSERT INTO iarstates (userID, filesize, iarfilename) VALUES (:userID, :filesize, :iarfilename)'); + $statementIARSTART->execute(['userID' => $_SESSION['UUID'], 'filesize' => 0, 'iarfilename' => $iarname]); } }