remove unused upgrade procedures, migrated a few minor functions and files to PDO database, fixed FROXLOR_INSTALL_DIR define for master-cronjob, fixes #1294
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php if (!defined('MASTER_CRONJOB')) die('You cannot access this file directly!');
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -16,7 +16,6 @@
|
||||
* @package Cron
|
||||
*
|
||||
*/
|
||||
|
||||
if(@php_sapi_name() != 'cli'
|
||||
&& @php_sapi_name() != 'cgi'
|
||||
&& @php_sapi_name() != 'cgi-fcgi')
|
||||
@@ -25,8 +24,9 @@ if(@php_sapi_name() != 'cli'
|
||||
}
|
||||
|
||||
// ensure that default timezone is set
|
||||
if(function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get"))
|
||||
{
|
||||
if (function_exists("date_default_timezone_set")
|
||||
&& function_exists("date_default_timezone_get")
|
||||
) {
|
||||
@date_default_timezone_set(@date_default_timezone_get());
|
||||
}
|
||||
|
||||
@@ -38,116 +38,93 @@ $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
|
||||
|
||||
define('FROXLOR_INSTALL_DIR', dirname(dirname(__FILE__)));
|
||||
// TODO remove when not needed anymore
|
||||
$pathtophpfiles = dirname(dirname(__FILE__));
|
||||
|
||||
// should the froxlor installation guessing not work correctly,
|
||||
// uncomment the following line, and put your path in there!
|
||||
//$pathtophpfiles = '/var/www/froxlor/';
|
||||
// create and open the lockfile!
|
||||
|
||||
$keepLockFile = false;
|
||||
$debugHandler = fopen($lockfile, 'w');
|
||||
fwrite($debugHandler, 'Setting Lockfile to ' . $lockfile . "\n");
|
||||
fwrite($debugHandler, 'Setting Froxlor installation path to ' . $pathtophpfiles . "\n");
|
||||
|
||||
// open the lockfile directory and scan for existing lockfiles
|
||||
|
||||
$lockDirHandle = opendir($lockdir);
|
||||
|
||||
while($fName = readdir($lockDirHandle))
|
||||
{
|
||||
if($lockFilename == substr($fName, 0, strlen($lockFilename))
|
||||
&& $lockfName != $fName)
|
||||
{
|
||||
// Check if last run jailed out with an exception
|
||||
while ($fName = readdir($lockDirHandle)) {
|
||||
|
||||
if ($lockFilename == substr($fName, 0, strlen($lockFilename))
|
||||
&& $lockfName != $fName
|
||||
) {
|
||||
// Check if last run jailed out with an exception
|
||||
$croncontent = file($lockdir . $fName);
|
||||
$lastline = $croncontent[(count($croncontent) - 1)];
|
||||
|
||||
if($lastline == '=== Keep lockfile because of exception ===')
|
||||
{
|
||||
if ($lastline == '=== Keep lockfile because of exception ===') {
|
||||
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);
|
||||
system("kill -CHLD " . (int)$check_pid . " 1> /dev/null 2> /dev/null", $check_pid_return);
|
||||
|
||||
if($check_pid_return == 1)
|
||||
{
|
||||
if ($check_pid_return == 1) {
|
||||
// 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);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
} else {
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes the Usersettings eg. MySQL-Username/Passwort etc.
|
||||
*/
|
||||
|
||||
require ($pathtophpfiles . '/lib/userdata.inc.php');
|
||||
// Includes the Usersettings eg. MySQL-Username/Passwort etc.
|
||||
require FROXLOR_INSTALL_DIR . '/lib/userdata.inc.php';
|
||||
fwrite($debugHandler, 'Userdatas included' . "\n");
|
||||
|
||||
// Legacy sql-root-information
|
||||
if(isset($sql['root_user']) && isset($sql['root_password']) && (!isset($sql_root) || !is_array($sql_root)))
|
||||
{
|
||||
if (isset($sql['root_user'])
|
||||
&& isset($sql['root_password'])
|
||||
&& (!isset($sql_root) || !is_array($sql_root))
|
||||
) {
|
||||
$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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes the Functions
|
||||
*/
|
||||
// Includes the Functions
|
||||
require FROXLOR_INSTALL_DIR . '/lib/functions.php';
|
||||
|
||||
require ($pathtophpfiles . '/lib/functions.php');
|
||||
|
||||
/**
|
||||
* Includes the MySQL-Tabledefinitions etc.
|
||||
*/
|
||||
|
||||
require ($pathtophpfiles . '/lib/tables.inc.php');
|
||||
//Includes the MySQL-Tabledefinitions etc.
|
||||
require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php';
|
||||
fwrite($debugHandler, 'Table definitions included' . "\n");
|
||||
|
||||
/**
|
||||
* Includes the MySQL-Connection-Class
|
||||
*/
|
||||
|
||||
//Includes the MySQL-Connection-Class
|
||||
fwrite($debugHandler, 'Database Class has been loaded' . "\n");
|
||||
$db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']);
|
||||
|
||||
if($db->link_id == 0)
|
||||
{
|
||||
/**
|
||||
* Do not proceed further if no database connection could be established
|
||||
*/
|
||||
|
||||
if ($db->link_id == 0) {
|
||||
// Do not proceed further if no database connection could be established
|
||||
fclose($debugHandler);
|
||||
unlink($lockfile);
|
||||
die('Froxlor can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
|
||||
@@ -157,8 +134,7 @@ fwrite($debugHandler, 'Database-connection established' . "\n");
|
||||
unset($sql);
|
||||
$result = $db->query("SELECT `settingid`, `settinggroup`, `varname`, `value` FROM `" . TABLE_PANEL_SETTINGS . "`");
|
||||
|
||||
while($row = $db->fetch_array($result))
|
||||
{
|
||||
while ($row = $db->fetch_array($result)) {
|
||||
$settings[$row['settinggroup']][$row['varname']] = $row['value'];
|
||||
}
|
||||
|
||||
@@ -170,8 +146,9 @@ fwrite($debugHandler, 'Froxlor settings have been loaded from the database' . "\
|
||||
* if settings['system']['mod_fcgid_ownvhost'] is set, we have to check
|
||||
* whether the permission of the files are still correct
|
||||
*/
|
||||
if((int)$settings['system']['mod_fcgid'] == 1 && (int)$settings['system']['mod_fcgid_ownvhost'] == 1)
|
||||
{
|
||||
if ((int)$settings['system']['mod_fcgid'] == 1
|
||||
&& (int)$settings['system']['mod_fcgid_ownvhost'] == 1
|
||||
) {
|
||||
fwrite($debugHandler, 'Checking froxlor file permissions');
|
||||
$mypath = makeCorrectDir(dirname(dirname(__FILE__))); // /var/www/froxlor, needed for chown
|
||||
$user = $settings['system']['mod_fcgid_httpuser'];
|
||||
@@ -181,17 +158,13 @@ if((int)$settings['system']['mod_fcgid'] == 1 && (int)$settings['system']['mod_f
|
||||
safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($mypath));
|
||||
}
|
||||
|
||||
/**
|
||||
* be sure HTMLPurifier's cache folder is writable
|
||||
*/
|
||||
// be sure HTMLPurifier's cache folder is writable
|
||||
safe_exec('chmod -R 0755 '.escapeshellarg(dirname(__FILE__).'/classes/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer'));
|
||||
/**
|
||||
* end of HTMLPurifier check
|
||||
*/
|
||||
|
||||
if(!isset($settings['panel']['version'])
|
||||
|| $settings['panel']['version'] != $version)
|
||||
{
|
||||
|
||||
if (!isset($settings['panel']['version'])
|
||||
|| $settings['panel']['version'] != $version
|
||||
) {
|
||||
/**
|
||||
* Do not proceed further if the Database version is not the same as the script version
|
||||
*/
|
||||
@@ -208,17 +181,9 @@ fwrite($debugHandler, 'Froxlor version and database version are correct' . "\n")
|
||||
|
||||
$cronscriptDebug = ($settings['system']['debug_cron'] == '1') ? true : false;
|
||||
|
||||
/**
|
||||
* Create a new idna converter
|
||||
*/
|
||||
|
||||
// Create a new idna converter
|
||||
$idna_convert = new idna_convert_wrapper();
|
||||
|
||||
/**
|
||||
* Initialize logging
|
||||
*/
|
||||
|
||||
// Initialize logging
|
||||
$cronlog = FroxlorLogger::getInstanceOf(array('loginname' => 'cronjob'), $db, $settings);
|
||||
fwrite($debugHandler, 'Logger has been included' . "\n");
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user