Howto:Export PBX userlist from PBX with e164 numbering schema

From innovaphone-wiki

Jump to: navigation, search

Contents

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

The 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 contain only user's extensions, without subscriber number, area and country prefix. Also, if a numbering node scheme is implemented on the PBX, there is no way to retrieve all PBX numbers in e164 normalised format over LDAP.

As workaround it is possible to use the PBX's XML interface to retrive the 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 interprete the sample PHP script you have to install the PHP command line processor or to use a 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){
//filter objects with "Hide from LDAP", non user objects and objects without number
if($pbx_entry['type'] == "ep" && $pbx_entry['hide'] != "true" && isset($pbx_entry['e164'])){
$csv .= $pbx_entry['cn'].";";//add long name
if($normalise) $csv .= "00";// normalise phone number
$csv .= str_replace(".","",$pbx_entry['e164']);//add phonenumber, remove .
$csv .= ";".$pbx_entry['node'];//add node name
$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 $pbx_ip, $user and $pass. If your numbering node scheme implements a full E164 tree, set $normalize to true. Set it to false otherwise.

Usage

Open a command prompt and change to the location 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 the file 'phonebook.csv in the current directory 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 Articles

Personal tools