Displaying asterisk online status on a web page

Posted by Borre Mosch on 8 July 2010

Because the Infi office has consisted of multiple office spaces for some time now, problems began to arise when diverting calls to employees that were inadvertantly offline. Misdirecting calls leads to waiting customers. As we would like to avoid this, we thought it might be a good idea to display the status of employees within the phone system (available / on the phone / offline) on the phone number page of our internal wiki site.

Our phone system consists of an asterisk PBX server. Asterisk PHP APIs are available, but they proved to be too slow to be usable in this case, so we decided to use the servers 'asterisk' command in combination with PHPs exec function:

sudo /usr/sbin/asterisk -r -x 'sip show peers' will show all known users, together with the IP address they used to login

Example output

sudo /usr/sbin/asterisk -r -x 'core show channels' will show all current calls

Example output

We recommend using sudo because it is much safer than granting the apache user root rights. Now, we use regular expressions to find the user information in the output, and, depending on what we find, we display an icon for the employees current status. Our wiki can then show the status of an employee by including:

<img src="http://pbx/image_available.php?user=username"/>

Which looks like this:





Full source code

Icons used: http://code.google.com/p/twotiny/

Comments:

Posted by VG on 16 January 2012, 22:01:
Hi,
When am tried to execute the Peer Status, am getting blank page.
Can you people, please let me know where should i have to change the code to get the accurate result.

Thanks in advance.

Post a comment:

Name:
E-mail*:
Comment:
*optional, will not be published.