Changeset View
Changeset View
Standalone View
Standalone View
lib/Autodiscover.php
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public static function run() | ||||
// Detect request type | // Detect request type | ||||
foreach ($uris as $uri) { | foreach ($uris as $uri) { | ||||
// Outlook/Activesync | // Outlook/Activesync | ||||
if (stripos($uri, 'autodiscover.xml') !== false) { | if (stripos($uri, 'autodiscover.xml') !== false) { | ||||
$type = 'Microsoft'; | $type = 'Microsoft'; | ||||
break; | break; | ||||
} | } | ||||
// Microsoft Autodiscover V2 | |||||
elseif (stripos($uri, 'autodiscover.json') !== false) { | |||||
$type = 'Json'; | |||||
break; | |||||
} | |||||
// Mozilla Thunderbird (Kmail/Kontact/Evolution) | // Mozilla Thunderbird (Kmail/Kontact/Evolution) | ||||
else if (strpos($uri, 'config-v1.1.xml') !== false) { | else if (strpos($uri, 'config-v1.1.xml') !== false) { | ||||
$type = 'Mozilla'; | $type = 'Mozilla'; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (!$type) { | if (!$type) { | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | class Autodiscover | ||||
*/ | */ | ||||
protected function error($msg) | protected function error($msg) | ||||
{ | { | ||||
header("HTTP/1.0 500 $msg"); | header("HTTP/1.0 500 $msg"); | ||||
exit; | exit; | ||||
} | } | ||||
/** | /** | ||||
* Send 401 Unauthorized to the client end exit | |||||
*/ | |||||
protected function unauthorized($basicauth = true) | |||||
{ | |||||
if ($basicauth) { | |||||
header('WWW-Authenticate: Basic realm="'.$_SERVER['HTTP_HOST'].'"'); | |||||
} | |||||
header('HTTP/1.0 401 Unauthorized'); | |||||
exit; | |||||
} | |||||
/** | |||||
* Get services configuration | * Get services configuration | ||||
*/ | */ | ||||
protected function configure() | protected function configure() | ||||
{ | { | ||||
$pos = strrpos($this->email, '@'); | $pos = strrpos($this->email, '@'); | ||||
$this->config = array( | $this->config = array( | ||||
'email' => $this->email, | 'email' => $this->email, | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | private function find_user($email, $domain) | ||||
Log::debug("No entries found."); | Log::debug("No entries found."); | ||||
return; | return; | ||||
} | } | ||||
// parse result | // parse result | ||||
$entries = $result->entries(true); | $entries = $result->entries(true); | ||||
$dn = key($entries); | $dn = key($entries); | ||||
$entry = $entries[$dn]; | $entry = $entries[$dn]; | ||||
$result = array(); | $result = array('dn' => $dn); | ||||
foreach ($attributes as $idx => $attr) { | foreach ($attributes as $idx => $attr) { | ||||
$result[$idx] = is_array($entry[$attr]) ? current($entry[$attr]) : $entry[$attr]; | $result[$idx] = is_array($entry[$attr]) ? current($entry[$attr]) : $entry[$attr]; | ||||
} | } | ||||
return $result; | return $result; | ||||
} | } | ||||
/** | /** | ||||
* authenticate a user by his given dn and password | |||||
*/ | |||||
protected function authenticate($dn, $password) | |||||
{ | |||||
if (empty($this->_ldap_server)) { | |||||
return false; | |||||
} | |||||
$ldap = new Net_LDAP3(array( | |||||
'debug' => in_array(strtolower($this->conf->get('autodiscover', 'debug_mode')), array('trace', 'debug')), | |||||
'log_hook' => array($this, 'ldap_log'), | |||||
'hosts' => array($this->_ldap_server), | |||||
'port' => $this->_ldap_port, | |||||
'use_tls' => $this->_ldap_scheme == 'tls' | |||||
)); | |||||
// connect to LDAP | |||||
if (!$ldap->connect()) { | |||||
$this->error("Storage connection failed"); | |||||
return false; | |||||
} | |||||
// bind as given userdn | |||||
if (!$ldap->bind($dn, $password)) { | |||||
$this->unauthorized(); | |||||
return false; | |||||
} | |||||
$ldap->close(); | |||||
return true; | |||||
} | |||||
/** | |||||
* LDAP logging handler | * LDAP logging handler | ||||
*/ | */ | ||||
public function ldap_log($level, $msg) | public function ldap_log($level, $msg) | ||||
{ | { | ||||
if (is_array($msg)) { | if (is_array($msg)) { | ||||
$msg = implode("\n", $msg); | $msg = implode("\n", $msg); | ||||
} | } | ||||
Show All 23 Lines |