Sep
06
2010




How to use PHP to reboot a Poycom SIP Phone

I’m knee deep into writing Voice Provision .04(VP4) for VoiceIP Solutions.  Why write another Asterisk GUI?  Because the Trixbox and Elastix software is way to convoluted and makes customization difficult.  They are not well documented and don’t attribute credit back to Asterisk or Digium.

Standard Asterisk scripting and basic macro’s are easier to setup, maintain, develop and troubleshoot.  What I require is a basic PHP SIP/IAX2 user manager that stays out of the dial plan. It must be specifically designed to manage Polycom phones.  This is why I’ve been locked in my room the last 4 weeks and haven’t done any recent articles.  My apologies.

The goals for VP4 are simple, Dynamic realtime SIP user management and standard Asterisk dial plan work via the extensions.conf.  Since VoiceIP Solutions is a certified Polycom reseller, VP4 will include several functions for generating Polycom configuration files and allowing remote reboots of the phones.  In this post I will provide a example of PHP function that reboots a Polycom SoundPoint IP phone by sending a SIP Notify message.

This post assumes you have a basic grasp on LAMP(Linux Apache MySQL PHP).  Also you need a working registered Polycom phone provisioned via a boot server of some kind(HTTP,FTP, TFTP,etc…).  I have a tutorial on that here.

Goals of this Post:
– Install PHP-SIP class from Google Code
– provide example function in PHP

The first step is to set the global option to allow rebooting via SIP Notify.  Edit your Polycom’s sip.cfg file:

voIpProt.SIP.specialEvent.checkSync.alwaysReboot=”1″

Next, create a directory for our PHP in the Apache webroot.  I’m creating one named ‘polyreboot’.  Make a folder in that directory called ‘libs’ for the Google PHP-SIP class library.  Download the code from the project site.  There should be two PHP files(PhpSIP.class.php & PhpSIP.Exception.php)  plus a README.  Place them in the libs folder.  If you are running this script through a Web browser remember to change your permissions to Apache.  Also be weary of rouge apostraphe and newline changes when cutting and pasting PHP from my post or any Web page for that matter…

Create a new PHP file for our script.  I’m calling mine, ‘polycom-reboot.php’.

<?php

function polycom_reboot($phone) {

require_once(‘./libs/PhpSIP.class.php’);

//   PHP-SIP Class Library code

try {

$api = new PhpSIP(‘192.168.1.254’); // IP we will bind to

$api->addHeader(‘Event: check-sync’); // Polycom message to reboot

$api->setMethod(‘NOTIFY’);

$api->setFrom(‘sip:6000@192.168.1.254’); //not required, sender address.

$api->setUri($phone);                     //Full SIP address in the format ‘sip:user-exten@IP-ADDRESS’

$res = $api->send();

} catch (Exception $e) {

echo $e->getMessage().”\n”;

}

}

// Now we will execute the functon above
//
// use your test phones SIP ADDRESS instead of mine

polycom_reboot(‘sip:4000@192.168.1.25’) ;

?>

Run the script in a terminal or browser window and the phone should reboot.

The Google PHP-SIP project is pretty cool.  It has a API for setting up UDP SIP messages.  This isn’t an implementation of SIP.   No PHP SIP phones on the horizon, but it does allow you to send special messages easily.  I’ll probably use this library to send text messages to Polycom devices next, if possible.  I’m using this function to reboot phones after an edit is made.  Works like a champ!

If you have any questions or variations on this script leave a post.  If you are interested in contributing to Voice Provision .04 let me know.

If you like this article tell Google!!









Written by mattb in: Asterisk,Asterisk Post,Linux,Scripts | Tags: , , , , , , ,

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment