]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-6249 - easier way for human beings (as opposed to network engineers) to specify...
authortjhunt <tjhunt>
Mon, 16 Oct 2006 13:38:36 +0000 (13:38 +0000)
committertjhunt <tjhunt>
Mon, 16 Oct 2006 13:38:36 +0000 (13:38 +0000)
lang/en_utf8/help/quiz/requiresubnet.html
lib/moodlelib.php

index 68bb1093927b2b8abf2ab1fed3a748f7a4fc2f93..f989d87cfc44f364c901aa9ffd124db16414d6ee 100644 (file)
    to be sure that only people in a certain room are able to
    access the quiz.</p>
 
-<p>For example:  <b>192.168. , 231.54.211.0/20, 231.3.56.211</b></p>
+<p>For example: <b>192.168. , 231.54.211.0/20, 231.3.56.211, 231.3.56.10-20</b></p>
 
-<p>There are three types of numbers you can use (you can not use
-   text based domain names like example.com):
+<p>There are four types of numbers you can use (you can not use
+   text based domain names like example.com):</p>
+   
 <ol>
 <li>Full IP addresses, such as <b>192.168.10.1</b> which will match
     a single computer (or proxy).</li>
@@ -21,7 +22,9 @@
     starting with those numbers.</li>
 <li>CIDR notation, such as <b>231.54.211.0/20</b> which allows you to specify
     more detailed subnets.</li>
+<li>A range of IP addresses <b>231.3.56.10-20</b> The range applies to the last
+    part of the address, so this means all the IP addresses from 231.3.56.10
+    to 231.3.56.20.</li>
 </ol>
-</p>
 
 <p>Spaces are ignored.</p>
index 283483ebbc4a4b6d4fbc622791d76b94a508b3c0..b78fd10214866daca7bdb73f5027a642a6861142 100644 (file)
@@ -5950,9 +5950,10 @@ function make_unique_id_code($extra='') {
  * Function to check the passed address is within the passed subnet
  *
  * The parameter is a comma separated string of subnet definitions.
- * Subnet strings can be in one of two formats:
+ * Subnet strings can be in one of three formats:
  *   1: xxx.xxx.xxx.xxx/xx
  *   2: xxx.xxx
+ *   3: xxx.xxx.xxx.xxx-xxx   //a range of IP addresses in the last group.
  * Code for type 1 modified from user posted comments by mediator at
  * {@link http://au.php.net/manual/en/function.ip2long.php}
  *
@@ -5969,11 +5970,18 @@ function address_in_subnet($addr, $subnetstr) {
     foreach ($subnets as $subnet) {
         $subnet = trim($subnet);
         if (strpos($subnet, '/') !== false) { /// type 1
-
             list($ip, $mask) = explode('/', $subnet);
             $mask = 0xffffffff << (32 - $mask);
             $found = ((ip2long($addr) & $mask) == (ip2long($ip) & $mask));
-
+        } else if (strpos($subnet, '-') !== false)  {/// type 3
+            $subnetparts = explode('.', $subnet);
+            $addrparts = explode('.', $addr);
+            $subnetrange = explode('-', array_pop($subnetparts));
+            if (count($subnetrange) == 2) {
+                $lastaddrpart = array_pop($addrparts);
+                $found = ($subnetparts == $addrparts &&
+                        $subnetrange[0] <= $lastaddrpart && $lastaddrpart <= $subnetrange[1]);
+            }
         } else { /// type 2
             $found = (strpos($addr, $subnet) === 0);
         }
@@ -5982,7 +5990,6 @@ function address_in_subnet($addr, $subnetstr) {
             break;
         }
     }
-
     return $found;
 }