]> git.mjollnir.org Git - moodle.git/commitdiff
UNTESTED changes to allow multiple hosts to be used for POP3/IMAP/NNTP authentication
authormoodler <moodler>
Fri, 16 Jan 2004 09:17:20 +0000 (09:17 +0000)
committermoodler <moodler>
Fri, 16 Jan 2004 09:17:20 +0000 (09:17 +0000)
Please test them.

auth/imap/config.html
auth/imap/lib.php
auth/nntp/config.html
auth/nntp/lib.php
auth/pop3/config.html
auth/pop3/lib.php
lang/en/auth.php

index 8a6dfb04d18032a6e822d781d6a950b1174945ea..15d5309e11508bb1e8f11b257dcbc9bf23172b33 100644 (file)
@@ -16,7 +16,8 @@
        <?php  if (isset($err["auth_imaphost"])) formerr($err["auth_imaphost"]); ?>
        </TD>
     <TD>
-    <?php  print_string("auth_imaphost","auth") ?>
+    <?php  print_string("auth_imaphost","auth") ?> 
+    <?php  print_string("auth_multiplehosts","auth") ?>
     </TD>
 </TR>
 
index 1bf4fd46a72020e4e61f4934112a246d65e7fcd9..0cc6fe2f8f8e4e64ee4367d4d5f96c6f57664a77 100644 (file)
@@ -7,34 +7,40 @@ function auth_user_login ($username, $password) {
 
     global $CFG;
 
-    switch ($CFG->auth_imaptype) {
-        case "imapssl":
-            $host = "{".$CFG->auth_imaphost.":$CFG->auth_imapport/imap/ssl}";
-        break;
-
-        case "imapcert":
-            $host = "{".$CFG->auth_imaphost.":$CFG->auth_imapport/imap/ssl/novalidate-cert}";
-        break;
-
-        case "imaptls":
-            $host = "{".$CFG->auth_imaphost.":$CFG->auth_imapport/imap/notls}";
-        break;
-
-        default:
-            $host = "{".$CFG->auth_imaphost.":$CFG->auth_imapport}";
+    $hosts = split(';', $CFG->auth_imaphost);   // Could be multiple hosts
+
+    foreach ($hosts as $host) {                 // Try each host in turn
+
+        $host = trim($host);
+
+        switch ($CFG->auth_imaptype) {
+            case "imapssl":
+                $host = '{'.$host.":$CFG->auth_imapport/imap/ssl}";
+            break;
+    
+            case "imapcert":
+                $host = '{'.$host.":$CFG->auth_imapport/imap/ssl/novalidate-cert}";
+            break;
+    
+            case "imaptls":
+                $host = '{'.$host.":$CFG->auth_imapport/imap/notls}";
+            break;
+    
+            default:
+                $host = '{'.$host.":$CFG->auth_imapport}";
+        }
+
+        error_reporting(0);
+        $connection = imap_open($host, $username, $password, OP_HALFOPEN);
+        error_reporting($CFG->debug);   
+
+        if ($connection) {
+            imap_close($connection);
+            return true;
+        }
     }
 
-    error_reporting(0);
-    $connection = imap_open($host, $username, $password, OP_HALFOPEN);
-    error_reporting($CFG->debug);   
-
-    if ($connection) {
-        imap_close($connection);
-        return true;
-
-    } else {
-        return false;
-    }
+    return false;  // No match
 }
 
 
index 3cf54ae3511960445502dfe4723bf25d0c717bbc..caf0c3a9d278b124092d255affb1822ae8ef6f87 100644 (file)
@@ -15,6 +15,7 @@
        </TD>
     <TD>
     <?php  print_string("auth_nntphost","auth") ?>
+    <?php  print_string("auth_multiplehosts","auth") ?>
     </TD>
 </TR>
 
index de0a2d597e0004bf9228351992e8c78b8e8e2ee9..7fd6836feccad9ad92c0c07ae60a9ae0a7db3005 100644 (file)
@@ -8,19 +8,22 @@ function auth_user_login ($username, $password) {
 
     global $CFG;
 
-    $host = "{".$CFG->auth_nntphost.":$CFG->auth_nntpport/nntp}";
+    $hosts = split(';', $CFG->auth_nntphost);   // Could be multiple hosts
 
-    error_reporting(0);
-    $connection = imap_open($host, $username, $password, OP_HALFOPEN);
-    error_reporting($CFG->debug);   
+    foreach ($hosts as $host) {                 // Try each host in turn
+        $host = '{'.trim($host).":$CFG->auth_nntpport/nntp}";
 
-    if ($connection) {
-        imap_close($connection);
-        return true;
+        error_reporting(0);
+        $connection = imap_open($host, $username, $password, OP_HALFOPEN);
+        error_reporting($CFG->debug);   
 
-    } else {
-        return false;
+        if ($connection) {
+            imap_close($connection);
+            return true;
+        }
     }
+
+    return false;    // No match
 }
 
 
index 1f5acfa623c7f5292f4051527cf4d01f36b9ad5f..103375c348f465832441f523643024477f27d6f2 100644 (file)
@@ -17,6 +17,7 @@
        </TD>
     <TD>
     <?php  print_string("auth_pop3host","auth") ?>
+    <?php  print_string("auth_multiplehosts","auth") ?>
     </TD>
 </TR>
 
index 5602f0065edc89254a4a4594ce573484b1d0f6f2..a383905756adb679b2e34b950f0c15ca5c825acb 100644 (file)
@@ -7,29 +7,35 @@ function auth_user_login ($username, $password) {
 
     global $CFG;
 
-    switch ($CFG->auth_pop3type) {
-        case "pop3":
-            $host = "{".$CFG->auth_pop3host.":$CFG->auth_pop3port/pop3}INBOX";
-        break;
-        case "pop3notls":
-            $host = "{".$CFG->auth_pop3host.":$CFG->auth_pop3port/pop3/notls}INBOX";
-        break;
-        case "pop3cert":
-            $host = "{".$CFG->auth_pop3host.":$CFG->auth_pop3port/pop3/ssl/novalidate-cert}INBOX";
-        break;
+    $hosts = split(';', $CFG->auth_pop3host);   // Could be multiple hosts
+
+    foreach ($hosts as $host) {                 // Try each host in turn
+
+        $host = trim($host);
+
+        switch ($CFG->auth_pop3type) {
+            case "pop3":
+                $host = '{'.$host.":$CFG->auth_pop3port/pop3}INBOX";
+            break;
+            case "pop3notls":
+                $host = '{'.$host.":$CFG->auth_pop3port/pop3/notls}INBOX";
+            break;
+            case "pop3cert":
+                $host = '{'.$host.":$CFG->auth_pop3port/pop3/ssl/novalidate-cert}INBOX";
+            break;
+        }
+
+        error_reporting(0);
+        $connection = imap_open($host, $username, $password, OP_HALFOPEN);
+        error_reporting($CFG->debug);   
+        if ($connection) {
+            imap_close($connection);
+            return true;
+        }
     }
 
-    error_reporting(0);
-    $connection = imap_open($host, $username, $password, OP_HALFOPEN);
-    error_reporting($CFG->debug);   
-
-    if ($connection) {
-        imap_close($connection);
-        return true;
-
-    } else {
-        return false;
-    }
+    return false;  // No matches found
 }
 
 
index 6c88a34207effec48dca0163a062f3cb4de7cba4..06edb9fbaf4a5bbe28d8fe0cb492218998d80ce1 100644 (file)
@@ -40,6 +40,7 @@ $string['auth_ldapextrafields'] = 'These fields are optional.  You can choose to
 $string['auth_ldaptitle'] = 'Use an LDAP server';
 $string['auth_manualdescription'] = 'This method removes any way for users to create their own accounts.  All accounts must be manually created by the admin user.';
 $string['auth_manualtitle'] = 'Manual accounts only';
+$string['auth_multiplehosts'] = 'Multiple hosts can be specified (eg host1.com;host2.com;host3.com';
 $string['auth_nntpdescription'] = 'This method uses an NNTP server to check whether a given username and password is valid.';
 $string['auth_nntphost'] = 'The NNTP server address. Use the IP number, not DNS name.';
 $string['auth_nntpport'] = 'Server port (119 is the most common)';