Pulling Extensions out of PBXinaFlash

frederic

Guru
Joined
May 18, 2008
Messages
58
Reaction score
4
For our internal website (i.e. employee facing, not customer facing), we wanted to create a list of alphabetically sorted employees with their extension.

Using PHP, this turned out to be trivial, and I'm sharing this since I'm sure I'm not the only one who would like such a thing.

Code:
  $dbname="asterisk";
  $hpbx="<remoteip>";
  $upbx="<username>";
  $ppbx="<password>";
  $dbh=mysql_connect ($hpbx,$upbx,$ppbx) or die ('I cannot connect to the database because: ' . mysql_error(). '');
  mysql_select_db ("$dbname") or die('I cannot select the database because: ' . mysql_error());
  $query = "SELECT * FROM users ORDER BY name ;";
  $result = mysql_query($query);
  $num = mysql_num_rows($result);
  for ($x=1; $x<=$num; $x++) $ext[$x] = mysql_fetch_assoc($result);
  mysql_free_result($result);
  echo "<table>";
  for ($x=1; $x<=$num; $x++) echo "<tr><td>".$ext[$x][extension]."</td><td>".$ext[$x][name]."</td></tr>"; 
  echo "</table>";

Obviously hpbx (hostname), upbx (username) and ppbx (password) need to be set appropriately for your system, and further if your PBX and webserver are on different physical servers (thus different IP addresses) you'll have to use "mysql" admin program to grant priviledges to the remote server like so:

Code:
mysql> grant all on asterisk.* to root@'<webserverip>' identified by 'passw0rd';

The 'passw0rd' is whatever you want the password to be.

To remove such priviledges, you use the revoke command in the same manner:

Code:
mysql> revoke grant option on asterisk.* from root@'<webserverip>' ;

Hope that helps. While we do run httpd (web server) on the PBX box, it's heavily restricted to only administrators, and does not have public access as a web device. Only sip/iax ports are open and those too are limited by iptables rather aggressively.

You will notice in the code there are two "for" loops. If you are going to cut and paste this code you can combine them into one loop however we have them seperate because all of the heavy lifting (opening db, reading extensions) are functions residing in a common file thus useful for other purposes than simply displaying in a browser. This way the actual page just has to display records after calling the functions. I combined them here to make life easy.

Enjoy.
 
I realize the module sorts extensions by number, but you could've just used/modified the 'Print Extensions' that comes w/ FreePBX.
 
Actually this sorts by name, though sorting by another field is just as easy.

This code is part of our corporate intranet, therefore displaying the data with everything else. This script does not require web access to the PBX server, which was our goal for security reasons.
 

Members online

No members online now.

Forum statistics

Threads
26,687
Messages
174,410
Members
20,257
Latest member
Dempan
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Back
Top