176 lines
4.1 KiB
PHP
176 lines
4.1 KiB
PHP
<?
|
|
#####################################################################
|
|
# Asterisk Directory for Aastra SIP Phones R2.0.0 or better
|
|
#
|
|
# php source code
|
|
# Provided by Aastra Telecom Ltd 2007
|
|
#
|
|
# Parses
|
|
# - SIP users
|
|
# - IAX users
|
|
#
|
|
# Warning
|
|
# Location of Asterisk config files is set to "/etc/asterisk"
|
|
#####################################################################
|
|
|
|
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);
|
|
}
|
|
|
|
# Location of asterisk config files
|
|
$location = "/etc/asterisk/";
|
|
|
|
# Global Variables
|
|
$Server = "http://".$_SERVER['SERVER_ADDR'].$_SERVER['SCRIPT_NAME'];
|
|
|
|
# Init number of records
|
|
$index=0;
|
|
|
|
# Parse sip.conf
|
|
$sip_array=parse_ini_file($location."sip_additional.conf", true);
|
|
while ($v=current($sip_array))
|
|
{
|
|
if((isset($v['callerid'])) and (key($sip_array)!="register"))
|
|
{
|
|
$temp=$v['callerid'];
|
|
$len=strlen($temp);
|
|
$callerid=substr($temp,0,$len-(strlen(strrchr($temp, '<'))));
|
|
$directory[] = "<Prompt>". $callerid."</Prompt>\n"."<URI>Dial:".key($sip_array)."</URI>\n"."<Selection>".key($sip_array)."</Selection>\n"."<Dial>".key($sip_array)."</Dial>\n";
|
|
$index++;
|
|
}
|
|
next($sip_array);
|
|
}
|
|
|
|
# Parse iax.conf
|
|
$iax_array=parse_ini_file($location."iax.conf", true);
|
|
while($v=current($iax_array))
|
|
{
|
|
if(isset($v['name']))
|
|
{
|
|
$directory[]="<Prompt>".$v['name']."</Prompt>\n"."<URI>Dial:".key($iax_array)."</URI>\n"."<Dial>".key($iax_array)."</Dial>\n";
|
|
$index++;
|
|
}
|
|
next($iax_array);
|
|
}
|
|
|
|
# Sort Directory
|
|
sort($directory);
|
|
|
|
# Get header info
|
|
$header=Aastra_decode_HTTP_header();
|
|
switch($header[0])
|
|
{
|
|
case 'Aastra53i':
|
|
$MaxLines=13;
|
|
break;
|
|
default:
|
|
$MaxLines=15;
|
|
break;
|
|
}
|
|
|
|
# Retrieve last page
|
|
$last=intval($index/$MaxLines);
|
|
if(($index-$last*$MaxLines) != 0) $last++;
|
|
|
|
# Retrieve current page
|
|
$page=$_GET['page'];
|
|
if (empty($page)) $page=1;
|
|
|
|
# Display Page
|
|
$output ="<AastraIPPhoneTextMenu destroyOnExit=\"yes\">";
|
|
$output .= "<Title>Directory ($page/$last)</Title>\n";
|
|
$index=1;
|
|
foreach ($directory as $v)
|
|
{
|
|
if(($index>=(($page-1)*$MaxLines+1)) and ($index<=$page*$MaxLines))
|
|
{
|
|
$output .= "<MenuItem>\n";
|
|
$output .= $v;
|
|
$output .= "</MenuItem>\n";
|
|
}
|
|
$index++;
|
|
}
|
|
|
|
# Depending on the phone
|
|
switch($header[0])
|
|
{
|
|
case 'Aastra53i':
|
|
# Previous button as a menu
|
|
if($page!=1)
|
|
{
|
|
$previous=$page-1;
|
|
$output .= "<MenuItem>\n";
|
|
$output .= "<Prompt>Previous</Prompt>\n"."<URI>".$Server."?page=".$previous."</URI>\n";
|
|
$output .= "</MenuItem>\n";
|
|
}
|
|
# Next button as a menu
|
|
if($page!=$last)
|
|
{
|
|
$next=$page+1;
|
|
$output .= "<MenuItem>\n";
|
|
$output .= "<Prompt>Next</Prompt>\n";
|
|
$output .= "<URI>".$Server."?page=".$next."</URI>\n";
|
|
$output .= "</MenuItem>\n";
|
|
}
|
|
break;
|
|
default:
|
|
# Dial button
|
|
$output .= "<SoftKey index=\"1\">\n";
|
|
$output .= "<Label>Dial</Label>\n";
|
|
$output .= "<URI>SoftKey:Select</URI>\n";
|
|
$output .= "</SoftKey>\n";
|
|
|
|
# Next button
|
|
if($page!=$last)
|
|
{
|
|
$next=$page+1;
|
|
$output .= "<SoftKey index=\"5\">\n";
|
|
$output .= "<Label>Next</Label>\n";
|
|
$output .= "<URI>$Server?page=$next</URI>\n";
|
|
$output .= "</SoftKey>\n";
|
|
}
|
|
|
|
# Previous button
|
|
if($page!=1)
|
|
{
|
|
$previous=$page-1;
|
|
$output .= "<SoftKey index=\"2\">\n";
|
|
$output .= "<Label>Previous</Label>\n";
|
|
$output .= "<URI>$Server?page=$previous</URI>\n";
|
|
$output .= "</SoftKey>\n";
|
|
}
|
|
|
|
# Exit Button
|
|
$output .= "<SoftKey index=\"6\">\n";
|
|
$output .= "<Label>Exit</Label>\n";
|
|
$output .= "<URI>SoftKey:Exit</URI>\n";
|
|
$output .= "</SoftKey>\n";
|
|
break;
|
|
}
|
|
|
|
# End of the object
|
|
$output .= "</AastraIPPhoneTextMenu>\n";
|
|
|
|
# HTTP header and output
|
|
header("Content-Type: text/xml");
|
|
header("Content-Length: ".strlen($output));
|
|
echo $output;
|
|
?>
|
|
|