Jump to content

LDAP-results are incomplete


zenlord

Recommended Posts

Hi,

 

First post on the forums. I am a self-thought PHP-coder and after some relatively simple websites I'm currently building a intranet-website to interconnect several of the services we're using in our 3-people-office.

 

This time I'm stuck connecting the asterisk-call-data-records to our ldap-addressbook. I would like to show the name of the person that has called our office. This is my code:

 

	function TBS_tel($BlockName,&$CurrRec,$RecNum){
	// 1. Extraheer ID van het toestel waarmee getelefoneerd werd
	$CurrRec['src_dev_id'] = substr($CurrRec['channel'],4,3);
	$CurrRec['dst_dev_id'] = substr($CurrRec['dstchannel'],4,3);

	// 2. Haal de persoonsgegevens uit de LDAP-dir
	// Persoonsgegevens zoeken
	$notNumbers = array(".", "/", ":", " ", "-");
	if ($CurrRec['dcontext'] == "internal") {
		// Zoeken op dst:
		$tel = str_replace($notNumbers, "", $CurrRec['dst']);
	} else {
		// Zoeken op src:
		$tel = str_replace($notNumbers, "", $CurrRec['src']);
	}
	[b]$filter = "(|(mobile=$tel)(Phone=$tel)(homePhone=$tel))";[/b]
	$attributes = array("sn", "givenName", "dn", "title", "o");
	$result = ldap_search(CNX_LDAP, LDAP_DIR_ADR, $filter, $attributes);
	$persID = ldap_get_entries(CNX_LDAP, $result);
		$CurrRec['pers_id'] = $persID[0]["title"][0];
		$CurrRec['pers_id'] .= " ";
		$CurrRec['pers_id'] .= $persID[0]["givenname"][0];
		$CurrRec['pers_id'] .= " <a href=\"link.php?dn=";
		$CurrRec['pers_id'] .= urlencode($persID[0]["dn"]);
		$CurrRec['pers_id'] .= "\">";
		$CurrRec['pers_id'] .= $persID[0]["sn"][0];
		$CurrRec['pers_id'] .= "</a>";
			if ($persID[0][2]) 
			{ 
		$CurrRec['pers_id'] .= "<br /><a href=\"link.php?org=";
		$CurrRec['pers_id'] .= urlencode($persID[0]["o"][0]);
		$CurrRec['pers_id'] .= "\">";
		$CurrRec['pers_id'] .= $persID[0]["o"][0]."</a>";
			}
	ldap_free_result($result);
	}

This code is working, but not completely: everytime $tel is equal to a mobile number, then it outputs the requested data. But if we are called by someone with a number that is in 'Phone' or 'homePhone', than the result is blank.

 

I have tried to ditch the capitals in 'Phone', I have tried to remove the (mobile=$tel)-filter, but to no effect. My guess is that the bug is situated on the bold line of my code. Am I overlooking something silly here?

 

Thank you in advance...

Link to comment
Share on other sites

OK, I found the problem myself.

 

Seems like I was mislead by phpldapadmin. Phpldapadmin showed the values of the attribute 'telephoneNumber' under (probably an alias) 'Phone'. Of course PHP doesn't know the attribute 'Phone'.

 

So: if an LDAP-filter doesn't return the expected values, check the relevant RFC's. The one for inetOrgPerson can be found here:

http://www.rfc-archive.org/getrfc.php?rfc=2798

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.