2013-11-04 08:03:29 +00:00
< ? php if ( ! defined ( 'MASTER_CRONJOB' )) die ( 'You cannot access this file directly!' );
2010-01-27 08:54:31 +00:00
/**
* This file is part of the Froxlor project .
* Copyright ( c ) 2003 - 2009 the SysCP Team ( see authors ) .
* 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 Florian Lippert < flo @ syscp . org > ( 2003 - 2009 )
* @ author Froxlor team < team @ froxlor . org > ( 2010 - )
* @ license GPLv2 http :// files . froxlor . org / misc / COPYING . txt
* @ package Cron
2011-05-04 09:59:20 +00:00
*
2010-01-27 08:54:31 +00:00
*/
2013-11-28 11:35:20 +00:00
if ( @ php_sapi_name () != 'cli'
&& @ php_sapi_name () != 'cgi'
&& @ php_sapi_name () != 'cgi-fcgi'
) {
2010-01-27 08:54:31 +00:00
die ( 'This script will only work in the shell.' );
}
2010-03-30 09:18:22 +00:00
// ensure that default timezone is set
2013-11-04 08:03:29 +00:00
if ( function_exists ( " date_default_timezone_set " )
&& function_exists ( " date_default_timezone_get " )
) {
2010-03-30 09:18:22 +00:00
@ date_default_timezone_set ( @ date_default_timezone_get ());
}
2010-01-27 08:54:31 +00:00
$lockdir = '/var/run/' ;
$lockFilename = 'froxlor_' . basename ( $_SERVER [ 'PHP_SELF' ], '.php' ) . '.lock-' ;
$lockfName = $lockFilename . getmypid ();
$lockfile = $lockdir . $lockfName ;
// guess the froxlor installation path
// normally you should not need to modify this script anymore, if your
// froxlor installation isn't in /var/www/froxlor
2013-11-04 08:03:29 +00:00
define ( 'FROXLOR_INSTALL_DIR' , dirname ( dirname ( __FILE__ )));
2010-01-27 08:54:31 +00:00
// create and open the lockfile!
$keepLockFile = false ;
$debugHandler = fopen ( $lockfile , 'w' );
fwrite ( $debugHandler , 'Setting Lockfile to ' . $lockfile . " \n " );
2013-11-28 11:35:20 +00:00
fwrite ( $debugHandler , 'Setting Froxlor installation path to ' . FROXLOR_INSTALL_DIR . " \n " );
2010-01-27 08:54:31 +00:00
// open the lockfile directory and scan for existing lockfiles
$lockDirHandle = opendir ( $lockdir );
2013-11-04 08:03:29 +00:00
while ( $fName = readdir ( $lockDirHandle )) {
2010-01-27 08:54:31 +00:00
2013-11-04 08:03:29 +00:00
if ( $lockFilename == substr ( $fName , 0 , strlen ( $lockFilename ))
&& $lockfName != $fName
) {
// Check if last run jailed out with an exception
2010-01-27 08:54:31 +00:00
$croncontent = file ( $lockdir . $fName );
$lastline = $croncontent [( count ( $croncontent ) - 1 )];
2013-11-04 08:03:29 +00:00
if ( $lastline == '=== Keep lockfile because of exception ===' ) {
2010-01-27 08:54:31 +00:00
fclose ( $debugHandler );
unlink ( $lockfile );
die ( 'Last cron jailed out with an exception. Exiting...' . " \n " . 'Take a look into the contents of ' . $lockdir . $fName . '* for more information!' . " \n " );
}
// Check if cron is running or has died.
$check_pid = substr ( strstr ( $fName , " - " ), 1 );
2010-04-12 05:49:16 +00:00
system ( " kill -CHLD " . ( int ) $check_pid . " 1> /dev/null 2> /dev/null " , $check_pid_return );
2010-01-27 08:54:31 +00:00
2013-11-04 08:03:29 +00:00
if ( $check_pid_return == 1 ) {
2010-01-27 08:54:31 +00:00
// Result: Existing lockfile/pid isnt running
// Most likely it has died
//
// Action: Remove it and continue
//
fwrite ( $debugHandler , 'Previous cronjob didn\'t exit clean. PID: ' . $check_pid . " \n " );
fwrite ( $debugHandler , 'Removing lockfile: ' . $lockdir . $fName . " \n " );
unlink ( $lockdir . $fName );
2013-11-04 08:03:29 +00:00
} else {
2010-01-27 08:54:31 +00:00
// Result: A Cronscript with this pid
// is still running
// Action: remove my own Lock and die
//
// close the current lockfile
fclose ( $debugHandler );
// ... and delete it
unlink ( $lockfile );
die ( 'There is already a Cronjob in progress. Exiting...' . " \n " . 'Take a look into the contents of ' . $lockdir . $lockFilename . '* for more information!' . " \n " );
}
}
}
2013-11-04 08:03:29 +00:00
// Includes the Usersettings eg. MySQL-Username/Passwort etc.
require FROXLOR_INSTALL_DIR . '/lib/userdata.inc.php' ;
2010-01-27 08:54:31 +00:00
fwrite ( $debugHandler , 'Userdatas included' . " \n " );
// Legacy sql-root-information
2013-11-04 08:03:29 +00:00
if ( isset ( $sql [ 'root_user' ])
&& isset ( $sql [ 'root_password' ])
&& ( ! isset ( $sql_root ) || ! is_array ( $sql_root ))
) {
2010-01-27 08:54:31 +00:00
$sql_root = array ( 0 => array ( 'caption' => 'Default' , 'host' => $sql [ 'host' ], 'user' => $sql [ 'root_user' ], 'password' => $sql [ 'root_password' ]));
unset ( $sql [ 'root_user' ]);
unset ( $sql [ 'root_password' ]);
}
2013-11-04 08:03:29 +00:00
// Includes the Functions
require FROXLOR_INSTALL_DIR . '/lib/functions.php' ;
2010-01-27 08:54:31 +00:00
2013-11-04 08:03:29 +00:00
//Includes the MySQL-Tabledefinitions etc.
require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php' ;
2010-01-27 08:54:31 +00:00
fwrite ( $debugHandler , 'Table definitions included' . " \n " );
2013-11-28 11:35:20 +00:00
// try database connection, it will throw
// and exception itself if failed
try {
Database :: query ( " SELECT 1 " );
} catch ( Exception $e ) {
2013-11-04 08:03:29 +00:00
// Do not proceed further if no database connection could be established
2010-01-27 08:54:31 +00:00
fclose ( $debugHandler );
unlink ( $lockfile );
2013-11-28 11:35:20 +00:00
die ( $e -> getMessage ());
2010-01-27 08:54:31 +00:00
}
fwrite ( $debugHandler , 'Database-connection established' . " \n " );
2013-11-28 11:35:20 +00:00
$result_stmt = Database :: query ( "
SELECT `settingid` , `settinggroup` , `varname` , `value`
FROM `" . TABLE_PANEL_SETTINGS . "`
" );
2010-01-27 08:54:31 +00:00
2013-11-28 11:35:20 +00:00
while ( $row = $result_stmt -> fetch ( PDO :: FETCH_ASSOC )) {
2010-01-27 08:54:31 +00:00
$settings [ $row [ 'settinggroup' ]][ $row [ 'varname' ]] = $row [ 'value' ];
}
unset ( $row );
2010-01-29 19:20:29 +00:00
fwrite ( $debugHandler , 'Froxlor settings have been loaded from the database' . " \n " );
2010-01-27 08:54:31 +00:00
2010-08-27 05:53:25 +00:00
/**
* if settings [ 'system' ][ 'mod_fcgid_ownvhost' ] is set , we have to check
* whether the permission of the files are still correct
*/
2013-11-04 08:03:29 +00:00
if (( int ) $settings [ 'system' ][ 'mod_fcgid' ] == 1
&& ( int ) $settings [ 'system' ][ 'mod_fcgid_ownvhost' ] == 1
) {
2010-08-27 05:53:25 +00:00
fwrite ( $debugHandler , 'Checking froxlor file permissions' );
2013-11-28 11:35:20 +00:00
$mypath = makeCorrectDir ( FROXLOR_INSTALL_DIR );
2010-08-27 05:53:25 +00:00
$user = $settings [ 'system' ][ 'mod_fcgid_httpuser' ];
$group = $settings [ 'system' ][ 'mod_fcgid_httpgroup' ];
// all the files and folders have to belong to the local user
// now because we also use fcgid for our own vhost
safe_exec ( 'chown -R ' . $user . ':' . $group . ' ' . escapeshellarg ( $mypath ));
}
2013-11-04 08:03:29 +00:00
// be sure HTMLPurifier's cache folder is writable
2010-10-05 20:24:08 +00:00
safe_exec ( 'chmod -R 0755 ' . escapeshellarg ( dirname ( __FILE__ ) . '/classes/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer' ));
2013-11-04 08:03:29 +00:00
if ( ! isset ( $settings [ 'panel' ][ 'version' ])
|| $settings [ 'panel' ][ 'version' ] != $version
) {
2010-01-27 08:54:31 +00:00
/**
* Do not proceed further if the Database version is not the same as the script version
*/
fclose ( $debugHandler );
unlink ( $lockfile );
2013-09-23 10:27:11 +00:00
$errormessage = " Version of file doesnt match version of database. Exiting... \n \n " ;
$errormessage .= " Possible reason: Froxlor update \n " ;
$errormessage .= " Information: Current version in database: " . $settings [ 'panel' ][ 'version' ] . " - version of Froxlor files: " . $version . " \n " ;
$errormessage .= " Solution: Please visit your Foxlor admin interface for further information. \n " ;
die ( $errormessage );
2010-01-27 08:54:31 +00:00
}
2010-01-29 19:20:29 +00:00
fwrite ( $debugHandler , 'Froxlor version and database version are correct' . " \n " );
2010-01-27 08:54:31 +00:00
$cronscriptDebug = ( $settings [ 'system' ][ 'debug_cron' ] == '1' ) ? true : false ;
2013-11-04 08:03:29 +00:00
// Create a new idna converter
2010-01-27 08:54:31 +00:00
$idna_convert = new idna_convert_wrapper ();
2013-11-04 08:03:29 +00:00
// Initialize logging
2013-11-04 12:28:23 +00:00
$cronlog = FroxlorLogger :: getInstanceOf ( array ( 'loginname' => 'cronjob' ), $settings );
2010-01-27 08:54:31 +00:00
fwrite ( $debugHandler , 'Logger has been included' . " \n " );