$dn = urldecode(trim($_SERVER["QUERY_STRING"]));
if (!$dn){
header("Location: /wpldap/help.php?vcard_wrongdn");
exit;
};
require_once("inc/setup.php");
require_once("inc/functions.php");
require_once("inc/class.vcard.php");
$lc=@ldap_connect($ldapServer, $ldapPort);
$ldapV3 = ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3);
if ($lc) {
//if ($debug) echo "Binding as [$ldapLogin:$ldapPwd]
";
if (@ldap_bind($lc, $ldapLogin, $ldapPwd)){
//if ($debug) echo "Searching for ";
$attr[]="*"; //sosame vsetky attribs
/*
if ($debug){
echo "attr[]=";
for ($i=0;$i\n";
};
*/
$queryStr="(objectClass=*)";
//if ($debug) echo "queryStr=[$queryStr]
\n";
$result=@ldap_search($lc, $dn, $queryStr, $attr, 0, 1); //just 1 record
//$result=@ldap_search($lc, $dn); //just 1 record
/*
ldap_search(
connection $this->res
base_dn $this->dn_all
filter sets the restrictions
attributes as array array of attributes returned
attrsonly 1 = return only the attributes, 0 = return attributes and values
amount number of results to return; 0 means all
time limit time limit in seconds; 0 means no limit
deref handling of aliases:
LDAP_DEREF_NEVER never resolv aliases
LDAP_DEREF_SEARCHING not if base object is called
LDAP_DEREF_FINDING only if base object is called
LDAP_DEREF_ALWAYS always resolv aliases
$result=ldap_search($lc, $ldapDN, "(objectclass=*)");
*/
if (!$result){
header("Location: /wpldap/help.php?vcard_wrongdn");
//echo "Zaznam $dn nenajdeny.
Pravdepodobne ho prave niekto zmazal.$brn";
exit;
};
// if ($debug) echo "Search result is ".$result."
";
// if ($debug) echo "Number of entires returned is ".ldap_count_entries($lc,$result)."
";
// if ($debug) echo "Getting entries ...
";
$info = ldap_get_entries($lc, $result);
// if ($debug) echo "Data for ".$info["count"]." items returned:
\n";
// if ($debug) echo "info[count] = ".$info["count"]."
";
if (!ldap_count_entries($lc,$result)){
return;
};
//ziskame zoznam attribs podla toho co mame zadane v setup.php/schema
$attrList=getArraySlice($schema,0);
//attrList je pole a vyzera nejako takto: ("cn","sn","givenName",...)
$attrString=implode(",",$attrList);
// if ($debug) echo "attrString=[".$attrString."]$brn";
//attrString je string a vyzera nejako takto: "cn,sn,givenName,..."
//mohol by som to spucit do jedneho s nasledujucim prikazom, ale vyzeralo
//by to velmi hnusne a o par dni by som to urcite ani sam nepochopil
$attrValues=getRecordAttribList($info[0],$attrString);
//attrValues je pole a obsahuje vyplnene data v rovnakom poradi ako $attrList
//toto budeme potrebovat right now tak si to vysosneme este raz
list($cn, $sn, $givenname, $userpassword, $telephonenumber, $mail, $ou, $st, $l, $description, $seealso, $usercertificate, $keysize, $browsertype) = getRecordAttribList($info[0],"cn,sn,givenname,userpassword,telephonenumber,mail,ou,st,l,description,seealso,usercertificate,keysize,browsertype");
$name = (( (''==$sn) || (''==$givenname) )?($cn):($sn.'_'.$givenname));
header('Content-Type: text/x-vcard');
header('Content-Disposition: inline; filename='.$name.'-'.$wpldapName.'.vcf');
if (eregi("(o=[^,]+)",$dn,$out)){
$o = substr($out[0],2);
} else {
$o = '';
};
//echo "
\no=[$o]
\n";
$vCard = (object) new vCard('','');
$vCard->setFirstName($givenname);
$vCard->setMiddleName('');
if ($sn!=""){
$vCard->setLastName($sn);
} else {
$vCard->setLastName($cn);
};
//prazdne sa mozu vynechat
$vCard->setEducationTitle('');
$vCard->setAddon('');
$vCard->setNickname('');
$vCard->setCompany($o);
$vCard->setOrganisation('');
$vCard->setDepartment($ou);
$vCard->setJobTitle('');
$vCard->setNote($decription);
$vCard->setTelephoneWork1($telephonenumber);
$vCard->setTelephoneWork2('');
$vCard->setTelephoneHome1('');
$vCard->setTelephoneHome2('');
$vCard->setCellphone('');
$vCard->setCarphone('');
$vCard->setPager('');
$vCard->setAdditionalTelephone('');
$vCard->setFaxWork('');
$vCard->setFaxHome('');
$vCard->setISDN('');
$vCard->setPreferredTelephone($telephonenumber);
$vCard->setTelex('');
$vCard->setWorkStreet('');
$vCard->setWorkZIP('');
$vCard->setWorkCity($l);
$vCard->setWorkRegion('');
$vCard->setWorkCountry($st);
$vCard->setHomeStreet('');
$vCard->setHomeZIP('');
$vCard->setHomeCity('');
$vCard->setHomeRegion('');
$vCard->setHomeCountry('');
$vCard->setPostalStreet('');
$vCard->setPostalZIP('');
$vCard->setPostalCity('');
$vCard->setPostalRegion('');
$vCard->setPostalCountry('');
$vCard->setURLWork('');
$vCard->setRole('');
$vCard->setBirthday('');
$vCard->setEMail($mail);
echo $vCard->getCardOutput();
exit;
} else {
header('Content-Type: text/html');
echo "Nemozem sa nalogovat na LDAP server! Je nutne skontrolovat konfiguraciu $wpldapName.
\nKontaktuje prosim administratora systemu.";
}; // if bind
//if ($debug) echo "Closing connection";
ldap_close($lc);
} else {
header('Content-Type: text/html');
echo "Nemozem sa pripojit k LDAP serveru na adrese $ldapServer:$ldapPort
\nKontaktuje prosim administratora systemu.";
};
?>