From f95ad4b43a5c1d0653aa5721600d8f39d5fcfc34 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 16 Jan 2004 09:17:20 +0000 Subject: [PATCH] UNTESTED changes to allow multiple hosts to be used for POP3/IMAP/NNTP authentication Please test them. --- auth/imap/config.html | 3 ++- auth/imap/lib.php | 58 ++++++++++++++++++++++++------------------- auth/nntp/config.html | 1 + auth/nntp/lib.php | 21 +++++++++------- auth/pop3/config.html | 1 + auth/pop3/lib.php | 48 +++++++++++++++++++---------------- lang/en/auth.php | 1 + 7 files changed, 76 insertions(+), 57 deletions(-) diff --git a/auth/imap/config.html b/auth/imap/config.html index 8a6dfb04d1..15d5309e11 100644 --- a/auth/imap/config.html +++ b/auth/imap/config.html @@ -16,7 +16,8 @@ - + + diff --git a/auth/imap/lib.php b/auth/imap/lib.php index 1bf4fd46a7..0cc6fe2f8f 100644 --- a/auth/imap/lib.php +++ b/auth/imap/lib.php @@ -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 } diff --git a/auth/nntp/config.html b/auth/nntp/config.html index 3cf54ae351..caf0c3a9d2 100644 --- a/auth/nntp/config.html +++ b/auth/nntp/config.html @@ -15,6 +15,7 @@ + diff --git a/auth/nntp/lib.php b/auth/nntp/lib.php index de0a2d597e..7fd6836fec 100644 --- a/auth/nntp/lib.php +++ b/auth/nntp/lib.php @@ -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 } diff --git a/auth/pop3/config.html b/auth/pop3/config.html index 1f5acfa623..103375c348 100644 --- a/auth/pop3/config.html +++ b/auth/pop3/config.html @@ -17,6 +17,7 @@ + diff --git a/auth/pop3/lib.php b/auth/pop3/lib.php index 5602f0065e..a383905756 100644 --- a/auth/pop3/lib.php +++ b/auth/pop3/lib.php @@ -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 } diff --git a/lang/en/auth.php b/lang/en/auth.php index 6c88a34207..06edb9fbaf 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -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)'; -- 2.39.5