From 13170e698e081e3c17b636c6a3af81788b56ace0 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 10 Jan 2018 18:20:03 +0100 Subject: [PATCH 1/4] Fixed overflow problems in cron --- pandora_server/lib/PandoraFMS/Tools.pm | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 7487081c24..d2c82dcd44 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -1373,7 +1373,7 @@ sub cron_next_execution_date { if($mon ne '*') { my ($mon_down, $mon_up) = cron_get_interval ($mon); if (defined($mon_up)) { - $mon = $mon_down - 1 . "-" . $mon_up - 1; + $mon = ($mon_down - 1) . "-" . ($mon_up - 1); } else { $mon = $mon_down - 1; } @@ -1395,7 +1395,6 @@ sub cron_next_execution_date { # Get first next date candidate from next cron configuration # Initialize some vars my @nex_time_array = @curr_time_array; - my $prev_ovfl = 0; # Update minutes my ($min_down, undef) = cron_get_interval ($min); @@ -1412,7 +1411,6 @@ sub cron_next_execution_date { if ($nex_time == 0) { #Update the month day if overflow - $prev_ovfl = 1; $nex_time_array[1] = 0; $nex_time_array[2]++; $nex_time = cron_valid_date(@nex_time_array, $cur_year); @@ -1437,18 +1435,16 @@ sub cron_next_execution_date { $nex_time_array[1] = ($hour_down eq '*') ? 0 : $hour_down; # When an overflow is passed check the hour update again - if ($prev_ovfl) { - $nex_time = cron_valid_date(@nex_time_array, $cur_year); + $nex_time = cron_valid_date(@nex_time_array, $cur_year); + if ($nex_time >= $cur_time) { return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array); } - $prev_ovfl = 0; # Check if next day is in cron $nex_time_array[2]++; $nex_time = cron_valid_date(@nex_time_array, $cur_year); if ($nex_time == 0) { #Update the month if overflow - $prev_ovfl = 1; $nex_time_array[2] = 1; $nex_time_array[3]++; $nex_time = cron_valid_date(@nex_time_array, $cur_year); @@ -1467,18 +1463,17 @@ sub cron_next_execution_date { $nex_time_array[2] = ($mday_down eq '*') ? 1 : $mday_down; # When an overflow is passed check the hour update in the next execution - if ($prev_ovfl) { - $nex_time = cron_valid_date(@nex_time_array, $cur_year); + $nex_time = cron_valid_date(@nex_time_array, $cur_year); + if ($nex_time >= $cur_time) { return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array); } - $prev_ovfl = 0; # Check if next month is in cron $nex_time_array[3]++; $nex_time = cron_valid_date(@nex_time_array, $cur_year); if ($nex_time == 0) { #Update the year if overflow - $prev_ovfl = 1; + $nex_time_array[3] = 0; $cur_year++; $nex_time = cron_valid_date(@nex_time_array, $cur_year); } @@ -1488,11 +1483,11 @@ sub cron_next_execution_date { #Update the month if fails my ($mon_down, undef) = cron_get_interval ($mon); - $nex_time_array[3] = ($mday_down eq '*') ? 0 : $mday_down; + $nex_time_array[3] = ($mon_down eq '*') ? 0 : $mon_down; # When an overflow is passed check the hour update in the next execution - if ($prev_ovfl) { - $nex_time = cron_valid_date(@nex_time_array, $cur_year); + $nex_time = cron_valid_date(@nex_time_array, $cur_year); + if ($nex_time >= $cur_time) { return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array); } From f653fb0f26c1a1b761fd3293147448095ec7b9ec Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 10 Jan 2018 18:31:13 +0100 Subject: [PATCH 2/4] Fixed month order on cron --- pandora_console/include/functions_html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 1e63b5356f..77be3387e0 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -929,7 +929,7 @@ function html_print_extended_select_for_cron ($hour = '*', $minute = '*', $mday } # Months - for ($i = 0; $i < 12; $i++) { + for ($i = 1; $i <= 12; $i++) { $months[$i] = date('F', mktime (0, 0, 0, $i, 1)); } From 0929154625561798d2ca71ab56804f09153c50b6 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 10 Jan 2018 18:31:33 +0100 Subject: [PATCH 3/4] Fixed overflow problems in cron (console) --- pandora_console/include/functions_cron.php | 26 ++++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/pandora_console/include/functions_cron.php b/pandora_console/include/functions_cron.php index efa5f2f342..63fc0c20e3 100644 --- a/pandora_console/include/functions_cron.php +++ b/pandora_console/include/functions_cron.php @@ -94,7 +94,7 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = if ($cron_array[3] != '*') { $mon_s = cron_get_interval ($cron_array[3]); if ($mon_s['up'] !== false) { - $cron_array[3] = $mon_s['down'] - 1 . "-" . $mon_s['up'] - 1; + $cron_array[3] = ($mon_s['down'] - 1) . "-" . ($mon_s['up'] - 1); } else { $cron_array[3] = $mon_s['down'] - 1; } @@ -106,10 +106,6 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = $nex_time = $cur_time + $module_interval; $nex_time_array = explode (" ", date ("i H d m Y", $nex_time)); if (cron_is_in_cron($cron_array, $nex_time_array)) return $nex_time; - - // Get first next date candidate from next cron configuration - // Initialize some vars - $prev_ovfl = false; // Update minutes $min_s = cron_get_interval ($cron_array[0]); @@ -128,7 +124,6 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = if ($nex_time === false) { // Update the month day if overflow - $prev_ovfl = true; $nex_time_array[1] = 0; $nex_time_array[2]++; $nex_time = cron_valid_date($nex_time_array); @@ -155,20 +150,18 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = $nex_time_array[1] = ($hour_s['down'] == '*') ? 0 : $hour_s['down']; // When an overflow is passed check the hour update again - if ($prev_ovfl) { - $nex_time = cron_valid_date($nex_time_array); + $nex_time = cron_valid_date($nex_time_array); + if ($nex_time >= $cur_time) { if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) { return $nex_time; } } - $prev_ovfl = false; // Check if next day is in cron $nex_time_array[2]++; $nex_time = cron_valid_date($nex_time_array); if ($nex_time === false) { // Update the month if overflow - $prev_ovfl = true; $nex_time_array[2] = 1; $nex_time_array[3]++; $nex_time = cron_valid_date($nex_time_array); @@ -189,21 +182,20 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = $nex_time_array[2] = ($mday_s['down'] == '*') ? 1 : $mday_s['down']; // When an overflow is passed check the hour update in the next execution - if ($prev_ovfl) { - $nex_time = cron_valid_date($nex_time_array); + $nex_time = cron_valid_date($nex_time_array); + if ($nex_time >= $cur_time) { if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) { return $nex_time; } } - $prev_ovfl = false; // Check if next month is in cron $nex_time_array[3]++; $nex_time = cron_valid_date($nex_time_array); if ($nex_time === false) { #Update the year if overflow - $prev_ovfl = true; - $nex_time_array[3]++; + $nex_time_array[3] = 0; + $nex_time_array[4]++; $nex_time = cron_valid_date($nex_time_array); } @@ -217,8 +209,8 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = $nex_time_array[3] = ($mon_s['down'] == '*') ? 0 : $mon_s['down']; // When an overflow is passed check the hour update in the next execution - if ($prev_ovfl) { - $nex_time = cron_valid_date($nex_time_array); + $nex_time = cron_valid_date($nex_time_array); + if ($nex_time >= $cur_time) { if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) { return $nex_time; } From a8963d554089bb05023e62e543bb6be884177a1d Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 10 Jan 2018 18:54:53 +0100 Subject: [PATCH 4/4] Fixed month cron in console (don't substract 1) --- pandora_console/include/functions_cron.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/functions_cron.php b/pandora_console/include/functions_cron.php index 63fc0c20e3..c83b96aa9c 100644 --- a/pandora_console/include/functions_cron.php +++ b/pandora_console/include/functions_cron.php @@ -90,15 +90,8 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = // Get cron configuration $cron_array = explode (" ", $cron); - // Months start from 0 - if ($cron_array[3] != '*') { - $mon_s = cron_get_interval ($cron_array[3]); - if ($mon_s['up'] !== false) { - $cron_array[3] = ($mon_s['down'] - 1) . "-" . ($mon_s['up'] - 1); - } else { - $cron_array[3] = $mon_s['down'] - 1; - } - } + + // REMARKS: Months start from 1 in php (different to server) // Get current time if ($cur_time === false) $cur_time = time(); @@ -134,7 +127,7 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = $nex_time = cron_valid_date($nex_time_array); if ($nex_time === false) { #Update the year if overflow - $nex_time_array[3] = 0; + $nex_time_array[3] = 1; $nex_time_array[4]++; $nex_time = cron_valid_date($nex_time_array); } @@ -167,7 +160,7 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = $nex_time = cron_valid_date($nex_time_array); if ($nex_time === false) { // Update the year if overflow - $nex_time_array[3] = 0; + $nex_time_array[3] = 1; $nex_time_array[4]++; $nex_time = cron_valid_date($nex_time_array); } @@ -194,7 +187,7 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = $nex_time = cron_valid_date($nex_time_array); if ($nex_time === false) { #Update the year if overflow - $nex_time_array[3] = 0; + $nex_time_array[3] = 1; $nex_time_array[4]++; $nex_time = cron_valid_date($nex_time_array); } @@ -206,7 +199,7 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval = // Update the month if fails $mon_s = cron_get_interval ($cron_array[3]); - $nex_time_array[3] = ($mon_s['down'] == '*') ? 0 : $mon_s['down']; + $nex_time_array[3] = ($mon_s['down'] == '*') ? 1 : $mon_s['down']; // When an overflow is passed check the hour update in the next execution $nex_time = cron_valid_date($nex_time_array);