]> git.mxchange.org Git - ctracker.git/blobdiff - libs/lib_general.php
No more ORDER BY required, cool.
[ctracker.git] / libs / lib_general.php
index 3e14cb1c2c5c276cfedf1acf9433d01e362cbb41..84dd1bf0f7818a73db7c5189da467e2dc74f3260 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            3.0.0
- * @copyright  Copyright (c) 2009, 2010 Cracker Tracker Team
+ * @copyright  Copyright (c) 2009 - 2011 Cracker Tracker Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -73,14 +73,17 @@ if (!function_exists('implode_secure')) {
        } // END - function
 } // END - if
 
-// Getter for ctracker_debug
+// Getter for ctracker_debug_enabled
 function isCrackerTrackerDebug () {
        // Is it set?
-       return ((isset($GLOBALS['ctracker_debug'])) && ($GLOBALS['ctracker_debug'] === true));
+       return ((isset($GLOBALS['ctracker_debug_enabled'])) && ($GLOBALS['ctracker_debug_enabled'] === TRUE));
 }
 
 // Determines the real remote address
 function determineCrackerTrackerRealRemoteAddress () {
+       // Initial value
+       $address = '0.0.0.0';
+
        // Is a proxy in use?
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                // Proxy was used
@@ -88,9 +91,9 @@ function determineCrackerTrackerRealRemoteAddress () {
        } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
                // Yet, another proxy
                $address = $_SERVER['HTTP_CLIENT_IP'];
-       } else {
+       } elseif (isset($_SERVER['REMOTE_ADDR'])) {
                // The regular address when no proxy was used
-               $address = $_SERVER['REMOTE_ADDR'];
+               $address = getenv('REMOTE_ADDR');
        }
 
        // This strips out the real address from proxy output
@@ -119,8 +122,8 @@ function crackerTrackerUserAgent () {
 
        // Is the entry there?
        if (isset($_SERVER['HTTP_USER_AGENT'])) {
-               // Then use it
-               $ua = $_SERVER['HTTP_USER_AGENT'];
+               // Then use it securely
+               $ua = crackerTrackerSecureString($_SERVER['HTTP_USER_AGENT']);
        } // END - if
 
        // Return it
@@ -129,18 +132,36 @@ function crackerTrackerUserAgent () {
 
 // Detects the script name
 function crackerTrackerScriptName () {
+       // Is it there?
+       if (!isset($_SERVER['SCRIPT_NAME'])) {
+               // Return NULL
+               return NULL;
+       } // END - if
+
        // Should always be there!
        return crackerTrackerSecureString($_SERVER['SCRIPT_NAME']);
 }
 
 // Detects the query string
 function crackerTrackerQueryString () {
+       // Is it there?
+       if (!isset($_SERVER['QUERY_STRING'])) {
+               // Return NULL
+               return NULL;
+       } // END - if
+
        // Should always be there!
-       return crackerTrackerEscapeString($_SERVER['QUERY_STRING']);
+       return crackerTrackerEscapeString(urldecode($_SERVER['QUERY_STRING']));
 }
 
 // Detects the server's name
 function crackerTrackerServerName () {
+       // Is it there?
+       if (!isset($_SERVER['SERVER_NAME'])) {
+               // Return NULL
+               return NULL;
+       } // END - if
+
        // Should always be there!
        return crackerTrackerSecureString($_SERVER['SERVER_NAME']);
 }
@@ -153,7 +174,7 @@ function crackerTrackerReferer () {
        // Is it there?
        if (isset($_SERVER['HTTP_REFERER'])) {
                // Then use it securely
-               $referer = crackerTrackerSecureString($_SERVER['HTTP_REFERER']);
+               $referer = crackerTrackerSecureString(urldecode($_SERVER['HTTP_REFERER']));
        } // END - if
 
        // Return it
@@ -199,7 +220,7 @@ function isCrackerTrackerFileFound ($FQFN) {
 // Loads a given "template" (this is more an include file)
 function crackerTrackerLoadTemplate ($template) {
        // Create the full-qualified filename (FQFN)
-       $FQFN = sprintf("%s/templates/%s.tpl.php",
+       $FQFN = sprintf('%s/templates/%s.tpl.php',
                dirname(__FILE__),
                $template
        );
@@ -220,7 +241,7 @@ function crackerTrackerLoadTemplate ($template) {
 // Loads a given "template" (this is more an include file)
 function crackerTrackerLoadLocalizedTemplate ($template) {
        // Create the full-qualified filename (FQFN)
-       $FQFN = sprintf("%s/templates/%s/%s.tpl.php",
+       $FQFN = sprintf('%s/templates/%s/%s.tpl.php',
                dirname(__FILE__),
                getCrackerTrackerLanguage(),
                $template
@@ -259,7 +280,7 @@ function crackerTrackerLanguage () {
        } // END - if
 
        // Construct FQFN
-       $FQFN = sprintf("%s/language/%s.php",
+       $FQFN = sprintf('%s/language/%s.php',
                dirname(__FILE__),
                getCrackerTrackerLanguage()
        );
@@ -270,9 +291,7 @@ function crackerTrackerLanguage () {
                $GLOBALS['ctracker_language'] = 'en';
 
                // Construct FQFN again
-               $FQFN = sprintf("%s/language/en.php",
-                       dirname(__FILE__)
-               );
+               $FQFN = sprintf('%s/language/en.php', dirname(__FILE__));
        } // END - if
 
        // Load the language file
@@ -280,12 +299,12 @@ function crackerTrackerLanguage () {
 }
 
 // Loads a given email template and passes through $content
-function crackerTrackerLoadEmailTemplate ($template, array $content = array(), $language) {
+function crackerTrackerLoadEmailTemplate ($template, array $content = array(), $language = NULL) {
        // Init language
        crackerTrackerLanguage();
 
        // Generate the FQFN
-       $FQFN = sprintf("%s/mails/%s/%s.tpl",
+       $FQFN = sprintf('%s/mails/%s/%s.tpl',
                dirname(__FILE__),
                getCrackerTrackerLanguage($language),
                $template
@@ -331,12 +350,21 @@ function crackerTrackerOutputLocalized ($message) {
 // Compiles the given code
 function crackerTrackerCompileCode ($code) {
        // Find all $content[foo]
-       preg_match_all('/\$content((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches);
+       preg_match_all('/\$(content|GLOBALS)((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches);
+
+       // Replace " with {QUOTE}
+       $code = str_replace('"', '{QUOTE}', $code);
 
        // Replace all
        foreach ($matches[0] as $key=>$match) {
                // Replace it
-               $code = str_replace($match, "\" . \$content['" . $matches[3][$key] . "'] . \"", $code);
+               if (substr($match, 0, 8) == '$GLOBALS') {
+                       // $GLOBALS
+                       $code = str_replace($match, "\" . \$GLOBALS['" . $matches[4][$key] . "'] . \"", $code);
+               } elseif (substr($match, 0, 8) == '$content') {
+                       // $content
+                       $code = str_replace($match, "\" . \$content['" . $matches[4][$key] . "'] . \"", $code);
+               }
        } // END - foreach
 
        // Return it
@@ -344,7 +372,7 @@ function crackerTrackerCompileCode ($code) {
 }
 
 // "Getter" for language
-function getCrackerTrackerLanguage ($lang = null) {
+function getCrackerTrackerLanguage ($lang = NULL) {
        // Default is from browser
        $language = $GLOBALS['ctracker_language'];
 
@@ -377,7 +405,7 @@ function getCrackerTrackerTicketId () {
 function sendCrackerTrackerCookie () {
        // Set the cookie
        // @TODO Why can't domain be set to value from crackerTrackerServerName() ?
-       setcookie('ctracker_ticket', getCrackerTrackerTicketId(), (time() + 60*60*24), '/', '', crackerTrackerSecured(), true);
+       setcookie('ctracker_ticket', getCrackerTrackerTicketId(), (time() + 60*60*24), '/', '', crackerTrackerSecured(), TRUE);
        $_COOKIE['ctracker_ticket'] = getCrackerTrackerTicketId();
 }
 
@@ -402,24 +430,23 @@ function crackerTrackerRedirectSameUrl () {
        }
 
        // And redirect
-       sendRawRedirect($url);
+       crackerTrackerSendRawRedirect($url);
 }
 
 /**
- * Send a HTTP redirect to the browser. This function wass taken from DokuWiki
+ * Send a HTTP redirect to the browser. This function was taken from DokuWiki
  * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into this script.
  *
- * ----------------------------------------------------------------------------
- * If you want to redirect, please use redirectToUrl(); instead
- * ----------------------------------------------------------------------------
- *
  * Works arround Microsoft IIS cookie sending bug. Does exit the script.
  *
  * @link    http://support.microsoft.com/kb/q176113/
  * @author  Andreas Gohr <andi@splitbrain.org>
  * @access  private
  */
-function sendRawRedirect ($url) {
+function crackerTrackerSendRawRedirect ($url) {
+       // Better remove any data by ctracker
+       unsetCtrackerData();
+
        // always close the session
        session_write_close();
 
@@ -428,7 +455,7 @@ function sendRawRedirect ($url) {
 
        // check if running on IIS < 6 with CGI-PHP
        if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
-               (strpos($_SERVER['GATEWAY_INTERFACE'],'CGI') !== false) &&
+               (strpos($_SERVER['GATEWAY_INTERFACE'],'CGI') !== FALSE) &&
                (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
                ($matches[1] < 6)) {
                // Send the IIS header
@@ -440,5 +467,35 @@ function sendRawRedirect ($url) {
        exit();
 }
 
+// Removes all ctracker-related data from global space
+function unsetCtrackerData () {
+       // Unset all ctracker data
+       foreach (array(
+                       'ctracker_host',
+                       'ctracker_dbname',
+                       'ctracker_user',
+                       'ctracker_password',
+                       'ctracker_debug_enabled',
+                       'ctracker_email',
+                       'ctracker_whitelist',
+                       'ctracker_get_blacklist',
+                       'ctracker_post_blacklist',
+                       'ctracker_header',
+                       'ctracker_post_track',
+                       'ctracker_checkworm',
+                       'ctracker_check_post',
+                       'ctracker_last_sql',
+                       'ctracker_last_result',
+                       'ctracker_config',
+                       'ctracker_updates',
+                       'ctracker_language',
+                       'ctracker_localized',
+                       'ctracker_link',
+               ) as $key) {
+                       // Unset it
+                       unset($GLOBALS[$key]);
+       } // END - foreach
+}
+
 // [EOF]
 ?>