From 8a46143b5ddd10f44f2c357e7f265e8e65412553 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 24 May 2019 18:22:17 +0200 Subject: [PATCH 1/7] Added lastrun to database --- database.sql | 1 + webcron.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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/webcron.php b/webcron.php index 29a56fe..7a554f8 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 <= 1558742600 and (nextrun <= lastrun OR lastrun = -1)'); $stmt->execute(array(time())); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); $client = new \GuzzleHttp\Client(); From 925c9fd6f3b3406979c8641db937d8de3bf7355c Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 24 May 2019 18:23:14 +0200 Subject: [PATCH 2/7] Updated editjob --- editjob.php | 17 +++++++++++++++-- templates/editjob.html.twig | 12 ++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/editjob.php b/editjob.php index 15b609c..b977eb2 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'); @@ -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 = $nextrunObj->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/templates/editjob.html.twig b/templates/editjob.html.twig index a877cdb..1f531ac 100644 --- a/templates/editjob.html.twig +++ b/templates/editjob.html.twig @@ -52,6 +52,18 @@ +
+ +
+ + + + + + + +
+
From 2d336d6a123dd3129859aaf92808aef7ec2622af Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 24 May 2019 18:23:23 +0200 Subject: [PATCH 3/7] Updated addjob --- addjob.php | 15 +++++++++++++-- templates/addjob.html.twig | 14 +++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/addjob.php b/addjob.php index ddf817d..44b60ca 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 = $nextrunObj->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/templates/addjob.html.twig b/templates/addjob.html.twig index bee1f2a..b6c07ec 100644 --- a/templates/addjob.html.twig +++ b/templates/addjob.html.twig @@ -56,7 +56,19 @@
- + +
+ +
+ + + + + + + +
+
From 9cf294fcd12f73310b593c0462071106e39fc43a Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 24 May 2019 18:29:25 +0200 Subject: [PATCH 4/7] Updated javascript --- js/site.js | 1 + 1 file changed, 1 insertion(+) 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(); From 2944074706f322507e13d04a7b7469f84f909cbc Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 24 May 2019 18:35:12 +0200 Subject: [PATCH 5/7] Updated editjob Forgot to add variable --- editjob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editjob.php b/editjob.php index b977eb2..e2858c5 100644 --- a/editjob.php +++ b/editjob.php @@ -61,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") { From 9dde6495cdf25d279a304724749e3a80faebd329 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 24 May 2019 18:36:12 +0200 Subject: [PATCH 6/7] Pushed eternal to end of input --- templates/addjob.html.twig | 6 +++--- templates/editjob.html.twig | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/addjob.html.twig b/templates/addjob.html.twig index b6c07ec..34e754b 100644 --- a/templates/addjob.html.twig +++ b/templates/addjob.html.twig @@ -60,13 +60,13 @@
- - - + +  Eternal +
diff --git a/templates/editjob.html.twig b/templates/editjob.html.twig index 1f531ac..978a93e 100644 --- a/templates/editjob.html.twig +++ b/templates/editjob.html.twig @@ -55,13 +55,13 @@
- - - + +  Eternal +
From 0809cd3c4b252ded0caab104ffe4969b93c57c25 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 24 May 2019 18:41:28 +0200 Subject: [PATCH 7/7] Fixed bugs --- addjob.php | 2 +- editjob.php | 2 +- webcron.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addjob.php b/addjob.php index 44b60ca..a74c4a3 100644 --- a/addjob.php +++ b/addjob.php @@ -70,7 +70,7 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") { if (!$eternal) { $lastrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['lastrun']); - $lastrun = $nextrunObj->getTimestamp(); + $lastrun = $lastrunObj->getTimestamp(); } else { $lastrun = -1; } diff --git a/editjob.php b/editjob.php index e2858c5..168ba2c 100644 --- a/editjob.php +++ b/editjob.php @@ -81,7 +81,7 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") { if (!$eternal) { $lastrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['lastrun']); - $lastrun = $nextrunObj->getTimestamp(); + $lastrun = $lastrunObj->getTimestamp(); } else { $lastrun = -1; } diff --git a/webcron.php b/webcron.php index 7a554f8..eb18749 100644 --- a/webcron.php +++ b/webcron.php @@ -67,7 +67,7 @@ if (file_exists("cache/get-services.trigger")) { } } -$stmt = $db->prepare('SELECT * FROM jobs WHERE nextrun <= 1558742600 and (nextrun <= lastrun OR lastrun = -1)'); +$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();