Nortel CallPilot LDAP Lookup

Where I work right now, they use a Nortel phone system. For voicemail, they use CallPilot. The CallPilot system happens to be on the network, which is rather intriguing. For the department I am in, we use an Asterisk phone system that talks to the Nortel. I’ve always wondered however if there was an phone directory of the extensions. I was told no. So I did some digging. I happened across and LDAP server running on the CallPilot system. After some hacking, I discovered that the LDAP system had all the names in it (outdated of course). Two caveats though: it is only the extensions which have voicemail and it is using LDAP 2.0.

So come to find out, no one makes a free LDAP browser that actually supports version 2.0, and certainly none that will talk to the hacked version on the CallPilot system. LDAP 2.0 is ancient as I heard it quoted on one website. But, PHP supports 2.0. So I took my Active Directory lookup script, and modified it for use with CallPilot. I’ve posted a script below that you can use if you’d like to do lookups against this directory. It uses any voicemail user and password (I used mine for instance). Next, I may be playing with the IMAP server that appears to be running on the CallPilot system. That should prove interesting…

<?php

// Specify server settings here
$CP_Server="0.0.0.0"; // Enter the IP address of your CallPilot System
$CP_User="mail=12345671111@CALLPILOT.domain.com,dc=nortel,dc=ca"; // The extention was prefixed with the VPIM
$CP_Password=""; // Password for voicemail box
$CP_Root="addressbook=user,dc=nortel,dc=ca"; // You should probably leave this alone

function connectLDAP($server,$user,$password) {

	// Issue the connect command
	$cp_connect=ldap_connect($server) or
	die ("Could not connect to LDAP");

	// These options are required for MS Active Directory
	ldap_set_option($cp_connect, LDAP_OPT_PROTOCOL_VERSION, 2);
	ldap_set_option($cp_connect, LDAP_OPT_REFERRALS, 0);

	// Bind to AD with the username and password
	$ds_connect = ldap_bind($cp_connect,$user,$password) or
	die("Couldn't bind to CallPilot!");

	// Return handler
	return $cp_connect;

}

function disconnectLDAP($handle) {

	// Disconnect from the server
	ldap_unbind($handle);

}

function searchLDAP($ldap,$query,$root,$sort) {

	// Query the LDAP server
	// Future: Want adjust the array on the fly later, such as objectclass
	$sr=ldap_search($ldap, $root, $query);
	 
	// If a sort field was requested, adjust the list
	if ($sort) {
		$st=ldap_sort($ldap, $sr, $sort);
	}
	 
	// Generate the array, and return
	 
	$info = ldap_get_entries($ldap, $sr);
	 
	return $info;
 
}

// Start the script, check for extention
if ($_REQUEST["ext"]) {
	$cp = connectLDAP($CP_Server,$CP_User,$CP_Password);
	$query = "(&(telephonenumber=".$_REQUEST["ext"]."))"; // Put whatever you want here
	$sort = "";

	$info = searchLDAP($cp, $query, $CP_Root, $sort);

	if ($info["count"]>0) {
		echo "Name: " . $info[0]["givenname"][0] . " " . $info[0]["sn"][0] . " (" . $info[0]["cn"][0] . ")<br />";
		echo "Department: " . $info[0]["department"][0] . "<br />";
		echo "Extension: " . $info[0]["telephonenumber"][0] . "<br /><br />";
		echo "<pre>";
		print_r($info); // print the array
		echo "</pre>";
	}
	else {
		echo "No such user found for " . $_REQUEST["ext"] . ".";
	}
	 
	disconnectLDAP($cp);
}
else {
	echo "Please specify an extension.";
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *