* * Based heavily on the authentication plug-ins included in phpBB3 RC1 * which were largely written by Sergey Kanareykin. * * This is for authentication to any server supported by PHP's IMAP functions * * @copyright (c) 2007 Tim Ginn * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ /** * Login function */ function login_imap(&$username, &$password) { global $db, $config, $user; // Connect to the IMAP server running on port 143 on example.com using tls $mbox = @imap_open($config['imap_server'], $username, $password, OP_HALFOPEN); if (!$mbox) { $mbox = @imap_open($config['imap_altserver'], $username, $password, OP_HALFOPEN); if (!$mbox) { // Give status about wrong password... return array( 'status' => LOGIN_ERROR_PASSWORD, 'error_msg' => 'LOGIN_ERROR_PASSWORD', 'user_row' => array('user_id' => ANONYMOUS), ); } } imap_close($mbox); $sql ='SELECT user_id, username, user_password, user_passchg, user_email, user_type FROM ' . USERS_TABLE . " WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row) { // User inactive... if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) { return array( 'status' => LOGIN_ERROR_ACTIVE, 'error_msg' => 'ACTIVE_ERROR', 'user_row' => $row, ); } // Successful login... set user_login_attempts to zero... return array( 'status' => LOGIN_SUCCESS, 'error_msg' => false, 'user_row' => $row, ); } else { // retrieve default group id $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $db->sql_escape('REGISTERED') . "' AND group_type = " . GROUP_SPECIAL; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { trigger_error('NO_GROUP'); } // generate user account data $imap_user_row = array( 'username' => $username, 'user_password' => md5($password), 'user_email' => '', 'group_id' => (int) $row['group_id'], 'user_type' => USER_NORMAL, 'user_ip' => $user->ip, ); // this is the user's first login so create an empty profile return array( 'status' => LOGIN_SUCCESS_CREATE_PROFILE, 'error_msg' => false, 'user_row' => $imap_user_row, ); } } /** * This function is used to output any required fields in the authentication * admin panel. It also defines any required configuration table fields. */ function acp_imap(&$new) { global $user; $tpl = '

' . $user->lang['IMAP_SERVER_EXPLAIN'] . '

' . $user->lang['IMAP_ALTSERVER_EXPLAIN'] . '
'; // These are fields required in the config table return array( 'tpl' => $tpl, 'config' => array('imap_server') ); } ?>