From: Christian Weiske Date: Thu, 22 May 2008 06:29:46 +0000 (+0000) Subject: add files X-Git-Url: https://git.cweiske.de/ldaptomb.git/commitdiff_plain/8dab6fd52693e225802f01e0100a8315ab022d6a add files --- 8dab6fd52693e225802f01e0100a8315ab022d6a diff --git a/config.php.dist b/config.php.dist new file mode 100644 index 0000000..e9374b9 --- /dev/null +++ b/config.php.dist @@ -0,0 +1,19 @@ + array( + 'host' => 'FIXME', + 'binddn' => 'cn=FIXME,ou=users,dc=example,dc=org', + 'bindpw' => 'FIXME', + 'basedn' => 'ou=adressbuch,dc=example,dc=org', + ), + 'mediatomb' => array( + 'host' => 'FIXME', + 'port' => 49152, + 'user' => 'FIXME', + 'pass' => 'FIXME', + + 'addressdir' => 'Adresses', + 'mimetype' => 'audio/x-satellite-mpeg2' + ), +); +?> \ No newline at end of file diff --git a/ldapaddresses2mediatomb.php b/ldapaddresses2mediatomb.php new file mode 100644 index 0000000..904d8ca --- /dev/null +++ b/ldapaddresses2mediatomb.php @@ -0,0 +1,100 @@ + +* @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