We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1764
    • 680 Posts
    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.
      • 22097
      • 37 Posts
      Interesting stuff. I would personally make it LDAP authentication, but that should be a piece of cake after reading this plugin. Thanks for sharing this!
        • 1764
        • 680 Posts
        Quote from: Olaf at Aug 31, 2005, 02:10 AM

        I would personally make it LDAP authentication, but that should be a piece of cake after reading this plugin.

        Yea, I’d like to work on an LDAP plugin but I don’t have a access to an LDAP server I can test againts and installing and configuring an LDAP server can be a pain in the neck. I do have access to an Active Directory network which uses LDAP, I know. But I’d imagine Microsoft has somehow closed it off so that you can’t access it like a normal server.
          • 21301
          • 93 Posts
          Quote from: aNoble at Aug 31, 2005, 06:16 AM

          Yea, I’d like to work on an LDAP plugin but I don’t have a access to an LDAP server I can test againts
          I’ve been thinking about writing an LDAP plugin as well. And I have two LDAP servers running. It should be possible to give you access for testing somehow. Let me know if that could be usefull. If you have a linux server I could help you setting one up. Once you know how it works it’s really not that hard. But you’re right about the pain in the neck. Eg spaces at the start of a configline in your configfile break the installation.

          The M$ LDAP implementation is not a ’real’ one. It’s just a shallow interface glued to the outside of the Active Dir engine.
            • 1764
            • 680 Posts
            Quote from: theo at Aug 31, 2005, 06:40 AM

            I’ve been thinking about writing an LDAP plugin as well. And I have two LDAP servers running. It should be possible to give you access for testing somehow.

            Thanks for the offer but it will be a while before I can get to working on an LDAP plugin. I have some more work on QuickEdit I need to get done plus a couple of side projects I’m working on. If I get the time I’ll make sure to contact you about it though.
              • 34162
              • 1 Posts
              Quote from: aNoble at Aug 30, 2005, 11:24 PM

              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.

              Adam: can you contact me about this when you get a chance? Just drop me an email. Thanks!
                • 10226
                • 412 Posts
                Wow talk about a resurrection... Anyway I am running Evo 1.0.3. I’m pretty sure I did it right, and it appears to do nothing.

                Anyone know if it is compatible with my version and what might cause it to be ignored?

                Thanks!