Remotely Reboot a Cisco 79xx Phone (without SIP NOTIFY)
filed in Linux, Tech Help on Sep.02, 2008
After several days of emailing back and forth with Ciscos tech support, I got tired of waiting for an official way to restart Cisco 79xx phones. Then it hit me that I could do it using something I like to call EUI for emulated user interaction.
It’s pretty basic: I have a PHP script based on the push2phone function that was designed by Alex to remotely dial these phones. Since rebooting the phone is just a matter of pressing Settings -> **#**, all we have to do is tell the phone to dial these digits and it will reboot. (This script assumes that you already have the authorization script set up in SEP<MAC>.cnf.xml and that it is allowing the username and password at the top to reboot the phone.
First we need to be able to convert an extension to an IP address to make things user friendly. That shouldn’t be too hard with asterisk and ’sip show peers’:
$ips = array();
exec(”asterisk -r -x \”sip show peers\”",$ips);
$ip = false;
foreach($ips as $key => $data){
if(strpos($data,$exten.”/”.$exten) !== false){
$data = preg_split(”/[\s]+/”, $data);
$ip = $data[1];
$data = preg_split(”/[\/]+/”, $data[0]);
}
}
if(!$ip)
die(”Couldn’t find extension: “.$exten.”\n”);
This function actually does the dirty work of pushing commands out to the phone and is based on this: http://www.voip-info.org/wiki-Cisco+79XX+XML+Push
function push2phone($ip, $uri, $uid, $pwd){
$auth = base64_encode($uid.”:”.$pwd);
$xml = “<CiscoIPPhoneExecute><ExecuteItem Priority=\”0\” URL=\”".$uri.”\”/></CiscoIPPhoneExecute>”;
echo $xml.”\n”;
$xml = “XML=”.urlencode($xml);
$post = “POST /CGI/Execute HTTP/1.0\r\n”;
$post .= “Host: $ip\r\n”;
$post .= “Authorization: Basic $auth\r\n”;
$post .= “Connection: close\r\n”;
$post .= “Content-Type: application/x-www-form-urlencoded\r\n”;
$post .= “Content-Length: “.strlen($xml).”\r\n\r\n”;
$fp = fsockopen ( $ip, 80, $errno, $errstr, 30);
if(!$fp){ echo “$errstr ($errno)<br>\n”; }
else
{
fputs($fp, $post.$xml);
flush();
while (!feof($fp))
{
$response .= fgets($fp, 128);
flush();
}
}
return $response;
}
Now all we have to do is create something to call this script with the correct URIs and wait until the phone has had time to respond in between our virtual button pushes. This is the bit of code that I use to set up the URI/wait sequences to reboot the phones. The first part of the second array is the key we want to press and the second is how long we should wait after pressing it. You can figure out the wait time by performing the EUI yourself:
$actions['reboot'][0] = array(0 => “Key:Settings”, 1 => “2″);
$actions['reboot'][1] = array(0 => “Key:KeyPadStar”, 1 => “.3″);
$actions['reboot'][2] = array(0 => “Key:KeyPadStar”, 1 => “.3″);
$actions['reboot'][3] = array(0 => “Key:KeyPadPound”, 1 => “.3″);
$actions['reboot'][4] = array(0 => “Key:KeyPadStar”, 1 => “.3″);
$actions['reboot'][5] = array(0 => “Key:KeyPadStar”, 1 => “.3″);
phonePush is attached. It needs to be run on the asterisk server with PHP installed and compiled with CLI. The syntax is like this: php phonePush.php reboot 363 (<action> <extension>).
These pages were helpful to me:
http://www.cisco.com/en/US/docs/voice_ip_comm/cuipph/all_models/xsi/3_3_4/english/programming/guide/ip334ch3.html#wp1033107
http://search.cpan.org/src/MRPALMER/Cisco-IPPhone-0.05/IPPhone.pm