<?php
$client = strstr ($_SERVER["HTTP_USER_AGENT"], "Allegro-Software-WebClient");
if(!$client) {
include('error.htm');
} else {
header("Content-type: text/xml");
header("Connection: close");
function ld_browse() {
include('../../config.inc.php');
$ds=ldap_connect($ld_server);
if ($ds) {
$r=ldap_bind($ds, $ld_binddn, $ld_bindpw) or exit(">>Could not bind to $ld_server<<") ;;
$sr=ldap_search($ds, $ld_basedn, "objectClass=person") or exit(">>Unable to search ldap server $ld_server<<");
echo "<CiscoIPPhoneMenu>\n";
echo "\t<Title>Telefonbuch</Title>\n";
echo "\t<Prompt>Bitte auswaehlen</Prompt>\n";
$list = ldap_get_entries($ds, $sr);
for ($i=0; $i<$list["count"]; $i++) {
$find=array("ä","ö","ü","é","Ä","Ö","Ü");
$replace=array("ae","oe","ue","e","Ae","Oe","Ue");
$string=$list[$i]["cn"][0];
$string2=htmlentities($string);
$string2=str_replace($find,$replace,$string2);
$name=explode(" ", $string2);
if ($name[1] == "") {
} else {
echo "\n";
echo "\t<MenuItem>\n";
echo "\t\t<Name>". $name[1] ." ". $name[0] ."</Name>\n";
echo "\t\t<URL>".$url_base."?action=detail&sn=".$list[$i]["usncreated"][0]."</URL>\n";
echo "\t</MenuItem>\n";
}
}
echo "\n</CiscoIPPhoneMenu>\n";
ldap_close($ds);
} else {
echo "error";
}
}
function ld_detail() {
include('../../config.inc.php');
$ds=ldap_connect($ld_server);
if ($ds) {
$r=ldap_bind($ds, $ld_binddn, $ld_bindpw) or exit(">>Could not bind to $ld_server<<") ;;
$search=$_GET['sn'];
$sr=ldap_search($ds, $ld_basedn, "usncreated=".$search."") or exit(">>Unable to search ldap server $ld_server<<");
echo "<CiscoIPPhoneDirectory>\n";
$detail = ldap_get_entries($ds, $sr);
for ($i=0; $i<$detail["count"]; $i++) {
$string=$detail[$i]["cn"][0];
$name=explode(" ", $string);
echo "\t<Title>". $name[1] ." ". $name[0] ."</Title>\n";
echo "\t<Prompt></Prompt>\n";
if ($detail[$i]["telephonenumber"][0]) {
echo "\n";
echo "\t<DirectoryEntry>\n";
echo "\t\t<Name>Geschäftlich</Name>\n";
echo "\t\t<Telephone>" . $detail[$i]["telephonenumber"][0] ."</Telephone>\n";
echo "\t</DirectoryEntry>\n";
}
if ($detail[$i]["homephone"][0]) {
echo "\n";
echo "\t<DirectoryEntry>\n";
echo "\t\t<Name>Privat</Name>\n";
echo "\t\t<Telephone>" . $detail[$i]["homephone"][0] ."</Telephone>\n";
echo "\t</DirectoryEntry>\n";
}
if ($detail[$i]["mobile"][0]) {
echo "\n";
echo "\t<DirectoryEntry>\n";
echo "\t\t<Name>Mobil</Name>\n";
echo "\t\t<Telephone>" . $detail[$i]["mobile"][0] ."</Telephone>\n";
echo "\t</DirectoryEntry>\n";
}
}
echo "\n</CiscoIPPhoneDirectory>";
ldap_close($ds);
} else {
echo "error";
}
}
function ld_search() {
include('../../config.inc.php');
echo "<CiscoIPPhoneInput>\n";
echo "<Title>Suchen im AD</Title>\n";
echo "<Prompt>Suchbegriff eingeben</Prompt>\n";
echo "<URL>".$url_base."?action=do_search</URL>\n";
echo "\t<InputItem>";
echo "\t\t<DisplayName>Nachname</DisplayName>\n";
echo "\t\t<QueryStringParam>sn</QueryStringParam>";
echo "\t\t<DefaultValue></DefaultValue>";
echo "\t\t<InputFlags>A</InputFlags>";
echo "\t</InputItem>";
echo "\t<InputItem>";
echo "\t\t<DisplayName>Vorname</DisplayName>\n";
echo "\t\t<QueryStringParam>gn</QueryStringParam>";
echo "\t\t<DefaultValue></DefaultValue>";
echo "\t\t<InputFlags>A</InputFlags>";
echo "\t</InputItem>\n";
echo "</CiscoIPPhoneInput>\n";
}
function ld_do_search() {
include('../../config.inc.php');
$ds=ldap_connect($ld_server);
if ($ds) {
$r=ldap_bind($ds, $ld_binddn, $ld_bindpw) or exit(">>Could not bind to $ld_server<<") ;;
$q_sn=$_GET['sn'];
$q_gn=$_GET['gn'];
$sr=ldap_search($ds, $ld_basedn, "(&(givenName=".$q_gn."*)(sn=".$q_sn."*))") or exit(">>Unable to search ldap server $ld_server<<");
echo "<CiscoIPPhoneMenu>\n";
echo "\t<Title>Telefonbuch</Title>\n";
echo "\t<Prompt></Prompt>\n";
$dosearch = ldap_get_entries($ds, $sr);
for ($i=0; $i<$dosearch["count"]; $i++) {
$string=$dosearch[$i]["cn"][0];
$string=preg_replace('/ö/','/oe/',$string);
$name=explode(" ", $string);
if ($name[1] == "") {
} else {
echo "\n";
echo "\t<MenuItem>\n";
echo "\t\t<Name>". $name[1] ." ". $name[0] ."</Name>\n";
echo "\t\t<URL>".$url_base."?action=detail&sn=".$dosearch[$i]["usncreated"][0]."</URL>\n";
echo "\t</MenuItem>\n";
}
}
echo "\n</CiscoIPPhoneMenu>\n";
ldap_close($ds);
} else {
echo "error";
}
}
function ld_debug() {
include('../../config.inc.php');
$ds=ldap_connect($ld_server);
if ($ds) {
$r=ldap_bind($ds, $ld_binddn, $ld_bindpw) or exit(">>Could not bind to $ld_server<<") ;;
$sr=ldap_search($ds, $ld_basedn, "objectClass=contact") or exit(">>Unable to search ldap server $ld_server<<");
$foo = ldap_get_entries($ds, $sr);
echo "<pre>";
print_r($foo);
echo "</pre>";
ldap_close($ds);
} else {
echo "error";
}
}
switch ($_GET['action']) {
case browse:
ld_browse();
break;
case detail:
ld_detail();
break;
case search:
ld_search();
break;
case do_search:
ld_do_search();
break;
case debug:
ld_debug();
break;
}
}
?>