<?php
/*
 * Variomedia PHP Cronjob Editor
 * Version 1.0
 * (C) 2018 Variomedia AG
 */
$username = get_current_user(); ?>
<!DOCTYPE html>
<html lang="de">
  <head>
    <meta charset="utf-8" />
    <title>Variomedia Cronjob Editor</title>
  </head> 
  <body>
    <?php if ((time() - getlastmod()) > 3600): ?><h2>Die Ausf&uuml;hrung des Scripts wurde abgebrochen!</h2>
    Dieses Script kann aus Sicherheitsgr&uuml;den eine Stunde nach Erstellung nicht mehr ausgef&uuml;hrt werden.<br>
    Sie sollten dieses Script entfernen oder bei Bedarf neu installieren.
  </body>
</html>
    <?php elseif (isset($_POST['username'])):
      if ($_POST['username'] != $username): ?><h2>Falscher FTP-Benutzername!</h2>
    <form action='cron.php' method='post'>
      <p>Bitte geben Sie Ihren FTP-Benutzernamen ein:<br><input name='username' type='password' size='16' maxlength='64'></p>
      <input type='submit' value='Anmelden'>
    </form>
  </body>
</html>
      <?php else:
        if (isset($_POST['reset'])):
          exec("crontab -r &> /dev/null"); ?><h3>Crontab gel&ouml;scht.</h3>
    <form action='cron.php' method='post'>
      <input type='hidden' name='username' value='<?php print($username); ?>'>
      <textarea name='cron' cols='100' rows='20'></textarea><br>
      <input type='checkbox' name='reset' value='reset'>Crontab l&ouml;schen<br>
      <input type='submit' value='&Uuml;bernehmen'>
    </form>
    <br>Hilfe und weitere Informationen finden Sie <a href="https://www.variomedia.de/faq/Wie-richte-ich-einen-Cronjob-ein/article/86" target="_blank" target="_blank">hier</a>.
  </body>
</html>
        <?php elseif (isset($_POST['cron'])):
          $cron = trim($_POST['cron']) . "\r\n";
          $cmd = "printf -- " . escapeshellarg($cron) . " | dos2unix | crontab - 2>&1";
          $ret = shell_exec($cmd);
          if ($ret != ""): ?><h2>Beim Einrichten des Cronjobs ist ein Fehler aufgetreten!</h2>
    <h4>Fehlermeldung vom System:</h4>
    <?php print($ret . "<br>\n"); ?>
    <h3>Bitte &uuml;berpr&uuml;fen Sie das Crontab auf Syntaxfehler:</h3>
          <?php else: ?><h3>Neues Crontab installiert:</h3>
          <?php endif; ?><form action='cron.php' method='post'>
      <input type='hidden' name='username' value='<?php print($username); ?>'>
      <textarea name='cron' cols='100' rows='20'><?php print(stripslashes($cron)); ?></textarea><br>
      <input type='checkbox' name='reset' value='reset'>Crontab l&ouml;schen<br>
      <input type='submit' value='&Uuml;bernehmen'>
    </form>
    <br>Hilfe und weitere Informationen finden Sie <a href="https://www.variomedia.de/faq/Wie-richte-ich-einen-Cronjob-ein/article/86" target="_blank" target="_blank">hier</a>.
  </body>
</html>
        <?php else: ?><h3>Installiertes Crontab:</h3>
          <?php $crontab = shell_exec('crontab -l 2> /dev/null'); ?>
    <form action='cron.php' method='post'>
      <input type='hidden' name='username' value='<?php print($username); ?>'>
      <textarea name='cron' cols='100' rows='20'><?php print($crontab); ?></textarea><br>
      <input type='checkbox' name='reset' value='reset'>Crontab l&ouml;schen<br>
      <input type='submit' value='&Uuml;bernehmen'>
    </form>
    <br>Hilfe und weitere Informationen finden Sie <a href="https://www.variomedia.de/faq/Wie-richte-ich-einen-Cronjob-ein/article/86" target="_blank" target="_blank">hier</a>.
  </body>
</html>
      <?php endif;
      endif;
    else: ?><form action='cron.php' method='post'>
      <p>Bitte geben Sie Ihren FTP-Benutzernamen ein:<br><input name='username' type='password' size='16' maxlength='64'></p>
      <input type='submit' value='Anmelden'>
    </form>
  </body>
</html>
    <?php endif; ?>
