XML Features

From Snom Asterisk Portal

Asterisk 1.2 > Asterisk 1.2/XML Features

Contents

Feature description

With the xml-minibrowser (that is included in the snom 3xx firmware) it is possible to display custom dialogs on the phone screen. Examples for the usage of this feature are widespread: It could display a stock ticker, news headlines, available extensions of your PBX, members of a callgroup in your PBX or even the unread messages in your mailbox. Another custom application for snoms XML browser is the snom Football EM/WM prediction game.

Snom phones fetch the xml-dialogs from a webserver via HTTP, which is not included in Asterisk. You may need to install a webserver on your asterisk machine, for example the famous "Apache" webserver. The script example in this article was tested under Debian/Ubuntu with the Apache2 webserver and PHP5.

This example covers a simple xml-web-application, that interacts with the asterisk and displays the results on the phone screen.

Configure Asterisk

You do not need to configure anything in Asterisk for this application. Our example calls the asterisk CLI with a shell execute to obtain the necessary information.

Configure Operating System

The example application is written in PHP. You need a working httpd/PHP environment for the script to work.

It is necessary for the webserver to execute the call to the Asterisk CLI with root privileges (or the user you are running Asterisk with), otherwise access to the CLI will not be granted.

To grant access for the user "www-data" to the command "asterisk" with root privileges we use sudo. Insert the following line into your /etc/sudoers file:

www-data        ALL=(ALL) NOPASSWD: /usr/sbin/asterisk 

Please note that this is a definite security risk for your PBX. Do not use this simple method for productive environments, unless you know what you are doing. Instead you should write a shell-script that executes asterisk with the needed parameters and only allow access to this single script. Securing web applications is outside the scope of this article.

The PHP Script

Save this script as "/var/www/peers.php" (for example) on your Asterisk:

<SnomIPPhoneDirectory>
<Title>Online Extensions</Title>
<Prompt>Prompt</Prompt>
<?php
// get peer list from asterisk and filter unwanted lines through grep
$plain = shell_exec("sudo /usr/sbin/asterisk -rx \"sip show peers\" | grep -v -e '^Name/username' -e ' sip peers ' -e '^Verbosity' -e '^Debug' -e 'Remote UNIX'");

// use regular expressions to create an array with all online peers
// a peer is online, if it has an IP address in the list.
// no valid IP address means the peer is offline / not registered.

$expression = '=^(?P<name>[^\s]+)/[^\s]+\s+(?P<ipaddr>[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})=m';
$res = preg_match_all($expression, $plain, $output, PREG_SET_ORDER);
if ($res)
{
	foreach($output as $peer)
	{
		echo "<DirectoryEntry>", "\n";
		echo "<Name>", $peer['name'], "</Name>", "\n";
		echo "<Telephone>", $peer['name'], "</Telephone>", "\n";
		echo "</DirectoryEntry>", "\n";
	}
}	
else 
{
	echo "<DirectoryEntry>", "\n";
	echo "<Name>NO PEERS ONLINE</Name>", "\n";
	echo "<Telephone></Telephone>", "\n";
	echo "</DirectoryEntry>", "\n";
}
?>
</SnomIPPhoneDirectory>
</source>

Configure snom phones

snom 3xx

  • Go to "Setup -> Function Keys" and define a function key with Button Type "Action URL" and enter the URL to your peers.php in the Number field. (i.e. "http://myasterisk/peers.php")

When you save this change and press the corresponding button on your phone, a list with all available SIP peers of your Asterisk should be displayed on the phone screen. You can use the up and down keys to navigate through the list and the enter key to directly call a peer.

snom m3

The m3 handset does not support displaying XML pages.