From bd6c043a3124914a3dc541b56400f551add987bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 24 Sep 2010 23:45:38 +0000 Subject: [PATCH] Fixed a triggered error in bigintval() --- inc/extensions/ext- | 5 + inc/extensions/ext-sponsor.php | 13 ++ inc/extensions/ext-surfbar.php | 2 +- inc/module-functions.php | 198 +++++++++++++++++++------------ inc/modules/guest/what-login.php | 2 +- 5 files changed, 140 insertions(+), 80 deletions(-) diff --git a/inc/extensions/ext- b/inc/extensions/ext- index 9ed104da1a..ffc09d4eff 100644 --- a/inc/extensions/ext- +++ b/inc/extensions/ext- @@ -52,6 +52,9 @@ enableExtensionProductive(false); switch (getExtensionMode()) { case 'register': // Do stuff when installation is running (modules.php?module=admin is called) // SQL commands to run + + // Register module + //addModuleSql('foo','Y','Y','N','N'); break; case 'remove': // Do stuff when removing extension @@ -60,10 +63,12 @@ switch (getExtensionMode()) { case 'activate': // Do stuff when admin activates this extension // SQL commands to run + //addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='N', `hidden`='N', `admin_only`='N', `mem_only`='N' WHERE `module`='foo' LIMIT 1"); break; case 'deactivate': // Do stuff when admin deactivates this extension // SQL commands to run + //addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='Y' WHERE `module`='foo' LIMIT 1"); break; case 'update': // Update an extension diff --git a/inc/extensions/ext-sponsor.php b/inc/extensions/ext-sponsor.php index db17a5eb8e..abab5c3624 100644 --- a/inc/extensions/ext-sponsor.php +++ b/inc/extensions/ext-sponsor.php @@ -372,6 +372,17 @@ PRIMARY KEY (`id`) // addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `sponsor_ref_points` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 100.00000"); addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `sponsor_min_points` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 1000.00000"); + // + // Register module + // + addModuleSql('sponsor','Y','Y','N','N'); + addModuleSql('sponsor_confirm','Y','Y','N','N'); + addModuleSql('sponsor_ref','Y','Y','N','N'); + + // Update name, if not yet set + addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `title`='Sponsorbereich' WHERE `module`='sponsor' AND `title`='' LIMIT 1"); + addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `title`='Sponsor-Bestätigung' WHERE `module`='sponsor_confirm' AND `title`='' LIMIT 1"); + addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `title`='Sponsor-Referallink' WHERE `module`='sponsor_ref' AND `title`='' LIMIT 1"); break; case 'remove': // Do stuff when removing extension @@ -399,6 +410,7 @@ PRIMARY KEY (`id`) addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what`='sponsor' LIMIT 1"); addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_sponsor_menu` SET `active`='Y' WHERE active='N'"); addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_sponsor_registry` SET `is_active`='Y' WHERE `is_active`='N'"); + addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='N', `hidden`='N', `admin_only`='N', `mem_only`='N' WHERE `module` IN ('sponsor','sponsor_confirm','sponsor_ref') LIMIT 3"); break; case 'deactivate': // Do stuff when admin deactivates this extension @@ -407,6 +419,7 @@ PRIMARY KEY (`id`) addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N', `locked`='Y' WHERE `what`='sponsor' LIMIT 1"); addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_sponsor_menu` SET `active`='N' WHERE `active`='Y'"); addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_sponsor_registry` SET `is_active`='N' WHERE `is_active`='Y'"); + addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='Y' WHERE `module` IN ('sponsor','sponsor_confirm','sponsor_ref') LIMIT 3"); break; case 'update': // Update an extension diff --git a/inc/extensions/ext-surfbar.php b/inc/extensions/ext-surfbar.php index 1e4f5313d1..1b4520f31f 100644 --- a/inc/extensions/ext-surfbar.php +++ b/inc/extensions/ext-surfbar.php @@ -194,7 +194,7 @@ UNIQUE KEY `status_action` (`actions_status`,`actions_action`) addAdminMenuSql('surfbar','list_surfbar_actions','Mitgliederaktionen','Listet alle Mitgliederaktionen auf.',6); // Register module - addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg` (`module`,`locked`,`hidden`,`admin_only`,`mem_only`) VALUES('surfbar','Y','Y','N','N')"); + addModuleSql('surfbar','Y','Y','N','N'); break; case 'remove': // Do stuff when removing extension diff --git a/inc/module-functions.php b/inc/module-functions.php index e9ca5598c5..724822eda0 100644 --- a/inc/module-functions.php +++ b/inc/module-functions.php @@ -94,50 +94,31 @@ function getModuleTitle ($module) { return $data['title']; } -// Check validity of a given module name (no file extension) -function checkModulePermissions ($module = '') { - // Is it empty (default), then take the current one - if (empty($module)) $module = getModule(); - - // Do we have cache? - if (isset($GLOBALS['module_status'][$module])) { - // Then use it - return $GLOBALS['module_status'][$module]; - } // END - if - - // Filter module name (names with low chars and underlines are fine!) - $module = preg_replace('/[^a-z_]/', '', $module); - - // Check for prefix is a extension... - $modSplit = explode('_', $module); - $extension = ''; $module_chk = $module; - //* DEBUG: */ debugOutput(__LINE__.'*'.count($modSplit).'/'.$module.'*'); - if (count($modSplit) == 2) { - // Okay, there is a seperator (_) in the name so is the first part a module? - //* DEBUG: */ debugOutput(__LINE__.'*'.$modSplit[0].'*'); - if (isExtensionActive($modSplit[0])) { - // The prefix is an extension's name, so let's set it - $extension = $modSplit[0]; $module = $modSplit[1]; - } // END - if - } // END - if +// Checks if module_status entry is there +function isModuleStatusSet ($module) { + // Check it + return (isset($GLOBALS['module_status'][$module])); +} - // Major error in module registry is the default - $ret = 'major'; +// Setter module status +function setModuleStatus ($module, $status) { + $GLOBALS['module_status'][$module] = $status; +} - // Check if script is installed if not return a 'done' to prevent some errors - if ((isInstallationPhase()) || (!isAdminRegistered())) { - // Not installed or no admin registered or in installation phase - return 'done'; +// Getter for module status +function getModuleStatus ($module) { + // Is the module_status entry there? + if (!isModuleStatusSet($module)) { + // Abort + debug_report_bug('Module status not set. module=' . $module); } // END - if - // Init data array - $data = array( - 'locked' => 'Y', - 'hidden' => 'N', - 'admin_only' => 'N', - 'mem_only' => 'N' - ); + // Return it + return $GLOBALS['module_status'][$module]; +} +// Checks wether the given module is registered +function isModuleRegistered ($module) { // By default nothing is found $found = false; @@ -145,72 +126,113 @@ function checkModulePermissions ($module = '') { if (isExtensionInstalledAndNewer('cache', '0.1.2')) { // Is the cache there? //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using cache.'); - if (isset($GLOBALS['cache_array']['modules']['locked'][$module_chk])) { - // Check cache - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache found.'); - $data['locked'] = $GLOBALS['cache_array']['modules']['locked'][$module_chk]; - $data['hidden'] = $GLOBALS['cache_array']['modules']['hidden'][$module_chk]; - $data['admin_only'] = $GLOBALS['cache_array']['modules']['admin_only'][$module_chk]; - $data['mem_only'] = $GLOBALS['cache_array']['modules']['mem_only'][$module_chk]; - + if (isset($GLOBALS['cache_array']['modules']['locked'][$module])) { // Update cache hits incrementStatsEntry('cache_hits'); + + // Is found $found = true; } else { // No, then we have to update it! - $ret = 'cache_miss'; + setModuleStatus($module, 'cache_miss'); } } elseif (!isExtensionActive('cache')) { // Check for module in database //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using database.'); $result = SQL_QUERY_ESC("SELECT `locked`, `hidden`, `admin_only`, `mem_only` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1", - array($module_chk), __FUNCTION__, __LINE__); + array($module), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) == 1) { // Read data //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Entry found.'); - $data = SQL_FETCHARRAY($result); + $GLOBALS['cache_array']['modules'][$module] = SQL_FETCHARRAY($result); $found = true; } elseif (isDebugModeEnabled()) { // Debug message only in debug-mode... - logDebugMessage(__FUNCTION__, __LINE__, 'Module ' . $module_chk . ' not found!'); + logDebugMessage(__FUNCTION__, __LINE__, 'Module ' . $module . ' not found!'); } // Free result SQL_FREERESULT($result); } - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret); + + // Return status + return $found; +} + +// Check validity of a given module name (no file extension) +function checkModulePermissions ($module = '') { + // Is it empty (default), then take the current one + if (empty($module)) $module = getModule(); + + // Do we have cache? + if (isModuleStatusSet($module)) { + // Then use it + return getModuleStatus($module); + } // END - if + + // Filter module name (names with low chars and underlines are fine!) + $module = preg_replace('/[^a-z_]/', '', $module); + + // Check for prefix is a extension... + $modSplit = explode('_', $module); + $extension = ''; $module_chk = $module; + //* DEBUG: */ debugOutput(__LINE__.'*'.count($modSplit).'/'.$module.'*'); + if (count($modSplit) == 2) { + // Okay, there is a seperator (_) in the name so is the first part a module? + //* DEBUG: */ debugOutput(__LINE__.'*'.$modSplit[0].'*'); + if (isExtensionActive($modSplit[0])) { + // The prefix is an extension's name, so let's set it + $extension = $modSplit[0]; $module = $modSplit[1]; + } // END - if + } // END - if + + // Major error in module registry is the default + setModuleStatus($module_chk, 'major'); + + // Check if script is installed if not return a 'done' to prevent some errors + if ((isInstallationPhase()) || (!isAdminRegistered())) { + // Not installed or no admin registered or in installation phase + // Set status + setModuleStatus($module_chk, 'done'); + + // Return status + return 'done'; + } // END - if + + // Check if the module is registered + $found = isModuleRegistered($module_chk); // Is the module found? if ($found === true) { // Check returned values against current access permissions // - // Admin access ----- Guest access ----- --- Guest or member? --- - if ((isAdmin()) || (($data['locked'] != 'Y') && ($data['admin_only'] != 'Y') && (($data['mem_only'] != 'Y') || (isMember())))) { + // Admin access ----- Guest access ----- --- Guest or member? --- + if ((isAdmin()) || (($GLOBALS['cache_array']['modules']['locked'][$module_chk] != 'Y') && ($GLOBALS['cache_array']['modules']['admin_only'][$module_chk] != 'Y') && (($GLOBALS['cache_array']['modules']['mem_only'][$module_chk] != 'Y') || (isMember())))) { // If you are admin you are welcome for everything! - $ret = 'done'; - } elseif ($data['locked'] == 'Y') { + setModuleStatus($module_chk, 'done'); + } elseif ($GLOBALS['cache_array']['modules']['locked'][$module_chk] == 'Y') { // Module is locked - $ret = 'locked'; - } elseif (($data['mem_only'] == 'Y') && (!isMember())) { + setModuleStatus($module_chk, 'locked'); + } elseif (($GLOBALS['cache_array']['modules']['mem_only'][$module_chk] == 'Y') && (!isMember())) { // You have to login first! - $ret = 'mem_only'; - } elseif (($data['admin_only'] == 'Y') && (!isAdmin())) { + setModuleStatus($module_chk, 'mem_only'); + } elseif (($GLOBALS['cache_array']['modules']['admin_only'][$module_chk] == 'Y') && (!isAdmin())) { // Only the Admin is allowed to enter this module! - $ret = 'admin_only'; + setModuleStatus($module_chk, 'admin_only'); } else { // @TODO Nothing helped??? logDebugMessage(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%s,admin=%s,mem=%s", - $ret, - $data['locked'], - $data['admin_only'], - $data['mem_only'] + getModuleStatus($module_chk), + $GLOBALS['cache_array']['modules']['locked'][$module_chk], + $GLOBALS['cache_array']['modules']['admin_only'][$module_chk], + $GLOBALS['cache_array']['modules']['mem_only'][$module_chk] )); } } // END - if // Still no luck or not found? - if (($found === false) && (!isExtensionActive('cache')) && ($ret != 'done')) { - // ----- Legacy module ----- ---- Module in base folder ---- --- Module with extension's name --- + if (($found === false) && (!isExtensionActive('cache')) && (getModuleStatus($module_chk) != 'done')) { + // ----- Legacy module ----- ---- Module in base folder ---- --- Module with extension's name --- if ((isIncludeReadable(sprintf("inc/modules/%s.php", $module))) || (isIncludeReadable(sprintf("%s.php", $module))) || (isIncludeReadable(sprintf("%s/%s.php", $extension, $module)))) { // Data is missing so we add it if (isExtensionInstalledAndNewer('sql_patches', '0.3.6')) { @@ -229,6 +251,7 @@ function checkModulePermissions ($module = '') { // Everthing is fine? if (SQL_AFFECTEDROWS() < 1) { // Something bad happend! + setModuleStatus($module_chk, 'major'); return 'major'; } // END - if @@ -237,13 +260,13 @@ function checkModulePermissions ($module = '') { if ((isHtmlOutputMode()) || (isRawOutputMode())) rebuildCache('modules', 'modules'); // And reload data - unset($GLOBALS['module_status'][$module]); - $ret = checkModulePermissions($module_chk); + unset($GLOBALS['module_status'][$module_chk]); + return checkModulePermissions($module_chk); } else { // Module not found we don't add it to the database - $ret = '404'; + setModuleStatus($module_chk, '404'); } - } elseif (($ret == 'cache_miss') && (isHtmlOutputMode())) { + } elseif ((getModuleStatus($module_chk) == 'cache_miss') && (isHtmlOutputMode())) { // Rebuild the cache files rebuildCache('modules', 'modules'); } elseif ($found === false) { @@ -251,18 +274,19 @@ function checkModulePermissions ($module = '') { logDebugMessage(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. ret=%s, locked=%s, hidden=%s, mem=%s, admin=%s, output_mode=%s", $module, $ret, - $data['locked'], - $data['hidden'], - $data['mem_only'], - $data['admin_only'], + $GLOBALS['cache_array']['modules']['locked'][$module_chk], + $GLOBALS['cache_array']['modules']['hidden'][$module_chk], + $GLOBALS['cache_array']['modules']['mem_only'][$module_chk], + $GLOBALS['cache_array']['modules']['admin_only'][$module_chk], getScriptOutputMode() )); } + // Debug log + logDebugMessage(__FUNCTION__, __LINE__, sprintf("module=%s, statyus=%s", $module_chk, getModuleStatus($module_chk))); + // Return the value - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret); - $GLOBALS['module_status'][$module] = $ret; - return $ret; + return getModuleStatus($module_chk); } // Checks if the module has a menu @@ -316,5 +340,23 @@ function ifModuleHasMenu ($mod, $forceDb = false) { return $ret; } +// Adds a SQL for given module +function addModuleSql ($module, $locked, $hidden, $adminOnly, $memOnly) { + // Is the module already registered? + if (!isModuleRegistered($module)) { + // Add it + addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg` (`module`,`locked`,`hidden`,`admin_only`,`mem_only`) VALUES('" . $module . "','" . $locked . "','" . $hidden . "','" . $adminOnly . "','" . $memOnly . "')"); + } else { + // Already registered + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Already registered: module=%s,locked=%s,hidden=%s,admin=%s,mem=%s", + $module, + $locked, + $hidden, + $adminOnly, + $memOnly + )); + } +} + // [EOF] ?> diff --git a/inc/modules/guest/what-login.php b/inc/modules/guest/what-login.php index 15863bb1f9..ca30263105 100644 --- a/inc/modules/guest/what-login.php +++ b/inc/modules/guest/what-login.php @@ -62,7 +62,7 @@ if ((isMemberIdSet()) && (isSessionVariableSet('u_hash'))) { $userid = getMemberId(); } elseif ((isPostRequestParameterSet('id')) && (isPostRequestParameterSet('password')) && (isFormSent())) { // Set userid and crypt password when login data was submitted - if (isExtensionActive('nickname')) { + if ((isExtensionActive('nickname')) && (isNicknameUsed(postRequestParameter('id')))) { // Nickname entered $userid = SQL_ESCAPE(postRequestParameter('id')); } else { -- 2.39.5