3 * Provides LDAP address entries on the UPnP server
5 * @author Christian Weiske <cweiske@php.net>
6 * @license LGPL http://www.gnu.org/copyleft/lesser.html
8 require_once 'Net/LDAP2.php';
9 require_once 'Services/MediaTomb.php';
10 require_once 'config.php';
14 'binddn' => $GLOBALS['ldaptombConfig']['ldap']['binddn'],
15 'bindpw' => $GLOBALS['ldaptombConfig']['ldap']['bindpw'],
16 'basedn' => $GLOBALS['ldaptombConfig']['ldap']['basedn'],
17 'host' => $GLOBALS['ldaptombConfig']['ldap']['host']
20 $mt = new Services_MediaTomb(
21 $GLOBALS['ldaptombConfig']['mediatomb']['user'],
22 $GLOBALS['ldaptombConfig']['mediatomb']['pass'],
23 $GLOBALS['ldaptombConfig']['mediatomb']['host'],
24 $GLOBALS['ldaptombConfig']['mediatomb']['port']
28 $arAttributes = array(
30 'homePhone' => 'Tel: ',
31 'mobile' => 'Handy: ',
32 'telephoneNumber' => 'Arbeit: ',
38 $ldap = Net_LDAP2::connect($config);
39 if (PEAR::isError($ldap)) {
40 die('Could not connect to LDAP-server: '.$ldap->getMessage());
43 $folderFilter = Net_LDAP2_Filter::create('objectclass', 'equals', 'organizationalUnit');
44 $addressFilter = Net_LDAP2_Filter::combine(
47 Net_LDAP2_Filter::create('cn', 'any'),
48 Net_LDAP2_Filter::combine(
51 Net_LDAP2_Filter::create('telephoneNumber', 'any'),
52 Net_LDAP2_Filter::create('mobile', 'any'),
53 Net_LDAP2_Filter::create('homePhone', 'any'),
59 $search = $ldap->search(null, $folderFilter, array('scope' => 'one', 'attributes' => array('ou')));
61 $mtAddressDir = $mt->getContainerByPath(
62 $GLOBALS['ldaptombConfig']['mediatomb']['addressdir']
65 //deletes subentries which is what we want - a clean tree
66 $mtAddressDir->delete();
69 foreach ($search as $ldapfolder) {
70 $strFolderName = $ldapfolder->getValue('ou');
71 echo $strFolderName . "\n";
72 $addrSearch = $ldap->search(
79 foreach ($addrSearch->sorted(array('cn'), SORT_ASC) as $addrEntry) {
80 $mtEntry = $mt->createContainerByPath(
81 $GLOBALS['ldaptombConfig']['mediatomb']['addressdir']
82 . '/' . $strFolderName
83 . '/' . $addrEntry->getValue('cn')
85 echo " " . $addrEntry->getValue('cn') . "\n";
86 foreach ($arAttributes as $strLdapKey => $strPrefix) {
87 $val = $addrEntry->getValue($strLdapKey);
88 if (PEAR::isError($val)) {
91 $mtEntry->createExternalLink(
92 $strPrefix . $val, 'http://example.org',
94 $GLOBALS['ldaptombConfig']['mediatomb']['mimetype']
96 echo ' ' . $strPrefix . $val . "\n";