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:
Michael Kaufmann (d00p)
2013-11-04 09:03:29 +01:00
parent e549ab2cbb
commit e3750a2988
7 changed files with 56 additions and 154 deletions

View File

@@ -19,10 +19,6 @@
define('AREA', 'admin'); define('AREA', 'admin');
/**
* Include our init.php, which manages Sessions, Language etc.
*/
$need_db_sql_data = true; $need_db_sql_data = true;
$need_root_db_sql_data = true; $need_root_db_sql_data = true;
require ("./lib/init.php"); require ("./lib/init.php");

View File

@@ -22,7 +22,9 @@ showUpdateStep("Upgrading SysCP ".$settings['panel']['version']." to Froxlor ".
updateToVersion($updateto); updateToVersion($updateto);
// add field frontend // add field frontend
$db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('panel','frontend','".$frontend."')"); Database::query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` SET
`settinggroup` = 'panel',
`varname` = 'frontend',
`value` = 'froxlor'"
);
$settings['panel']['frontend'] = $frontend; $settings['panel']['frontend'] = $frontend;
?>

View File

@@ -35,72 +35,14 @@ try {
* since froxlor, we have to check if there's still someone * since froxlor, we have to check if there's still someone
* out there using syscp and needs to upgrade * out there using syscp and needs to upgrade
*/ */
if(!isFroxlor()) if(!isFroxlor()) {
{
/**
* First case: We are updating from a version < 1.0.10
*/
if(!isset($settings['panel']['version'])
|| (substr($settings['panel']['version'], 0, 3) == '1.0' && $settings['panel']['version'] != '1.0.10'))
{
$updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 1.0 to 1.0.10");
include_once (makeCorrectFile(dirname(__FILE__).'/updates/syscp/1.0/update_1.0_1.0.10.inc.php'));
}
/**
* Second case: We are updating from version = 1.0.10
*/
if($settings['panel']['version'] == '1.0.10')
{
$updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 1.0.10 to 1.2-beta1");
include_once (makeCorrectFile(dirname(__FILE__).'/updates/syscp/1.0/update_1.0.10_1.2-beta1.inc.php'));
}
/**
* Third case: We are updating from a version > 1.2-beta1
*/
if(substr($settings['panel']['version'], 0, 3) == '1.2')
{
$updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 1.2-beta1 to 1.2.19");
include_once (makeCorrectFile(dirname(__FILE__).'/updates/syscp/1.2/update_1.2-beta1_1.2.19.inc.php'));
}
/**
* 4th case: We are updating from 1.2.19 to 1.2.20 (prolly the last from the 1.2.x series)
*/
if(substr($settings['panel']['version'], 0, 6) == '1.2.19')
{
$updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 1.2.19 to 1.4");
include_once (makeCorrectFile(dirname(__FILE__).'/updates/syscp/1.2/update_1.2.19_1.4.inc.php'));
}
/**
* 5th case: We are updating from a version >= 1.4
*/
if(substr($settings['panel']['version'], 0, 3) == '1.4')
{
$updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 1.4");
include_once (makeCorrectFile(dirname(__FILE__).'/updates/syscp/1.4/update_1.4.inc.php'));
}
/** /**
* Upgrading SysCP to Froxlor-0.9 * Upgrading SysCP to Froxlor-0.9
*
* when we reach this part, all necessary updates
* should have been installes automatically by the
* update scripts.
*/ */
include_once (makeCorrectFile(dirname(__FILE__).'/updates/froxlor/upgrade_syscp.inc.php')); include_once (makeCorrectFile(dirname(__FILE__).'/updates/froxlor/upgrade_syscp.inc.php'));
} }
if(isFroxlor()) if (isFroxlor()) {
{
include_once (makeCorrectFile(dirname(__FILE__).'/updates/froxlor/0.9/update_0.9.inc.php')); include_once (makeCorrectFile(dirname(__FILE__).'/updates/froxlor/0.9/update_0.9.inc.php'));
$filelog->logAction(ADM_ACTION, LOG_WARNING, '--------------- END LOG ---------------'); $filelog->logAction(ADM_ACTION, LOG_WARNING, '--------------- END LOG ---------------');
unset($filelog); unset($filelog);

View File

@@ -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. * This file is part of the Froxlor project.
@@ -16,7 +16,6 @@
* @package Cron * @package Cron
* *
*/ */
if(@php_sapi_name() != 'cli' if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi' && @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi') && @php_sapi_name() != 'cgi-fcgi')
@@ -25,8 +24,9 @@ if(@php_sapi_name() != 'cli'
} }
// ensure that default timezone is set // 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()); @date_default_timezone_set(@date_default_timezone_get());
} }
@@ -38,116 +38,93 @@ $lockfile = $lockdir . $lockfName;
// guess the froxlor installation path // guess the froxlor installation path
// normally you should not need to modify this script anymore, if your // normally you should not need to modify this script anymore, if your
// froxlor installation isn't in /var/www/froxlor // 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__)); $pathtophpfiles = dirname(dirname(__FILE__));
// should the froxlor installation guessing not work correctly, // should the froxlor installation guessing not work correctly,
// uncomment the following line, and put your path in there! // uncomment the following line, and put your path in there!
//$pathtophpfiles = '/var/www/froxlor/'; //$pathtophpfiles = '/var/www/froxlor/';
// create and open the lockfile! // create and open the lockfile!
$keepLockFile = false; $keepLockFile = false;
$debugHandler = fopen($lockfile, 'w'); $debugHandler = fopen($lockfile, 'w');
fwrite($debugHandler, 'Setting Lockfile to ' . $lockfile . "\n"); fwrite($debugHandler, 'Setting Lockfile to ' . $lockfile . "\n");
fwrite($debugHandler, 'Setting Froxlor installation path to ' . $pathtophpfiles . "\n"); fwrite($debugHandler, 'Setting Froxlor installation path to ' . $pathtophpfiles . "\n");
// open the lockfile directory and scan for existing lockfiles // open the lockfile directory and scan for existing lockfiles
$lockDirHandle = opendir($lockdir); $lockDirHandle = opendir($lockdir);
while($fName = readdir($lockDirHandle)) while ($fName = readdir($lockDirHandle)) {
{
if($lockFilename == substr($fName, 0, strlen($lockFilename))
&& $lockfName != $fName)
{
// Check if last run jailed out with an exception
if ($lockFilename == substr($fName, 0, strlen($lockFilename))
&& $lockfName != $fName
) {
// Check if last run jailed out with an exception
$croncontent = file($lockdir . $fName); $croncontent = file($lockdir . $fName);
$lastline = $croncontent[(count($croncontent) - 1)]; $lastline = $croncontent[(count($croncontent) - 1)];
if($lastline == '=== Keep lockfile because of exception ===') if ($lastline == '=== Keep lockfile because of exception ===') {
{
fclose($debugHandler); fclose($debugHandler);
unlink($lockfile); 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"); 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 if cron is running or has died.
$check_pid = substr(strstr($fName, "-"), 1); $check_pid = substr(strstr($fName, "-"), 1);
system("kill -CHLD " . (int)$check_pid . " 1> /dev/null 2> /dev/null", $check_pid_return); 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 // Result: Existing lockfile/pid isnt running
// Most likely it has died // Most likely it has died
// //
// Action: Remove it and continue // Action: Remove it and continue
// //
fwrite($debugHandler, 'Previous cronjob didn\'t exit clean. PID: ' . $check_pid . "\n"); fwrite($debugHandler, 'Previous cronjob didn\'t exit clean. PID: ' . $check_pid . "\n");
fwrite($debugHandler, 'Removing lockfile: ' . $lockdir . $fName . "\n"); fwrite($debugHandler, 'Removing lockfile: ' . $lockdir . $fName . "\n");
unlink($lockdir . $fName); unlink($lockdir . $fName);
}
else } else {
{
// Result: A Cronscript with this pid // Result: A Cronscript with this pid
// is still running // is still running
// Action: remove my own Lock and die // Action: remove my own Lock and die
// //
// close the current lockfile // close the current lockfile
fclose($debugHandler); fclose($debugHandler);
// ... and delete it // ... and delete it
unlink($lockfile); 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"); 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.
* Includes the Usersettings eg. MySQL-Username/Passwort etc. require FROXLOR_INSTALL_DIR . '/lib/userdata.inc.php';
*/
require ($pathtophpfiles . '/lib/userdata.inc.php');
fwrite($debugHandler, 'Userdatas included' . "\n"); fwrite($debugHandler, 'Userdatas included' . "\n");
// Legacy sql-root-information // 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'])); $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_user']);
unset($sql['root_password']); 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 FROXLOR_INSTALL_DIR . '/lib/tables.inc.php';
/**
* Includes the MySQL-Tabledefinitions etc.
*/
require ($pathtophpfiles . '/lib/tables.inc.php');
fwrite($debugHandler, 'Table definitions included' . "\n"); fwrite($debugHandler, 'Table definitions included' . "\n");
/** //Includes the MySQL-Connection-Class
* Includes the MySQL-Connection-Class
*/
fwrite($debugHandler, 'Database Class has been loaded' . "\n"); fwrite($debugHandler, 'Database Class has been loaded' . "\n");
$db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']); $db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']);
if($db->link_id == 0) if ($db->link_id == 0) {
{ // Do not proceed further if no database connection could be established
/**
* Do not proceed further if no database connection could be established
*/
fclose($debugHandler); fclose($debugHandler);
unlink($lockfile); unlink($lockfile);
die('Froxlor can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...'); 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); unset($sql);
$result = $db->query("SELECT `settingid`, `settinggroup`, `varname`, `value` FROM `" . TABLE_PANEL_SETTINGS . "`"); $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']; $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 * if settings['system']['mod_fcgid_ownvhost'] is set, we have to check
* whether the permission of the files are still correct * 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'); fwrite($debugHandler, 'Checking froxlor file permissions');
$mypath = makeCorrectDir(dirname(dirname(__FILE__))); // /var/www/froxlor, needed for chown $mypath = makeCorrectDir(dirname(dirname(__FILE__))); // /var/www/froxlor, needed for chown
$user = $settings['system']['mod_fcgid_httpuser']; $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)); 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')); 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 * 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; $cronscriptDebug = ($settings['system']['debug_cron'] == '1') ? true : false;
/** // Create a new idna converter
* Create a new idna converter
*/
$idna_convert = new idna_convert_wrapper(); $idna_convert = new idna_convert_wrapper();
/** // Initialize logging
* Initialize logging
*/
$cronlog = FroxlorLogger::getInstanceOf(array('loginname' => 'cronjob'), $db, $settings); $cronlog = FroxlorLogger::getInstanceOf(array('loginname' => 'cronjob'), $db, $settings);
fwrite($debugHandler, 'Logger has been included' . "\n"); fwrite($debugHandler, 'Logger has been included' . "\n");
?>

View File

@@ -15,23 +15,20 @@
* *
*/ */
/* /**
* Function checkLastGuid * Function checkLastGuid
* *
* Checks if the system's last guid * Checks if the system's last guid is not higher than the one saved
* is not higher than the one saved * in froxlor's database. If it's higher, froxlor needs to
* in froxlor's database. * set its last guid to this one to avoid conflicts with libnss-users
* If it's higher, froxlor needs to
* set its last guid to this one
* to avoid conflicts with libnss-users
* *
* @param int guid (from froxlor database) * @param int guid (from froxlor database)
* *
* @return null * @return null
*/ */
function checkLastGuid() { function checkLastGuid() {
global $log, $cronlog, $db, $settings, $theme; global $log, $cronlog, $settings;
$mylog = null; $mylog = null;
if (isset($cronlog) && $cronlog instanceof FroxlorLogger) { if (isset($cronlog) && $cronlog instanceof FroxlorLogger) {
@@ -45,7 +42,8 @@ function checkLastGuid() {
$update_to_guid = 0; $update_to_guid = 0;
$froxlor_guid = 0; $froxlor_guid = 0;
$result = $db->query_first("SELECT MAX(`guid`) as `fguid` FROM `".TABLE_PANEL_CUSTOMERS."`"); $result_stmt = Database::query("SELECT MAX(`guid`) as `fguid` FROM `".TABLE_PANEL_CUSTOMERS."`");
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
$froxlor_guid = $result['fguid']; $froxlor_guid = $result['fguid'];
$g_file = '/etc/group'; $g_file = '/etc/group';

View File

@@ -32,7 +32,6 @@
* 3 - SHA-256 $5$ * 3 - SHA-256 $5$
* 4 - SHA-512 $6$ * 4 - SHA-512 $6$
*/ */
function makeCryptPassword ($password) { function makeCryptPassword ($password) {
global $settings; global $settings;

View File

@@ -17,7 +17,7 @@
define('MASTER_CRONJOB', 1); define('MASTER_CRONJOB', 1);
include_once(dirname(__FILE__) . '/../lib/cron_init.php'); include_once(dirname(dirname(__FILE__)) . '/lib/cron_init.php');
$jobs_to_run = includeCronjobs($debugHandler); $jobs_to_run = includeCronjobs($debugHandler);