Fixes/rewrites for missing sql_patches and check on admin's default access mode ...
[mailer.git] / inc / functions.php
index 44ba689b58698b62acb3820db3fe324c990c9053..c875a91aee04841958e6e8b7fc6116a155c61fca 100644 (file)
@@ -80,7 +80,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
                default:
                        // Huh, something goes wrong or maybe you have edited config.php ???
                        DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid renderer %s detected.", constant('OUTPUT_MODE')));
-                       mxchange_die("<strong>{--FATAL_ERROR--}:</strong> {--LANG_NO_RENDER_DIRECT--}");
+                       app_die(__FUNCTION__, __LINE__, "<strong>{--FATAL_ERROR--}:</strong> {--LANG_NO_RENDER_DIRECT--}");
                        break;
                }
        } elseif ((constant('_OB_CACHING') == "on") && (isset($GLOBALS['footer_sent'])) && ($GLOBALS['footer_sent'] == 1)) {
@@ -129,7 +129,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
                        // Was that eval okay?
                        if (empty($newContent)) {
                                // Something went wrong!
-                               mxchange_die("Evaluation error:<pre>".htmlentities($eval)."</pre>");
+                               app_die(__FUNCTION__, __LINE__, "Evaluation error:<pre>".htmlentities($eval)."</pre>");
                        } // END - if
                        $OUTPUT = $newContent;
                } // END - while
@@ -2233,10 +2233,13 @@ function FIX_DELETED_COOKIES ($cookies) {
 }
 
 // Output error messages in a fasioned way and die...
-function mxchange_die ($msg) {
+function app_die ($F, $L, $msg) {
        // Load header
        LOAD_INC_ONCE("inc/header.php");
 
+       // Prepare message for output
+       $msg = sprintf(getMessage('MXCHANGE_HAS_DIED'), basename($F), $L, $msg);
+
        // Load the message template
        LOAD_TEMPLATE("admin_settings_saved", false, $msg);
 
@@ -2466,7 +2469,7 @@ function WRITE_FILE ($FQFN, $content) {
                $return = file_put_contents($FQFN, $content);
        } else {
                // Write it with fopen
-               $fp = fopen($FQFN, 'w') or mxchange_die("Cannot write file ".basename($FQFN)."!");
+               $fp = fopen($FQFN, 'w') or app_die(__FUNCTION__, __LINE__, "Cannot write file ".basename($FQFN)."!");
                fwrite($fp, $content);
                fclose($fp);
 
@@ -2512,7 +2515,10 @@ function clearOutputBuffer () {
 function searchDirsRecursive ($dir, &$last_changed) {
        // Get dir as array
        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):dir=".$dir."<br />\n";
-       $ds = GET_DIR_AS_ARRAY($dir, "", true, false);
+       // 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 = GET_DIR_AS_ARRAY($dir, "", true, false, $excludePattern);
        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ds[]=".count($ds)."<br />\n";
 
        // Walk through all entries
@@ -2520,29 +2526,25 @@ function searchDirsRecursive ($dir, &$last_changed) {
                // Generate proper FQFN
                $FQFN = str_replace("//", "/", constant('PATH') . $dir. "/". $d);
 
-               // Does it match what we are looking for? (We skip a lot files already!)
-               if (!preg_match('@(\.|\.\.|\.revision|\.svn|debug\.log|\.cache|config\.php)$@', $d)) {          // no ., .., .revision,  .svn, debug.log or .cache in the filename
-
-                       // 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 (FILE_READABLE($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 - if
+               // 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 (FILE_READABLE($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
 }
 
@@ -2757,7 +2759,7 @@ function debug_report_bug ($message = "") {
        $debug .= "Thank you for finding bugs.";
 
        // And abort here
-       // @TODO This cannot be rewritten to mxchange_die(), try to find a solution for this.
+       // @TODO This cannot be rewritten to app_die(), try to find a solution for this.
        die($debug);
 }
 
@@ -2830,9 +2832,11 @@ function GENERATE_AID_LINK ($aid) {
        $admin = "<span class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</span>";
 
        // Zero? = Not assigned
-       if ($aid > 0) {
+       if (bigintval($aid) > 0) {
                // Load admin's login
                $login = GET_ADMIN_LOGIN($aid);
+
+               // Is the login valid?
                if ($login != "***") {
                        // Is the extension there?
                        if (EXT_IS_ACTIVE("admins")) {
@@ -3090,7 +3094,7 @@ function DEBUG_LOG ($funcFile, $line, $message, $force=true) {
                $message = str_replace("\r", "", str_replace("\n", "", $message));
 
                // Log this message away
-               $fp = fopen(constant('PATH')."inc/cache/debug.log", 'a') or mxchange_die("Cannot write logfile debug.log!");
+               $fp = fopen(constant('PATH')."inc/cache/debug.log", 'a') or app_die(__FUNCTION__, __LINE__, "Cannot write logfile debug.log!");
                fwrite($fp, date("d.m.Y|H:i:s", time())."|".basename($funcFile)."|".$line."|".strip_tags($message)."\n");
                fclose($fp);
        } // END - if
@@ -3315,7 +3319,7 @@ function CACHE_PURGE_ADMIN_MENU ($id=0, $action="", $what="", $str="") {
 
 // Translates the "pool type" into human-readable
 function TRANSLATE_POOL_TYPE ($type) {
-       // Default type is unknown
+       // Default?type is unknown
        $translated = sprintf(getMessage('POOL_TYPE_UNKNOWN'), $type);
 
        // Generate constant
@@ -3331,10 +3335,34 @@ function TRANSLATE_POOL_TYPE ($type) {
        return $translated;
 }
 
+// Determines the real remote address
+function determineRealRemoteAddress () {
+       // Is a proxy in use?
+       if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
+               // Proxy was used
+               $address = $_SERVER['HTTP_X_FORWARDED_FOR'];
+       } elseif (isset($_SERVER['HTTP_CLIENT_IP'])){
+               // Yet, another proxy
+               $address = $_SERVER['HTTP_CLIENT_IP'];
+       } else {
+               // The regular address when no proxy was used
+               $address = $_SERVER['REMOTE_ADDR'];
+       }
+
+       // This strips out the real address from proxy output
+       if (strstr($address, ",")){
+               $addressArray = explode(",", $address);
+               $address = $addressArray[0];
+       } // END - if
+
+       // Return the result
+       return $address;
+}
+
 // "Getter" for remote IP number
 function GET_REMOTE_ADDR () {
        // Get remote ip from environment
-       $remoteAddr = getenv('REMOTE_ADDR');
+       $remoteAddr = determineRealRemoteAddress();
 
        // Is removeip installed?
        if (EXT_IS_ACTIVE("removeip")) {