combined all cronscripts into one master-cronfile (user only needs to add one file to the crontab);

This commit is contained in:
Michael Kaufmann (d00p) 2010-01-25 12:50:38 +00:00
parent d1d872942a
commit 9fdece761e
26 changed files with 187 additions and 291 deletions

View File

@ -123,8 +123,9 @@ if(!isset($settings['panel']['frontend'])
include_once ('./updates/froxlor/upgrade_syscp.inc.php');
}
if(!isset($settings['panel']['frontend'])
|| $settings['panel']['frontend'] == 'froxlor')
if(isset($settings['panel']['frontend'])
&& $settings['panel']['frontend'] == 'froxlor')
{
if($settings['panel']['version'] == '0.9-r1')
{

View File

@ -136,27 +136,6 @@ fwrite($debugHandler, 'Table definitions included' . "\n");
fwrite($debugHandler, 'Database Class has been loaded' . "\n");
$db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']);
// If one cronscript needs root, it should say $needrootdb = true before the include
if(isset($needrootdb)
&& $needrootdb === true)
{
$db_root = new db($sql_root[0]['host'], $sql_root[0]['user'], $sql_root[0]['password'], '');
if($db_root->link_id == 0)
{
/**
* Do not proceed further if no database connection could be established
*/
fclose($debugHandler);
unlink($lockfile);
die('root can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
}
unset($db_root->password);
fwrite($debugHandler, 'Database-rootconnection established' . "\n");
}
if($db->link_id == 0)
{
/**
@ -198,45 +177,6 @@ fwrite($debugHandler, 'Froxlor Version and Database Version are correct' . "\n")
$cronscriptDebug = ($settings['system']['debug_cron'] == '1') ? true : false;
$cronbasedir = makeCorrectDir($pathtophpfiles . '/scripts/');
$crondir = new DirectoryIterator($cronbasedir);
$cronfilename = basename($_SERVER['PHP_SELF'], '.php');
$cronscriptFullName = makeCorrectFile($cronbasedir . basename($_SERVER['PHP_SELF']));
$inc_crons = array();
foreach($crondir as $file)
{
if(!$file->isDot()
&& !$file->isDir()
&& preg_match("/^" . $cronfilename . "\.inc\.(.*)\.php$/D", $file->getFilename()))
{
if(fileowner($cronscriptFullName) == $file->getOwner()
&& filegroup($cronscriptFullName) == $file->getGroup()
&& $file->isReadable())
{
$inc_crons[] = $file->getPathname();
}
else
{
fwrite($debugHandler, 'WARNING! uid and/or gid of "' . $cronscriptFullName . '" and "' . $file->getPathname() . '" don\'t match! Execution aborted!' . "\n");
fclose($debugHandler);
die('WARNING! uid and/or gid of "' . $cronscriptFullName . '" and "' . $file->getPathname() . '" don\'t match! Execution aborted!');
}
}
}
if(isset($inc_crons[0]))
{
natsort($inc_crons);
foreach($inc_crons as $cfile)
{
fwrite($debugHandler, 'Including ...' . $cfile . "\n");
include_once ($cfile);
}
}
unset($file, $crondir, $cronname, $cronscriptFullName, $cronfilename, $cronbasedir);
fwrite($debugHandler, 'Functions have been included' . "\n");
/**
* Create a new idna converter
*/

View File

@ -0,0 +1,44 @@
<?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 includeCronjobs($path, $debugHandler)
{
$cronbasedir = makeCorrectDir($path);
$crondir = new DirectoryIterator($cronbasedir);
foreach($crondir as $file)
{
if($file->isDot()) continue;
if($file->isFile())
{
if(fileowner(__FILE__) == $file->getOwner()
&& filegroup(__FILE__) == $file->getGroup()
&& $file->isReadable())
{
fwrite($debugHandler, 'Including ...' . $file->getPathname() . "\n");
include_once($file->getPathname());
}
else
{
fwrite($debugHandler, 'WARNING! uid and/or gid of "' . __FILE__ . '" and "' . $file->getPathname() . '" don\'t match! Execution aborted!' . "\n");
fclose($debugHandler);
die('WARNING! uid and/or gid of "' . __FILE__ . '" and "' . $file->getPathname() . '" don\'t match! Execution aborted!');
}
}
}
}

View File

@ -0,0 +1,59 @@
<?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 openRootDB
*
* creates a mysql-connection as root-user
* and stores it in the global variable $db_root
*
* @param int debugHandler (file-object)
* @param int lockfile (file-object)
*
* @return null
*/
function openRootDB($debugHandler, $lockfile)
{
global $db_root;
// If one cronscript needs root, it should say $needrootdb = true before the include
if(isset($needrootdb)
&& $needrootdb === true)
{
$db_root = new db($sql_root[0]['host'], $sql_root[0]['user'], $sql_root[0]['password'], '');
if($db_root->link_id == 0)
{
/**
* Do not proceed further if no database connection could be established
*/
fclose($debugHandler);
unlink($lockfile);
die('root can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
}
unset($db_root->password);
fwrite($debugHandler, 'Database-rootconnection established' . "\n");
}
}
function closeRootDB()
{
global $db_root;
if(isset($db_root)) unset($db_root);
}

View File

@ -0,0 +1,68 @@
<?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 Cron
* @version $Id: $
*/
include_once(dirname(__FILE__) . '/../lib/cron_init.php');
/*
* include jobs that run always (5 minutes if cron is setup that way)
*/
includeCronjobs($pathtophpfiles . '/scripts/jobs/always/', $debugHandler);
/*
* include hourly jobs
*/
$today = time();
if(date('i', $today) == '00')
{
includeCronjobs($pathtophpfiles . '/scripts/jobs/hourly/', $debugHandler);
}
/*
* include daily jobs (once a day)
*/
$today = time();
if(date('Hi', $today) == '0000')
{
includeCronjobs($pathtophpfiles . '/scripts/jobs/daily/', $debugHandler);
}
/*
* include daily jobs (once a day)
*/
$today = time();
if(date('dHi', $today) == '010000')
{
includeCronjobs($pathtophpfiles . '/scripts/jobs/monthly/', $debugHandler);
}
fwrite($debugHandler, 'Cronfiles have been included' . "\n");
/*
* we have to check the system's last guid with every cron run
* in case the admin installed new software which added a new user
* so users in the database don't conflict with system users
*/
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Checking system\'s last guid');
checkLastGuid($settings['system']['lastguid']);
/*
* shutdown cron
*/
include_once($pathtophpfiles . '/lib/cron_shutdown.php');
?>

View File

@ -17,10 +17,9 @@
* @version $Id$
*/
$needrootdb = true;
require (dirname(__FILE__) . '/../lib/cron_init.php');
openRootDB($debugHandler, $lockfile);
$Aps = new ApsInstaller($settings, $db, $db_root);
$Aps->InstallHandler();
require (dirname(__FILE__) . '/../lib/cron_shutdown.php');
closeRootDB();
?>
?>

View File

@ -21,8 +21,6 @@
* @todo skip mail parsing after x bytes for large mails
*/
$needrootdb = false;
require (dirname(__FILE__) . '/../lib/cron_init.php');
$mail = new PHPMailer();
//dont do anything when module is disabled
@ -229,14 +227,4 @@ if($db->num_rows($result) > 0)
}
}
/**
* STARTING CRONSCRIPT FOOTER
*/
include ($pathtophpfiles . '/lib/cron_shutdown.php');
/**
* END CRONSCRIPT FOOTER
*/
?>

View File

@ -17,20 +17,7 @@
* @version $Id$
*/
/**
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
* When using this "header" you have to change $lockFilename for your needs.
* Don't forget to also copy the footer which closes database connections
* and the lockfile! (Note: This "header" also establishes a mysql-root-
* connection, if you don't need it, see for the header in cron_tasks.php)
*/
$needrootdb = true;
include (dirname(__FILE__) . '/../lib/cron_init.php');
/**
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
*/
openRootDB($debugHandler, $lockfile);
/**
* Check if table exists, otherwise create it
@ -69,14 +56,4 @@ while($cronFileIncludeRow = $db->fetch_array($cronFileIncludeResult))
}
}
/**
* STARTING CRONSCRIPT FOOTER
*/
include ($pathtophpfiles . '/lib/cron_shutdown.php');
/**
* END CRONSCRIPT FOOTER
*/
?>

View File

@ -17,19 +17,6 @@
* @version $Id$
*/
/**
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
* When using this "header" you have to change $lockFilename for your needs.
* Don't forget to also copy the footer which closes database connections
* and the lockfile!
*/
include (dirname(__FILE__) . '/../lib/cron_init.php');
/**
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
*/
/**
* LOOK INTO EVERY CUSTOMER DIR TO SEE IF THERE ARE ANY .HTACCESS FILE TO "TRANSLATE"
*/
@ -54,16 +41,6 @@ else
fwrite($debugHandler, ' cron_lighttp.htaccess: You don\'t use Lighttpd, you do not have to run this cronscript!' . "\n");
}
/**
* STARTING CRONSCRIPT FOOTER
*/
include ($pathtophpfiles . '/lib/cron_shutdown.php');
/**
* END CRONSCRIPT FOOTER
*/
/**
* FUNCTIONS
*/

View File

@ -17,19 +17,6 @@
* @version $Id$
*/
/**
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
* When using this "header" you have to change $lockFilename for your needs.
* Don't forget to also copy the footer which closes database connections
* and the lockfile!
*/
include (dirname(__FILE__) . '/../lib/cron_init.php');
/**
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
*/
/**
* LOOK INTO TASKS TABLE TO SEE IF THERE ARE ANY UNDONE JOBS
*/
@ -257,24 +244,6 @@ if($db->num_rows($result_tasks) != 0)
unset($where);
}
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP() WHERE `settinggroup` = \'system\' AND `varname` = \'last_tasks_run\' ');
/*
* we have to check the system's last guid with every cron run
* in case the admin installed new software which added a new user
* so users in the database don't conflict with system users
*/
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Checking system\'s last guid');
checkLastGuid($settings['system']['lastguid']);
/**
* STARTING CRONSCRIPT FOOTER
*/
include ($pathtophpfiles . '/lib/cron_shutdown.php');
/**
* END CRONSCRIPT FOOTER
*/
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP() WHERE `settinggroup` = \'system\' AND `varname` = \'last_tasks_run\' ');
?>

View File

@ -17,20 +17,7 @@
* @version $Id$
*/
/**
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
* When using this "header" you have to change $lockFilename for your needs.
* Don't forget to also copy the footer which closes database connections
* and the lockfile! (Note: This "header" also establishes a mysql-root-
* connection, if you don't need it, see for the header in cron_tasks.php)
*/
$needrootdb = true;
include (dirname(__FILE__) . '/../lib/cron_init.php');
/**
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
*/
openRootDB($debugHandler, $lockfile);
/**
* TRAFFIC AND DISKUSAGE MESSURE
@ -388,14 +375,6 @@ while($row = $db->fetch_array($result))
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP() WHERE `settinggroup` = \'system\' AND `varname` = \'last_traffic_run\' ');
/**
* STARTING CRONSCRIPT FOOTER
*/
include ($pathtophpfiles . '/lib/cron_shutdown.php');
/**
* END CRONSCRIPT FOOTER
*/
closeRootDB();
?>

View File

@ -17,21 +17,6 @@
* @version $Id$
*/
/**
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
* When using this "header" you have to change $lockFilename for your needs.
* Don't forget to also copy the footer which closes database connections
* and the lockfile! (Note: This "header" also establishes a mysql-root-
* connection, if you don't need it, see for the header in cron_tasks.php)
*/
$needrootdb = false;
include (dirname(__FILE__) . '/../lib/cron_init.php');
/**
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
*/
/**
* RESET USED TICKETS COUNTER
*/
@ -49,14 +34,4 @@ if($cycle == '0'
$db->query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `tickets_used` = '0'");
}
/**
* STARTING CRONSCRIPT FOOTER
*/
include ($pathtophpfiles . '/lib/cron_shutdown.php');
/**
* END CRONSCRIPT FOOTER
*/
?>

View File

@ -17,10 +17,7 @@
* @version $Id$
*/
$needrootdb = false;
require (dirname(__FILE__) . '/../lib/cron_init.php');
$Aps = new ApsUpdater($db);
$Aps->UpdateHandler();
require (dirname(__FILE__) . '/../lib/cron_shutdown.php');
?>
?>

View File

@ -17,21 +17,6 @@
* @version $Id$
*/
/**
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
* When using this "header" you have to change $lockFilename for your needs.
* Don't forget to also copy the footer which closes database connections
* and the lockfile! (Note: This "header" also establishes a mysql-root-
* connection, if you don't need it, see for the header in cron_tasks.php)
*/
$needrootdb = false;
include (dirname(__FILE__) . '/../lib/cron_init.php');
/**
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
*/
/**
* ARCHIVING CLOSED TICKETS
*/
@ -63,14 +48,4 @@ while($row_ticket = $db->fetch_array($result_tickets))
fwrite($debugHandler, 'Archived ' . $archiving_count . ' tickets' . "\n");
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP() WHERE `settinggroup` = \'system\' AND `varname` = \'last_archive_run\' ');
/**
* STARTING CRONSCRIPT FOOTER
*/
include ($pathtophpfiles . '/lib/cron_shutdown.php');
/**
* END CRONSCRIPT FOOTER
*/
?>

View File

@ -17,19 +17,6 @@
* @version $Id$
*/
/**
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
* When using this "header" you have to change $lockFilename for your needs.
* Don't forget to also copy the footer which closes database connections
* and the lockfile!
*/
include (dirname(__FILE__) . '/../lib/cron_init.php');
/**
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
*/
fwrite($debugHandler, 'Trafficreport run started...' . "\n");
$yesterday = time() - (60 * 60 * 24);
@ -229,14 +216,5 @@ if(date('d') == '01')
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP()
WHERE `settinggroup` = \'system\' AND `varname` = \'last_traffic_report_run\' ');
/**
* STARTING CRONSCRIPT FOOTER
*/
include ($pathtophpfiles . '/lib/cron_shutdown.php');
/**
* END CRONSCRIPT FOOTER
*/
?>

View File

@ -5,10 +5,4 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#
# Regular cron jobs for the froxlor package
#
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_tasks.php
0 0 * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_traffic.php
30 0 * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_ticketarchive.php
0 1 * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_used_tickets_reset.php
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_autoresponder.php
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_apsinstaller.php
*/30 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_apsupdater.php
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/froxlor_master_cronjob.php

View File

@ -5,10 +5,4 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#
# Regular cron jobs for the froxlor package
#
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_tasks.php
0 0 * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_traffic.php
30 0 * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_ticketarchive.php
0 1 * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_used_tickets_reset.php
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_autoresponder.php
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_apsinstaller.php
*/30 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_apsupdater.php
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/froxlor_master_cronjob.php

View File

@ -7,10 +7,4 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin
#
# Please check that all following paths are correct
#
*/5 * * * * root /usr/lib/php5/bin/php -q /var/www/froxlor/scripts/cron_tasks.php
0 0 * * * root /usr/lib/php5/bin/php -q /var/www/froxlor/scripts/cron_traffic.php
30 0 * * * root /usr/lib/php5/bin/php -q /var/www/froxlor/scripts/cron_ticketarchive.php
0 1 * * * root /usr/lib/php5/bin/php -q /var/www/froxlor/scripts/cron_used_tickets_reset.php
*/5 * * * * root /usr/lib/php5/bin/php -q /var/www/froxlor/scripts/cron_autoresponder.php
*/5 * * * * root /usr/lib/php5/bin/php -q /var/www/froxlor/scripts/cron_apsinstaller.php
*/30 * * * * root /usr/lib/php5/bin/php -q /var/www/froxlor/scripts/cron_apsupdater.php
*/5 * * * * root /usr/lib/php5/bin/php -q /var/www/froxlor/scripts/froxlor_master_cronjob.php

View File

@ -5,10 +5,4 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#
# Regular cron jobs for the froxlor package
#
*/5 * * * * root /usr/bin/php5 -q /srv/www/htdocs/froxlor/scripts/cron_tasks.php
0 0 * * * root /usr/bin/php5 -q /srv/www/htdocs/froxlor/scripts/cron_traffic.php
30 0 * * * root /usr/bin/php5 -q /srv/www/htdocs/froxlor/scripts/cron_ticketarchive.php
0 1 * * * root /usr/bin/php5 -q /var/www/htdocs/froxlor/scripts/cron_used_tickets_reset.php
*/5 * * * * root /usr/bin/php5 -q /var/www/htdocs/froxlor/scripts/cron_autoresponder.php
*/5 * * * * root /usr/bin/php5 -q /var/www/htdocs/froxlor/scripts/cron_apsinstaller.php
*/30 * * * * root /usr/bin/php5 -q /var/www/htdocs/froxlor/scripts/cron_apsupdater.php
*/5 * * * * root /usr/bin/php5 -q /srv/www/htdocs/froxlor/scripts/froxlor_master_cronjob.php

View File

@ -5,10 +5,4 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#
# Regular cron jobs for the froxlor package
#
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_tasks.php
0 0 * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_traffic.php
30 0 * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_ticketarchive.php
0 1 * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_used_tickets_reset.php
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_autoresponder.php
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_apsinstaller.php
*/30 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/cron_apsupdater.php
*/5 * * * * root /usr/bin/php5 -q /var/www/froxlor/scripts/froxlor_master_cronjob.php