added imap authentication support to webui

This commit is contained in:
SJ 2012-12-10 12:41:40 +01:00
parent ced28c70c8
commit 989f8c2211
2 changed files with 38 additions and 0 deletions

View File

@ -25,6 +25,10 @@ define('GOOGLE_CLIENT_ID', 'xxxxxxxxxxx');
define('GOOGLE_CLIENT_SECRET', 'xxxxxxxxxxxxx');
define('GOOGLE_DEVELOPER_KEY', 'xxxxxxxxxxxx');
define('GOOGLE_APPLICATION_NAME', 'piler enterprise email archiver');
define('ENABLE_IMAP_AUTH', 0);
define('IMAP_HOST', 'mail.yourdomain.com');
define('IMAP_PORT', 993);
define('IMAP_SSL', true);
define('REMOTE_IMAGE_REPLACEMENT', '/view/theme/default/images/remote.gif');
define('ICON_ARROW_UP', '/view/theme/default/images/arrowup.gif');

View File

@ -5,6 +5,11 @@ class ModelUserAuth extends Model {
public function checkLogin($username = '', $password = '') {
$ok = 0;
if(ENABLE_IMAP_AUTH == 1) {
require 'Zend/Mail/Protocol/Imap.php';
$ok = $this->checkLoginAgainstIMAP($username, $password);
}
$query = $this->db->query("SELECT " . TABLE_USER . ".username, " . TABLE_USER . ".uid, " . TABLE_USER . ".realname, " . TABLE_USER . ".dn, " . TABLE_USER . ".password, " . TABLE_USER . ".isadmin, " . TABLE_USER . ".domain FROM " . TABLE_USER . ", " . TABLE_EMAIL . " WHERE " . TABLE_EMAIL . ".email=? AND " . TABLE_EMAIL . ".uid=" . TABLE_USER . ".uid", array($username));
if(!isset($query->row['password'])) { return 0; }
@ -69,6 +74,35 @@ class ModelUserAuth extends Model {
}
private function checkLoginAgainstIMAP($username = '', $password = '') {
$user = array();
$imap = new Zend_Mail_Protocol_Imap(IMAP_HOST, IMAP_PORT, IMAP_SSL);
if($imap->login($username, $password)) {
$imap->logout();
$query = $this->db->query("SELECT email, uid FROM " . TABLE_EMAIL . " WHERE email=?", array($username));
if($query->num_rows == 0) {
$a = explode("@", $username);
$user['uid'] = $this->model_user_user->get_next_uid();
$user['username'] = $username;
$user['realname'] = $a[0];
$user['password'] = generate_random_string(8);
$user['domain'] = @$a[1];
$user['isadmin'] = 0;
$user['email'] = $username;
$this->model_user_user->add_user($user);
}
return 1;
}
return 0;
}
public function check_ntlm_auth() {
if(!isset($_SERVER['REMOTE_USER'])) { return 0; }