I wrote this plugin to authenticate users against an IMAP server.
Requirements:
Your MODx manager or user account must have an account with the same name on your mail server. Also, your mail server must have IMAP access available from whatever network your webserver is located on.
Caution:
Make sure that you copy all of the configurations form the plugin comments into the Plugin configuration box in the Configurations tab. The configuraton settings in the comments are on separate lines for readability so you’ll have to combine them into one line before inserting them into the configurations box.
Also, please be sure to review and set all of the configuration settings. If you don’t understand one of the settings you should probably learn. The default settings are set for the most secure settings not the most common settings.
Support:
Before submitting a support request to this forum there are a few things you should check. First of all, check your error logs. Not all PHP installations have IMAP support built in. The error logs will let you know if this is the case. Make sure that your mail server is properly set up for IMAP access and that network settings and security settings are not preventing your form using external IMAP authentication. Also, check the plugin’s configuration settings to make sure that every things is correctly configured for your mail server.
Protecting my own neck:
We are talking about potentially unencrypted user authentication over the internet. Your should understand the security implications of using this type of authentication method before using it in a production environment. Please understand that the configuration you choose in connecting to your mail server affects the lever of security. Neither the developer of the plugin nor the MODx team can be held responsible for any security breaches which may occur as a result of the use of this code.
Whew. Now that I’ve said all that let me say that this plugin has the potential to be very secure if used right (i.e. SSL encryption on the login page and the IMAP connection) . And even if it isn’t used right it’s probably no less secure than a lot of the authentication you’re using day in and day out.
So without any further adieu...
/*
* Written by: Adam Crownoble
* Contact: [email protected]
* Created: 8/8/2005
* Name: IMAP Authentication
* For: MODX CMS (modxcms.com)
* Code Type: Plugin
* Description: Authenticate againts a IMAP mail server
* Configuration: &server=IMAP Server;string;[your mail server url]
&port=IMAP Port;int;993
&ssl=SSL;list;Yes,No;Yes
&validate_ssl_cert=Validate SSL Certificate;list;Yes,No;Yes
* Events: OnManagerAuthentication and/or OnWebAuthentication
*/
/*
License
IMAP Authentication - A MODx plugin that allows authentication against an IMAP server
Copyright (C) 2005 Adam Crownoble
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Psuedo Constants
$eventId = 0;
$box = "INBOX";
$eventName = $modx->Event->activePlugin;
// Generate flags
$flags = '/imap';
if($ssl == 'Yes') $flags .= '/ssl';
if($validate_ssl_cert != 'Yes') $flags .= '/novalidate-cert';
// Assume authentication failed
$success = false;
// If IMAP extension not installed...
if(!function_exists('imap_open')) {
// Get the event's
if($eventName == 'OnManagerAuthentication') {
$eventId = 81;
} elseif($eventName == 'OnWebAuthentication') {
$eventId = 79;
}
// Log an error
$modx->logEvent($eventId, 3, 'The PHP IMAP extension must be enabled for the IMAP Authentication plugin to work.', 'IMAP Authentication Plugin');
// If the IMAP extension exists...
} else {
// Attempt to open an imap connection to the server using the given username and password
// If the connection fails PHP will throw an error so we use @ to supress it
$imap_conn = @imap_open("{"."$server:$port$flags"."}$box", $username, $userpassword);
// If we successfully connected to the server...
if($imap_conn) {
// Set the success variable to true
$success = true;
// Close the imap connection
//imap_close($imap_conn);
}
}
// Return the succes boolean
$modx->Event->output($success);
P.S. I have not tested this with web users yet but it should work. This plugin will not work well with my ManagerLogin snippet or any other login method that is run through the frontend because of some error handling issues.