<?php
#echo "ami";
#echo "ami22";
$command=$_GET["cmd"];
$socket = fsockopen("127.0.0.1","5038", $errno, $errstr, 10);
if (!$socket){
echo "$errstr ($errno)\n";
}else{
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: araña\r\n");
fputs($socket, "Secret: arañasos\r\n\r\n");
fputs($socket, "Action: Command\r\n");
fputs($socket, "Command: $command\r\n\r\n");
# fputs($socket, "Action: Logoff\r\n\r\n");
while (!feof($socket)){
echo fgets($socket); // .'<br>';
}
fclose($socket);
#}
}
/*
while(true) {
// read a line from the socket
$line = socket_read($socket, 1024, PHP_NORMAL_READ);
if(substr($line, -1) === "\r") {
// read/skip one byte from the socket
// we assume that the next byte in the stream must be a \n.
// this is actually bad in practice; the script is vulnerable to unexpected values
socket_read($socket, 1, PHP_BINARY_READ);
}
# $message = parseLine($line);
echo $line."<br>";
#if($message->type === "QUIT") break;
}
*/
?>
#!/usr/bin/php -q
<?php
// hangup call trunk
//
#$command=$_GET["cmd"];
$socket = fsockopen("127.0.0.1","5038", $errno, $errstr, 10);
if (!$socket){
echo "$errstr ($errno)\n";
}else{
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: Araña\r\n");
fputs($socket, "Secret: picadura*\r\n\r\n");
#fputs($socket, "Action: Command\r\n");
#fputs($socket, "Command: $command\r\n\r\n");
#fputs($socket, "Action: Logoff\r\n\r\n");
while(true){
while (!feof($socket)){
$read = trim( fgets($socket));
//if(str_contains('Event: Hangup',$read)){
if ($read == 'Event: Hangup') {
$show = true;
$send = '';
}
if(isset($show)){
if($show){
$send .= $read."\n";
}
}
if(empty($read)){
if(isset($show)){
if($show){
#echo $send;
$url = 'https://ami';
$data = array('ami' =>$send);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
}
}
$show = false;
}
}
sleep(1);
}
fclose($socket);
}