From 989f8c2211c5297fc022297dc4f4dd885e74a3a7 Mon Sep 17 00:00:00 2001 From: SJ Date: Mon, 10 Dec 2012 12:41:40 +0100 Subject: [PATCH] added imap authentication support to webui --- webui/config.php | 4 ++++ webui/model/user/auth.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/webui/config.php b/webui/config.php index 25975f39..e08ec0ce 100644 --- a/webui/config.php +++ b/webui/config.php @@ -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'); diff --git a/webui/model/user/auth.php b/webui/model/user/auth.php index 6f3d5dbd..2ca34eb4 100644 --- a/webui/model/user/auth.php +++ b/webui/model/user/auth.php @@ -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; }