From 58b29a924c48e7c1ce38c435c92e541b53984c56 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 22 Feb 2008 22:06:56 +0000 Subject: [PATCH] handling of boolean constants improved (not fully) --- admin.php | 2 +- agb.php | 2 +- beg.php | 2 +- birthday_confirm.php | 2 +- confirm.php | 2 +- doubler.php | 2 +- img.php | 2 +- inc/config.php | 7 ---- inc/db/lib-mysql3.php | 5 ++- inc/db/lib.php | 10 ++---- inc/extensions.php | 4 +-- inc/extensions/ext-order.php | 2 +- inc/extensions/ext-sql_patches.php | 8 +++-- inc/fatal_errors.php | 4 +-- inc/functions.php | 20 ++++++++--- inc/header.php | 4 +-- inc/install-inc.php | 17 ++++++---- inc/language.php | 7 ++-- inc/libs/cache_functions.php | 16 +++------ inc/load_extensions.php | 2 +- inc/modules/admin.php | 8 ++--- inc/mysql-connect.php | 54 +++++++++++++++--------------- inc/mysql-manager.php | 34 ++++++------------- inc/session.php | 2 +- inc/stylesheet.php | 4 +-- inc/theme-manager.php | 2 +- index.php | 4 +-- install.php | 2 +- lead-confirm.php | 2 +- login.php | 2 +- mailid.php | 2 +- mailid_top.php | 2 +- ref.php | 2 +- show_bonus.php | 2 +- 34 files changed, 116 insertions(+), 126 deletions(-) diff --git a/admin.php b/admin.php index 8c26089496..f73daff908 100644 --- a/admin.php +++ b/admin.php @@ -45,7 +45,7 @@ $GLOBALS['module'] = "admin"; $CSS = -1; require ("inc/config.php"); // Is the script installed? -if (defined('mxchange_installed') && (mxchange_installed)) +if (defined('mxchange_installed') && (isBooleanConstantAndTrue('mxchange_installed'))) { // Simply redirect... :-) LOAD_URL("modules.php?module=admin&action=login"); diff --git a/agb.php b/agb.php index a321428bc3..c9c2654fc8 100644 --- a/agb.php +++ b/agb.php @@ -45,7 +45,7 @@ $GLOBALS['module'] = "agb"; $CSS = -1; require ("inc/config.php"); // Is the script installed? -if (defined('mxchange_installed') && (mxchange_installed)) +if (defined('mxchange_installed') && (isBooleanConstantAndTrue('mxchange_installed'))) { // Simply redirect... :-) LOAD_URL("modules.php?module=index&what=agb"); diff --git a/beg.php b/beg.php index 712a362f90..c5442dfc4c 100644 --- a/beg.php +++ b/beg.php @@ -49,7 +49,7 @@ $msg = null; require ("inc/config.php"); // Is the script installed? -if (defined('mxchange_installed') && (mxchange_installed)) { +if (defined('mxchange_installed') && (isBooleanConstantAndTrue('mxchange_installed'))) { // Check for userid if (!empty($_GET['uid'])) { // Init user ID diff --git a/birthday_confirm.php b/birthday_confirm.php index cd2236573b..8dd674554a 100644 --- a/birthday_confirm.php +++ b/birthday_confirm.php @@ -44,7 +44,7 @@ $GLOBALS['module'] = "birthday_confirm"; $CSS = -1; // Load the required file(s) require ("inc/config.php"); -if (defined('mxchange_installed') && (mxchange_installed)) +if (defined('mxchange_installed') && (isBooleanConstantAndTrue('mxchange_installed'))) { // Script is installed so let's check for his confirmation link... $uid = strip_tags(bigintval($_GET['uid'])); diff --git a/confirm.php b/confirm.php index 6e44e25308..571941f329 100644 --- a/confirm.php +++ b/confirm.php @@ -45,7 +45,7 @@ $GLOBALS['module'] = "confirm"; $CSS = -1; require ("inc/config.php"); // Is the script installed? -if (defined('mxchange_installed') && (mxchange_installed) && (admin_registered)) +if (defined('mxchange_installed') && (isBooleanConstantAndTrue('mxchange_installed')) && (isBooleanConstantAndTrue('admin_registered'))) { // Base URL for redirection $URL = URL."/modules.php?module=index&what=confirm&hash="; diff --git a/doubler.php b/doubler.php index f2690ca9bd..e8a088bc8c 100644 --- a/doubler.php +++ b/doubler.php @@ -48,7 +48,7 @@ $CSS = "0"; require ("inc/config.php"); // Is the script installed? -if (defined('mxchange_installed') && (mxchange_installed)) +if (defined('mxchange_installed') && (isBooleanConstantAndTrue('mxchange_installed'))) { // Probe for referral ID if (!empty($_GET['refid'])) $GLOBALS['refid'] = bigintval($_GET['refid']); diff --git a/img.php b/img.php index 82855eee2e..8710bd0ba1 100644 --- a/img.php +++ b/img.php @@ -44,7 +44,7 @@ $GLOBALS['module'] = "img"; $CSS = -1; // Load the required file(s) require ("inc/config.php"); -if (defined('mxchange_installed') && (mxchange_installed)) +if (defined('mxchange_installed') && (isBooleanConstantAndTrue('mxchange_installed'))) { if (!empty($_GET['code'])) { diff --git a/inc/config.php b/inc/config.php index 3e98b5af6b..ace37e5d15 100644 --- a/inc/config.php +++ b/inc/config.php @@ -110,13 +110,6 @@ define('DEBUG_MODE', false); // When we are not installing if (!defined('mxchange_installing')) define('mxchange_installing', false); -// Language stuff (default is german) -require_once(PATH."inc/language.php"); - -// We need general functions and database stuff here -require_once(PATH."inc/functions.php"); -require_once(PATH."inc/mysql-manager.php"); - // Your MySQL data (we don't like M$ SQL ;-) ) $MySQL = array( // CFG: MYSQL-HOST diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index c0af223167..0c2b15b17f 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -43,6 +43,9 @@ function SQL_QUERY($sql_string, $F, $L) { global $link, $CSS, $_CONFIG, $OK; + // Remove \t, \n and \r from queries they may confuse some MySQL version I have heard + $sql_string = str_replace("\t", " ", str_replace("\n", " ", str_replace("\r", " ", $sql_string))); + // Run SQL command $result = @mysql_query($sql_string, $link) or ADD_FATAL($F." (".$L."):".mysql_error()."
@@ -54,7 +57,7 @@ function SQL_QUERY($sql_string, $F, $L) $_CONFIG['sql_count']++; // Debug output - //* DEBUG: */ print "Query=".$sql_string.", affected=".SQL_AFFECTEDROWS().", numrows=".SQL_NUMROWS($result)."
\n"; + //* DEBUG: */ print "Query=
".$sql_string."
, affected=".SQL_AFFECTEDROWS().", numrows=".SQL_NUMROWS($result)."
\n"; if (($CSS != "1") && ($CSS != "-1") && (DEBUG_MODE) && (DEBUG_SQL)) { diff --git a/inc/db/lib.php b/inc/db/lib.php index 6bc4e73971..d461ebf1e1 100644 --- a/inc/db/lib.php +++ b/inc/db/lib.php @@ -32,8 +32,7 @@ ************************************************************************/ // Some security stuff... -if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) -{ +if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) { $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php"; require($INC); } @@ -44,13 +43,10 @@ if (_DB_TYPE == "_DB_TYPE") define('_DB_TYPE', "mysql3"); // Create include file name $INC = PATH."inc/db/lib-"._DB_TYPE.".php"; -if (file_exists($INC)) -{ +if ((file_exists($INC)) && (is_readable($INC))) { // Include abstraction layer require_once($INC); -} - else -{ +} else { // Bye, bye... die("Cannot load database abstraction layer! R.I.P."); } diff --git a/inc/extensions.php b/inc/extensions.php index a2aeb3f1ad..3e301719a8 100644 --- a/inc/extensions.php +++ b/inc/extensions.php @@ -268,7 +268,7 @@ function EXT_IS_ACTIVE ($ext_name, $ignore_admin=false, $ignore_cache=false) global $cacheArray, $_CONFIG; // Extensions are all inactive during installation - if ((!mxchange_installed) || (mxchange_installing) || (empty($ext_name))) return false; + if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing')) || (empty($ext_name))) return false; // Extension's file name will also be checked $file = PATH."inc/extensions/ext-".$ext_name.".php"; @@ -325,7 +325,7 @@ function GET_EXT_VERSION ($ext_name) { $ret = false; // Extensions are all inactive during installation - if ((!mxchange_installed) || (mxchange_installing)) return ""; + if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing'))) return ""; // Is the cache written? if (!empty($cacheArray['extensions']['ext_version'][$ext_name])) { diff --git a/inc/extensions/ext-order.php b/inc/extensions/ext-order.php index 34ff7e382a..3244efa020 100644 --- a/inc/extensions/ext-order.php +++ b/inc/extensions/ext-order.php @@ -297,7 +297,7 @@ default: // Do stuff when extension is loaded unset($dummy); // Do daily reset only when installed and extension version is at least 0.1.1 - if ((defined('__DAILY_RESET')) && (!mxchange_installing) && (mxchange_installed) && (admin_registered) && (GET_EXT_VERSION("order") >= "0.1.1")) + if ((defined('__DAILY_RESET')) && (isBooleanConstantAndTrue('mxchange_installed')) && (isBooleanConstantAndTrue('mxchange_installed')) && (isBooleanConstantAndTrue('admin_registered')) && (GET_EXT_VERSION("order") >= "0.1.1")) { // Reset mail order values $result_ext = SQL_QUERY("UPDATE "._MYSQL_PREFIX."_user_data SET mail_orders=0 WHERE mail_orders > 0", __FILE__, __LINE__); diff --git a/inc/extensions/ext-sql_patches.php b/inc/extensions/ext-sql_patches.php index 2b232dd8b5..a4b5179c53 100644 --- a/inc/extensions/ext-sql_patches.php +++ b/inc/extensions/ext-sql_patches.php @@ -39,13 +39,13 @@ if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF']))) } // Version number -$EXT_VERSION = "0.4.1"; +$EXT_VERSION = "0.4.2"; // Auto-set extension version if (!isset($EXT_VER)) $EXT_VER = $EXT_VERSION; // Version history array (add more with , "0.1" and so on) -$EXT_VER_HISTORY = array("0.0", "0.0.1", "0.0.2", "0.0.3", "0.0.4", "0.0.5", "0.0.6", "0.0.7", "0.0.8", "0.0.9", "0.1.0", "0.1.1", "0.1.2", "0.1.3", "0.1.4", "0.1.5", "0.1.6", "0.1.7", "0.1.8", "0.1.9", "0.2.0", "0.2.1", "0.2.2", "0.2.3", "0.2.4", "0.2.5", "0.2.6", "0.2.7", "0.2.8", "0.2.9", "0.3.0", "0.3.1", "0.3.2", "0.3.3", "0.3.4", "0.3.5", "0.3.6", "0.3.7", "0.3.8", "0.3.9", "0.4.0", "0.4.1"); +$EXT_VER_HISTORY = array("0.0", "0.0.1", "0.0.2", "0.0.3", "0.0.4", "0.0.5", "0.0.6", "0.0.7", "0.0.8", "0.0.9", "0.1.0", "0.1.1", "0.1.2", "0.1.3", "0.1.4", "0.1.5", "0.1.6", "0.1.7", "0.1.8", "0.1.9", "0.2.0", "0.2.1", "0.2.2", "0.2.3", "0.2.4", "0.2.5", "0.2.6", "0.2.7", "0.2.8", "0.2.9", "0.3.0", "0.3.1", "0.3.2", "0.3.3", "0.3.4", "0.3.5", "0.3.6", "0.3.7", "0.3.8", "0.3.9", "0.4.0", "0.4.1", "0.4.2"); switch ($EXT_LOAD_MODE) { @@ -521,6 +521,10 @@ PRIMARY KEY (id) // Update notes (these will be set as task text!) $UPDATE_NOTES = "Tabellen-Schlüssel neu gesetzt und Parsing-Zeit im Footer eingeblendet."; break; + + case "0.4.2": // SQL queries for v0.4.2 + $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_online` ADD INDEX `admin_member` (`is_admin`, `is_member`)"; + break; } break; diff --git a/inc/fatal_errors.php b/inc/fatal_errors.php index edee328c70..6bb6a0ca55 100644 --- a/inc/fatal_errors.php +++ b/inc/fatal_errors.php @@ -45,7 +45,7 @@ if ((sizeof($FATAL) > 0) || (!empty($FATAL[0]))) // Set unset variable if (empty($check)) $check = ""; - if (mxchange_installing) { + if (isBooleanConstantAndTrue('mxchange_installing')) { // While we are installing ouput other header than while it is installed... :-) $OUT = ""; foreach ($FATAL as $key=>$value) { @@ -61,7 +61,7 @@ if ((sizeof($FATAL) > 0) || (!empty($FATAL[0]))) // Load main template LOAD_TEMPLATE("install_fatal_table", false, $OUT); - } elseif (mxchange_installed) { + } elseif (isBooleanConstantAndTrue('mxchange_installed')) { // Display all runtime fatal errors $OUT = ""; foreach ($FATAL as $key=>$value) { diff --git a/inc/functions.php b/inc/functions.php index c449c058a2..150de6cc59 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -166,7 +166,7 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) { // Output the raw HTML code function OUTPUT_RAW ($HTML) { - if ((mxchange_installed) && (basename($_SERVER['PHP_SELF']) != "install.php")) { + if ((isBooleanConstantAndTrue('mxchange_installed')) && (basename($_SERVER['PHP_SELF']) != "install.php")) { // Not in install-mode so strip slashes away echo stripslashes($HTML); } else { @@ -273,13 +273,13 @@ function LOAD_TEMPLATE($template, $return=false, $content="") { } // Does the special template exists? - if (!file_exists($file)) { + if ((!file_exists($file)) || (!is_readable($file))) { // Reset to default template $file = $BASE.$template.".tpl"; } // Now does the final template exists? - if (file_exists($file)) { + if ((file_exists($file)) && (is_readable($file))) { // The local file does exists so we load it. :) $tmpl_file = implode("", file($file)); @@ -298,7 +298,7 @@ function LOAD_TEMPLATE($template, $return=false, $content="") { // Add surrounding HTML comments to help finding bugs faster $ret = "\n".$ret."\n"; - } elseif ((IS_ADMIN()) || ((mxchange_installing) && (!mxchange_installed))) { + } elseif ((IS_ADMIN()) || ((isBooleanConstantAndTrue('mxchange_installing')) && (!isBooleanConstantAndTrue('mxchange_installed')))) { // Only admins shall see this warning or when installation mode is active $ret = "
".TEMPLATE_404."
(".basename($file).")
@@ -1998,7 +1998,9 @@ function ADD_URL_DATA($URL) // function generatePassString($passHash) { global $_CONFIG; - $ret = "*FAILED*"; + + // Return vanilla password hash + $ret = $passHash; // Is a secret key and master salt already initialized? if ((!empty($_CONFIG['secret_key'])) && (!empty($_CONFIG['master_salt']))) { @@ -2019,6 +2021,7 @@ function generatePassString($passHash) { $start += 4; $newHash .= $mod; } + //* DEBUG: */ die($passHash."
".$newHash." (".strlen($newHash).")"); $ret = generateHash($newHash, $_CONFIG['master_salt']); } @@ -2109,6 +2112,13 @@ function set_session ($var, $value) { //* DEBUG: */ echo "IGNORED:".$var."=".$value."
\n"; return true; } +// Check wether a boolean constant is set +// Taken from user comments in PHP documentation for function constant() +function isBooleanConstantAndTrue($constname) { // : Boolean + $res = false; + if (defined($constname)) $res = (constant($constname) === true); + return($res); +} // ////////////////////////////////////////////// diff --git a/inc/header.php b/inc/header.php index dee383f81f..20500100af 100644 --- a/inc/header.php +++ b/inc/header.php @@ -68,7 +68,7 @@ if (($header != "1") && ($header != "2")) { // Remember title in constant for the template define('__PAGE_TITLE', html_entity_decode($TITLE)); - } elseif ((!mxchange_installed) || (!admin_registered)) { + } elseif ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndTrue('admin_registered'))) { // Load language file because it was missing in installation finalizer step... *sigh* require_once(sprintf("%sinc/language/install_%s.php", PATH, @@ -94,7 +94,7 @@ if (($header != "1") && ($header != "2")) { LOAD_TEMPLATE("metadata"); // Add meta description to header - if ((mxchange_installed) && (admin_registered) && ($GLOBALS['module'] != "admin") && ($GLOBALS['module'] != "login") && (isset($db)) && (isset($link))) { + if ((isBooleanConstantAndTrue('mxchange_installed')) && (isBooleanConstantAndTrue('admin_registered')) && ($GLOBALS['module'] != "admin") && ($GLOBALS['module'] != "login") && (isset($db)) && (isset($link))) { // Add meta description not in admin and login module and when the script is installed META_DESCRIPTION($GLOBALS['module'], $GLOBALS['what']); } diff --git a/inc/install-inc.php b/inc/install-inc.php index 5e0a39a00d..14d36d3efb 100644 --- a/inc/install-inc.php +++ b/inc/install-inc.php @@ -36,16 +36,18 @@ ************************************************************************/ // Some security stuff... -if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) -{ +if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) { $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php"; require($INC); } // function install_WriteData ($file, $comment, $prefix, $suffix, $DATA, $sneak=0) { - $done = false; $sneak++; - if (file_exists($file)) { + // Initialize all and count up the "seak" value + $done = false; + $next = 0; + $sneak++; + if ((file_exists($file)) && (is_readable($file))) { $search = "CFG: ".$comment; $tmp = $file.".tmp"; $fp = @fopen($file, 'r') or OUTPUT_HTML("READ: ".$file."
"); @@ -66,6 +68,7 @@ function install_WriteData ($file, $comment, $prefix, $suffix, $DATA, $sneak=0) fputs($fp_tmp, $line); } fclose($fp_tmp); + // Finished writing tmp file $done = true; } @@ -125,7 +128,7 @@ if ((isset($_GET['page']) && ($_GET['page'] == 5))) { } // Is MXChange installed or no admin registered so far? -if ((!mxchange_installed) || (!admin_registered)) +if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndTrue('admin_registered'))) { // Set URL for FORM actions define('__BURL_ACTION', $burl); @@ -320,7 +323,7 @@ if ((!mxchange_installed) || (!admin_registered)) break; case "finalize": // Write captured data to files - if ((!empty($_POST['finalize'])) && (!mxchange_installed)) { + if ((!empty($_POST['finalize'])) && (!isBooleanConstantAndTrue('mxchange_installed'))) { // You have submitted data then we have to reset the fatal messages $FATAL = array(); $SQLs = array(); @@ -454,7 +457,7 @@ if ((!mxchange_installed) || (!admin_registered)) LOAD_URL($URL); } } - elseif (mxchange_installed) + elseif (isBooleanConstantAndTrue('mxchange_installed')) { // Redirection after writing data... :-) LOAD_TEMPLATE("install_finished"); diff --git a/inc/language.php b/inc/language.php index 4516d20bec..f39d09b567 100644 --- a/inc/language.php +++ b/inc/language.php @@ -38,12 +38,12 @@ if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) require($INC); } +// Set default language if (empty($mx_lang)) $mx_lang = DEFAULT_LANG; // Look for file $file = sprintf(PATH."inc/language/%s.php", $mx_lang); -if (!file_exists($file)) -{ +if ((!file_exists($file)) || (!is_readable($file))) { // Switch to default (DO NOT CHANGE!!!) set_session("mx_lang", "de"); $mx_lang = "de"; @@ -55,8 +55,7 @@ require($file); unset($file); // Check for installation mode -if (!mxchange_installed) -{ +if (isBooleanConstantAndTrue('mxchange_installing')) { // Load matching language file require(PATH."inc/language/install_".$mx_lang.".php"); } diff --git a/inc/libs/cache_functions.php b/inc/libs/cache_functions.php index 2e42b1dd95..cfb4cd4cae 100644 --- a/inc/libs/cache_functions.php +++ b/inc/libs/cache_functions.php @@ -61,31 +61,25 @@ class mxchange_cache { // Check if we can create a file inside the path @touch($path."dummy.tmp", 'w'); - if (file_exists($path."dummy.tmp")) - { + if (file_exists($path."dummy.tmp")) { // Yes, we can do. So let's remove it - unlink($path."dummy.tmp"); + @unlink($path."dummy.tmp"); // Is there a .htaccess file? - if (file_exists($path.".htaccess")) - { + if (file_exists($path.".htaccess")) { // Update database that we have tested it $result = SQL_QUERY("UPDATE "._MYSQL_PREFIX."_config SET cache_tested='1' WHERE config=0 LIMIT 1", __FILE__, __LINE__); $this->ret="done"; // All done! return "done"; - } - else - { + } else { // Stop! Set a .htaccess file first $this->ret="htaccess"; return "htaccess"; } } - } - elseif ($tested) - { + } elseif ($tested) { // System already tested $this->ret="done"; return "done"; diff --git a/inc/load_extensions.php b/inc/load_extensions.php index 0f35a1acfd..b7499dae51 100644 --- a/inc/load_extensions.php +++ b/inc/load_extensions.php @@ -43,7 +43,7 @@ $EXT_CSS_FILES = array(); $ADD = ""; // Skip loading extensions -if ((!mxchange_installed) || (mxchange_installing)) return; +if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing'))) return; // Load default sql_patches extension if present if (file_exists(PATH."inc/extensions/ext-sql_patches.php") && is_readable(PATH."inc/extensions/ext-sql_patches.php")) diff --git a/inc/modules/admin.php b/inc/modules/admin.php index a4e8aeb1e4..083009f303 100644 --- a/inc/modules/admin.php +++ b/inc/modules/admin.php @@ -52,7 +52,7 @@ FIX_DELETED_COOKIES(array('admin_login', 'admin_md5', 'admin_last', 'admin_to')) // Is the logout empty? if (empty($_GET['logout'])) $_GET['logout'] = ""; -if (!admin_registered) { +if (!isBooleanConstantAndTrue('admin_registered')) { // Admin is not registered so we have to inform the user if ((isset($_POST['ok'])) && ((empty($_POST['login'])) || (empty($_POST['pass'])) || (strlen($_POST['pass']) < 4))) $_POST['ok'] = "***"; if ((isset($_POST['ok'])) && ($_POST['ok'] != "***")) { @@ -89,7 +89,7 @@ if (!admin_registered) { // Any other kind $ret = "done"; } - if (!admin_registered) { + if (!isBooleanConstantAndTrue('admin_registered')) { // Write to config that registration is done admin_WriteData(PATH."inc/config.php", "ADMIN-SETUP", "define ('admin_registered', ", ");", "true", 0); @@ -255,7 +255,7 @@ if (!admin_registered) { } } elseif ($_GET['logout'] == "1") { // Only try to remove cookies - if (set_session("admin_login", "", (time() - 3600), COOKIE_PATH) && set_session("admin_md5", "", (time() - 3600), COOKIE_PATH) && set_session("admin_last", "", (time() - 3600), COOKIE_PATH) && set_session("admin_to", "", (time() - 3600), COOKIE_PATH)) { + if (set_session("admin_login", "") && set_session("admin_md5", "") && set_session("admin_last", "") && set_session("admin_to", "")) { // Also remove array elements unset($_SESSION['admin_login']); unset($_SESSION['admin_md5']); @@ -337,7 +337,7 @@ if (!admin_registered) { } } -if (admin_registered) +if (isBooleanConstantAndTrue('admin_registered')) { // Check config.php and inc directory for right access rights if (is_INCWritable("config")) ADD_FATAL(FATAL_CONFIG_WRITABLE); diff --git a/inc/mysql-connect.php b/inc/mysql-connect.php index 3a53518b75..6f2f6182a1 100644 --- a/inc/mysql-connect.php +++ b/inc/mysql-connect.php @@ -44,63 +44,64 @@ define('DEBUG_SQL', false); // Load library require_once(PATH."inc/db/lib.php"); +// Load general functions +require_once(PATH."inc/functions.php"); // Non-database functions +require_once(PATH."inc/extensions.php"); +require_once(PATH."inc/language.php"); + // Check if the user setups his MySQL stuff... -if ((empty($MySQL['login'])) && (!mxchange_installing) && (!isset($_GET['installing'])) && (mxchange_installed)) -{ +if ((empty($MySQL['login'])) && (!isBooleanConstantAndTrue('mxchange_installing')) && (!isset($_GET['installing'])) && (isBooleanConstantAndTrue('mxchange_installed'))) { // No login entered and outside installation mode echo "".LANG_WARNING.": "; - if (mxchange_installed) - { + if (isBooleanConstantAndTrue('mxchange_installed')) { // You have changed my configuration file! die(DIE_CONFIG_CHANGED_YOU); - } - else - { + } else { // Please run the installation script (maybe again) die(DIE_RUN_INSTALL_MYSQL); } -} - elseif ((!mxchange_installing) && (!isset($_GET['installing'])) && (empty($MySQL['password'])) && (warn_no_pass)) -{ +} elseif ((!isBooleanConstantAndTrue('mxchange_installing')) && (!isset($_GET['installing'])) && (empty($MySQL['password'])) && (warn_no_pass)) { // No database password entered!!! echo "".LANG_WARNING.": ".WARN_NULL_PASSWORD; } + +// Init configuration arrays +$_CONFIG = array( + 'code_length' => 0 +); + // Check if this file is writeable or read-only and warn the user -if ((!mxchange_installing) && (mxchange_installed)) -{ +if ((!isBooleanConstantAndTrue('mxchange_installing')) && (isBooleanConstantAndTrue('mxchange_installed'))) { // Check for write-permission for config.php and inc directory if (empty($GLOBALS['module'])) $GLOBALS['module'] = "index"; - if (($GLOBALS['module'] != "admin") && (admin_registered)) - { + if (($GLOBALS['module'] != "admin") && (isBooleanConstantAndTrue('admin_registered')) && (!isset($_SERVER['WINDIR']))) { if (is_INCWritable("config")) ADD_FATAL(FATAL_CONFIG_WRITABLE); if (is_INCWritable("dummy")) ADD_FATAL(FATAL_INC_WRITABLE); } - - // Init configuration arrays - $_CONFIG = array( - 'code_length' => 0 - ); $EXT_CSS_FILES = array(); - // Load general stuff, like... - require_once(PATH."inc/extensions.php"); // Extension management - require_once(PATH."inc/functions.php"); // Non-database functions + // Load "databases" aka static arrays require_once(PATH."inc/databases.php"); // Several hard-coded databases (arrays, constants) if ((!empty($MySQL['host'])) && (!empty($MySQL['login'])) && (!empty($MySQL['password'])) && (!empty($MySQL['dbase']))) { // Connect to DB + global $link; $link = SQL_CONNECT($MySQL['host'], $MySQL['login'], $MySQL['password'], __FILE__, __LINE__); // Is the link valid? if (is_resource($link)) { // Choose the database + global $db; $db = SQL_SELECT_DB($MySQL['dbase'], $link, __FILE__, __LINE__); // Is it a valid resource? if ($db === true) { // Load configuration stuff - $result = SQL_QUERY("SELECT pass_len, points_register, points_ref, least_cats, check_double_email, check_double_pass, admin_notify, url_tlock, test_text, max_tlength, test_subj, autosend_active, max_send, url_blacklist, auto_purge, auto_purge_active, last_update, unconfirmed, profile_lock, online_timeout, mad_timestamp, mad_count, profile_update, send_prof_update, resend_profile_update, code_length, patch_level, patch_ctime, guest_stats, ref_payout, activate_xchange, order_multi_page, display_refid, ip_timeout, allow_direct_pay, config FROM "._MYSQL_PREFIX."_config WHERE config=0 LIMIT 1", __FILE__, __LINE__); + $result = SQL_QUERY("SELECT pass_len, points_register, points_ref, least_cats, check_double_email, check_double_pass, admin_notify, url_tlock, test_text, max_tlength, test_subj, autosend_active, max_send, url_blacklist, auto_purge, auto_purge_active, last_update, unconfirmed, profile_lock, online_timeout, mad_timestamp, mad_count, profile_update, send_prof_update, resend_profile_update, code_length, patch_level, patch_ctime, guest_stats, ref_payout, activate_xchange, order_multi_page, display_refid, ip_timeout, allow_direct_pay, config +FROM "._MYSQL_PREFIX."_config +WHERE config=0 +LIMIT 1", __FILE__, __LINE__); if (SQL_NUMROWS($result) == 1) { // Load data when previous SQL query did not fail @@ -120,7 +121,7 @@ if ((!mxchange_installing) && (mxchange_installed)) require_once(PATH."inc/mysql-manager.php"); // Functions which interact with the database // Run daily reset - if ((date("d", $_CONFIG['last_update']) != date("d", time()) || (DEBUG_MODE == true)) && (!mxchange_installing) && (mxchange_installed) && (admin_registered) && (!isset($_GET['register'])) && ($CSS != 1)) { + if ((date("d", $_CONFIG['last_update']) != date("d", time()) || (DEBUG_MODE == true)) && (!isBooleanConstantAndTrue('mxchange_installing')) && (isBooleanConstantAndTrue('mxchange_installed')) && (isBooleanConstantAndTrue('admin_registered')) && (!isset($_GET['register'])) && ($CSS != 1)) { // Do daily things in external PHP file but only when script is completely setup $INC_POOL[] = PATH."inc/reset/reset_daily.php"; @@ -231,7 +232,6 @@ if ((!mxchange_installing) && (mxchange_installed)) // Include required files require_once(PATH."inc/databases.php"); - require_once(PATH."inc/extensions.php"); require_once(PATH."inc/theme-manager.php"); require_once(PATH."inc/load_extensions.php"); require_once(PATH."inc/session.php"); @@ -244,7 +244,7 @@ if ((!mxchange_installing) && (mxchange_installed)) } // Double-check installation mode - if ((!mxchange_installed) || (!admin_registered)) { + if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndTrue('admin_registered'))) { // Check for file permissions if (!is_INCWritable("config")) { ADD_FATAL(CONFIG_IS_WRITE_PROTECTED); @@ -260,7 +260,7 @@ if ((!mxchange_installing) && (mxchange_installed)) // Any fatal messages? if (!is_array($FATAL)) $FATAL = array(); -if (((sizeof($FATAL) > 0) || (!empty($FATAL[0]))) && (mxchange_installed) && (!mxchange_installing) && ($CSS != "1")) +if (((sizeof($FATAL) > 0) || (!empty($FATAL[0]))) && (isBooleanConstantAndTrue('mxchange_installed')) && (!isBooleanConstantAndTrue('mxchange_installing')) && ($CSS != "1")) { // One or more fatal error(s) occur during connect... include (PATH."inc/header.php"); diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index da0aa71596..f8b4da5cde 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -44,18 +44,14 @@ function ADD_MODULE_TITLE($mod) global $cacheArray, $_CONFIG; $name = ""; $result = false; // Load title - if (!mxchange_installing) - { - if ((GET_EXT_VERSION("cache") >= "0.1.2") && (isset($cacheArray['modules']['module'])) && (is_array($cacheArray['modules']['module'])) && (isset($cacheArray['modules']['module'][$mod]))) - { + if (!isBooleanConstantAndTrue('mxchange_installed')) { + if ((GET_EXT_VERSION("cache") >= "0.1.2") && (isset($cacheArray['modules']['module'])) && (is_array($cacheArray['modules']['module'])) && (isset($cacheArray['modules']['module'][$mod]))) { // Load from cache $name = $cacheArray['modules']['title'][$mod]; // Update cache hits $_CONFIG['cache_hits']++; - } - else - { + } else { // Load from database $result = SQL_QUERY_ESC("SELECT title FROM "._MYSQL_PREFIX."_mod_reg WHERE module='%s' LIMIT 1", array($mod), __FILE__, __LINE__); list($name) = SQL_FETCHROW($result); @@ -67,12 +63,10 @@ function ADD_MODULE_TITLE($mod) $name = trim($name); // Still no luck or empty title? - if (empty($name)) - { + if (empty($name)) { // No name found $name = LANG_UNKNOWN_MODULE." (".$mod.")"; - if (SQL_NUMROWS($result) == 0) - { + if (SQL_NUMROWS($result) == 0) { // Add module to database $dummy = CHECK_MODULE($mod); } @@ -104,7 +98,7 @@ function CHECK_MODULE($mod) { $ret = "major"; // Check if script is installed if not return a "done" to prevent some errors - if ((!mxchange_installed) || (mxchange_installing) || (!admin_registered)) return "done"; + if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing')) || (!isBooleanConstantAndTrue('admin_registered'))) return "done"; // Check if cache is latest version $locked = 'Y'; $hidden = 'N'; $admin = 'N'; $mem = 'N'; $found = false; @@ -394,31 +388,26 @@ function IS_ADMIN($admin="") //* DEBUG: */ echo __LINE__."ADMIN:".$admin."
"; // If admin login is not given take current from cookies... - if ((empty($admin)) && (!empty($_SESSION['admin_login'])) && (!empty($_SESSION['admin_md5']))) - { + if ((empty($admin)) && (!empty($_SESSION['admin_login'])) && (!empty($_SESSION['admin_md5']))) { $admin = SQL_ESCAPE($_SESSION['admin_login']); $passCookie = $_SESSION['admin_md5']; } //* DEBUG: */ echo __LINE__."ADMIN:".$admin."/".$passCookie."
"; // Search in array for entry - if ((!empty($passCookie)) && (isset($cacheArray['admins']['password'][$admin])) && (!empty($admin))) - { + if ((!empty($passCookie)) && (isset($cacheArray['admins']['password'][$admin])) && (!empty($admin))) { // Count cache hits $_CONFIG['cache_hits']++; // Login data is valid or not? $valPass = generatePassString($cacheArray['admins']['password'][$admin]); - } - elseif (!empty($admin)) - { + } elseif (!empty($admin)) { // Search for admin $result = SQL_QUERY_ESC("SELECT HIGH_PRIORITY password FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1", array($admin), __FILE__, __LINE__); // Is he admin? $passDB = ""; - if (SQL_NUMROWS($result) == 1) - { + if (SQL_NUMROWS($result) == 1) { // Admin login was found so let's load password from DB list($passDB) = SQL_FETCHROW($result); $valPass = generatePassString($passDB); @@ -428,8 +417,7 @@ function IS_ADMIN($admin="") SQL_FREERESULT($result); } - if (!empty($valPass)) - { + if (!empty($valPass)) { // Check if password is valid //* DEBUG: */ echo __LINE__."*".$valPass."/".$passCookie)."*
"; $ret = (($valPass == $passCookie) || (($valPass == "*FAILED*") && (!EXT_IS_ACTIVE("cache")))); diff --git a/inc/session.php b/inc/session.php index 4d8c9d6013..b0420aa12d 100644 --- a/inc/session.php +++ b/inc/session.php @@ -85,7 +85,7 @@ if (empty($_SESSION['refid']) || (!empty($GLOBALS['refid'])) || (($_SESSION['ref } // Test session if index.php or modules.php is loaded -if ((basename($_SERVER['PHP_SELF']) == "index.php") || (basename($_SERVER['PHP_SELF']) == "modules.php") || (mxchange_installing)) { +if ((basename($_SERVER['PHP_SELF']) == "index.php") || (basename($_SERVER['PHP_SELF']) == "modules.php") || (isBooleanConstantAndTrue('mxchange_installing'))) { if (count($_SESSION) > 0) { // Session variables accepted! define('__COOKIES', true); diff --git a/inc/stylesheet.php b/inc/stylesheet.php index 9c3a67dd9e..a341fd599f 100644 --- a/inc/stylesheet.php +++ b/inc/stylesheet.php @@ -44,7 +44,7 @@ $STYLES = array( ); // Add stylesheet for installation -if ((basename($_SERVER['PHP_SELF']) == "install.php") || (!mxchange_installed) || (isset($_GET['installing']))) $STYLES[] = "install.css"; +if ((basename($_SERVER['PHP_SELF']) == "install.php") || (!isBooleanConstantAndTrue('mxchange_installed')) || (isset($_GET['installing']))) $STYLES[] = "install.css"; // When no CSS output-mode is set, set it to file-output if (empty($_CONFIG['css_php'])) $_CONFIG['css_php'] = "FILE"; @@ -94,7 +94,7 @@ if (($CSS == "1") || ($_CONFIG['css_php'] == "DIRECT")) { // Now we load all CSS files from css.php! OUTPUT_HTML("