X-Git-Url: https://git.cweiske.de/auerswald-callnotifier.git/blobdiff_plain/29ff32499e239e6189b80ef3b9e76384920205a7..7a39f860d268b6afd1e170cb4007726691d5c2b5:/src/callnotifier/CallMonitor/Detailler/LDAP.php diff --git a/src/callnotifier/CallMonitor/Detailler/LDAP.php b/src/callnotifier/CallMonitor/Detailler/LDAP.php index 833fd46..72fe07b 100644 --- a/src/callnotifier/CallMonitor/Detailler/LDAP.php +++ b/src/callnotifier/CallMonitor/Detailler/LDAP.php @@ -1,10 +1,43 @@ ldap = \Net_LDAP2::connect($ldapConfig); + if (\PEAR::isError($this->ldap)) { + throw new \Exception( + 'Could not connect to LDAP-server: ' . $this->ldap->getMessage() + ); + } } public function loadCallDetails(CallMonitor_Call $call) @@ -18,7 +51,40 @@ class CallMonitor_Detailler_LDAP implements CallMonitor_Detailler protected function loadName($number) { - return 'foo'; + $filter = \Net_LDAP2_Filter::combine( + 'or', + array( + \Net_LDAP2_Filter::create('companyPhone', 'equals', $number), + \Net_LDAP2_Filter::create('homePhone', 'equals', $number), + \Net_LDAP2_Filter::create('mobile', 'equals', $number), + \Net_LDAP2_Filter::create('otherPhone', 'equals', $number), + \Net_LDAP2_Filter::create('telephoneNumber', 'equals', $number), + ) + ); + $options = array( + 'scope' => 'sub', + 'attributes' => array('displayName', 'givenName', 'sn', 'cn') + ); + + $search = $this->ldap->search(null, $filter, $options); + if (\PEAR::isError($search)) { + throw new \Exception( + 'Error searching LDAP: ' . $search->getMessage() + ); + } + if ($search->count() == 0) { + return null; + } + + $arEntry = $search->shiftEntry()->getValues(); + if (isset($arEntry['displayName'])) { + return $arEntry['displayName']; + } else if (isset($arEntry['sn']) && $arEntry['givenName']) { + return $arEntry['givenName'] . ' ' . $arEntry['sn']; + } else if (isset($arEntry['cn'])) { + return $arEntry['cn']; + } + return null; } }