2013-11-09 11:19:21 +01:00
|
|
|
<?php
|
2013-11-10 12:51:41 +01:00
|
|
|
|
2013-12-09 15:43:08 +01:00
|
|
|
// Run configuration
|
|
|
|
define('LOG_WRITE_CURRENT_FILE', 'ManiaControl.log'); // Write current log to extra file in base dir
|
|
|
|
define('LOG_NAME_USE_DATE', true); // Use current date as suffix for log file name in logs folder
|
|
|
|
define('LOG_NAME_USE_PID', true); // Use current process id as suffix for log file name in logs folder
|
2014-05-09 11:02:39 +02:00
|
|
|
define('MIN_PHP_VERSION', "5.4");
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2013-11-10 02:55:08 +01:00
|
|
|
// Define base dir
|
2014-05-03 21:37:28 +02:00
|
|
|
define('ManiaControlDir', __DIR__ . DIRECTORY_SEPARATOR);
|
2013-11-09 11:19:21 +01:00
|
|
|
|
2014-05-03 22:30:38 +02:00
|
|
|
// Enable error reporting
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
|
2014-03-19 11:11:25 +01:00
|
|
|
// Define fatal error level
|
|
|
|
define('E_FATAL', E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_USER_ERROR);
|
|
|
|
|
2013-11-09 11:19:21 +01:00
|
|
|
// Set process settings
|
2013-12-09 15:43:08 +01:00
|
|
|
ini_set('memory_limit', '64M');
|
2013-11-09 11:19:21 +01:00
|
|
|
if (function_exists('date_default_timezone_get') && function_exists('date_default_timezone_set')) {
|
|
|
|
date_default_timezone_set(@date_default_timezone_get());
|
|
|
|
}
|
|
|
|
|
2013-12-09 15:43:08 +01:00
|
|
|
// Build log file name
|
2014-05-03 21:37:28 +02:00
|
|
|
$logFileName = ManiaControlDir . 'logs' . DIRECTORY_SEPARATOR;
|
2014-05-03 22:54:42 +02:00
|
|
|
if (!is_dir($logFileName) && !mkdir($logFileName)) {
|
|
|
|
echo "Couldn't create Logs Folder, please check the File Permissions!";
|
2013-11-10 17:23:00 +01:00
|
|
|
}
|
2014-03-19 11:11:25 +01:00
|
|
|
$logFileName .= 'ManiaControl';
|
2014-01-27 20:16:20 +01:00
|
|
|
if (LOG_NAME_USE_DATE) {
|
|
|
|
$logFileName .= '_' . date('Y-m-d');
|
|
|
|
}
|
|
|
|
if (LOG_NAME_USE_PID) {
|
|
|
|
$logFileName .= '_' . getmypid();
|
|
|
|
}
|
2013-12-09 15:43:08 +01:00
|
|
|
$logFileName .= '.log';
|
|
|
|
define('LOG_FILE', $logFileName);
|
2013-11-09 11:19:21 +01:00
|
|
|
|
2013-12-09 15:43:08 +01:00
|
|
|
// Delete old current log file
|
|
|
|
if (LOG_WRITE_CURRENT_FILE) {
|
2014-05-03 21:37:28 +02:00
|
|
|
$currentLogFileName = ManiaControlDir . LOG_WRITE_CURRENT_FILE;
|
2013-12-09 15:43:08 +01:00
|
|
|
if (file_exists($currentLogFileName) && is_writable($currentLogFileName)) {
|
|
|
|
unlink($currentLogFileName);
|
|
|
|
}
|
|
|
|
define('LOG_CURRENT_FILE', $currentLogFileName);
|
|
|
|
}
|
2013-11-10 02:55:08 +01:00
|
|
|
|
2014-04-13 12:34:45 +02:00
|
|
|
logMessage('Starting ManiaControl ...');
|
|
|
|
|
2014-05-09 11:02:39 +02:00
|
|
|
/** Check for Min PHP version */
|
|
|
|
logMessage('Checking for minimum required PHP-Version ' . MIN_PHP_VERSION . ' ... ', false);
|
|
|
|
if (phpversion() >= MIN_PHP_VERSION) {
|
|
|
|
logMessage(phpversion() . " OK!", true, false);
|
|
|
|
} else {
|
|
|
|
logMessage('TOO OLD VERSION!', true, false);
|
|
|
|
logMessage(' -- Make sure that you install at least PHP 5.4', true, false);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2014-04-13 12:34:45 +02:00
|
|
|
/**
|
|
|
|
* Checking if all the needed libraries are installed.
|
|
|
|
* - MySQLi
|
|
|
|
* - cURL
|
|
|
|
*/
|
|
|
|
logMessage('Checking for installed MySQLi ... ', false);
|
2014-04-13 13:11:19 +02:00
|
|
|
if (extension_loaded('mysqli')) {
|
2014-05-09 11:02:39 +02:00
|
|
|
logMessage('FOUND!', true, false);
|
2014-05-02 17:50:30 +02:00
|
|
|
} else {
|
2014-05-09 11:02:39 +02:00
|
|
|
logMessage('NOT FOUND!', true, false);
|
|
|
|
logMessage(' -- You don\'t have MySQLi installed, make sure to check: http://www.php.net/manual/en/mysqli.installation.php', true, false);
|
2014-04-13 12:34:45 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
logMessage('Checking for installed cURL ... ', false);
|
2014-05-01 20:18:55 +02:00
|
|
|
if (extension_loaded('curl')) {
|
2014-05-09 11:02:39 +02:00
|
|
|
logMessage('FOUND!', true, false);
|
2014-05-02 17:50:30 +02:00
|
|
|
} else {
|
2014-05-09 11:02:39 +02:00
|
|
|
logMessage('NOT FOUND!', true, false);
|
|
|
|
logMessage('You don\'t have cURL installed, make sure to check: http://www.php.net/manual/en/curl.installation.php', true, false);
|
2014-04-13 12:34:45 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2013-12-14 23:30:51 +01:00
|
|
|
/**
|
|
|
|
* Log and echo the given text
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2013-12-14 23:30:51 +01:00
|
|
|
* @param string $message
|
2014-05-02 17:50:30 +02:00
|
|
|
* @param bool $eol
|
2014-05-09 11:02:39 +02:00
|
|
|
* @param bool $date
|
2013-12-14 23:30:51 +01:00
|
|
|
*/
|
2014-05-09 11:02:39 +02:00
|
|
|
function logMessage($message, $eol = true, $date = true) {
|
|
|
|
if ($date) {
|
|
|
|
$date = date('d.M y H:i:s');
|
|
|
|
$message = $date . ' ' . $message;
|
|
|
|
}
|
|
|
|
|
2014-05-01 20:18:55 +02:00
|
|
|
if ($eol) {
|
|
|
|
$message .= PHP_EOL;
|
|
|
|
}
|
2014-05-09 11:02:39 +02:00
|
|
|
|
2014-01-27 20:16:20 +01:00
|
|
|
if (defined('LOG_CURRENT_FILE')) {
|
2014-05-03 22:48:53 +02:00
|
|
|
if (!is_writable(dirname(LOG_CURRENT_FILE)) || !file_put_contents(LOG_CURRENT_FILE, $message, FILE_APPEND)) {
|
|
|
|
echo 'Current-Logfile not write-able, please check the File Permissions!';
|
2014-03-13 18:47:40 +01:00
|
|
|
}
|
|
|
|
}
|
2014-05-03 22:48:53 +02:00
|
|
|
if (!is_writable(dirname(LOG_FILE)) || !file_put_contents(LOG_FILE, $message, FILE_APPEND)) {
|
2014-05-03 21:37:28 +02:00
|
|
|
echo 'Logfile not write-able, please check the File Permissions!';
|
2014-01-27 20:16:20 +01:00
|
|
|
}
|
2013-12-09 15:43:08 +01:00
|
|
|
echo $message;
|
|
|
|
}
|
2013-11-09 11:19:21 +01:00
|
|
|
|
2014-01-27 09:07:25 +01:00
|
|
|
// Autoload Function that loads ManiaControl Class Files on Demand
|
2014-05-01 20:18:55 +02:00
|
|
|
spl_autoload_register(function ($className) {
|
|
|
|
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-01 20:18:55 +02:00
|
|
|
// Core file
|
|
|
|
$classDirectoryPath = preg_replace('/ManiaControl/', 'core', $classPath, 1);
|
2014-05-03 21:37:28 +02:00
|
|
|
$filePath = ManiaControlDir . $classDirectoryPath . '.php';
|
2014-05-01 20:18:55 +02:00
|
|
|
if (file_exists($filePath)) {
|
|
|
|
require_once $filePath;
|
|
|
|
return;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-01 20:18:55 +02:00
|
|
|
// Plugin file
|
2014-05-03 22:54:42 +02:00
|
|
|
$filePath = ManiaControlDir . 'plugins' . DIRECTORY_SEPARATOR . $classPath . '.php';
|
2014-05-01 20:18:55 +02:00
|
|
|
if (file_exists($filePath)) {
|
|
|
|
require_once $filePath;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
2014-01-27 09:07:25 +01:00
|
|
|
|
2013-12-09 15:43:08 +01:00
|
|
|
// Start ManiaControl
|
2014-01-27 09:07:25 +01:00
|
|
|
$maniaControl = new \ManiaControl\ManiaControl();
|
2013-11-10 02:55:08 +01:00
|
|
|
$maniaControl->run();
|