<?php
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
header('Content-Type: application/json');
echo json_encode($_REQUEST, JSON_PRETTY_PRINT);
$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']);
$socket = fsockopen("$host","$port", $errno, $errstr, 10);
if (!$socket){
echo "$errstr ($errno)\n";
}else{
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: admin\r\n");
fputs($socket, "Secret: oy13xtq7h\r\n\r\n");
$wrets=fgets($socket,128);
// echo $wrets;
fputs($socket, "Action: Originate\r\n" );
fputs($socket, "Channel: Local/$src@internal\r\n" );
fputs($socket, "Exten: $dst\r\n" );
fputs($socket, "Context: internal\r\n" );
fputs($socket, "Priority: 1\r\n" );
fputs($socket, "CallerID: $cid\r\n" );
fputs($socket, "Variable: __ext=$ext\r\n" );
fputs($socket, "Variable: __dest=$dest\r\n" );
fputs($socket, "Variable: __cid=$callerid\r\n" );
fputs($socket, "Async: yes\r\n\r\n" );
fputs($socket, "Action: Logoff\r\n\r\n");
while (!feof($socket)){
$result=fgets($socket);
$result= stristr($result,"$number");
$d=strlen($result);
}
fclose($socket);
}
?>
;;;;;;;;;;;;;;;;
exten=>_*x.,1,Noop(${EXTEN})
same=>n,Agi(/root/vars.py,${EXTEN})
same=>n,Noop(------${prefix} ${cid} ${dst}---)
;same=>n,Set(CALLERID(num)=${cid})
same => n,ExecIf($[${LEN(${cid})} > 0]?Set(CALLERID(num)=${cid}):)
same=>n,goto(internal,**${prefix}${dst},1)
same=>n,hangup()
---------
nano /root/vars.py
#!/usr/bin/env python3
import sys
number=sys.argv[1]
e=number.split('*')
e=[int(a) for a in e if len(a)>0]
cid='cid'
dst='dst'
prefix='prefix'
print(f'SET VARIABLE {prefix} "{e[0]}"\n')
print(f'SET VARIABLE {cid} "{e[1]}"\n')
print(f'SET VARIABLE {dst} "{e[2]}"\n')
.....
[usa]
exten=>_**1.,1,Gosub(monitor,${EXTEN:3},1)
same=>n,Dial(PJSIP/zadarma/sip:+${EXTEN:3}@185.45.155.17:5060,,r)
same=>n,hangup()
exten=>h,1,Noop(${path}${STRFTIME(${EPOCH},,%Y-%m-%d_%H-%M-%S)}-${EXTEN}_${src}.wav)
same=>n,System(python3 /root/s3_recordings.py ${file})
[voipcloud]
exten=>_**4.,1,Gosub(monitor,${EXTEN:3},1)
same=>n,Set(CALLERID(num)=+61480039787)
same=>n,Dial(PJSIP/t1/sip:+${EXTEN:3}@sipm2.au.voipcloud.online:7060,,r)
same=>n,hangup()
exten=>h,1,Noop(${path}${STRFTIME(${EPOCH},,%Y-%m-%d_%H-%M-%S)}-${EXTEN}_${src}.wav)
same=>n,System(python3 /root/s3_recordings.py ${file})