+<?php
+/**
+* Provides LDAP address entries on the UPnP server
+*
+* @author Christian Weiske <cweiske@php.net>
+* @license LGPL http://www.gnu.org/copyleft/lesser.html
+*/
+require_once 'Net/LDAP2.php';
+require_once 'Services/MediaTomb.php';
+require_once 'config.php';
+
+
+$config = array (
+ 'binddn' => $GLOBALS['ldaptombConfig']['ldap']['binddn'],
+ 'bindpw' => $GLOBALS['ldaptombConfig']['ldap']['bindpw'],
+ 'basedn' => $GLOBALS['ldaptombConfig']['ldap']['basedn'],
+ 'host' => $GLOBALS['ldaptombConfig']['ldap']['host']
+);
+
+$mt = new Services_MediaTomb(
+ $GLOBALS['ldaptombConfig']['mediatomb']['user'],
+ $GLOBALS['ldaptombConfig']['mediatomb']['pass'],
+ $GLOBALS['ldaptombConfig']['mediatomb']['host'],
+ $GLOBALS['ldaptombConfig']['mediatomb']['port']
+);
+
+
+$arAttributes = array(
+ 'cn' => '',
+ 'homePhone' => 'Tel: ',
+ 'mobile' => 'Handy: ',
+ 'telephoneNumber' => 'Arbeit: ',
+ 'street' => '',
+ 'postalCode' => '',
+ 'l' => '',
+);
+
+$ldap = Net_LDAP2::connect($config);
+if (PEAR::isError($ldap)) {
+ die('Could not connect to LDAP-server: '.$ldap->getMessage());
+}
+
+$folderFilter = Net_LDAP2_Filter::create('objectclass', 'equals', 'organizationalUnit');
+$addressFilter = Net_LDAP2_Filter::combine(
+ 'and',
+ array(
+ Net_LDAP2_Filter::create('cn', 'any'),
+ Net_LDAP2_Filter::combine(
+ 'or',
+ array(
+ Net_LDAP2_Filter::create('telephoneNumber', 'any'),
+ Net_LDAP2_Filter::create('mobile', 'any'),
+ Net_LDAP2_Filter::create('homePhone', 'any'),
+ )
+ )
+ )
+);
+
+$search = $ldap->search(null, $folderFilter, array('scope' => 'one', 'attributes' => array('ou')));
+
+$mtAddressDir = $mt->getContainerByPath(
+ $GLOBALS['ldaptombConfig']['mediatomb']['addressdir']
+);
+if ($mtAddressDir) {
+ //deletes subentries which is what we want - a clean tree
+ $mtAddressDir->delete();
+}
+
+foreach ($search as $ldapfolder) {
+ $strFolderName = $ldapfolder->getValue('ou');
+ echo $strFolderName . "\n";
+ $addrSearch = $ldap->search(
+ $ldapfolder->dn(),
+ $addressFilter,
+ array(
+ 'scope' => 'one'
+ )
+ );
+ foreach ($addrSearch->sorted(array('cn'), SORT_ASC) as $addrEntry) {
+ $mtEntry = $mt->createContainerByPath(
+ $GLOBALS['ldaptombConfig']['mediatomb']['addressdir']
+ . '/' . $strFolderName
+ . '/' . $addrEntry->getValue('cn')
+ );
+ echo " " . $addrEntry->getValue('cn') . "\n";
+ foreach ($arAttributes as $strLdapKey => $strPrefix) {
+ $val = $addrEntry->getValue($strLdapKey);
+ if (PEAR::isError($val)) {
+ continue;
+ }
+ $mtEntry->createExternalLink(
+ $strPrefix . $val, 'http://example.org',
+ $strPrefix . $val,
+ $GLOBALS['ldaptombConfig']['mediatomb']['mimetype']
+ );
+ echo ' ' . $strPrefix . $val . "\n";
+ }
+ }
+}
+?>
\ No newline at end of file