📄 email.auth.class.inc
字号:
<?php/*** @copyright Intermesh 2003* @author Merijn Schering <mschering@intermesh.nl>* @version $Revision: 1.31 $ $Date: 2006/04/10 13:21:10 $** 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.*/ require_once($GO_CONFIG->class_path.'base/base.auth.class.inc'); /*** This package can authenticate a user using an e-mail server supporting * IMAP or POP-3** @package Framework* @author Merijn Schering <mschering@intermesh.nl>* @since Group-Office 2.05*/class email_auth extends base_auth{ /** * This function logs a user in using a mail server * * @access public * * @param string $username * @param string $password * @param array $params The authentication source specified in auth_sources.inc * * @return bool */ function login($username, $password, $params) { global $GO_CONFIG, $GO_SECURITY, $GO_LANGUAGE, $GO_USERS, $GO_GROUPS, $GO_MODULES; $GO_SECURITY->user_id = 0; require_once($GO_CONFIG->class_path.'mail/imap.class.inc'); $imap = new imap(); $email_address = $username.'@'.$params['domain']; if ($params['add_domain_to_username']) { $username = $email_address; } if(isset($params['postfix_virtual_file']) && file_exists($params['postfix_virtual_file'])) { if(!$this->validate_user_domain($params['postfix_virtual_file'], $username, $params['domain'])) { return false; } } if ($imap->open($params['host'], $params['proto'], $params['port'], $username, $password, 'INBOX', 0, $params['ssl'], $params['novalidate_cert'])) { $imap->close(); if ( $profile = $GO_USERS->get_user_by_username( $email_address ) ) { $user_id = $profile['id']; if($profile['enabled'] != '1') { return false; } } else { $user['email'] = $user['username'] = $email_address; $user['password'] = $password; $user['sex'] = 'M'; // the user does not exist, so we have to add him. if ( !$user_id = $GO_USERS->add_user( $user, $GO_GROUPS->groupnames_to_ids($params['groups']), $GO_GROUPS->groupnames_to_ids($params['visible_groups']), $params['modules_read'], $params['modules_write'])) { die('FATAL ERROR: Failed adding mail user to Group-Office'); } else { $old_umask = umask( 000 ); @mkdir( $GO_CONFIG->file_storage_path.'users/'.$email_address, $GO_CONFIG->create_mode ); umask($old_umask); if ($params['create_email_account']) { $email_module = $GO_MODULES->get_module('email'); if($email_module) { require_once($email_module['class_path']."email.class.inc"); require_once($GO_LANGUAGE->get_language_file('email')); $email_client = new email(); if (!$account_id = $email_client->add_account($user_id, $params['proto'], $params['host'], $params['port'], $params['ssl'], $params['novalidate_cert'], $params['mbroot'], $username, $password, $username, $email_address, "", $params['auto_check_email'] )) { require_once($GO_LANGUAGE->get_language_file('email')); echo "<p class=\"Error\">".$registration_email_error."</p>"; echo "<p class=\"Error\">".$email_client->last_error."</p>"; }else { $account = $email_client->get_account($account_id); $email_client->synchronize_folders($account); } } } $profile = $GO_USERS->get_user($user_id); } } //$username = $email_address; //if local password is different from external the update it if(md5($password) != $profile['password']) { $GO_USERS->update_password($user_id, $password); $email_module = $GO_MODULES->get_module('email'); if($email_module) { require_once($email_module['class_path']."email.class.inc"); $email_client = new email(); $email_client->update_password($params['host'], $username, $password); } } $GO_SECURITY->logged_in( $user_id ); $GO_USERS->increment_logins( $user_id ); return true; } return false; } function validate_user_domain($virtual_file, $username, $domain) { $lines = file($virtual_file); foreach ($lines as $line) { if(preg_match('/.*'.$domain.'\s+'.$username.'/i', $line)) { return true; } } } }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -