]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14123 Full IPv6 support - replaced mnet ip_in_range() by standard ipv6 compatible...
authorskodak <skodak>
Fri, 9 Jan 2009 21:41:47 +0000 (21:41 +0000)
committerskodak <skodak>
Fri, 9 Jan 2009 21:41:47 +0000 (21:41 +0000)
admin/mnet/trustedhosts.php
mnet/lib.php
mnet/remote_client.php

index 932e84a6a6c7c739617ccc4a2cfb74b2331f9324..f8ed9176f604266d927b1a19e5f9abf8362a8aac 100644 (file)
     $in_range = false;
     if (!empty($test_ip_address)) {
         foreach($old_trusted_hosts as $host) {
-            list($network, $mask) = explode('/', $host.'/');
-            if (empty($network)) continue;
-            if (strlen($mask) == 0) $mask = 32;
-            
-            if (ip_in_range($test_ip_address, $network, $mask)) {
+            if (address_in_subnet($test_ip_address, $host)) {
                 $in_range = true;
-                $validated_by = $network.'/'.$mask;
+                $validated_by = $host;
                 break;
             }
         }
index 7539d0fda64c81ff0e96beb7f6fcb553775b7d00..8008e15f64bf65e38521cf806f358133a079158b 100644 (file)
@@ -412,27 +412,6 @@ function mnet_generate_keypair($dn = null, $days=28) {
     return $keypair;
 }
 
-/**
- * Check that an IP address falls within the given network/mask
- * ok for export
- *
- * @param  string   $address        Dotted quad
- * @param  string   $network        Dotted quad
- * @param  string   $mask           A number, e.g. 16, 24, 32
- * @return bool
- */
-function ip_in_range($address, $network, $mask) {
-   $lnetwork  = ip2long($network);
-   $laddress  = ip2long($address);
-
-   $binnet    = str_pad( decbin($lnetwork),32,"0","STR_PAD_LEFT" );
-   $firstpart = substr($binnet,0,$mask);
-
-   $binip     = str_pad( decbin($laddress),32,"0","STR_PAD_LEFT" );
-   $firstip   = substr($binip,0,$mask);
-   return(strcmp($firstpart,$firstip)==0);
-}
-
 /**
  * Check that a given function (or method) in an include file has been designated
  * ok for export
index f000766bb501aa6f64648256e2d85f1c358fe438..1f6e5acdbba211a90d5d9fc60b42f19c1546f120 100644 (file)
@@ -59,11 +59,7 @@ class mnet_remote_client extends mnet_peer {
         $trusted_hosts = explode(',', get_config('mnet', 'mnet_trusted_hosts'));
 
         foreach($trusted_hosts as $host) {
-            list($network, $mask) = explode('/', $host.'/');
-            if (empty($network)) continue;
-            if (strlen($mask) == 0) $mask = 32;
-            
-            if (ip_in_range($_SERVER['REMOTE_ADDR'], $network, $mask)) {
+            if (address_in_subnet(getremoteaddr(), $host)) {
                 return true;
             }
         }