13.9. Project 13.2. Build an Interactive Directory on a SIP Display Phone13.9.1.1 What you need for this project:
Cisco's 7900-series SIP phones can access a web service to drive interactive menus and application frontends right on the phone. These applications use the phone's display and soft buttons and are often tied, via a web server, to a backend database or PBX system like Asterisk. In this project, we'll build a simple, static user directory that you can browse with a 7900-series SIP phone.
Cisco's IP phones use XML markup to describe the user-interface elements the phone is capable of constructingsimple UI elements like images, button labels, and lists. The 7970G phone is even capable of displaying color graphics. (A fully functional web browser is a standard feature of the SCCP version of the 7970G.) The XML files are downloaded by the phone from a web server, so they can be static text files or CGI- or servlet-generated output. On the 7960 phone, there is a Directories key that is used to trigger an XML application on the phone's display. Despite its label, this key can be programmed to do anything, because you control the XML file that it loads. The URL used to find the directories file is found in the directory_url setting of the phone's SIP configuration file, which is loaded by TFTP when the phone starts up.
Once the config file is loaded by TFTP, the directory_url defines where the XML will be loaded from. The next step is to put that XML file at the path of the URL. Here's a sample of what a simple directory file might look like: <CiscoIPPhoneDirectory> <Title>Phone Directory</Title> <Prompt>Asterisk Extensions</Prompt> <DirectoryEntry> <Name>Wallingford, Ted</Name> <Telephone>105</Telephone> </DirectoryEntry> <DirectoryEntry> <Name>Wojtowicz, Susie</Name> <Telephone>106</Telephone> </DirectoryEntry> <DirectoryEntry> <Name>Gray, Sue</Name> <Telephone>107</Telephone> </DirectoryEntry> <DirectoryEntry> <Name>Wallingford, Jayne</Name> <Telephone>108</Telephone> </DirectoryEntry> </CiscoIPPhoneDirectory> So, your directory URL could point to a static XML file, or it could point to a dynamic Perl, PHP, or VB script. In any event, make sure that the proper headers are sent to the SIP phone, or you won't have good results. Here are the headers the 7900-series phones need: Content-type: text/xml Connection: close Expires: -1 If you're using PHP for your dynamic directory app, you should make a script with a name like 79xx-lib.php that lets you output these headers (and other 79xx-specific stuff) easily. A PHP header script for Cisco SIP phones would contain this: $header79xx="Content-type: text/xml\nConnection: close\nExpires: -1\n\n"; Now, the $header79xx PHP variable contains the headers, and you can place it at the start of your PHP directory script. The following script grabs a list of usernames and extensions from a fictitious MySQL database and outputs them as a 7900-series phone directory that can be accessed by pressing the Directories button. <? include "79xx-lib.php"; print $header79xx; $mysql_conn = mysql_connect("localhost","asterisk",""); mysql_select_db("directory",$mysql_conn); $rowset = mysql_query("SELECT username,extension FROM extensions", $mysql_conn); print("<CiscoIPPhoneDirectory>\n"); print("\t<Title>Giant Motor Corporation</Title>\n"); print("\t<Prompt>Office Phone Directory</Prompt>\n"); while($row = mysql_fetch_row($rowset)) { print("\t<DirectoryEntry>\n"); print("\t\t<Name>"); print($row[0]); print("</Name>\n"); print("\t\t<Telephone>"); print($row[1]); print("</Telephone>\n"); print("\t</DirectoryEntry>\n"); } print("</CiscoIPPhoneDirectory>\n"); ?> In the preceding PHP example, when the user presses the Directories button on the Cisco phone, the HTTP client downloads the output of the directory_url setting (which is driven by the PHP script), interpret it, and display the directory on the phone's LCD. The user can then place a call directly to any of the users in the directory.
|