193 lines
5.5 KiB
PHP
193 lines
5.5 KiB
PHP
<?
|
|
#####################################################################
|
|
# Asterisk Call Forward for Aastra SIP Phones R2.1.0 or better
|
|
#
|
|
# php source code
|
|
# Provided by Aastra Telecom Ltd 2007
|
|
#
|
|
# @user extension
|
|
# @action '' or check
|
|
# @key identification of the key used for the function
|
|
#####################################################################
|
|
|
|
include (dirname(__FILE__)."/phpagi/misc.php");
|
|
include (dirname(__FILE__)."/phpagi/phpagi-asmanager.php");
|
|
|
|
#####################################################################
|
|
# Aastra_decode_HTTP_header
|
|
#
|
|
# Returns an array
|
|
# 0 Phone Type
|
|
# 1 Phone MAC Address
|
|
# 2 Phone firmware version
|
|
#####################################################################
|
|
|
|
function Aastra_decode_HTTP_header()
|
|
{
|
|
$user_agent=$_SERVER["HTTP_USER_AGENT"];
|
|
if(stristr($user_agent,"Aastra"))
|
|
{
|
|
$value=preg_split("/ MAC:/",$user_agent);
|
|
$fin=preg_split("/ /",$value[1]);
|
|
$value[1]=preg_replace("/\-/","",$fin[0]);
|
|
$value[2]=preg_replace("/V:/","",$fin[1]);
|
|
}
|
|
else
|
|
{
|
|
$value[0]="MSIE";
|
|
$value[1]="NA";
|
|
$value[2]="NA";
|
|
}
|
|
|
|
return($value);
|
|
}
|
|
|
|
function Aastra_manage_cf($user,$action,$value)
|
|
{
|
|
# Connect to AGI
|
|
$cf="";
|
|
$as = new AGI_AsteriskManager();
|
|
$res = $as->connect();
|
|
|
|
# Depending on action
|
|
switch($action)
|
|
{
|
|
case 'cancel':
|
|
$res = $as->Command('database del CF '.$user);
|
|
break;
|
|
case 'set':
|
|
$res = $as->Command('database put CF '.$user.' '.$value);
|
|
$cf=$value;
|
|
break;
|
|
default:
|
|
#GET CFWD
|
|
$res = $as->Command('database get CF '.$user);
|
|
$line=split("\n", $res['data']);
|
|
$data=split(" ", $line[0]);
|
|
if($data[0]=="Value:") $cf=$data[1];
|
|
if($cf=="")
|
|
{
|
|
$data=split(" ", $line[1]);
|
|
if($data[0]=="Value:") $cf=$data[1];
|
|
}
|
|
break;
|
|
}
|
|
|
|
# Disconnect properly
|
|
$as->disconnect();
|
|
|
|
return($cf);
|
|
}
|
|
|
|
#####################################################################
|
|
# Global parameters
|
|
$Server = "http://".$_SERVER['SERVER_ADDR'].$_SERVER['SCRIPT_NAME'];
|
|
|
|
# Retrieve parameters
|
|
$user=$_GET['user'];
|
|
$action=$_GET['action'];
|
|
$value=$_GET['value'];
|
|
$key=$_GET['key'];
|
|
|
|
# Get header info
|
|
$header=Aastra_decode_HTTP_header();
|
|
|
|
# Depending on action
|
|
switch($action)
|
|
{
|
|
case 'cancel':
|
|
case 'set':
|
|
case 'check':
|
|
$cf=Aastra_manage_cf($user,$action,$value);
|
|
$output = "<AastraIPPhoneExecute triggerDestroyOnExit=\"yes\">\n";
|
|
$output .= "<ExecuteItem URI=\"".$Server."?action=msg&user=".$user."\"/>\n";
|
|
if($cf=='') $output .= "<ExecuteItem URI=\"Led: ".$key."=off\"/>\n";
|
|
else $output .= "<ExecuteItem URI=\"Led: ".$key."=on\"/>\n";
|
|
if($action!='check')
|
|
{
|
|
switch($header[0])
|
|
{
|
|
case "Aastra53i":
|
|
break;
|
|
default:
|
|
$output .= "<ExecuteItem URI=\"".$Server."?user=".$user."&key=".$key."\"/>\n";
|
|
break;
|
|
}
|
|
}
|
|
$output .= "</AastraIPPhoneExecute>\n";
|
|
break;
|
|
|
|
case 'change':
|
|
$cf=Aastra_manage_cf($user,$action,$value);
|
|
$output = "<AastraIPPhoneInputScreen type=\"number\" destroyOnExit=\"yes\">\n";
|
|
$output .= "<Title>Call Forward</Title>\n";
|
|
$output .= "<Prompt>Enter destination</Prompt>\n";
|
|
$output .= "<URL>".$Server."?user=$user&action=set&key=$key</URL>\n";
|
|
$output .= "<Parameter>value</Parameter>\n";
|
|
$output .= "<Default>$cf</Default>\n";
|
|
$output .= "</AastraIPPhoneInputScreen>\n";
|
|
break;
|
|
|
|
case 'msg':
|
|
$cf=Aastra_manage_cf($user,$action,$value);
|
|
$output = "<AastraIPPhoneStatus>\n";
|
|
$output .= "<Session>CFDND</Session>\n";
|
|
if ($cf=="") $output .= "<Message index=\"1\"></Message>\n";
|
|
else $output .= "<Message index=\"1\">CFWD activated</Message>\n";
|
|
$output .= "</AastraIPPhoneStatus>\n";
|
|
break;
|
|
|
|
default:
|
|
$cf=Aastra_manage_cf($user,$action,$value);
|
|
switch($header[0])
|
|
{
|
|
case "Aastra53i":
|
|
$output = "<AastraIPPhoneTextMenu destroyOnExit=\"yes\">\n";
|
|
if($cf=="") $output .= "<Title>CFWD deactivated</Title>\n";
|
|
else $output .= "<Title>CFWD set (".$cf.")</Title>\n";
|
|
if($cf!="")
|
|
{
|
|
$output .= "<MenuItem>\n";
|
|
$output .= "<Prompt>Cancel</Prompt>\n";
|
|
$output .= "<URI>$Server/cfwd.php?action=cancel&user=$user&key=$key</URI>\n";
|
|
$output .= "</MenuItem>\n";
|
|
}
|
|
$output .= "<MenuItem>\n";
|
|
$output .= "<Prompt>Change</Prompt>\n";
|
|
$output .= "<URI>$Server/cfwd.php?action=change&user=$user&key=$key</URI>\n";
|
|
$output .= "</MenuItem>\n";
|
|
$output .= "</AastraIPPhoneTextMenu>\n";
|
|
break;
|
|
|
|
default:
|
|
$output = "<AastraIPPhoneTextScreen destroyOnExit=\"yes\">\n";
|
|
$output .= "<Title>Call Forward for $user</Title>\n";
|
|
if ($cf=="") $output .= "<Text>Call Forward is currently deactivated.</Text>\n";
|
|
else $output .= "<Text>Call Forward is currently set to $cf.</Text>\n";
|
|
$output .= "<SoftKey index=\"1\">\n";
|
|
$output .= "<Label>Change</Label>\n";
|
|
$output .= "<URI>$Server/cfwd.php?action=change&user=$user&key=$key</URI>\n";
|
|
$output .= "</SoftKey>\n";
|
|
if($cf!="")
|
|
{
|
|
$output .= "<SoftKey index=\"2\">\n";
|
|
$output .= "<Label>Cancel</Label>\n";
|
|
$output .= "<URI>$Server/cfwd.php?action=cancel&user=$user&key=$key</URI>\n";
|
|
$output .= "</SoftKey>\n";
|
|
}
|
|
$output .= "<SoftKey index=\"6\">\n";
|
|
$output .= "<Label>Done</Label>\n";
|
|
$output .= "<URI>SoftKey:Exit</URI>\n";
|
|
$output .= "</SoftKey>\n";
|
|
$output .= "</AastraIPPhoneTextScreen>\n";
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
|
|
header("Content-Type: text/xml");
|
|
header("Content-Length: ".strlen($output));
|
|
echo $output;
|
|
exit;
|
|
?>
|