add files master
authorChristian Weiske <cweiske@cweiske.de>
Thu, 22 May 2008 06:29:46 +0000 (06:29 +0000)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 22 May 2008 06:29:46 +0000 (06:29 +0000)
config.php.dist [new file with mode: 0644]
ldapaddresses2mediatomb.php [new file with mode: 0644]

diff --git a/config.php.dist b/config.php.dist
new file mode 100644 (file)
index 0000000..e9374b9
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+$GLOBALS['ldaptombConfig'] = array(
+    'ldap' => 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 (file)
index 0000000..904d8ca
--- /dev/null
@@ -0,0 +1,100 @@
+<?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