From 420dd1fc3ebe94e10e7ed142b5557dc9506576d1 Mon Sep 17 00:00:00 2001 From: WibbenZ Date: Sun, 30 Aug 2015 00:28:14 +0200 Subject: [PATCH] Rework encryptionTypes, disable serverlist, update code style with load.database.php Updated code style of load.database.php Added missing new line at EOF in some files Disabled private serverlist.com ~ Fixed the warning about "passwordType" with TFS 1.1+ Rewrote the function insted to see if we have a config value for it, if we don't then it will try and find it in the website config (and for compat reason it will by default go to SHA1 if neither exists). --- classes/website.php | 23 +++++++---- config/config.php | 6 +-- install.php | 2 +- system/load.compat.php | 5 ++- system/load.database.php | 82 ++++++++++++++++++++++------------------ 5 files changed, 70 insertions(+), 48 deletions(-) diff --git a/classes/website.php b/classes/website.php index 4a199f8..6fa71df 100644 --- a/classes/website.php +++ b/classes/website.php @@ -118,14 +118,23 @@ public static function fileExists($path) return file_exists($path); } - public static function setPasswordsEncryption($encryption) - { - if(isset(self::$passwordsEncryptions[strtolower($encryption)])) - self::$passwordsEncryption = strtolower($encryption); - else + public static function updatePasswordEncryption() + { + $encryptionTypeLowerd = strtolower(self::getServerConfig()->getValue('passwordType')); + if (empty($encryptionTypeLowerd)) { // TFS 1.1+ + $encryptionTypeLowerd = $config['site']['encryptionType']; + if (empty($encryptionTypeLowerd)) { + $encryptionTypeLowerd = 'sha1'; + } + } + + if (isset(self::$passwordsEncryptions[$encryptionTypeLowerd])) { + self::$passwordsEncryption = $encryptionTypeLowerd; + } else { new Error_Critic('#C-12', 'Invalid passwords encryption ( ' . htmlspecialchars($encryption) . '). Must be one of these: ' . implode(', ', self::$passwordsEncryptions)); + } } - + public static function getPasswordsEncryption() { return self::$passwordsEncryption; @@ -227,4 +236,4 @@ public static function getCountryCode($IP) } return $lastCountryCode; } -} \ No newline at end of file +} diff --git a/config/config.php b/config/config.php index 8157197..c3725a5 100644 --- a/config/config.php +++ b/config/config.php @@ -10,6 +10,7 @@ $config['site']['item_images_extension'] = '.gif'; $config['site']['flag_images_url'] = 'http://flag-images.ots.me/'; $config['site']['flag_images_extension'] = '.png'; +$config['site']['encryptionType'] = 'sha1'; # Create Account Options $config['site']['one_email'] = false; @@ -25,7 +26,6 @@ $config['site']['newchar_towns'] = array(2); $config['site']['max_players_per_account'] = 7; - # Emails Config $config['site']['send_emails'] = false; $config['site']['mail_address'] = "xxxx@gmx.com"; @@ -37,7 +37,7 @@ $config['site']['smtp_pass'] = "xxxx"; # PAGE: whoisonline.php -$config['site']['private-servlist.com_server_id'] = 1; +$config['site']['private-servlist.com_server_id'] = 0; /* Server id on 'private-servlist.com' to show Players Online Chart (whoisonline.php page), set 0 to disable Chart feature. To use this feature you must register on 'private-servlist.com' and add your server. @@ -91,4 +91,4 @@ $config['site']['darkborder'] = '#D4C0A1'; $config['site']['lightborder'] = '#F1E0C6'; $config['site']['download_page'] = false; -$config['site']['serverinfo_page'] = true; \ No newline at end of file +$config['site']['serverinfo_page'] = true; diff --git a/install.php b/install.php index 6065eee..4c7b855 100644 --- a/install.php +++ b/install.php @@ -175,7 +175,7 @@ function setServerPath($newPath) Website::getDBHandle()->setDatabasePassword(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PASS)); else new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_PASS . ' in server config file.'); - Website::setPasswordsEncryption(Website::getServerConfig()->getValue('passwordType')); + Website::updatePasswordEncryption(); $SQL = Website::getDBHandle(); } diff --git a/system/load.compat.php b/system/load.compat.php index 6bf71f5..fe6bf80 100644 --- a/system/load.compat.php +++ b/system/load.compat.php @@ -49,8 +49,11 @@ $topic = $subtopic; $passwordency = Website::getServerConfig()->getValue('passwordType'); -if($passwordency == 'plain') +if (empty($passwordency)) { + $passwordency = 'sha1'; +} else if ($passwordency == 'plain') { $passwordency = ''; +} $news_content = ''; $vocation_name = array(); diff --git a/system/load.database.php b/system/load.database.php index bfbb629..30d9a13 100644 --- a/system/load.database.php +++ b/system/load.database.php @@ -1,39 +1,49 @@ isSetKey('mysqlHost')) -{ - define('SERVERCONFIG_SQL_HOST', 'mysqlHost'); - define('SERVERCONFIG_SQL_PORT', 'mysqlPort'); - define('SERVERCONFIG_SQL_USER', 'mysqlUser'); - define('SERVERCONFIG_SQL_PASS', 'mysqlPass'); - define('SERVERCONFIG_SQL_DATABASE', 'mysqlDatabase'); - define('SERVERCONFIG_SQLITE_FILE', 'sqlFile'); -} -else - new Error_Critic('#E-3', 'There is no key mysqlHost in server config', array(new Error('INFO', 'use server config cache: ' . (Website::getWebsiteConfig()->getValue('useServerConfigCache') ? 'true' : 'false') . ''))); -Website::setDatabaseDriver(Database::DB_MYSQL); -if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_HOST)) - Website::getDBHandle()->setDatabaseHost(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_HOST)); -else - new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_HOST . ' in server config file.'); -if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_PORT)) - Website::getDBHandle()->setDatabasePort(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PORT)); -else - new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_PORT . ' in server config file.'); -if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_DATABASE)) - Website::getDBHandle()->setDatabaseName(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_DATABASE)); -else - new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_DATABASE . ' in server config file.'); -if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_USER)) - Website::getDBHandle()->setDatabaseUsername(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_USER)); -else - new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_USER . ' in server config file.'); -if(Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_PASS)) - Website::getDBHandle()->setDatabasePassword(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PASS)); -else - new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_PASS . ' in server config file.'); + if (Website::getServerConfig()->isSetKey('mysqlHost')) { + define('SERVERCONFIG_SQL_HOST', 'mysqlHost'); + define('SERVERCONFIG_SQL_PORT', 'mysqlPort'); + define('SERVERCONFIG_SQL_USER', 'mysqlUser'); + define('SERVERCONFIG_SQL_PASS', 'mysqlPass'); + define('SERVERCONFIG_SQL_DATABASE', 'mysqlDatabase'); + define('SERVERCONFIG_SQLITE_FILE', 'sqlFile'); + } else { + new Error_Critic('#E-3', 'There is no key mysqlHost in server config', array(new Error('INFO', 'use server config cache: ' . (Website::getWebsiteConfig()->getValue('useServerConfigCache') ? 'true' : 'false') . ''))); + } -Website::setPasswordsEncryption(Website::getServerConfig()->getValue('passwordType')); -$SQL = Website::getDBHandle(); \ No newline at end of file + Website::setDatabaseDriver(Database::DB_MYSQL); + if (Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_HOST)) { + Website::getDBHandle()->setDatabaseHost(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_HOST)); + } else { + new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_HOST . ' in server config file.'); + } + + if (Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_PORT)) { + Website::getDBHandle()->setDatabasePort(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PORT)); + } else { + new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_PORT . ' in server config file.'); + } + + if (Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_DATABASE)) { + Website::getDBHandle()->setDatabaseName(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_DATABASE)); + } else { + new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_DATABASE . ' in server config file.'); + } + + if (Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_USER)) { + Website::getDBHandle()->setDatabaseUsername(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_USER)); + } else { + new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_USER . ' in server config file.'); + } + + if (Website::getServerConfig()->isSetKey(SERVERCONFIG_SQL_PASS)) { + Website::getDBHandle()->setDatabasePassword(Website::getServerConfig()->getValue(SERVERCONFIG_SQL_PASS)); + } else { + new Error_Critic('#E-7', 'There is no key ' . SERVERCONFIG_SQL_PASS . ' in server config file.'); + } + + Website::updatePasswordEncryption(); + $SQL = Website::getDBHandle();