#!/usr/bin/env php * @license http://www.gnu.org/licenses/agpl.html AGPL v3 or later */ if (!is_file(__DIR__ . '/config.php')) { echo "Copy config.php.dist to config.php and adjust it.\n"; exit(1); } require_once __DIR__ . '/config.php'; require_once 'Net/LDAP2.php'; $ldap = Net_LDAP2::connect($ldapcfg); if (Net_LDAP2::isError($ldap)) { die('Could not connect to LDAP-server: ' . $ldap->getMessage() . "\n"); } $numberfields = array( 'companyPhone', 'facsimileTelephoneNumber', 'homeFacsimileTelephoneNumber', 'homePhone', 'mobile', 'otherPhone', 'pager', 'telephoneNumber', ); $search = $ldap->search( null, null, array( 'scope' => 'sub', 'attributes' => array_merge( array('displayName', 'cn'), $numberfields ) ) ); if (Net_LDAP2::isError($search)) { die('Error searching: ' . $search->getMessage() . "\n"); } echo "Kurzwahl;Rufnummer;Name\n"; while ($entry = $search->shiftEntry()) { $a = $entry->getValues(); if (count($a) == 0) { continue; } if (strpos($entry->dn(), ',ou=test,') !== false) { continue; } if (isset($a['displayName'])) { $name = $a['displayName']; } else { $name = $a['cn']; } foreach ($numberfields as $nfield) { if (isset($a[$nfield])) { foreach ((array)$a[$nfield] as $fv) { echo sprintf( ";%s;%s\n", str_replace( array(' ', '+'), array('', '00'), $fv ), utf8_decode($name) ); } } } } ?>