more fixing on the cronjob part

This commit is contained in:
Michael Kaufmann (d00p)
2010-01-25 16:21:10 +00:00
parent 44716ff439
commit 1647d6ecfb
4 changed files with 71 additions and 9 deletions

View File

@@ -930,7 +930,7 @@ CREATE TABLE IF NOT EXISTS `cronjobs_run` (
`id` bigint(20) NOT NULL auto_increment,
`cronfile` varchar(250) NOT NULL,
`lastrun` int(15) NOT NULL DEFAULT '0',
`interval` varchar(100) DEFAULT '5 MINUTES',
`interval` varchar(100) DEFAULT '5 MINUTE',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
@@ -938,10 +938,10 @@ CREATE TABLE IF NOT EXISTS `cronjobs_run` (
# Dumping data for table `panel_phpconfigs`
#
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (1, 'cron_tasks.php', '5 MINUTES');
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (2, 'cron_legacy.php', '5 MINUTES');
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (3, 'cron_apsinstaller.php', '5 MINUTES');
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (4, 'cron_autoresponder.php', '5 MINUTES');
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (1, 'cron_tasks.php', '5 MINUTE');
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (2, 'cron_legacy.php', '5 MINUTE');
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (3, 'cron_apsinstaller.php', '5 MINUTE');
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (4, 'cron_autoresponder.php', '5 MINUTE');
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (5, 'cron_apsupdater.php', '1 HOUR');
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (6, 'cron_traffic.php', '1 DAY');
INSERT INTO `cronjobs_run` (`id`, `cronfile`, `interval`) VALUES (7, 'cron_used_tickets_reset.php', '1 MONTH');

View File

@@ -11,7 +11,7 @@
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Settings
* @package Functions
* @version $Id: $
*/
@@ -27,7 +27,14 @@ function getIntervalOptions()
while($row = $db->fetch_array($result))
{
$cron_intervals[$row['interval']] = $row['interval'];
if(validateSqlInterval($row['interval']))
{
$cron_intervals[$row['interval']] = $row['interval'];
}
else
{
$log->logAction(ADM_ACTION, LOG_ERROR, "Invalid SQL-Interval ".$row['interval']." detected. Please fix this in the database.");
}
}
return $cron_intervals;

View File

@@ -36,9 +36,9 @@ function getNextCronjobs()
if($name == '0') continue;
if($x == 0) {
$sql.= 'DATE_ADD(FROM_UNIXTIME(`lastrun`), INTERVAL '.$ival.') <= CURDATE()';
$sql.= 'DATE_ADD(FROM_UNIXTIME(`lastrun`), INTERVAL '.$ival.') <= UTC_TIMESTAMP()';
} else {
$sql.= ' OR DATE_ADD(UNIX_TIMESTAMP(`lastrun`), INTERVAL '.$ival.') <= CURDATE()';
$sql.= ' OR DATE_ADD(UNIX_TIMESTAMP(`lastrun`), INTERVAL '.$ival.') <= UTC_TIMESTAMP()';
}
$x++;
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
* @version $Id: $
*/
function validateSqlInterval($interval = null)
{
if(!$interval === null || $interval != '')
{
if(strstr($interval, ' ') !== false)
{
/*
* [0] = ([0-9]+)
* [1] = valid SQL-Interval expression
*/
$valid_expr = array(
'SECOND',
'MINUTE',
'HOUR',
'DAY',
'WEEK',
'MONTH',
'YEAR'
);
$interval_parts = explode(' ', $interval);
if(is_array($interval_parts)
&& isset($interval_parts[0])
&& isset($interval_parts[1]))
{
if(preg_match('/([0-9]+)/i', $interval_parts[0]))
{
if(in_array(strtoupper($interval_parts[1]), $valid_expr))
{
return true;
}
}
}
}
}
return false;
}