--- setup.php	2005-04-06 21:21:03.063041080 +0200
+++ setup-1.2.php	2005-04-06 21:27:39.656749672 +0200
@@ -1,5 +1,5 @@
 <?php
-/* Version 1.1 */
+/* Version 1.2 */
 
 function squirrelmail_plugin_init_ip_users() {
    global $squirrelmail_plugin_hooks;
@@ -9,6 +9,21 @@
 }
 
 function plugin_ip_users_login_verified() {
+
+function IP_Match($network, $ip) {
+   $ip_arr = explode("/",$network);
+   $network_long=ip2long($ip_arr[0]);
+
+   $mask_long= pow(2,32)-pow(2,(32-$ip_arr[1]));
+   $ip_long=ip2long($ip);
+
+   if (($ip_long & $mask_long) == $network_long) {
+       return 1;
+   } else {
+       return 0;
+   }
+}
+
    global $squirrelmail_plugin_hooks;
    global $login_username;
 
@@ -18,8 +33,9 @@
       $tmp = fgets($file, 1024);
       if (substr($tmp, 0, strpos($tmp, "|")) == "$login_username") {
          $valid_user=1;
-         if (substr($tmp, strpos($tmp, "|")+1) == "$REMOTE_ADDR\n" ||
-            substr($tmp, strpos($tmp, "|")+1) == "0\n") {
+         $rete=substr($tmp, strpos($tmp, "|")+1);
+         $indirizzo=getenv("REMOTE_ADDR");
+         if (IP_Match($rete,$indirizzo)) {
                $valid_user++;
          }
       }
@@ -27,6 +43,8 @@
    fclose($file);
    if($valid_user!=2) {
       echo "<html><body bgcolor=\"ffffff\">\n";
+        //      printf("Network:%s Address:%s\n<br>",$rete, $indirizzo);
+        //      print("Network: $rete -  Address: $indirizzo \n<br>");
       error_username_password_incorrect();
       exit;
    }
