Merge branch 'ent-1436-opciones-avanzadas-cron-modulos-sinteticos-no-funciona-correctamente-3' into 'develop'

Ent 1436 opciones avanzadas cron modulos sinteticos no funciona correctamente 3

See merge request artica/pandorafms!1112
This commit is contained in:
vgilc 2017-11-23 17:44:25 +01:00
commit ebc35ae791
6 changed files with 467 additions and 152 deletions

View File

@ -590,8 +590,7 @@ $table_advanced->colspan[10][1] = 6;
if (isset($id_agente) && $moduletype == MODULE_DATA) {
$has_remote_conf = enterprise_hook('config_agents_has_remote_configuration',array($agent["id_agente"]));
if ($has_remote_conf) {
$table_advanced->data[11][0] = __('Cron from') .
ui_print_help_tip (__('If cron is set the module interval is ignored and the module runs on the specified date and time'), true);
$table_advanced->data[11][0] = __('Cron from') . ui_print_help_icon ('cron', true);
$table_advanced->data[11][1] = html_print_extended_select_for_cron ($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, $disabledBecauseInPolicy);
$table_advanced->colspan[11][1] = 6;
@ -600,8 +599,7 @@ if (isset($id_agente) && $moduletype == MODULE_DATA) {
$table_advanced->colspan[12][1] = 6;
}
else {
$table_advanced->data[11][0] = __('Cron from') .
ui_print_help_tip (__('If cron is set the module interval is ignored and the module runs on the specified date and time'), true);
$table_advanced->data[11][0] = __('Cron from') . ui_print_help_icon ('cron', true);
$table_advanced->data[11][1] = html_print_extended_select_for_cron ($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, true);
$table_advanced->colspan[11][1] = 6;
@ -611,8 +609,7 @@ if (isset($id_agente) && $moduletype == MODULE_DATA) {
}
}
else {
$table_advanced->data[11][0] = __('Cron from') .
ui_print_help_tip (__('If cron is set the module interval is ignored and the module runs on the specified date and time'), true);
$table_advanced->data[11][0] = __('Cron from') . ui_print_help_icon ('cron', true);
$table_advanced->data[11][1] = html_print_extended_select_for_cron ($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, $disabledBecauseInPolicy);
$table_advanced->colspan[11][1] = 6;

View File

@ -30,24 +30,30 @@ function cron_update_module_interval ($module_id, $cron) {
$module_interval = db_get_value_filter('module_interval','tagente_modulo',array("id_agente_modulo" => $module_id));
return db_process_sql ('UPDATE tagente_estado SET current_interval = ' . $module_interval . ' WHERE id_agente_modulo = ' . (int) $module_id);
} else {
return db_process_sql ('UPDATE tagente_estado SET current_interval = ' . cron_next_execution ($cron) . ' WHERE id_agente_modulo = ' . (int) $module_id);
return db_process_sql (
'UPDATE tagente_estado SET current_interval = ' .
cron_next_execution ($cron, $module_interval, $module_id) .
' WHERE id_agente_modulo = ' .
(int) $module_id)
;
}
}
// Get the number of seconds left to the next execution of the given cron entry.
function cron_next_execution ($cron) {
function cron_next_execution ($cron, $module_interval, $module_id) {
// Get day of the week and month from cron config
list ($minute, $hour, $mday, $month, $wday) = explode (" ", $cron);
// Get current time
$cur_time = time();
// Get last execution time
$last_execution = db_get_value('utimestamp', 'tagente_estado', 'id_agente_modulo', $module_id);
$cur_time = ($last_execution !== false) ? $last_execution : time();
// Any day of the way
if ($wday == '*') {
$nex_time = cron_next_execution_date ($cron, $cur_time);
$nex_time = cron_next_execution_date ($cron, $cur_time, $module_interval);
return $nex_time - $cur_time;
}
@ -55,7 +61,7 @@ function cron_next_execution ($cron) {
$count = 0;
$nex_time = $cur_time;
do {
$nex_time = cron_next_execution_date ($cron, $nex_time);
$nex_time = cron_next_execution_date ($cron, $nex_time, $module_interval);
$nex_time_wd = $nex_time;
list ($nex_mon, $nex_wday) = explode (" ", date ("m w", $nex_time_wd));
@ -80,90 +86,202 @@ function cron_next_execution ($cron) {
}
// Get the next execution date for the given cron entry in seconds since epoch.
function cron_next_execution_date ($cron, $cur_time = false) {
function cron_next_execution_date ($cron, $cur_time = false, $module_interval = 300) {
// Get cron configuration
list ($min, $hour, $mday, $mon, $wday) = explode (" ", $cron);
$cron_array = explode (" ", $cron);
// Months start from 0
if ($mon != '*') {
$mon -= 1;
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;
}
}
// Get current time
if ($cur_time === false) {
$cur_time = time();
}
list ($cur_min, $cur_hour, $cur_mday, $cur_mon, $cur_year) = explode (" ", date ("i H d m Y", $cur_time));
if ($cur_time === false) $cur_time = time();
// Get first next date candidate from cron configuration
$nex_min = $min;
$nex_hour = $hour;
$nex_mday = $mday;
$nex_mon = $mon;
$nex_year = $cur_year;
$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;
// Replace wildcards
if ($min == '*') {
if ($hour != '*' || $mday != '*' || $wday != '*' || $mon != '*') {
$nex_min = 0;
// 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]);
$nex_time_array[0] = ($min_s['down'] == '*') ? 0 : $min_s['down'];
$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;
}
else {
$nex_min = $cur_min;
}
}
if ($hour == '*') {
if ($mday != '*' || $wday != '*' ||$mon != '*') {
$nex_hour = 0;
}
else {
$nex_hour = $cur_hour;
}
}
if ($mday == '*') {
if ($mon != '*') {
$nex_mday = 1;
}
else {
$nex_mday = $cur_mday;
}
}
if ($mon == '*') {
$nex_mon = $cur_mon;
}
// Find the next execution date
$count = 0;
do {
$next_time = mktime($nex_hour, $nex_min, 0, $nex_mon, $nex_mday, $nex_year);
if ($next_time > $cur_time) {
return $next_time;
}
if ($min == '*' && $hour == '*' && $wday == '*' && $mday == '*' && $mon == '*') {
list ($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year) = explode (" ", date ("i H d m Y", $next_time + SECONDS_1MINUTE));
}
else if ($hour == '*' && $wday == '*' && $mday == '*' && $mon == '*') {
list ($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year) = explode (" ", date ("i H d m Y", $next_time + SECONDS_1HOUR));
}
else if ($mday == '*' && $mon == '*') {
list ($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year) = explode (" ", date ("i H d m Y", $next_time + SECONDS_1DAY));
}
else if ($mon == '*') {
$nex_mon = $nex_mon + 1;
if ($nex_mon > 11) {
$nex_mon = 0;
$nex_year++;
// Check if next hour is in cron
$nex_time_array[1]++;
$nex_time = cron_valid_date($nex_time_array);
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);
if ($nex_time === false) {
// Update the month if overflow
$nex_time_array[2] = 1;
$nex_time_array[3]++;
$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[4]++;
$nex_time = cron_valid_date($nex_time_array);
}
}
else {
$nex_year++;
}
$count++;
}
while ($count < SECONDS_1DAY);
// Check the hour
if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) {
return $nex_time;
}
// Something went wrong, default to 5 minutes
return $cur_time + SECONDS_5MINUTES;
// Update the hour if fails
$hour_s = cron_get_interval ($cron_array[1]);
$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);
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);
if ($nex_time === false) {
// Update the year if overflow
$nex_time_array[3] = 0;
$nex_time_array[4]++;
$nex_time = cron_valid_date($nex_time_array);
}
}
// Check the day
if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) {
return $nex_time;
}
// Update the day if fails
$mday_s = cron_get_interval ($cron_array[2]);
$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);
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 = cron_valid_date($nex_time_array);
}
// Check the month
if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) {
return $nex_time;
}
// Update the month if fails
$mon_s = cron_get_interval ($cron_array[3]);
$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);
if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) {
return $nex_time;
}
}
// Update the year
$nex_time_array[4]++;
$nex_time = cron_valid_date($nex_time_array);
return ($nex_time !== false) ? $nex_time : $module_interval;
}
// Get an array with the cron interval
function cron_get_interval ($element) {
# Not a range
if (!preg_match('/(\d+)\-(\d+)/', $element, $capture)) {
return array(
'down' => $element,
'up' => false
);
}
return array(
'down' => $capture[1],
'up' => $capture[2]
);
}
// Returns if a date is in a cron. Recursive.
function cron_is_in_cron($elems_cron, $elems_curr_time) {
$elem_cron = array_shift($elems_cron);
$elem_curr_time = array_shift($elems_curr_time);
// If there is no elements means that is in cron
if ($elem_cron === null || $elem_curr_time === null) return true;
// Go to last element if current is a wild card
if ($elem_cron != '*') {
$elem_s = cron_get_interval($elem_cron);
// Check if there is no a range
if (($elem_s['up'] === false) && ($elem_s['down'] != $elem_curr_time)) {
return false;
}
// Check if there is on the range
if ($elem_s['up'] !== false) {
if ($elem_s['down'] < $elem_s['up']) {
if ($elem_curr_time < $elem_s['down'] || $elem_curr_time > $elem_s['up']){
return false;
}
} else {
if ($elem_curr_time > $elem_s['down'] || $elem_curr_time < $elem_s['up']){
return false;
}
}
}
}
return cron_is_in_cron($elems_cron, $elems_curr_time);
}
function cron_valid_date ($da) {
$st = sprintf("%04d:%02d:%02d %02d:%02d:00", $da[4], $da[3], $da[2], $da[1], $da[0]);
$time = strtotime($st);
return $time;
}
// Check if cron is properly constructed

View File

@ -0,0 +1,45 @@
<?php
/**
* @package Include/help/en
*/
?>
<h1>Cron for server modules</h1>
Using the configuration parameter sets <b>Cron from</b> and <b>Cron to</b> makes
it possible for a module to run only for certain periods of time.
The way in which it is configured is similar to the syntax of
<a style="font-size:14px;" href="https://en.wikipedia.org/wiki/Cron">cron</a>.
Just as they appear in the Pandora console, each one of the parameters
has three options.
<h4>Cron from: any</h4>
The module will not have restrictions in that parameter. Whatever the value is
will be executed, and it is equivalent to the asterisk (*) in the cron nomenclature. In this
case <b>Cron to</b> is ignored.
<h4>Cron from: different from any. Cron to: any</h4>
The module will run only during the time in which the date matches that
parameter. It is equivalent to writingjust one number in cron nomenclature.
<h4>Cron from: different from any. Cron to: different from any</h4>
The module will run only during the time specified between <b>Cron from</b> and <b>Cron to</b>.
It is equivalent to writing number dash number (n-n) in cron nomenclature.
<h2>Agent interval</h2>
As long as cron conditions are met, the agent will run following
its execution interval.
<h2>Examples</h2>
<ul>
<li><i>* * * * *</i>: No cron configured.</li>
<li><i>15 20 * * *</i>: It will run every day at 20:15.</li>
<li><i>* 20 * * *</i>: It will run every day during the hour 20, that is, from 20:00 to 20:59.</li>
<li><i>* 8-19 * * *</i>: It will run everyday from 8:00 to 19:59.</li>
<li><i>15-45 * 1-16 * *</i>: It will run every first 16 days of the month every hour, from quarter past to quarter to.</li>
<li><i>* * * 5 *</i>: It will run only in May.</li>
<ul>

View File

@ -0,0 +1,46 @@
<?php
/**
* @package Include/help/es
*/
?>
<h1>Cron para módulos de servidor</h1>
Mediante los grupos de parámetros de configuración <b>Cron desde</b> y <b>Cron hasta</b> se
puede hacer que un módulo solo se ejecute durante ciertos periodos de tiempo. El
modo en el que se configura es parecido a la sintaxis de
<a style="font-size:14px;" href="https://es.wikipedia.org/wiki/Cron_(Unix)">cron</a>.
Tal y como aparecen en la consola de Pandora, cada uno de los parámetros
tiene tres opciones.
<h4>Cron desde: cualquiera</h4>
El módulo no tendrá restricciones en ese parámetro. Se ejecutará cualquiera que
que sea el valor y equivale al asterisco (*) en la nomenclatura de cron. En este
caso se ignora <b>Cron desde</b>.
<h4>Cron desde: distinto de cualquiera. Cron hasta: cualquiera</h4>
El módulo se ejecutará solamente el tiempo en el que la fecha coincida con ese
parámetro. Equivale a escribir solamente un número en la nomenclatura de cron.
<h4>Cron desde: distinto de cualquiera. Cron hasta: distinto de cualquiera</h4>
El módulo se ejecutará entre el tiempo indicado en el <b>Cron desde</b> y el <b>Cron hasta</b>.
Equivale a escribir el número guión número (n-n) en la nomenclatura de cron.
<h2>Intervalo del agente</h2>
Mientras que se cumplan las condiciones de cron, el agente se ejecutará siguiendo
su intervalo de ejecución.
<h2>Ejemplos</h2>
<ul>
<li><i>* * * * *</i>: No hay cron configurado.</li>
<li><i>15 20 * * *</i>: Se ejecutará todos los días a las 20:15.</li>
<li><i>* 20 * * *</i>: Se ejecutará todos los días durante las 20 horas, es decir, entre las 20:00 y las 20:59.</li>
<li><i>* 8-19 * * *</i>: Se ejecutará todos los días entre las 8:00 y las 19:59.</li>
<li><i>15-45 * 1-16 * *</i>: Se ejecutará todos los primeros 16 días del mes a todas horas entre y cuarto y menos cuarto.</li>
<li><i>* * * 5 *</i>: Se ejecutará solamente en mayo.</li>
<ul>

View File

@ -0,0 +1,46 @@
<?php
/**
* @package Include/help/ja
*/
?>
<h1>Cron for server modules</h1>
Using the configuration parameter sets <b>Cron from</b> and <b>Cron to</b> makes
it possible for a module to run only for certain periods of time.
The way in which it is configured is similar to the syntax of
<a style="font-size:14px;" href="https://en.wikipedia.org/wiki/Cron">cron</a>.
Just as they appear in the Pandora console, each one of the parameters
has three options.
<h4>Cron from: any</h4>
The module will not have restrictions in that parameter. Whatever the value is
will be executed, and it is equivalent to the asterisk (*) in the cron nomenclature. In this
case <b>Cron to</b> is ignored.
<h4>Cron from: different from any. Cron to: any</h4>
The module will run only during the time in which the date matches that
parameter. It is equivalent to writingjust one number in cron nomenclature.
<h4>Cron from: different from any. Cron to: different from any</h4>
The module will run only during the time specified between <b>Cron from</b> and <b>Cron to</b>.
It is equivalent to writing number dash number (n-n) in cron nomenclature.
<h2>Agent interval</h2>
As long as cron conditions are met, the agent will run following
its execution interval.
<h2>Examples</h2>
<ul>
<li><i>* * * * *</i>: No cron configured.</li>
<li><i>15 20 * * *</i>: It will run every day at 20:15.</li>
<li><i>* 20 * * *</i>: It will run every day during the hour 20, that is, from 20:00 to 20:59.</li>
<li><i>* 8-19 * * *</i>: It will run everyday from 8:00 to 19:59.</li>
<li><i>15-45 * 1-16 * *</i>: It will run every first 16 days of the month every hour, from quarter past to quarter to.</li>
<li><i>* * * 5 *</i>: It will run only in May.</li>
<ul>

View File

@ -1335,7 +1335,12 @@ sub cron_next_execution_date {
# Months start from 0
if($mon ne '*') {
$mon -= 1;
my ($mon_down, $mon_up) = cron_get_interval ($mon);
if (defined($mon_up)) {
$mon = $mon_down - 1 . "-" . $mon_up - 1;
} else {
$mon = $mon_down - 1;
}
}
# Get current time
@ -1351,75 +1356,112 @@ sub cron_next_execution_date {
my @curr_time_array = ($cur_min, $cur_hour, $cur_mday, $cur_mon);
return ($nex_time) if cron_is_in_cron(\@cron_array, \@curr_time_array) == 1;
# Parse intervals
($min, undef) = cron_get_interval ($min);
($hour, undef) = cron_get_interval ($hour);
($mday, undef) = cron_get_interval ($mday);
($mon, undef) = cron_get_interval ($mon);
# Get first next date candidate from next cron configuration
# Initialize some vars
my @nex_time_array = @curr_time_array;
my $prev_ovfl = 0;
# Get first next date candidate from cron configuration
my ($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year)
= ($min, $hour, $mday, $mon, $cur_year);
# Update minutes
my ($min_down, undef) = cron_get_interval ($min);
$nex_time_array[0] = ($min_down eq '*') ? 0 : $min_down;
# Replace wildcards
if ($min eq '*') {
if ($hour ne '*' || $mday ne '*' || $wday ne '*' || $mon ne '*') {
$nex_min = 0;
}
else {
$nex_min = $cur_min;
}
}
if ($hour eq '*') {
if ($mday ne '*' || $wday ne '*' ||$mon ne '*') {
$nex_hour = 0;
}
else {
$nex_hour = $cur_hour;
}
}
if ($mday eq '*') {
if ($mon ne '*') {
$nex_mday = 1;
}
else {
$nex_mday = $cur_mday;
}
}
if ($mon eq '*') {
$nex_mon = $cur_mon;
$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);
}
# Find the next execution date
my $count = 0;
do {
my $next_time = timelocal(0, $nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year);
if ($next_time > $cur_time) {
return $next_time;
}
if ($min eq '*' && $hour eq '*' && $wday eq '*' && $mday eq '*' && $mon eq '*') {
($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year) = (localtime ($next_time + 60))[1, 2, 3, 4, 5];
}
elsif ($hour eq '*' && $wday eq '*' && $mday eq '*' && $mon eq '*') {
($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year) = (localtime ($next_time + 3600))[1, 2, 3, 4, 5];
}
elsif ($mday eq '*' && $mon eq '*') {
($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year) = (localtime ($next_time + 86400))[1, 2, 3, 4, 5];
}
elsif ($mon eq '*') {
$nex_mon = $nex_mon + 1;
if ($nex_mon > 11) {
$nex_mon = 0;
$nex_year++;
# Check if next hour is in cron
$nex_time_array[1]++;
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
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);
if ($nex_time == 0) {
#Update the month if overflow
$nex_time_array[2] = 1;
$nex_time_array[3]++;
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
if ($nex_time == 0) {
#Update the year if overflow
$cur_year++;
$nex_time_array[3] = 0;
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
}
}
else {
$nex_year++;
}
$count++;
} while ($count < 60);
}
#Check the hour
return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array);
#Update the hour if fails
my ($hour_down, undef) = cron_get_interval ($hour);
$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);
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);
if ($nex_time == 0) {
#Update the year if overflow
$nex_time_array[3] = 0;
$cur_year++;
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
}
}
#Check the day
return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array);
#Update the day if fails
my ($mday_down, undef) = cron_get_interval ($mday);
$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);
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;
$cur_year++;
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
}
#Check the month
return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array);
#Update the month if fails
my ($mon_down, undef) = cron_get_interval ($mon);
$nex_time_array[3] = ($mday_down eq '*') ? 0 : $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);
return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array);
}
$nex_time = cron_valid_date(@nex_time_array, $cur_year + 1);
# Something went wrong, default to 5 minutes
return $nex_time;
}
###############################################################################
@ -1430,8 +1472,11 @@ sub cron_next_execution_date {
sub cron_is_in_cron {
my ($elems_cron, $elems_curr_time) = @_;
my $elem_cron = shift(@$elems_cron);
my $elem_curr_time = shift (@$elems_curr_time);
my @deref_elems_cron = @$elems_cron;
my @deref_elems_curr_time = @$elems_curr_time;
my $elem_cron = shift(@deref_elems_cron);
my $elem_curr_time = shift (@deref_elems_curr_time);
#If there is no elements means that is in cron
return 1 unless (defined($elem_cron) || defined($elem_curr_time));
@ -1442,13 +1487,15 @@ sub cron_is_in_cron {
# Check if there is no a range
return 0 if (!defined($up) && ($down != $elem_curr_time));
# Check if there is on the range
if ($down < $up) {
return 0 if ($elem_curr_time < $down || $elem_curr_time > $up);
} else {
return 0 if ($elem_curr_time > $down || $elem_curr_time < $up);
if (defined($up)) {
if ($down < $up) {
return 0 if ($elem_curr_time < $down || $elem_curr_time > $up);
} else {
return 0 if ($elem_curr_time > $down || $elem_curr_time < $up);
}
}
}
return cron_is_in_cron($elems_cron, $elems_curr_time);
return cron_is_in_cron(\@deref_elems_cron, \@deref_elems_curr_time);
}
###############################################################################
# Returns the interval of a cron element. If there is not a range,
@ -1490,6 +1537,22 @@ sub cron_get_closest_in_range ($$) {
return $target;
}
###############################################################################
# Check if a date is valid to get timelocal
###############################################################################
sub cron_valid_date {
my ($min, $hour, $mday, $month, $year) = @_;
my $utime;
eval {
local $SIG{__DIE__} = sub {};
$utime = timelocal(0, $min, $hour, $mday, $month, $year);
};
if ($@) {
return 0;
}
return $utime;
}
###############################################################################
# Attempt to resolve the given hostname.
###############################################################################