* Fix bugs #3326 and #3392: problems with php_uname()
authorMartin Kutschker <martin.t.kutschker@blackbox.net>
Fri, 2 Jun 2006 12:08:43 +0000 (12:08 +0000)
committerMartin Kutschker <martin.t.kutschker@blackbox.net>
Fri, 2 Jun 2006 12:08:43 +0000 (12:08 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@1501 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
t3lib/class.t3lib_htmlmail.php

index f25e01f..9a8c068 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
 
        * Fix bug #3612: no c-prefix for URL fragment in menus (section index)
        * Fix bug #2493: TCE-forms don't skins icons / t3skin lacks undo.gif, csv.gif and savedoknew.gif (thanks to Clemens Riccabona for the latter)
+       * Fix bugs #3326 and #3392: problems with php_uname()
 
 2006-05-31  Ernesto Baschny <ernst@cron-it.de>
 
index 0a8c385..49b3d20 100755 (executable)
@@ -3202,6 +3202,37 @@ class t3lib_div {
                return $bInfo;
        }
 
+       /**
+        * Get the fully-qualified domain name of the host.
+        * Usage: 2
+        *
+        * @param       boolean         Use request host (when not in CLI mode).
+        * @return      string          The fully-qualified host name.
+        */
+       function getHostname($requestHost=TRUE) {
+               $host = '';
+               if ($requestHost && (!defined('TYPO3_cliMode') || !TYPO3_cliMode))      {
+                       $host = $_SERVER['HTTP_HOST'];
+               }
+               if (!$host)     {
+                               // will fail for PHP 4.1 and 4.2
+                       $host = @php_uname('n');
+                               // 'n' is ignored in broken installations
+                       if (strpos($host, ' ')) $host = '';
+               }
+                       // we have not found a FQDN yet
+               if ($host && strpos('.',$host) === FALSE)       {
+                       $ip = gethostbyname($host);
+                               // we got an IP address
+                       if ($ip != $host)       {
+                               $fqdn = gethostbyaddr($ip);
+                               if ($ip != $fqdn)       $host = $fqdn;
+                       }
+               }
+               if (!$host)     $host = 'localhost.localdomain';
+
+               return $host;
+       }
 
 
 
@@ -4237,18 +4268,11 @@ class t3lib_div {
 
                        // for CLI logging name is <fqdn-hostname>:<TYPO3-path>
                if (defined('TYPO3_cliMode') && TYPO3_cliMode)  {
-                               // find FQDN
-                       $host = php_uname('n');
-                       if (strpos($host,'.') === FALSE)        {
-                               $ip = gethostbyname($host);
-                               $fqdn = gethostbyaddr($ip);
-                               if ($ip != $fqdn)       $host = $fqdn;
-                       }
-                       $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = $TYPO3_CONF_VARS['SYS']['systemLogHost'] = $host.':'.PATH_site;
+                       $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = t3lib_div::getHostname(FALSE).':'.PATH_site;
                }
-                       // for Web logging name is <protocol>://<request-hostame>
+                       // for Web logging name is <protocol>://<request-hostame>/<site-path>
                else {
-                       $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
+                       $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
                }
 
                        // init custom logging
index 7ee6dfd..93612d2 100755 (executable)
@@ -269,11 +269,8 @@ class t3lib_htmlmail {
                global $TYPO3_CONF_VARS;
 
                        // Sets the message id
-               $host = php_uname('n');
-               if (strpos('.',$host) === FALSE) {
-                       $host = gethostbyaddr(gethostbyname($host));
-               }
-               if (!$host || $host == '127.0.0.1' || $host == 'localhost') {
+               $host = t3lib_div::getHostname();
+               if (!$host || $host == '127.0.0.1' || $host == 'localhost' || $host == 'localhost.localdomain') {
                        $host = ($TYPO3_CONF_VARS['SYS']['sitename'] ? preg_replace('/[^A-Za-z0-9_\-]/', '_', $TYPO3_CONF_VARS['SYS']['sitename']) : 'localhost') . '.TYPO3';
                }
                $this->messageid = md5(microtime()) . '@' . $host;
@@ -1431,4 +1428,4 @@ class t3lib_htmlmail {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']) {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']);
 }
-?>
\ No newline at end of file
+?>