-// Generate an PGP-like encrypted hash of given hash for e.g. cookies
-function generatePassString ($passHash) {
- // Return vanilla password hash
- $ret = $passHash;
-
- // Is a secret key and master salt already initialized?
- if ((getConfig('secret_key') != '') && (getConfig('master_salt') != '')) {
- // Only calculate when the secret key is generated
- $newHash = ''; $start = 9;
- for ($idx = 0; $idx < 10; $idx++) {
- $part1 = hexdec(substr($passHash, $start, 4));
- $part2 = hexdec(substr(getConfig('secret_key'), $start, 4));
- $mod = dechex($idx);
- if ($part1 > $part2) {
- $mod = dechex(sqrt(($part1 - $part2) * getConfig('_PRIME') / pi()));
- } elseif ($part2 > $part1) {
- $mod = dechex(sqrt(($part2 - $part1) * getConfig('_PRIME') / pi()));
- }
- $mod = substr(round($mod), 0, 4);
- $mod = str_repeat('0', 4-strlen($mod)) . $mod;
- //* DEBUG: */ echo "*" . $start.'=' . $mod."*<br />";
- $start += 4;
- $newHash .= $mod;
- } // END - for
-
- //* DEBUG: */ print($passHash."<br />" . $newHash." (".strlen($newHash).')');
- $ret = generateHash($newHash, getConfig('master_salt'));
- //* DEBUG: */ print($ret."<br />\n");
- } else {
- // Hash it simple
- //* DEBUG: */ echo "--" . $passHash."--<br />\n";
- $ret = md5($passHash);
- //* DEBUG: */ echo "++" . $ret."++<br />\n";
- }
-
- // Return result
- return $ret;
-}
-
-// Fix "deleted" cookies
-function fixDeletedCookies ($cookies) {
- // Is this an array with entries?
- if ((is_array($cookies)) && (count($cookies) > 0)) {
- // Then check all cookies if they are marked as deleted!
- foreach ($cookies as $cookieName) {
- // Is the cookie set to "deleted"?
- if (getSession($cookieName) == 'deleted') {
- setSession($cookieName, '');
- } // END - if
- } // END - foreach
- } // END - if
-}
-
-// 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;
-
- // Load header
- loadIncludeOnce('inc/header.php');
-
- // Rewrite message for output
- $message = sprintf(getMessage('MXCHANGE_HAS_DIED'), basename($F), $L, $message);
-
- // Better log this message away
- DEBUG_LOG($F, $L, $message);
-
- // Load the message template
- LOAD_TEMPLATE('admin_settings_saved', false, $message);
-
- // Load footer
- loadIncludeOnce('inc/footer.php');
- } else {
- // Script tried to kill itself twice
- debug_report_bug('Script wanted to kill itself more than once! Raw message=' . $message . ', file/function=' . $F . ', line=' . $L);
- }
-}
-
-// Display parsing time and number of SQL queries in footer
-function displayParsingTime() {
- // Is the timer started?
- if (!isset($GLOBALS['startTime'])) {
- // Abort here
- return false;
- } // END - if
-
- // Get end time
- $endTime = microtime(true);
-
- // "Explode" both times
- $start = explode(' ', $GLOBALS['startTime']);
- $end = explode(' ', $endTime);
- $runTime = $end[0] - $start[0];
- if ($runTime < 0) $runTime = 0;
- $runTime = translateComma($runTime);
-
- // Prepare output
- $content = array(
- 'runtime' => $runTime,
- 'numSQLs' => (getConfig('sql_count') + 1),
- 'numTemplates' => (getConfig('num_templates') + 1)
- );
-
- // Load the template
- LOAD_TEMPLATE('show_timings', false, $content);
-}
-
-// Check wether a boolean constant is set
-// Taken from user comments in PHP documentation for function constant()
-function isBooleanConstantAndTrue ($constName) { // : Boolean
- // Failed by default
- $res = false;
-
- // In cache?
- if (isset($GLOBALS['cache_array']['const'][$constName])) {
- // Use cache
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): " . $constName."-CACHE!<br />\n";
- $res = ($GLOBALS['cache_array']['const'][$constName] === true);
- } else {
- // Check constant
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): " . $constName."-RESOLVE!<br />\n";
- if (defined($constName)) {
- // Found!
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): " . $constName."-FOUND!<br />\n";
- $res = (constant($constName) === true);
- } // END - if
-
- // Set cache
- $GLOBALS['cache_array']['const'][$constName] = $res;
- }
- //* DEBUG: */ var_dump($res);
-
- // Return value
- return $res;
-}
-
-// Checks if a given apache module is loaded
-function isApacheModuleLoaded ($apacheModule) {
- // Check it and return result
- return (((function_exists('apache_get_modules')) && (in_array($apacheModule, apache_get_modules()))) || (!function_exists('apache_get_modules')));
-}
-
-// Get current theme name
-function getCurrentTheme() {
- // The default theme is 'default'... ;-)
- $ret = 'default';
-
- // Load default theme if not empty from configuration
- if (getConfig('default_theme') != '') $ret = getConfig('default_theme');
-
- if (!isSessionVariableSet('mxchange_theme')) {
- // Set default theme
- setSession('mxchange_theme', $ret);
- } elseif ((isSessionVariableSet('mxchange_theme')) && (GET_EXT_VERSION('sql_patches') >= '0.1.4')) {
- //die("<pre>".print_r($GLOBALS['cache_array']['themes'], true)."</pre>");
- // Get theme from cookie
- $ret = getSession('mxchange_theme');
-
- // Is it valid?
- if (getThemeId($ret) == 0) {
- // Fix it to default
- $ret = 'default';
- } // END - if
- } elseif ((!isInstalled()) && ((isInstalling()) || (getOutputMode() == true)) && ((REQUEST_ISSET_GET('theme')) || (REQUEST_ISSET_POST('theme')))) {
- // Prepare FQFN for checking
- $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), REQUEST_GET('theme'));
-
- // Installation mode active
- if ((REQUEST_ISSET_GET('theme')) && (isFileReadable($theme))) {
- // Set cookie from URL data
- setSession('mxchange_theme', REQUEST_GET('theme'));
- } elseif (isFileReadable(sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE(REQUEST_POST('theme'))))) {
- // Set cookie from posted data
- setSession('mxchange_theme', SQL_ESCAPE(REQUEST_POST('theme')));
- }
-
- // Set return value
- $ret = getSession('mxchange_theme');
- } else {
- // Invalid design, reset cookie
- setSession('mxchange_theme', $ret);
- }
-
- // Add (maybe) found theme.php file to inclusion list
- $INC = sprintf("theme/%s/theme.php", SQL_ESCAPE($ret));
-
- // Try to load the requested include file
- if (isIncludeReadable($INC)) ADD_INC_TO_POOL($INC);
-
- // Return theme value
- return $ret;
-}
-
-// Get id from theme
-function getThemeId ($name) {
- // Is the extension 'theme' installed?
- if (!EXT_IS_ACTIVE('theme')) {
- // Then abort here
- return 0;
- } // END - if
-
- // Default id
- $id = 0;
-
- // Is the cache entry there?
- if (isset($GLOBALS['cache_array']['themes']['id'][$name])) {
- // Get the version from cache
- $id = $GLOBALS['cache_array']['themes']['id'][$name];
-
- // Count up
- incrementConfigEntry('cache_hits');
- } elseif (GET_EXT_VERSION('cache') != '0.1.8') {
- // Check if current theme is already imported or not
- $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' LIMIT 1",
- array($name), __FUNCTION__, __LINE__);
-
- // Entry found?
- if (SQL_NUMROWS($result) == 1) {
- // Fetch data
- list($id) = SQL_FETCHROW($result);
- } // END - if
-
- // Free result
- SQL_FREERESULT($result);
- }
-
- // Return id
- return $id;
-}
-
-// Generates an error code from given account status
-function generateErrorCodeFromUserStatus ($status) {
- // @TODO The status should never be empty
- if (empty($status)) {
- // Something really bad happend here
- debug_report_bug(__FUNCTION__ . ': status is empty.');
- } // END - if
-
- // Default error code if unknown account status
- $errorCode = getCode('UNKNOWN_STATUS');
-
- // Generate constant name
- $constantName = sprintf("ID_%s", $status);
-
- // Is the constant there?
- if (isCodeSet($constantName)) {
- // Then get it!
- $errorCode = getCode($constantName);
- } else {
- // Unknown status
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown error status %s detected.", $status));
- }
-
- // Return error code
- return $errorCode;
-}
-
-// Function to search for the last modifified file
-function searchDirsRecursive ($dir, &$last_changed) {
- // Get dir as array
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):dir=" . $dir."<br />\n";
- // Does it match what we are looking for? (We skip a lot files already!)
- // RegexPattern to exclude ., .., .revision, .svn, debug.log or .cache in the filenames
- $excludePattern = '@(\.|\.\.|\.revision|\.svn|debug\.log|\.cache|config\.php)$@';
- $ds = getArrayFromDirectory($dir, '', true, false, $excludePattern);
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ds[]=".count($ds)."<br />\n";
-
- // Walk through all entries
- foreach ($ds as $d) {
- // Generate proper FQFN
- $FQFN = str_replace("//", '/', constant('PATH') . $dir. '/'. $d);
-
- // Is it a file and readable?
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):FQFN={$FQFN}<br />\n";
- if (isDirectory($FQFN)) {
- // $FQFN is a directory so also crawl into this directory
- $newDir = $d;
- if (!empty($dir)) $newDir = $dir . '/'. $d;
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):DESCENT: " . $newDir."<br />\n";
- searchDirsRecursive($newDir, $last_changed);
- } elseif (isFileReadable($FQFN)) {
- // $FQFN is a filename and no directory
- $time = filemtime($FQFN);
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):File: " . $d." found. (".($last_changed['time'] - $time).")<br />\n";
- if ($last_changed['time'] < $time) {
- // This file is newer as the file before
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>) - NEWER!<br />\n";
- $last_changed['path_name'] = $FQFN;
- $last_changed['time'] = $time;
- } // END - if
- }
- } // END - foreach
-}
-
-// "Getter" for revision/version data
-function getActualVersion ($type = 'Revision') {
- // By default nothing is new... ;-)
- $new = false;
-
- if (EXT_IS_ACTIVE('cache')) {
- // Check if REQUEST_GET('check_revision_data') is setted (switch for manually rewrite the .revision-File)
- if (REQUEST_ISSET_GET('check_revision_data') && REQUEST_GET('check_revision_data') == 'yes') {
- // Force rebuild by URL parameter
- $new = true;
- } elseif ((
- !isset($GLOBALS['cache_array']['revision'][$type])
- ) || (
- count($GLOBALS['cache_array']['revision']) < 3
- ) || (
- !$GLOBALS['cache_instance']->loadCacheFile('revision')
- )) {
- // Out-dated cache
- $new = true;
- } // END - if
-
- // Is the cache file outdated/invalid?
- if ($new === true){
- // Destroy cache file
- $GLOBALS['cache_instance']->destroyCacheFile();
-
- // @TODO shouldn't do the unset and the reloading $GLOBALS['cache_instance']->destroyCacheFile() Or a new methode like forceCacheReload('revision')?
- unset($GLOBALS['cache_array']['revision']);
-
- // Reload load_cach-revison.php
- loadInclude('inc/loader/load_cache-revision.php');
-
- // Abort here
- return;
- } // END - if
-
- // Return found value
- return $GLOBALS['cache_array']['revision'][$type][0];
- } else {
- // Old Version without ext-cache active (deprecated ?)
-
- // FQFN of revision file
- $FQFN = sprintf("%sinc/cache/.revision", constant('PATH'));
-
- // Check if REQUEST_GET('check_revision_data') is setted (switch for manually rewrite the .revision-File)
- if ((REQUEST_ISSET_GET('check_revision_data')) && (REQUEST_GET('check_revision_data') == 'yes')) {
- // Forced rebuild of .revision file
- $new = true;
- } else {
- // Check for revision file
- if (!isFileReadable($FQFN)) {
- // Not found, so we need to create it
- $new = true;
- } else {
- // Revision file found
- $ins_vers = explode("\n", readFromFile($FQFN));