XML Phonebook from FreePBX for Grandstream GXP-2020 Phones


This little script will generate a valid gs_phonebook.xml file from all extensions in FreePBX. The generated XML will be ready to be downloaded trough TFTP.

If there is a error or a improvement for this script, let me know :)

[php]
<?php
// File: gs_phonebook.php
// version: 1.0
// Date: 2011-03-16
// Author: Yves Menge (yves.menge@gmail.com)
// Description: Generating a XML Phonebook from FreePBX MySQL DB

//!!Enable for Debug only!!
error_reporting(E_ALL);
ini_set("display_errors", ON);

// Database settings
$DBhost = ""; //** Insert your host here
$DBuser = ""; //** Insert your DB user here
$DBpass = ""; //** Insert your password here
$DBdatabase = "asterisk"; //** change only when installed Free PBX in a non-common way!

// Connect to the Database and get all devices
$DBlink = mysql_connect($DBhost, $DBuser, $DBpass) or die("Could not connect to host.");
mysql_select_db($DBdatabase, $DBlink) or die("Could not find database.");
$DBquery = "SELECT user, description FROM devices ORDER BY description ASC";
$QUERYresult = mysql_query($DBquery, $DBlink) or die("Data not found.");

//Setup XMLWriter
$writer = new XMLWriter();
$writer->openURI(‚/tftpboot/gs_phonebook.xml‘); //** If your TFTP server is using another root directory as /tfptboot, chang the path here!
$writer->setIndent(4);

//Beginn output
$writer->startDocument(‚1.0‘);
$writer->startElement(‚AddressBook‘);

//Add extensions / contacts from devices to the xml phonebook
while ($contact=mysql_fetch_array($QUERYresult)){
$writer->startElement(‚Contact‘);
$writer->writeElement(‚LastName‘,$contact[‚description‘]);
$writer->writeElement(‚FirstName‘,“);
$writer->startElement(‚Phone‘);
$writer->writeElement(‚phonenumber‘,$contact[‚user‘]);
$writer->writeElement(‚accountindex‘,’0′);
$writer->endElement();
$writer->endElement();
}

$writer->endElement();
$writer->endDocument();
$writer->flush();
?>
[/php]

Remarks: I assume your TFTP server is configured to use /tftpboot/ as root directory. You’ll also have to set the correct settings inside your phones (or the end point manager) to force the phones downloading the generated gs_phonebook.xml from the server.


Schreibe eine Antwort zu SebAntwort abbrechen

3 Gedanken zu “XML Phonebook from FreePBX for Grandstream GXP-2020 Phones