<?php /* http://45.32.165.238/ami/webcall.php?src=101&dst=8095445555&trunk=400&cid=18007142323 */ $timeout=100; $host="127.0.0.1"; $port=5038; $src = preg_replace('/\s+/', '', $_GET[src]); $dst = preg_replace('/\s+/', '', $_GET[dst]); $trunk = preg_replace('/\s+/', '', $_GET[trunk]); $cid = preg_replace('/\s+/', '', $_GET[cid]); $id = preg_replace('/\s+/', '', $_GET[id]); $pitch = preg_replace('/\s+/', '', $_GET[pitch]); $num=$dst; $ext=$src ; $context="outbound-click-to-call"; $socket = fsockopen("$host",$port,$errno, $errstr, $timeout); fputs($socket, "Action: Login\r\n"); fputs($socket, "UserName: admin\r\n"); // fputs($socket, "Secret: Krtzv\r\n\r\n"); // // $wrets=fgets($socket,128); fputs($socket, "Action: Originate\r\n" ); fputs($socket, "Channel: Local/$src@from-internal/n\r\n" ); fputs($socket, "Exten: $dst\r\n" ); fputs($socket, "Context: $context\r\n" ); fputs($socket, "Priority: 1\r\n" ); fputs($socket, "CallerID: $cid\r\n" ); fputs($socket, "Variable: __trunk=$trunk\r\n" ); fputs($socket, "Variable: __dst=$dst\r\n" ); fputs($socket, "Variable: __src=$src\r\n" ); fputs($socket, "Variable: __cid=$cid\r\n" ); fputs($socket, "Variable: __id=$id\r\n" ); fputs($socket, "Variable: __pitch=$pitch\r\n" ); fputs($socket, "Async: yes\r\n\r\n" ); fputs($socket, "Action: Logoff\r\n\r\n"); sleep (1); $wrets=fgets($socket,128); echo $wrets; ?> <?php | |
// Define the API endpoint | |
$url = 'https://asterisk-voip.com'; | |
// Initialize a cURL session | |
$ch = curl_init($url); | |
// Define the headers | |
$headers = [ | |
'Accept: application/json', | |
'Authorization: Basic 12345password', | |
'Content-Type: multipart/form-data', | |
'X-CSRF-TOKEN: ' | |
]; | |
// Define the form data | |
$postFields = [ | |
'to' => "$argv[1]", | |
'from' => "$argv[2]", | |
'recording_file' => new CURLFile("$argv[3]"), // Replace with the actual file path | |
'start_time' => "$argv[5]", | |
'end_time' => "$argv[6]", | |
'call_length' => "$argv[4] Seconds" | |
]; | |
// Set the cURL options | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); | |
// Execute the request | |
$response = curl_exec($ch); | |
// Check for errors | |
if (curl_errno($ch)) { | |
echo 'Error:' . curl_error($ch); | |
} else { | |
// Print the response | |
echo $response; | |
} | |
// Close the cURL session | |
curl_close($ch); | |
?> | |
--------- | |
[outbound-click-to-call] | |
exten => _X.,1,Set(calltime=${STRFTIME(${EPOCH},,%Y%m%d%H%M%S)}) | |
same => n,Set(path=/var/www/html/click_2_call/monitor) | |
same => n,MixMonitor(${path}/${calltime}-${CALLERID(num)}-${EXTEN:3}.wav) | |
same=>n,Set(CALLERID(num)=9496504600) | |
same => n,Dial(PJSIP/${EXTEN}@Synapseglobal,120) | |
exten => h,1,Set(start_time=${CUT(CDR(start), ,2)}) ; Extract the time portion | |
same => n,Set(end_time=${CUT(CDR(end), ,2)}) | |
same => n,NoOp(Start Time Portion: ${start_time}) | |
same => n,NoOp(End Time Portion: ${end_time}) | |
same => n,Set(result=${SHELL(php /var/www/html/click_2_call/post_cdr.php "${CDR(dst)}" "${CDR(src)}" "${MIXMONITOR_FILENAME}" "${CDR(billsec)}" "${start_time}" "${end_time}")}) | |
same=>n,hangup() | |
Soporte & Consultoria
martes, 11 de junio de 2024
asterisk click to call and CDR post
domingo, 2 de junio de 2024
Ami event filter
#!/usr/bin/php
<?php
require("setting.php");
// Establish connection to Asterisk Manager Interface
$socket = fsockopen($host, "5038", $errno, $errstr, 10);
if (!$socket) {
echo "$errstr ($errno)\n";
} else {
// Send login action to AMI
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: $username\r\n");
fputs($socket, "Secret: $secret\r\n\r\n");
// Send WaitEvent action to AMI
fputs($socket, "Action: WaitEvent\r\n");
// Send Logoff action to AMI (to close the connection after receiving events)
fputs($socket, "Action: Logoff\r\n\r\n");
// Read AMI events
while (!feof($socket)) {
$result = fread($socket, 5000);
$result .= date("Y-m-d H:i:s");
$events = ["SoftHangupRequest", "Newchannel", "ChallengeResponseFailed", "InvalidPassword", "InvalidAccountID", "Hold", "Unhold"];
// Check for specific events and take appropriate actions
foreach ($events as $value) {
if (preg_match("/\b$value\b/i", $result, $match)) {
echo "$result\n";
if ($value === "SoftHangupRequest") {
echo "$result\n";
mail("ambiorixg12@gmail.com", "Soft Hangup Request Event", $result);
}
if ($value === "Newchannel") {
echo "$result\n";
mail("ambiorixg12@gmail.com", "New Channel Event", $result);
}
if ($value === "ChallengeResponseFailed") {
echo "$result\n";
mail("ambiorixg12@gmail.com", "Challenge Response Failed Event", $result);
}
if ($value === "InvalidPassword") {
echo "$result\n";
mail("ambiorixg12@gmail.com", "Invalid Password Event", $result);
}
if ($value === "InvalidAccountID") {
echo "$result\n";
mail("ambiorixg12@gmail.com", "Invalid Account ID Event", $result);
}
if ($value === "Hold") {
echo "$result\n";
mail("ambiorixg12@gmail.com", "Call is On Hold", $result);
}
if ($value === "Unhold") {
echo "$result\n";
mail("ambiorixg12@gmail.com", "Call has been Unheld", $result);
}
}
}
}
}
fclose($socket);
?>