From 63df9c12fbba3f9bb621843329cd5ad38ca070b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 1 Nov 2010 22:00:43 +0000 Subject: [PATCH] Non-existing columns cannot be dropped (now this scenario is safely detected and skipped) --- inc/db/lib-mysql3.php | 12 ++++ inc/extensions/ext-sql_patches.php | 24 +++---- inc/filters.php | 2 +- inc/functions.php | 2 +- inc/language/de.php | 2 +- inc/libs/surfbar_functions.php | 2 +- inc/template-functions.php | 103 ++++++++++++++--------------- inc/wrapper-functions.php | 24 +++++++ mailid_top.php | 4 +- 9 files changed, 105 insertions(+), 70 deletions(-) diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 8aeff002e2..747da66559 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -381,10 +381,19 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) { $tableArray = explode(' ', $sql); $tableName = str_replace('`', '', $tableArray[2]); + // Debug log + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sql . ',tableName=' . $tableName); + // Shall we add/drop? if (((strpos($sql, 'ADD') !== false) || (strpos($sql, 'DROP') !== false) || (strpos($sql, 'CHANGE') !== false)) && ($noIndex === true)) { // Try two columns, one should fix foreach (array(4,5) as $idx) { + // If an entry is not set, abort here + if (!isset($tableArray[$idx])) { + // Debug log this + logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',idx=' . $idx . ',sql=' . $sql . ' is missing!'); + } // END - if + // And column name as well $columnName = str_replace('`', '', $tableArray[$idx]); @@ -409,6 +418,9 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) { // Abort here because it is alreay there //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: ' . $sql); break; + } elseif ((SQL_HASZERONUMS($result)) && (strpos($sql, 'DROP') !== false)) { + // Abort here because we tried to drop a column which is not there (never created maybe) + break; } elseif ($columnName != 'KEY') { // Something didn't fit, we better log it logDebugMessage(__FUNCTION__, __LINE__, 'Possible problem: ' . $sql . ',hasZeroNums=' . intval(SQL_HASZERONUMS($result)) . ''); diff --git a/inc/extensions/ext-sql_patches.php b/inc/extensions/ext-sql_patches.php index 9ae78ef366..f472c40497 100644 --- a/inc/extensions/ext-sql_patches.php +++ b/inc/extensions/ext-sql_patches.php @@ -274,11 +274,14 @@ switch (getExtensionMode()) { break; case '0.2.4': // SQL queries for v0.2.4 - $auto_type = 'png'; // PNG image is the default - if ((isIncludeReadable('theme/'.getCurrentTheme().'/images/code_bg.jpg')) && function_exists('imagecreatefromjpeg')) { + // PNG image is the default + $auto_type = 'png'; + + // Is the JPEG file found and required PHP function there? + if ((isFileReadable(getPath() . 'theme/' . getCurrentTheme() . '/images/code_bg.jpg')) && function_exists('imagecreatefromjpeg')) { // Switch to JPEG format $auto_type = 'jpg'; - } + } // END - if addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `img_type` ENUM('jpg','png') NOT NULL DEFAULT '" . $auto_type . "'"); // Update notes (these will be set as task text!) @@ -689,15 +692,12 @@ PRIMARY KEY (`filter_id`) break; case '0.6.8': // SQL queries for v0.6.8 - addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_admin_menu` -CHANGE `action` `action` VARCHAR(50) NOT NULL, -CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL'); - addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_guest_menu` -CHANGE `action` `action` VARCHAR(50) NOT NULL, -CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL'); - addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_member_menu` -CHANGE `action` `action` VARCHAR(50) NOT NULL, -CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL'); + addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_admin_menu` CHANGE `action` `action` VARCHAR(50) NOT NULL'); + addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_admin_menu` CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL'); + addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_guest_menu` CHANGE `action` `action` VARCHAR(50) NOT NULL'); + addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_admin_menu` CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL'); + addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_member_menu` CHANGE `action` `action` VARCHAR(50) NOT NULL'); + addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_admin_menu` CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL'); // Update notes (these will be set as task text!) setExtensionUpdateNotes("Spalten verkürzt, damit die Schlüssel passen."); diff --git a/inc/filters.php b/inc/filters.php index 8ae57cee98..73828d019c 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -330,7 +330,7 @@ function FILTER_INIT_RANDOMIZER () { setConfigEntry('_PRIME', 591623); // Calculate "entropy" with the prime number (for code generation) - setConfigEntry('_ADD', (getPrime() * getPrime() / (pi() * getConfig('code_length') + 1))); + setConfigEntry('_ADD', (getPrime() * getPrime() / (pi() * getCodeLength() + 1))); // Simply init the randomizer with seed and _ADD value mt_srand(generateSeed() + getConfig('_ADD')); diff --git a/inc/functions.php b/inc/functions.php index 92e47c9c44..99ff9804f5 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -698,7 +698,7 @@ function generateRandomCode ($length, $code, $userid, $DATA = '') { } // At least 10 numbers shall be secure enought! - $len = getConfig('code_length'); + $len = getCodeLength(); if ($len == '0') $len = $length; if ($len == '0') $len = 10; diff --git a/inc/language/de.php b/inc/language/de.php index 4abf6b23b8..e321cf5acf 100644 --- a/inc/language/de.php +++ b/inc/language/de.php @@ -317,7 +317,7 @@ addMessages(array( 'MEMBER_UNKNOWN_MODE' => "Unbekannter Modus erkannt", 'MEMBER_CHANGED_EMAIL' => "Sie haben Ihre Email-Adresse geändert! Alte Adresse war", 'MEMBER_CHANGED_PASS' => "Sie haben Ihr Passwort geändert.", - 'MEMBER_CHANGED_DATA' => "änderung Ihrer Profildaten", + 'MEMBER_CHANGED_DATA' => "Änderung Ihrer Profildaten", 'MEMBER_MYDATA_MAIL_SENT' => "Es ist eine Email zu Ihnen unterwegs.", 'ADMIN_CHANGED_DATA' => "Profildaten geändert", 'ADMIN_MEMBER_CHANGED_PROFILE' => "Eines Ihrer Mitglieder hat seine Profildaten geändert.", diff --git a/inc/libs/surfbar_functions.php b/inc/libs/surfbar_functions.php index 340347e418..ee7784102c 100644 --- a/inc/libs/surfbar_functions.php +++ b/inc/libs/surfbar_functions.php @@ -952,7 +952,7 @@ function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') { $GLOBALS['surfbar_cache']['salt'] = 'INVALID'; // Get code length from config - $length = getConfig('code_length'); + $length = getCodeLength(); // Fix length to 10 if ($length == '0') $length = 10; diff --git a/inc/template-functions.php b/inc/template-functions.php index 56ee2adb8e..0c364ef457 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -766,9 +766,9 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 'fo // Insert the code in $img_code into jpeg or PNG image function generateImageOrCode ($img_code, $headerSent = true) { // Is the code size oversized or shouldn't we display it? - if ((strlen($img_code) > 6) || (empty($img_code)) || (getConfig('code_length') == '0')) { + if ((strlen($img_code) > 6) || (empty($img_code)) || (getCodeLength() == '0')) { // Stop execution of function here because of over-sized code length - debug_report_bug(__FUNCTION__, __LINE__, 'img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getConfig('code_length')); + debug_report_bug(__FUNCTION__, __LINE__, 'img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getCodeLength()); } elseif ($headerSent === false) { // Return an HTML code here return 'Image'; @@ -778,26 +778,24 @@ function generateImageOrCode ($img_code, $headerSent = true) { $img = sprintf("%s/theme/%s/images/code_bg.%s", getPath(), getCurrentTheme(), - getConfig('img_type') + getImgType() ); // Is it readable? if (isFileReadable($img)) { // Switch image type - switch (getConfig('img_type')) { - case 'jpg': - // Okay, load image and hide all errors + switch (getImgType()) { + case 'jpg': // Okay, load image and hide all errors $image = imagecreatefromjpeg($img); break; - case 'png': - // Okay, load image and hide all errors + case 'png': // Okay, load image and hide all errors $image = imagecreatefrompng($img); break; } // END - switch } else { - // Exit function here - logDebugMessage(__FUNCTION__, __LINE__, sprintf("File for image type %s not found.", getConfig('img_type'))); + // Silently log the error + logDebugMessage(__FUNCTION__, __LINE__, sprintf("File for image-type %s in theme %s not found.", getImgType(), getCurrentTheme())); return; } @@ -808,10 +806,10 @@ function generateImageOrCode ($img_code, $headerSent = true) { imagestring($image, 5, 14, 2, $img_code, $text_color); // Return to browser - setContentType('image/' . getConfig('img_type')); + setContentType('image/' . getImgType()); // Output image with matching image factory - switch (getConfig('img_type')) { + switch (getImgType()) { case 'jpg': imagejpeg($image); break; case 'png': imagepng($image); break; } // END - switch @@ -1097,28 +1095,28 @@ function generateEmailLink ($email, $table = 'admins') { // Output error messages in a fasioned way and die... function app_die ($F, $L, $message) { // Check if Script is already dieing and not let it kill itself another 1000 times - if (!isset($GLOBALS['app_died'])) { - // Make sure, that the script realy realy diese here and now - $GLOBALS['app_died'] = true; + if (isset($GLOBALS['app_died'])) { + // Script tried to kill itself twice + die('[' . __FUNCTION__ . ':' . __LINE__ . ']: Script wanted to kill itself more than once! Raw message=' . $message . ', file/function=' . $F . ', line=' . $L); + } // END - if - // Set content type as text/html - setContentType('text/html'); + // Make sure, that the script realy realy diese here and now + $GLOBALS['app_died'] = true; - // Load header - loadIncludeOnce('inc/header.php'); + // Set content type as text/html + setContentType('text/html'); - // Rewrite message for output - $message = sprintf(getMessage('MAILER_HAS_DIED'), basename($F), $L, $message); + // Load header + loadIncludeOnce('inc/header.php'); - // Load the message template - loadTemplate('app_die_message', false, $message); + // Rewrite message for output + $message = sprintf(getMessage('MAILER_HAS_DIED'), basename($F), $L, $message); - // Load footer - loadIncludeOnce('inc/footer.php'); - } else { - // Script tried to kill itself twice - die('['.__FUNCTION__.':'.__LINE__.']: Script wanted to kill itself more than once! Raw message=' . $message . ', file/function=' . $F . ', line=' . $L); - } + // Load the message template + loadTemplate('app_die_message', false, $message); + + // Load footer + loadIncludeOnce('inc/footer.php'); } // Display parsing time and number of SQL queries in footer @@ -1325,7 +1323,7 @@ function linenumberCode ($code) { // Add code $r .= '' . encodeEntities($c) . ''; - } + } // END - foreach return '
' . $r . '
'; } @@ -1464,6 +1462,9 @@ function escapeJavaScriptQuotes ($str) { // Send out mails depending on the 'mod/modes' combination // @TODO Lame description for this function function sendModeMails ($mod, $modes) { + // Init user data + $content = array (); + // Load hash if (fetchUserData(getMemberId())) { // Extract salt from cookie @@ -1527,45 +1528,43 @@ function sendModeMails ($mod, $modes) { $sub_mem = '{--MEMBER_CHANGED_DATA--}'; // Output success message - $content = '{--MEMBER_MYDATA_MAIL_SENT--}'; + $content['message'] = '{--MEMBER_MYDATA_MAIL_SENT--}'; break; default: // Unsupported module! logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported module %s detected.", $mod)); - $content = '{--UNKNOWN_MODULE--}'; + $content['message'] = '{--UNKNOWN_MODULE--}'; break; } // END - switch } else { // Passwords mismatch - $content = '{--MEMBER_PASSWORD_ERROR--}'; + $content['message'] = '{--MEMBER_PASSWORD_ERROR--}'; } } else { // Could not load profile - $content = '{--MEMBER_CANNOT_LOAD_PROFILE--}'; + $content['message'] = '{--MEMBER_CANNOT_LOAD_PROFILE--}'; } // Send email to user if required - if ((!empty($sub_mem)) && (!empty($message))) { + if ((!empty($sub_mem)) && (!empty($message)) && (!empty($content['email']))) { // Send member mail sendEmail($content['email'], $sub_mem, $message); } // END - if // Send only if no other error has occured - if (empty($content)) { - if ((!empty($sub_adm)) && (!empty($message_admin))) { - // Send admin mail - sendAdminNotification($sub_adm, $message_admin, $content, getMemberId()); - } elseif (isAdminNotificationEnabled()) { - // Cannot send mails to admin! - $content = '{--CANNOT_SEND_ADMIN_MAILS--}'; - } else { - // No mail to admin - $content = '{--MEMBER_MYDATA_MAIL_SENT--}'; - } - } // END - if + if ((!empty($sub_adm)) && (!empty($message_admin)) && (isAdminNotificationEnabled())) { + // Send admin mail + sendAdminNotification($sub_adm, $message_admin, $content, getMemberId()); + } elseif (isAdminNotificationEnabled()) { + // Cannot send mails to admin! + $content['message'] = '{--CANNOT_SEND_ADMIN_MAILS--}'; + } else { + // No mail to admin + $content['message'] = '{--MEMBER_MYDATA_MAIL_SENT--}'; + } // Load template - loadTemplate('admin_settings_saved', false, $content); + loadTemplate('admin_settings_saved', false, $content['message']); } // Generates a 'selection box' from given array @@ -1576,12 +1575,12 @@ function generateSelectionBoxFromArray ($options, $name, $optionValue, $optionCo // Walk through all options foreach ($options as $option) { - // Add the '; } } // END - foreach @@ -1696,7 +1695,7 @@ function doTemplateColorSwitch ($template, $clear = false, $return = true) { // Switch color if called from loadTemplate() //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SWITCH:' . $template); $GLOBALS['color_switch'][$template] = 3 - $GLOBALS['color_switch'][$template]; - } // END - if + } // Return CSS class name if ($return === true) { diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 6aed1f77e9..74f30d01b0 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -1867,6 +1867,30 @@ function getActivateXchange () { return $GLOBALS[__FUNCTION__]; } +// "Getter" for img_type +function getImgType () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('img_type'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for code_length +function getCodeLength () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('code_length'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // Checks wether proxy configuration is used function isProxyUsed () { // Do we have cache? diff --git a/mailid_top.php b/mailid_top.php index ceb720dce3..8b812839c4 100644 --- a/mailid_top.php +++ b/mailid_top.php @@ -176,7 +176,7 @@ if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalEr $img_code = '0'; if (!empty($code)) { // Generate code - $img_code = generateRandomCode(getConfig('code_length'), $code, $userId, $urlId); + $img_code = generateRandomCode(getCodeLength(), $code, $userId, $urlId); } // END - if // @TODO Rewrite this to a filter @@ -316,7 +316,7 @@ if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalEr $content['type'] = $type; $content['data'] = $urlId; $content['banner'] = loadTemplate('mailid_banner', true); - if (getConfig('code_length') > 0) { + if (getCodeLength() > 0) { // Generate Code $content['image'] = generateCaptchaCode($code, $type, $urlId, $userId); $templ = 'mailid_enter_code'; -- 2.39.2