I've transferred over my old PHP script onto my AstLinux install and it is
not working (worked perfectly on Ubuntu/Asterisk). I'm not sure where to
begin troubleshooting it--where would I find error messages/logs?

Can anyone see any obvious mistakes in the following?
--> called in extensions.conf with: exten => *10,n,AGI(features.agi)

features.agi
-----------------
#!/usr/bin/php -q
<?php
# turn off output buffering
ob_implicit_flush(false);
# turn of error reporting
error_reporting(0);
# create file handles if needed
if (!defined('STDIN'))
{
   define('STDIN', fopen('php://stdin', 'r'));
}
if (!defined('STDOUT'))
{
   define('STDOUT', fopen('php://stdout', 'w'));
}
if (!defined('STDERR'))
{
   define('STDERR', fopen('php://stderr', 'w'));
}
# retrieve all AGI variables from Asterisk
while (!feof(STDIN))
{
   $temp = trim(fgets(STDIN,4096));
   if (($temp == "") || ($temp == "\n"))
   {
       break;
   }
   $s = split(":",$temp);
   $name = str_replace("agi_","",$s[0]);
   $agi[$name] = trim($s[1]);
}

fwrite(STDOUT,"DATABASE GET global ec500\n");
fflush(STDOUT);
$ec500 = trim(fgets(STDIN,4096));
$ec500 = substr(strrchr($ec500,"("),1,-1);

fwrite(STDOUT,"DATABASE GET global dnd\n");
fflush(STDOUT);
$dnd = trim(fgets(STDIN,4096));
$dnd = substr(strrchr($dnd,"("),1,-1);

#
function push2cisco($ip, $uri)
{
   $auth = base64_encode("cisco:cisco");
   $xml  = "<CiscoIPPhoneExecute><ExecuteItem
Priority=\"0\"URL=\"".$uri."\"/></CiscoIPPhoneExecute>";
   $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;
}

function push2aastra($phone,$data)
{
   $xml = "xml=".$data;

   $post = "POST / HTTP/1.1\r\n";
   $post .= "Host: $phone\r\n";
   $post .= "Referer: pbx.lan\r\n";
   $post .= "Connection: Keep-Alive\r\n";
   $post .= "Content-Type: text/xml\r\n";
   $post .= "Content-Length: ".strlen($xml)."\r\n\r\n";

   $fp = @fsockopen ( $phone, 80, $errno, $errstr, 5);
   if($fp)
   {
     fputs($fp, $post.$xml);
     flush();
     fclose($fp);
   }
}

$cisco = "SEP001B0CACCB85.lan";
$aastra = "9143i.lan";

##############################
$xml = "<AastraIPPhoneExecute>\n";
if ($ec500=="true" && $dnd=="true") {
  $uri = "http://miniserver.lan/cisco/push_notify.php?ec500=true;dnd=true";;
  $xml .= "<ExecuteItem URI=\"Led: prgkey5=slowflash\"/>\n";
  $xml .= "<ExecuteItem URI=\"Led: prgkey6=slowflash\"/>\n";
} elseif ($ec500=="true" && $dnd=="false") {
  $uri = "http://miniserver.lan/cisco/push_notify.php?ec500=true;dnd=false";;
  $xml .= "<ExecuteItem URI=\"Led: prgkey5=slowflash\"/>\n";
  $xml .= "<ExecuteItem URI=\"Led: prgkey6=off\"/>\n";
} elseif ($ec500=="false" && $dnd=="true") {
  $uri = "http://miniserver.lan/cisco/push_notify.php?ec500=false;dnd=true";;
  $xml .= "<ExecuteItem URI=\"Led: prgkey5=off\"/>\n";
  $xml .= "<ExecuteItem URI=\"Led: prgkey6=slowflash\"/>\n";
} else {
  $uri = "Init:AppStatus";
  $xml .= "<ExecuteItem URI=\"Led: prgkey5=off\"/>\n";
  $xml .= "<ExecuteItem URI=\"Led: prgkey6=off\"/>\n";
}
$xml .= "</AastraIPPhoneExecute>\n";


push2aastra($aastra, $xml);
push2cisco($cisco, $uri);
?>


I use PHP to drive my aastra phones.   I go both ways with them.  im using
> mini-httpd so that I can have menus on the phones.. and I also use PHP
> through AGI to do push to the phones for pop up messages, lights, etc..
>
>
>
> There are a lot of examples on aastra's site for php with aastra phones..
>
>
>
> -Christopher
>
>
>
> From: Shamus Rask [mailto:[email protected]]
> Sent: Monday, July 19, 2010 8:40 AM
> To: astlinux-users
> Subject: [Astlinux-users] suggestions for AGI scripts
>
>
>
> In the past, I have install Asterisk on a full-fledged Ubuntu-based server.
> This has allowed me to create several AGI scripts that I use for passing
> XML
> to my Aastra phones to turn on/off/blink lights for different event
> notifications. I would like to enable similar functionality on my AstLinux
> install, but recognized that not all scripting languages are present.
>
>
>
> Can anyone suggest the best way to approach AGI functionality in AstLinux?
> Are there any examples out there, ideally with an XML-push?
>
>
>
> many thanks,
>
>  Shamus
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Astlinux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/astlinux-users

Donations to support AstLinux are graciously accepted via PayPal to 
[email protected].

Reply via email to