diff --git a/addjob.php b/addjob.php index ddf817d..a74c4a3 100644 --- a/addjob.php +++ b/addjob.php @@ -64,9 +64,17 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") { $name = $_POST['name']; $delay = $_POST['delay']; $expected = $_POST['expected']; + $eternal = (isset($_POST['eternal']) && $_POST['eternal'] == true) ? true : false; $nextrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['nextrun']); $nextrun = $nextrunObj->getTimestamp(); - + + if (!$eternal) { + $lastrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['lastrun']); + $lastrun = $lastrunObj->getTimestamp(); + } else { + $lastrun = -1; + } + if(!is_numeric($delay)) { header("location:addjob.php?error=invaliddelay"); exit; @@ -75,7 +83,10 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") { header("location:addjob.php?error=invalidnextrun"); exit; } - + if(!is_numeric($lastrun)) { + header("location:addjob.php?error=invalidlastrun"); + exit; + } $stmt = $db->prepare("INSERT INTO jobs(user, name, url, host, delay, nextrun, expected) VALUES(?, ?, ?, ?, ?, ?, ?)"); $stmt->execute(array($_SESSION["userID"], $name, $url, $host, $delay, $nextrun, $expected)); diff --git a/database.sql b/database.sql index 5b4fd20..b0436fb 100644 --- a/database.sql +++ b/database.sql @@ -59,6 +59,7 @@ CREATE TABLE IF NOT EXISTS `jobs` ( `host` varchar(50) NOT NULL DEFAULT 'localhost', `delay` int(11) NOT NULL, `nextrun` int(11) NOT NULL, + `lastrun` int(11) NOT NULL DEFAULT '-1', `expected` int(11) NOT NULL DEFAULT '200', PRIMARY KEY (`jobID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/editjob.php b/editjob.php index 15b609c..168ba2c 100644 --- a/editjob.php +++ b/editjob.php @@ -42,6 +42,7 @@ if ($_SERVER["REQUEST_METHOD"] == "GET") { $delay = $jobnameResult[0]['delay']; $expected = $jobnameResult[0]['expected']; $nextrun = date("d/m/Y H:i:s", $jobnameResult[0]['nextrun']); + $lastrun = ($jobnameResult[0]['lastrun'] == -1) ? -1 : date("d/m/Y H:i:s", $jobnameResult[0]['lastrun']); $loader = new Twig_Loader_Filesystem('templates'); @@ -60,7 +61,7 @@ if ($_SERVER["REQUEST_METHOD"] == "GET") { } - echo $twig->render('editjob.html.twig', array("name" => $name, "url" => $url, "host" => $host, "delay" => $delay, "expected" => $expected, 'nextrun' => $nextrun, "jobID" => $jobID, "error" => $error)); + echo $twig->render('editjob.html.twig', array("name" => $name, "url" => $url, "host" => $host, "delay" => $delay, "expected" => $expected, 'nextrun' => $nextrun, 'lastrun' => $lastrun, "jobID" => $jobID, "error" => $error)); } elseif ($_SERVER["REQUEST_METHOD"] == "POST") { @@ -74,8 +75,16 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") { $delay = $_POST['delay']; $host = $_POST['host']; $expected = $_POST['expected']; + $eternal = (isset($_POST['eternal']) && $_POST['eternal'] == true) ? true : false; $nextrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['nextrun']); $nextrun = $nextrunObj->getTimestamp(); + + if (!$eternal) { + $lastrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['lastrun']); + $lastrun = $lastrunObj->getTimestamp(); + } else { + $lastrun = -1; + } if(!is_numeric($delay)) { header("location:editjob.php?jobID=" . $jobID . "&error=invaliddelay"); @@ -85,10 +94,14 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") { header("location:editjob.php?jobID=" . $jobID . "&error=invalidnextrun"); exit; } + if(!is_numeric($lastrun)) { + header("location:editjob.php?jobID=" . $jobID . "&error=invalidlastrun"); + exit; + } - $stmt = $db->prepare("UPDATE jobs SET name = ?, url = ?, host = ?, delay = ?, nextrun = ?, expected = ? WHERE jobID = ?"); - $stmt->execute(array($name, $url, $host, $delay, $nextrun, $expected, $jobID)); + $stmt = $db->prepare("UPDATE jobs SET name = ?, url = ?, host = ?, delay = ?, nextrun = ?, expected = ?, lastrun = ? WHERE jobID = ?"); + $stmt->execute(array($name, $url, $host, $delay, $nextrun, $expected, $lastrun, $jobID)); header("location:overview.php?message=edited"); exit; diff --git a/js/site.js b/js/site.js index ed28c12..164703c 100644 --- a/js/site.js +++ b/js/site.js @@ -28,6 +28,7 @@ $(document).ready(function() { if(this.value != "custom") { $("input#delay").val($(this).data("val")); } }); $('#nextrunselector').datetimepicker( { format: 'DD/MM/YYYY HH:mm:ss' } ); + $('#lastrunselector').datetimepicker( { format: 'DD/MM/YYYY HH:mm:ss' } ); $("body").on("click", ".runcron", function() { $("#ajax_loader").show(); diff --git a/templates/addjob.html.twig b/templates/addjob.html.twig index bee1f2a..34e754b 100644 --- a/templates/addjob.html.twig +++ b/templates/addjob.html.twig @@ -56,7 +56,19 @@ - + +
+ +
+ + + + + +  Eternal + +
+
diff --git a/templates/editjob.html.twig b/templates/editjob.html.twig index a877cdb..978a93e 100644 --- a/templates/editjob.html.twig +++ b/templates/editjob.html.twig @@ -52,6 +52,18 @@
+
+ +
+ + + + + +  Eternal + +
+
diff --git a/webcron.php b/webcron.php index 29a56fe..eb18749 100644 --- a/webcron.php +++ b/webcron.php @@ -67,7 +67,7 @@ if (file_exists("cache/get-services.trigger")) { } } -$stmt = $db->prepare('SELECT jobID, url, host, delay, nextrun, expected FROM jobs WHERE nextrun <= ?'); +$stmt = $db->prepare('SELECT * FROM jobs WHERE nextrun <= ? and (nextrun <= lastrun OR lastrun = -1)'); $stmt->execute(array(time())); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); $client = new \GuzzleHttp\Client();