";
}
if(!empty($Cid))
{
$Cid=$_GET['Clid'];
echo "
".$Cid;
}
else
{
echo "Clid is Blank";
}
if(!empty($Pfile))
{
$Pfile=$_GET['Playfile'];
echo "
".$Pfile;
}
else
{
echo "Playfile is Blank";
}
if(!empty($Acode))
{
$Acode=$_GET['ACCcode'];
echo "
".$Acode;
}
else
{
echo "ACCcode is Blank";
}
if(!empty($Chnl))
{
$Chnl=$_GET['Channel'];
echo "
".$Chnl;
}
else
{
echo "Channel is Blank";
}
$port = 5038;
$username = "asteriskami";
$password = "\$12345";
$context = "testAMI";
$socket = stream_socket_client("tcp://localhost:5038");
if($socket)
{
echo "Connected to socket, sending authentication request.\n";
// Prepare authentication request
$authenticationRequest = "Action: Login\r\n";
$authenticationRequest .= "Username: asteriskami\r\n";
$authenticationRequest .= "Secret: \$12345\r\n";
$authenticationRequest .= "Events: on\r\n\r\n";
// Send authentication request
$authenticate = stream_socket_sendto($socket, $authenticationRequest);
if($authenticate > 0)
{
// Wait for server response
usleep(200000);
// Read server response
$authenticateResponse = fread($socket, 4096);
// Check if authentication was successful
if(strpos($authenticateResponse, 'Success') !== false)
{
echo "Authenticated to Asterisk Manager Inteface. Initiating call.\n";
// Prepare originate request
$originateRequest = "Action: Originate\r\n";
$originateRequest .= "Channel: $Chnl/$FinalMobile\r\n";
$originateRequest .= "Callerid: $Cid\r\n";
$originateRequest .= "Application: Playback\r\n";
$originateRequest .= "Data: /usr/local/$Pfile\r\n";
$originateRequest .= "Context: testAMI\r\n";
$originateRequest .= "Exten: 1005\r\n";
fputs($socket, "Account: $Acode\r\n" );
$originateRequest .= "Priority: 2\r\n";
$originateRequest .= "Async: yes\r\n\r\n";
$originate = stream_socket_sendto($socket, $originateRequest);
}
if($originate > 0)
{
// Wait for server response
usleep(1000);
$originateResponse = fread($socket, 4096);
echo $originateResponse . "\n";
$responce=fgets($socket,4096);
socket_close($sock);
echo $responce."\n";
// Check if originate was successful
if(strpos($originateResponse, 'Success') !== false)
{
echo "Call initiated, dialing.\n";
} else {
echo "Could not initiate call.\n";
}
} else {
echo "Could not write call initiation request to socket.\n";
}
} else {
echo "Could not authenticate to Asterisk Manager Interface.\n";
}
} else {
echo "Could not write authentication request to socket.\n";
}
echo "Unable to connect to socket.";
?>