Howto:Export PBX userlist from PBX with e164 numbering schema

From innovaphone wiki
Revision as of 22:54, 12 April 2008 by Afi (talk | contribs) (New page: ==Summary== This article provides information about export of PBX users data to a CSV file for using it in 3rd-party applications without XML interface. ==Applies To== This information ap...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Summary

This article provides information about export of PBX users data to a CSV file for using it in 3rd-party applications without XML interface.

Applies To

This information applies to

  • All V6 PBX platforms

Build v6 and later.


More Information

Problem Details

Innovaphone PBX built in LDAP Server is primarily designed for two objectives: provide phone numbers and names of PBX internal users for local phones and to enable replication of PBX objects to other devices. Phone numbers of user objects provided by this service are not e164 normalised and containing only user extension number, without subscriber number, location and country prefix.

In case an e164 numbering schema is implemented on the PBX, there no way to retrive all PBX numbers in e164 normalised format over LDAP.

As workaround it is possible to use XML interface of the PBX to retive needed data.

System Requirements

The code example in this article is based on PHP5. You can use other XML enabled programming languages for this purpose.

To interpete the sample PHP script you have to install PHP command line processor or to use PHP enabled web server.

Installation

The easy way is to download zip package with PHP Windows Binaries from PHP Download Site and to extract it to any directory on your windows pc. You may add the directory path to the PATH environment variable.

After that create a new file called get_pbx_phonebook.php with following code in it:

<?php
// PBX ip address
$pbx_ip = "192.168.0.1";
// admin username
$user = "admin";
// admin password
$pass = "ip6000";
// filename phonebook is written to
$filename = "phonebook.csv";
// add 00 to phone number?
$normalise = true;

// GET request
$get = "/PBX0/ADMIN/mod_cmd_login.xml?cmd=show&user=*";

// get XML Object List form PBX 
$xml_string = file_get_contents("http://".$user.":".$pass."@".$pbx_ip.$get);

// convert to UTF-8, create SimpleXMLElement
$xml = new SimpleXMLElement(utf8_encode($xml_string));

$csv = "";
$count = 0;

foreach($xml->children() as $pbx_entry){
	if($pbx_entry['type'] == "ep" && !isset($pbx_entry->pseudo)){//filter object types
		$csv .= $pbx_entry['cn'].";";//add long name
		if($normalise) $csv .= "00";// normalise phone number
		$csv .= str_replace(".","",$pbx_entry['e164']);//add phonenumber, remove .
		$csv .= "\r\n";//new line
		$count++;//just for statistic
	}
}

if(!$handle = fopen($filename,"w")) die("Failed to open file: ".$filename);;//open file
fwrite($handle,$csv);//write data
fclose($handle);//close file
echo $count." entries written to ".$filename;
?>


You have to change the IP-Address, device admin username and pass.

Usage

Open a command prompt and change to the loacation you stored get_pbx_phonebook.php in. In our example it is the same directory we have extracted PHP to.

Now you can run the script:

C:\Temp\php-5.2.5-Win32> php.exe get_pbx_phonebook.php
20 entries written to phonebook.csv
C:\Temp\php-5.2.5-Win32>

If everything's ok you will find in the same directory file phonebook.csv containing PBX users with e164 normalised phone numbers. Now you can use it to import it to LDAP Directory or edit it in MS Excel.


Related Files