Generiere E-Mail-Liste aus GAL

Folgendes kleines Skript ließt alle Konten mit E-Mail-Adressen aus der ADS aus und zeigt sie zum Ausdrucken im Browser an.

Das Skript zeigt wie der Zugriff von PHP per LDAP auf die ADS funktioniert. ldap muss allerdings in PHP aktiviert sein.

<?php
# gal.php: Globale Adresseliste aus ADS auslesen
#
# (c) 2008 by Florian Richter <Florian_Richter@gmx.de>

# Zeichenkodierung auf UTF8 setzten (LDAP-Standard)
header('content-type: text/html; charset=utf-8');

# Konfiguration
$server = "domainserver";
$userdn = "cn=benutzer,dc=domain,dc=net";
$passwd = "password";
$basedn = "dc=domain, dc=net";

$ldap_query = "(showInAddressBook=*)";

# Verbindung öffnen
$connectionId = ldap_connect("ldap://".$server)
		or die("Konnte keine Verbindung mit LDAP-Server herstellen");

# ADS Options setzen
ldap_set_option($connectionId, LDAP_OPT_REFERRALS, 0);
ldap_set_option($connectionId, LDAP_OPT_SIZELIMIT, 2000);
ldap_set_option($connectionId, LDAP_OPT_PROTOCOL_VERSION, 3);

# Authentifizieren
ldap_bind($connectionId, $userdn, $passwd)
	or die("Authentifizierung fehlgeschlagen");

# Suche starten
$sr = ldap_search($connectionId, $basedn, $ldap_query);

# sortieren
ldap_sort($connectionId, $sr, "displayname");

# Ergebnisse holen
$info = ldap_get_entries($connectionId, $sr);

?>
<html>
  <head>
    <title>GAL Klinikum Esslingen</title>
    <style>
      tr.gerade {
        background-color: #EEEEEE;
      }
    </style>
  </head>
  <body>
    <h1>Globale Adressliste des Klinikums Esslingen</h1>
    <table>
      <tr>
        <th>Name</th>
        <th>Abteilung</th>
        <th>E-Mail-Addresse</th>
      </tr>
      <?php
        for ($i=0; $i
      <tr
        <?php
          if($i%2 == 0) echo ' class="gerade"';
        ?>
      >
        <td>
          <?php
            echo $info[$i]["displayname"][0]
          ?>
        </td>
	<td>
          <?php
            if(isset($info[$i]['department'])) echo $info[$i]['department'][0];
          ?>
        </td>
	<td>
          <?php
            echo $info[$i]["mail"][0]
          ?>
        </td>
      </tr>
      <?php
        }
      ?>
    </table>
    <p>Anzahl: <?php echo $info["count"]; ?></p>
  </body>
</html>

26.06.2008. Schlagworte: . Uncategorized.

Noch keine Kommentare

Gib als Erster einen Kommentar ab!

Eine Antwort schreiben

Trackback URI