* Added TypoScript condition "hostname" for matching hostnames for IP addresses.
authorKasper Skårhøj <kasper@typo3.org>
Fri, 23 Apr 2004 15:28:40 +0000 (15:28 +0000)
committerKasper Skårhøj <kasper@typo3.org>
Fri, 23 Apr 2004 15:28:40 +0000 (15:28 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@225 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
t3lib/class.t3lib_matchcondition.php

index 45da238..60af395 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2004-04-23  Kasper Skårhøj,,,  <kasper@typo3.com>
 
+       * Added TypoScript condition "hostname" for matching hostnames for IP addresses.
+
+2004-04-23  Kasper Skårhøj,,,  <kasper@typo3.com>
+
        * Added API for configuring extra tables/fields for listing in Web > Page
 
 2004-04-23  Kasper Skårhøj,,,  <kasper@typo3.com>
index 81caaeb..fa2a02a 100755 (executable)
@@ -570,20 +570,19 @@ class t3lib_div {
                $IPpartsReq = explode('.',$baseIP);
                if (count($IPpartsReq)==4)      {
                        $values = t3lib_div::trimExplode(',',$list,1);
-                       reset($values);
-                       while(list(,$test)=each($values))       {
+
+                       foreach($values as $test)       {
                                list($test,$mask) = explode('/',$test);
 
                                if(intval($mask)) {
                                                // "192.168.3.0/24"
-                                       $lnet=ip2long($test);
-                                       $lip=ip2long($baseIP);
-                                       $binnet=str_pad( decbin($lnet),32,"0","STR_PAD_LEFT" );
-                                       $firstpart=substr($binnet,0,$mask);
-                                       $binip=str_pad( decbin($lip),32,"0","STR_PAD_LEFT" );
-                                       $firstip=substr($binip,0,$mask);
-                                       $yes=(strcmp($firstpart,$firstip)==0);
-
+                                       $lnet = ip2long($test);
+                                       $lip = ip2long($baseIP);
+                                       $binnet = str_pad( decbin($lnet),32,"0","STR_PAD_LEFT" );
+                                       $firstpart = substr($binnet,0,$mask);
+                                       $binip = str_pad( decbin($lip),32,"0","STR_PAD_LEFT" );
+                                       $firstip = substr($binip,0,$mask);
+                                       $yes = (strcmp($firstpart,$firstip)==0);
                                } else {
                                                // "192.168.*.*"
                                        $IPparts = explode('.',$test);
@@ -603,6 +602,34 @@ class t3lib_div {
        }
 
        /**
+        * Match fully qualified domain name with list of strings with wildcard
+        *
+        * @param       string         $baseIP is the current remote IP address for instance, typ. REMOTE_ADDR
+        * @param       string          $list is a comma-list of domain names to match with. *-wildcard allowed but cannot be part of a string, so it must match the full host name (eg. myhost.*.com => correct, myhost.*domain.com => wrong)
+        * @return      boolean         True if a domain name mask from $list matches $baseIP
+        */
+       function cmpFQDN($baseIP, $list)        {
+               if (count(explode('.',$baseIP))==4)     {
+                       $resolvedHostName = explode('.', gethostbyaddr($baseIP));
+                       $values = t3lib_div::trimExplode(',',$list,1);
+
+                       foreach($values as $test)       {
+                               $hostNameParts = explode('.',$test);
+                               $yes = 1;
+
+                               foreach($hostNameParts as $index => $val)       {
+                                       $val = trim($val);
+                                       if (strcmp($val,'*') && strcmp($resolvedHostName[$index],$val)) {
+                                               $yes=0;
+                                       }
+                               }
+                               if ($yes) return true;
+                       }
+               }
+               return false;
+       }
+
+       /**
         * Check for item in list
         *
         * Check if an item exists in a comma-separated list of items.
@@ -3406,4 +3433,4 @@ class t3lib_div {
        }
 }
 
-?>
+?>
\ No newline at end of file
index 906ebc7..c61d4c8 100644 (file)
@@ -177,6 +177,9 @@ class t3lib_matchCondition {
                                case 'IP':
                                        if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $pcs[1]))    {return true;}
                                break;
+                               case 'hostname':
+                                       if (t3lib_div::cmpFQDN(t3lib_div::getIndpEnv('REMOTE_ADDR'), $pcs[1]))  {return true;}
+                               break;
                                        // hour, minute, dayofweek, dayofmonth, month
                                case 'hour':
                                case 'minute':