2012-10-23 Ramon Novoa <rnovoa@artica.es>
* include/functions_cron.php: Added to repository. Cron related
functions.
* include/functions_html.php, pandoradb.sql,
pandoradb.postgreSQL.sql, pandoradb.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
godmode/agentes/module_manager_editor_common.php,
godmode/agentes/configurar_agente.php,
godmode/agentes/module_manager_editor.php: Added support for remote
cron modules.
* godmode/netflow/nf_item_list.php,
godmode/netflow/nf_report_item.php,
operation/netflow/nf_view.php,
include/functions_netflow.php: Added a description to report items.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7083 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-10-23 12:45:25 +02:00
|
|
|
<?php
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
// Pandora FMS- http://pandorafms.com
|
2012-10-23 Ramon Novoa <rnovoa@artica.es>
* include/functions_cron.php: Added to repository. Cron related
functions.
* include/functions_html.php, pandoradb.sql,
pandoradb.postgreSQL.sql, pandoradb.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
godmode/agentes/module_manager_editor_common.php,
godmode/agentes/configurar_agente.php,
godmode/agentes/module_manager_editor.php: Added support for remote
cron modules.
* godmode/netflow/nf_item_list.php,
godmode/netflow/nf_report_item.php,
operation/netflow/nf_view.php,
include/functions_netflow.php: Added a description to report items.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7083 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-10-23 12:45:25 +02:00
|
|
|
// ==================================================
|
|
|
|
// Copyright (c) 20012 Artica Soluciones Tecnologicas
|
|
|
|
// Please see http://pandorafms.org for full contribution list
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation; version 2
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
global $config;
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
require_once $config['homedir'].'/include/functions_db.php';
|
2012-10-23 Ramon Novoa <rnovoa@artica.es>
* include/functions_cron.php: Added to repository. Cron related
functions.
* include/functions_html.php, pandoradb.sql,
pandoradb.postgreSQL.sql, pandoradb.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
godmode/agentes/module_manager_editor_common.php,
godmode/agentes/configurar_agente.php,
godmode/agentes/module_manager_editor.php: Added support for remote
cron modules.
* godmode/netflow/nf_item_list.php,
godmode/netflow/nf_report_item.php,
operation/netflow/nf_view.php,
include/functions_netflow.php: Added a description to report items.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7083 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-10-23 12:45:25 +02:00
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the execution interval of the given module.
|
2019-01-30 16:18:44 +01:00
|
|
|
function cron_update_module_interval($module_id, $cron)
|
|
|
|
{
|
2019-02-22 12:53:35 +01:00
|
|
|
// Check for a valid cron.
|
2019-01-30 16:18:44 +01:00
|
|
|
if (!cron_check_syntax($cron)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cron == '* * * * *') {
|
2019-02-22 12:53:35 +01:00
|
|
|
$module_interval = db_get_value_filter(
|
|
|
|
'module_interval',
|
|
|
|
'tagente_modulo',
|
|
|
|
['id_agente_modulo' => $module_id]
|
|
|
|
);
|
|
|
|
return db_process_sql(
|
|
|
|
'UPDATE tagente_estado SET current_interval = '.$module_interval.' WHERE id_agente_modulo = '.(int) $module_id
|
|
|
|
);
|
2019-01-30 16:18:44 +01:00
|
|
|
} else {
|
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-10-23 Ramon Novoa <rnovoa@artica.es>
* include/functions_cron.php: Added to repository. Cron related
functions.
* include/functions_html.php, pandoradb.sql,
pandoradb.postgreSQL.sql, pandoradb.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
godmode/agentes/module_manager_editor_common.php,
godmode/agentes/configurar_agente.php,
godmode/agentes/module_manager_editor.php: Added support for remote
cron modules.
* godmode/netflow/nf_item_list.php,
godmode/netflow/nf_report_item.php,
operation/netflow/nf_view.php,
include/functions_netflow.php: Added a description to report items.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7083 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-10-23 12:45:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the number of seconds left to the next execution of the given cron entry.
|
2019-01-30 16:18:44 +01:00
|
|
|
function cron_next_execution($cron, $module_interval, $module_id)
|
|
|
|
{
|
2019-02-22 12:53:35 +01:00
|
|
|
// Get day of the week and month from cron config.
|
2019-01-30 16:18:44 +01:00
|
|
|
$cron_array = explode(' ', $cron);
|
|
|
|
$minute = $cron_array[0];
|
|
|
|
$hour = $cron_array[1];
|
|
|
|
$mday = $cron_array[2];
|
|
|
|
$month = $cron_array[3];
|
|
|
|
$wday = $cron_array[4];
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Get last execution time.
|
|
|
|
$last_execution = db_get_value(
|
|
|
|
'utimestamp',
|
|
|
|
'tagente_estado',
|
|
|
|
'id_agente_modulo',
|
|
|
|
$module_id
|
|
|
|
);
|
2019-01-30 16:18:44 +01:00
|
|
|
$cur_time = ($last_execution !== false) ? $last_execution : time();
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Any day of the way.
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($wday == '*') {
|
2019-02-22 12:53:35 +01:00
|
|
|
$nex_time = cron_next_execution_date(
|
|
|
|
$cron,
|
|
|
|
$cur_time,
|
|
|
|
$module_interval
|
|
|
|
);
|
2019-01-30 16:18:44 +01:00
|
|
|
return ($nex_time - $cur_time);
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// A specific day of the week.
|
2019-01-30 16:18:44 +01:00
|
|
|
$count = 0;
|
|
|
|
$nex_time = $cur_time;
|
|
|
|
do {
|
2019-02-22 12:53:35 +01:00
|
|
|
$nex_time = cron_next_execution_date(
|
|
|
|
$cron,
|
|
|
|
$nex_time,
|
|
|
|
$module_interval
|
|
|
|
);
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_wd = $nex_time;
|
|
|
|
|
|
|
|
$array_nex = explode(' ', date('m w', $nex_time_wd));
|
|
|
|
$nex_mon = $array_nex[0];
|
|
|
|
$nex_wday = $array_nex[1];
|
|
|
|
|
|
|
|
do {
|
2019-02-22 12:53:35 +01:00
|
|
|
// Check the day of the week.
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($nex_wday == $wday) {
|
|
|
|
return ($nex_time_wd - $cur_time);
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Move to the next day of the month.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_wd += SECONDS_1DAY;
|
|
|
|
|
|
|
|
$array_nex_w = explode(' ', date('m w', $nex_time_wd));
|
|
|
|
$nex_mon_wd = $array_nex_w[0];
|
|
|
|
$nex_wday = $array_nex_w[1];
|
|
|
|
} while ($mday == '*' && $nex_mon_wd == $nex_mon);
|
|
|
|
|
|
|
|
$count++;
|
|
|
|
} while ($count < SECONDS_1MINUTE);
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Something went wrong, default to 5 minutes.
|
2019-01-30 16:18:44 +01:00
|
|
|
return SECONDS_5MINUTES;
|
2012-10-23 Ramon Novoa <rnovoa@artica.es>
* include/functions_cron.php: Added to repository. Cron related
functions.
* include/functions_html.php, pandoradb.sql,
pandoradb.postgreSQL.sql, pandoradb.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
godmode/agentes/module_manager_editor_common.php,
godmode/agentes/configurar_agente.php,
godmode/agentes/module_manager_editor.php: Added support for remote
cron modules.
* godmode/netflow/nf_item_list.php,
godmode/netflow/nf_report_item.php,
operation/netflow/nf_view.php,
include/functions_netflow.php: Added a description to report items.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7083 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-10-23 12:45:25 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2012-10-23 Ramon Novoa <rnovoa@artica.es>
* include/functions_cron.php: Added to repository. Cron related
functions.
* include/functions_html.php, pandoradb.sql,
pandoradb.postgreSQL.sql, pandoradb.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
godmode/agentes/module_manager_editor_common.php,
godmode/agentes/configurar_agente.php,
godmode/agentes/module_manager_editor.php: Added support for remote
cron modules.
* godmode/netflow/nf_item_list.php,
godmode/netflow/nf_report_item.php,
operation/netflow/nf_view.php,
include/functions_netflow.php: Added a description to report items.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7083 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-10-23 12:45:25 +02:00
|
|
|
// Get the next execution date for the given cron entry in seconds since epoch.
|
2019-01-30 16:18:44 +01:00
|
|
|
function cron_next_execution_date($cron, $cur_time=false, $module_interval=300)
|
|
|
|
{
|
2019-02-22 12:53:35 +01:00
|
|
|
// Get cron configuration.
|
2019-01-30 16:18:44 +01:00
|
|
|
$cron_array = explode(' ', $cron);
|
|
|
|
|
|
|
|
// REMARKS: Months start from 1 in php (different to server)
|
2019-02-22 12:53:35 +01:00
|
|
|
// Get current time.
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($cur_time === false) {
|
|
|
|
$cur_time = time();
|
|
|
|
}
|
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update minutes.
|
2019-01-30 16:18:44 +01:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Check if next hour is in cron.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_array[1]++;
|
|
|
|
$nex_time = cron_valid_date($nex_time_array);
|
|
|
|
|
|
|
|
if ($nex_time === false) {
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the month day if overflow.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_array[1] = 0;
|
|
|
|
$nex_time_array[2]++;
|
|
|
|
$nex_time = cron_valid_date($nex_time_array);
|
|
|
|
if ($nex_time === false) {
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the month if overflow.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_array[2] = 1;
|
|
|
|
$nex_time_array[3]++;
|
|
|
|
$nex_time = cron_valid_date($nex_time_array);
|
|
|
|
if ($nex_time === false) {
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the year if overflow.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_array[3] = 1;
|
|
|
|
$nex_time_array[4]++;
|
|
|
|
$nex_time = cron_valid_date($nex_time_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Check the hour.
|
2019-01-30 16:18:44 +01:00
|
|
|
if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) {
|
|
|
|
return $nex_time;
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the hour if fails.
|
2019-01-30 16:18:44 +01:00
|
|
|
$hour_s = cron_get_interval($cron_array[1]);
|
|
|
|
$nex_time_array[1] = ($hour_s['down'] == '*') ? 0 : $hour_s['down'];
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// When an overflow is passed check the hour update again.
|
2019-01-30 16:18:44 +01:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Check if next day is in cron.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_array[2]++;
|
|
|
|
$nex_time = cron_valid_date($nex_time_array);
|
|
|
|
if ($nex_time === false) {
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the month if overflow.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_array[2] = 1;
|
|
|
|
$nex_time_array[3]++;
|
|
|
|
$nex_time = cron_valid_date($nex_time_array);
|
|
|
|
if ($nex_time === false) {
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the year if overflow.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_array[3] = 1;
|
|
|
|
$nex_time_array[4]++;
|
|
|
|
$nex_time = cron_valid_date($nex_time_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Check the day.
|
2019-01-30 16:18:44 +01:00
|
|
|
if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) {
|
|
|
|
return $nex_time;
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the day if fails.
|
2019-01-30 16:18:44 +01:00
|
|
|
$mday_s = cron_get_interval($cron_array[2]);
|
|
|
|
$nex_time_array[2] = ($mday_s['down'] == '*') ? 1 : $mday_s['down'];
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// When an overflow is passed check the hour update in the next execution.
|
2019-01-30 16:18:44 +01:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Check if next month is in cron.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_array[3]++;
|
|
|
|
$nex_time = cron_valid_date($nex_time_array);
|
|
|
|
if ($nex_time === false) {
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the year if overflow.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_array[3] = 1;
|
|
|
|
$nex_time_array[4]++;
|
|
|
|
$nex_time = cron_valid_date($nex_time_array);
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Check the month.
|
2019-01-30 16:18:44 +01:00
|
|
|
if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) {
|
|
|
|
return $nex_time;
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the month if fails.
|
2019-01-30 16:18:44 +01:00
|
|
|
$mon_s = cron_get_interval($cron_array[3]);
|
|
|
|
$nex_time_array[3] = ($mon_s['down'] == '*') ? 1 : $mon_s['down'];
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// When an overflow is passed check the hour update in the next execution.
|
2019-01-30 16:18:44 +01:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Update the year.
|
2019-01-30 16:18:44 +01:00
|
|
|
$nex_time_array[4]++;
|
|
|
|
$nex_time = cron_valid_date($nex_time_array);
|
|
|
|
|
|
|
|
return ($nex_time !== false) ? $nex_time : $module_interval;
|
2017-11-23 12:30:04 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Get an array with the cron interval.
|
2019-01-30 16:18:44 +01:00
|
|
|
function cron_get_interval($element)
|
|
|
|
{
|
2019-02-22 12:53:35 +01:00
|
|
|
// Not a range.
|
2019-01-30 16:18:44 +01:00
|
|
|
if (!preg_match('/(\d+)\-(\d+)/', $element, $capture)) {
|
|
|
|
return [
|
|
|
|
'down' => $element,
|
|
|
|
'up' => false,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'down' => $capture[1],
|
|
|
|
'up' => $capture[2],
|
|
|
|
];
|
2017-11-23 12:30:04 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2017-11-23 12:30:04 +01:00
|
|
|
// Returns if a date is in a cron. Recursive.
|
2019-01-30 16:18:44 +01:00
|
|
|
function cron_is_in_cron($elems_cron, $elems_curr_time)
|
|
|
|
{
|
|
|
|
$elem_cron = array_shift($elems_cron);
|
|
|
|
$elem_curr_time = array_shift($elems_curr_time);
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// If there is no elements means that is in cron.
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($elem_cron === null || $elem_curr_time === null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Go to last element if current is a wild card.
|
2019-01-30 16:18:44 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Check if there is on the range.
|
2019-01-30 16:18:44 +01:00
|
|
|
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);
|
2017-11-23 12:30:04 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
function cron_valid_date($da)
|
|
|
|
{
|
2019-02-22 12:53:35 +01:00
|
|
|
$st = sprintf(
|
|
|
|
'%04d:%02d:%02d %02d:%02d:00',
|
|
|
|
$da[4],
|
|
|
|
$da[3],
|
|
|
|
$da[2],
|
|
|
|
$da[1],
|
|
|
|
$da[0]
|
|
|
|
);
|
2019-01-30 16:18:44 +01:00
|
|
|
$time = strtotime($st);
|
|
|
|
return $time;
|
2012-10-23 Ramon Novoa <rnovoa@artica.es>
* include/functions_cron.php: Added to repository. Cron related
functions.
* include/functions_html.php, pandoradb.sql,
pandoradb.postgreSQL.sql, pandoradb.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
godmode/agentes/module_manager_editor_common.php,
godmode/agentes/configurar_agente.php,
godmode/agentes/module_manager_editor.php: Added support for remote
cron modules.
* godmode/netflow/nf_item_list.php,
godmode/netflow/nf_report_item.php,
operation/netflow/nf_view.php,
include/functions_netflow.php: Added a description to report items.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7083 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-10-23 12:45:25 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
// Check if cron is properly constructed.
|
2019-01-30 16:18:44 +01:00
|
|
|
function cron_check_syntax($cron)
|
|
|
|
{
|
2019-02-22 12:53:35 +01:00
|
|
|
return preg_match(
|
|
|
|
'/^[\d|\*].* .*[\d|\*].* .*[\d|\*].* .*[\d|\*].* .*[\d|\*]$/',
|
|
|
|
$cron
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cron_list_table()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$read_perms = check_acl($config['id_user'], 0, 'RR');
|
|
|
|
$write_perms = check_acl($config['id_user'], 0, 'RW');
|
|
|
|
$manage_perms = check_acl($config['id_user'], 0, 'RM');
|
|
|
|
$manage_pandora = check_acl($config['id_user'], 0, 'PM');
|
|
|
|
|
|
|
|
$url = 'index.php?extension_in_menu=gservers&sec=extensions&sec2=enterprise/extensions/cron&';
|
|
|
|
|
|
|
|
$user_groups = implode(
|
|
|
|
',',
|
|
|
|
array_keys(users_get_groups())
|
|
|
|
);
|
|
|
|
|
|
|
|
$defined_tasks = db_get_all_rows_filter(
|
|
|
|
'tuser_task_scheduled',
|
|
|
|
'id_grupo IN ('.$user_groups.')'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!check_acl($config['id_user'], 0, 'PM')) {
|
|
|
|
$read_tasks = [];
|
|
|
|
foreach ($defined_tasks as $task) {
|
|
|
|
$function_name = db_get_value(
|
|
|
|
'function_name',
|
|
|
|
'tuser_task',
|
|
|
|
'id',
|
|
|
|
$task['id_user_task']
|
|
|
|
);
|
|
|
|
|
|
|
|
if (($function_name != 'cron_task_execute_custom_script')
|
|
|
|
&& ($function_name != 'cron_task_do_backup')
|
|
|
|
) {
|
|
|
|
$read_tasks[] = $task;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$defined_tasks = $read_tasks;
|
|
|
|
|
|
|
|
if (empty($defined_tasks)) {
|
|
|
|
$defined_tasks = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($defined_tasks !== false) {
|
|
|
|
echo '<h2>'.__('Scheduled jobs').'</h2>';
|
|
|
|
|
|
|
|
$table = new stdClass();
|
|
|
|
$table->class = 'databox data';
|
|
|
|
$table->width = '100%';
|
|
|
|
$table->data = [];
|
|
|
|
$table->head = [];
|
|
|
|
$table->head[0] = '';
|
|
|
|
$table->head[1] = __('User');
|
|
|
|
$table->head[2] = __('Task');
|
|
|
|
$table->head[3] = __('Scheduled');
|
|
|
|
$table->head[4] = __('Next execution');
|
|
|
|
$table->head[5] = __('Last run');
|
|
|
|
$table->head[6] = __('Group');
|
|
|
|
$table->head[7] = __('Actions');
|
|
|
|
$table->align[7] = 'left';
|
|
|
|
|
|
|
|
foreach ($defined_tasks as $task) {
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$function_name = db_get_value(
|
|
|
|
'function_name',
|
|
|
|
'tuser_task',
|
|
|
|
'id',
|
|
|
|
$task['id_user_task']
|
|
|
|
);
|
|
|
|
|
|
|
|
switch ($function_name) {
|
|
|
|
case 'cron_task_generate_report':
|
|
|
|
if ($write_perms || $manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} else {
|
|
|
|
$data[0] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[1] = $task['id_usuario'];
|
|
|
|
$data[2] = db_get_value(
|
|
|
|
'name',
|
|
|
|
'tuser_task',
|
|
|
|
'id',
|
|
|
|
$task['id_user_task']
|
|
|
|
);
|
|
|
|
$args = unserialize($task['args']);
|
|
|
|
$report = reports_get_report($args[0]);
|
|
|
|
|
|
|
|
// Check ACL in reports_get_report return false.
|
|
|
|
if ($report === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$email = $args[1];
|
|
|
|
$data[2] .= '<br>- '.__('Report').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer&id=".$args[0]."'>";
|
|
|
|
$data[2] .= $report['name'].'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Email').": <a href='mailto:".$email."'>";
|
|
|
|
$data[2] .= ui_print_truncate_text($email, 60, false).'</a>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cron_task_generate_report_by_template':
|
|
|
|
if ($write_perms || $manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} else {
|
|
|
|
$data[0] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[1] = $task['id_usuario'];
|
|
|
|
$data[2] = db_get_value(
|
|
|
|
'name',
|
|
|
|
'tuser_task',
|
|
|
|
'id',
|
|
|
|
$task['id_user_task']
|
|
|
|
);
|
|
|
|
|
|
|
|
$args = unserialize($task['args']);
|
|
|
|
|
|
|
|
$filter = [];
|
|
|
|
$filter['id_report'] = $args[0];
|
|
|
|
$template = db_get_row_filter(
|
|
|
|
'treport_template',
|
|
|
|
$filter,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
// Check ACL in reports_get_report return false.
|
|
|
|
if ($template === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$agents_id = $args[1];
|
|
|
|
$id_group = $args[2];
|
|
|
|
$report_per_agent = $args[0];
|
|
|
|
$report_name = $args[3];
|
|
|
|
$email = $args[4];
|
|
|
|
$data[2] .= '<br>- '.__('Template').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer";
|
|
|
|
$data[2] .= '&id='.$args[0]."'>".$template['name'].'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Agents').': '.$agents_id.'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Report per agent').': '.$report_per_agent.'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Report name').': '.$report_name.'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Email').": <a href='mailto:".$email."'>".$email.'</a>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cron_task_execute_custom_script':
|
|
|
|
if ($manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} else {
|
|
|
|
$data[0] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[1] = $task['id_usuario'];
|
|
|
|
$data[2] = db_get_value(
|
|
|
|
'name',
|
|
|
|
'tuser_task',
|
|
|
|
'id',
|
|
|
|
$task['id_user_task']
|
|
|
|
);
|
|
|
|
|
|
|
|
$args = unserialize($task['args']);
|
|
|
|
$data[2] .= '<br>- '.__('Custom script').': '.$args[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cron_task_save_report_to_disk':
|
|
|
|
if ($write_perms || $manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} else {
|
|
|
|
$data[0] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[1] = $task['id_usuario'];
|
|
|
|
$data[2] = db_get_value(
|
|
|
|
'name',
|
|
|
|
'tuser_task',
|
|
|
|
'id',
|
|
|
|
$task['id_user_task']
|
|
|
|
);
|
|
|
|
|
|
|
|
$args = unserialize($task['args']);
|
|
|
|
$report = reports_get_report($args[0]);
|
|
|
|
|
|
|
|
// Check ACL in reports_get_report return false.
|
|
|
|
if ($report === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = $args[1];
|
|
|
|
$data[2] .= '<br>- '.__('Report').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer";
|
|
|
|
$data[2] .= '&id='.$args[0]."'>".$report['name'].'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Path').': '.$path.'</a>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cron_task_save_xml_report_to_disk':
|
|
|
|
if ($write_perms || $manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} else {
|
|
|
|
$data[0] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[1] = $task['id_usuario'];
|
|
|
|
$data[2] = db_get_value('name', 'tuser_task', 'id', $task['id_user_task']);
|
|
|
|
$args = unserialize($task['args']);
|
|
|
|
$report = reports_get_report($args[0]);
|
|
|
|
|
|
|
|
// Check ACL in reports_get_report return false.
|
|
|
|
if ($report === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = $args[1];
|
|
|
|
$data[2] .= '<br>- '.__('Report').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer";
|
|
|
|
$data[2] .= '&id='.$args[0]."'>".$report['name'].'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Path').': '.$path.'</a>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cron_task_do_backup':
|
|
|
|
if ($manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} else {
|
|
|
|
$data[0] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[1] = $task['id_usuario'];
|
|
|
|
$data[2] = db_get_value(
|
|
|
|
'name',
|
|
|
|
'tuser_task',
|
|
|
|
'id',
|
|
|
|
$task['id_user_task']
|
|
|
|
);
|
|
|
|
$args = unserialize($task['args']);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Ignore.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[3] = cron_get_scheduled_string($task['scheduled']);
|
|
|
|
$data[4] = date('Y/m/d H:i:s', $args['first_execution']);
|
|
|
|
$data[5] = empty($task['last_run']) ? __('Never') : date('Y/m/d H:i:s', $task['last_run']);
|
|
|
|
|
|
|
|
$data[6] = ui_print_group_icon($task['id_grupo'], true);
|
|
|
|
|
|
|
|
if ($function_name == 'cron_task_do_backup' || $function_name == 'cron_task_execute_custom_script') {
|
|
|
|
if ($manage_pandora) {
|
|
|
|
$data[7] = '<a href="'.$url;
|
|
|
|
$data[7] .= 'edit_task=1&id='.$task['id'].'">';
|
|
|
|
$data[7] .= html_print_image(
|
|
|
|
'images/config.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Edit')]
|
|
|
|
);
|
|
|
|
$data[7] .= '</a>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($manage_pandora) {
|
|
|
|
$data[7] .= '<a href="'.$url;
|
|
|
|
$data[7] .= 'delete_task=1&id_user_task='.$task['id'].'">';
|
|
|
|
$data[7] .= html_print_image(
|
|
|
|
'images/cross.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Delete')]
|
|
|
|
);
|
|
|
|
$data[7] .= '</a>';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($write_perms || $manage_pandora) {
|
|
|
|
$data[7] = '<a href="'.$url;
|
|
|
|
$data[7] .= 'edit_task=1&id='.$task['id'].'">';
|
|
|
|
$data[7] .= html_print_image(
|
|
|
|
'images/config.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Edit')]
|
|
|
|
);
|
|
|
|
$data[7] .= '</a>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($manage_perms || $manage_pandora) {
|
|
|
|
$data[7] .= '<a href="'.$url;
|
|
|
|
$data[7] .= 'delete_task=1&id_user_task='.$task['id'].'">';
|
|
|
|
$data[7] .= html_print_image(
|
|
|
|
'images/cross.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Delete')]
|
|
|
|
);
|
|
|
|
$data[7] .= '</a>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push($table->data, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
html_print_table($table);
|
|
|
|
}
|
2016-02-05 09:53:45 +01:00
|
|
|
}
|