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.
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:
The 'passw0rd' is whatever you want the password to be.
To remove such priviledges, you use the revoke command in the same manner:
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.
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.