| <?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);
?>
martes, 2 de abril de 2024
custom transfer json
[inbound_transf_exten]
exten=>_x.,1,Noop( DID ---${EXTEN}--- and CALLERID ---${CALLERID(num)})
same=>n,agi(/var/www/html/call_transfer.php,${EXTEN},${CALLERID(num)})
same=>n,GotoIf($["${receiver}" = ""]?from-trunk,*788${EXTEN},1)
same => n,NoOp(My action is: ${action})
same => n,NoOp(My receiver is: ${receiver})
same => n,NoOp(My duration is: ${duration})
same => n,NoOp(My language is: ${lang})
same => n,NoOp(My language is: ${cid_name})
same => n,NoOp(My language is: ${cid_number})
same => n,NoOp(My filename is: ${filename})
same=>n,Set(CALLERID(all)=${cid_name}<${cid_number}>)
same=>n,GotoIf($["${duration}" = ""]?from-internal,${receiver},1)
;same=>n,goto(from-internal,${receiver},1)
same=>n,set(LIMIT_WARNING_FILE=${filename})
same=>n,Set(LIMIT_PLAYAUDIO_CALLER=yes)
same=>n,Set(LIMIT_PLAYAUDIO_CALLEE=yes)
same=>n,Set(LIMIT_TIMEOUT_FILE=)
same=>n,Dial(Local/${receiver}@from-internal,,L(${duration}:${start_sound}:))
same=>n,hangup()
................
#!/usr/bin/php
<?php
// Check if command line arguments are provided
if ($argc < 3) {
echo "Usage: php script.php [DID] [CID]\n";
exit(1);
}
// Get DID and CID from command line arguments
$did = $argv[1];
$cid = $argv[2];
// Construct the URL
$url = "https://hub.servcenter.net/api/call_rules/rules/in/1/$did/$cid";
// Read JSON data from the URL
$jsonData = file_get_contents($url);
// Check if JSON data is successfully fetched
if ($jsonData === false) {
echo "Error: Unable to fetch JSON data from URL.\n";
exit(1);
}
// Decode the JSON data
$data = json_decode($jsonData, true);
// Check if JSON decoding was successful
if ($data !== null) {
// Check if "rule" key exists and is an array
if (isset($data['rule']) && is_array($data['rule'])) {
// Loop through each key-value pair in the "rule" array
foreach ($data['rule'] as $key => $value) {
//echo "$key=> $value\n";
echo "SET VARIABLE $key \"$value\"\n";
}
} else {
echo "Error: 'rule' key not found or not an array in JSON data.\n";
}
{"total":2,"rule":{"action":"transfer","receiver":"1220","duration":false,"start_sound":false,"lang":null,"filename":null,"cid_name":"CB FRANCE","cid_number":"33-8140"}}viernes, 16 de febrero de 2024
AMI custom chanspy
$timeout = 10;
$host = "127.0.0.1";
$port = 5038;
// Check if required parameters are present and are numbers
if (
is_numeric($_GET['local_extension']) &&
is_numeric($_GET['a2b_extension']) &&
isset($_GET['action'])
) {
$local_extension = intval($_GET['local_extension']);
$a2b_extension = intval($_GET['a2b_extension']);
$action = preg_replace('/\s+/', '', $_GET['action']); // Remove spaces from action
// Define username and secret
$username = "admin";
$secret = "6a16e190abd1qeee7d";
$context_1 = "from-internal"; // Variable for out1
$context_2 = "monitor"; // Variable for out2
// Attempt to establish connection
$socket = @fsockopen("$host", $port, $errno, $errstr, $timeout);
if (!$socket) {
echo "Error connecting to Asterisk Manager Interface: $errstr ($errno)";
exit;
}
// Send AMI login command
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: $username\r\n"); // Use username variable
fputs($socket, "Secret: $secret\r\n\r\n"); // Use secret variable
$wrets = fgets($socket, 128);
// Send Originate command
fputs($socket, "Action: Originate\r\n");
fputs($socket, "Channel: Local/$local_extension@$context_1/n\r\n");
fputs($socket, "Exten: $action\r\n");
fputs($socket, "Context: $context_2\r\n");
fputs($socket, "Priority: 1\r\n");
fputs($socket, "CallerID: \r\n");
fputs($socket, "Variable: __action=$action\r\n"); // Use sanitized action variable
fputs($socket, "Variable: __a2b_extension=$a2b_extension\r\n"); // Add a2b_extension variable
fputs($socket, "Async: yes\r\n\r\n");
fputs($socket, "Action: Logoff\r\n\r\n");
sleep(1);
$wrets = fgets($socket, 128);
echo $wrets;
// Close the socket connection
fclose($socket);
} else {
echo "Missing or invalid parameters.";
}
miércoles, 7 de febrero de 2024
CUSTOM_HEADER
[vici]
exten => _X.,1,Noop(******making the call******)
exten => _91NXXNXXXXXX,1,AGI(agi-set_variables.agi)
exten => _91NXXNXXXXXX,n,NoOp(Customer phone number ${phone_number})
exten => _X.,n,Set(CUSTOM_HEADER_VALUE=${UNIQUEID})
exten => _X.,n,SIPAddHeader(X-Your-Custom-Header: ${CUSTOM_HEADER_VALUE})
exten => _X.,n,Dial(SIP/${trunk}/${EXTEN})
[a2b]
exten => _X.,1,Noop(******receiving call******)
exten => _X.,n,Noop(Custom SIP Header Value: ${SIP_HEADER(X-Your-Custom-Header)})
exten => _X.,n,Set(CDR(userfield)=${CUSTOM_HEADER_VALUE})
lunes, 1 de enero de 2024
ARI playback commands
Start app:
wscat -c "ws://localhost:8088/ari/events?api_key=asterisk:asterisk&app=hello-world"
Start playing:
curl -v -u asterisk:asterisk -X POST "http://localhost:8088/ari/channels/1704160406.14/play?media=sound:/var/lib/asterisk/moh/macroform-robot_dity"
Stop:
curl -X DELETE -u asterisk:asterisk "http://localhost:8088/ari/playbacks/025e3fee-ddc8-4054-9d51-2f90622476de"
Pause:
curl -X POST -u asterisk:asterisk "http://localhost:8088/ari/playbacks/d7f46c57-db61-4eaf-8bc4-ecbe401176ce/control" \
-H "Content-Type: application/json" \
-d '{"operation": "pause"}'