forked from Jolt1/Jolt-Select-Dial-PBX
-
Notifications
You must be signed in to change notification settings - Fork 5
/
call.php
74 lines (63 loc) · 2.13 KB
/
call.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$strUser = "user123"; #specify the asterisk manager username you want to login with
$strSecret = "pass123"; #specify the password for the above user
$strHost = "127.0.0.1";
//Clean up EXT
$ext = $_GET['exten'];
$ext = filter_var($ext, FILTER_SANITIZE_NUMBER_INT);
$ext = preg_replace("/[^0-9,.]/", "", $ext);
$strChannel = "SIP/".$ext;
$strContext = "from-internal";
#specify the amount of time you want to try calling the specified channel before hangin up
$strWaitTime = "30";
#specify the priority you wish to place on making this call
$strPriority = "1";
#specify the maximum amount of retries
$strMaxRetry = "2";
if(isset($_GET['number'])){
$number=strtolower($_GET['number']);}
elseif(isset($_GET['phone'])){
$number=strtolower($_GET['phone']);
}
//Clean up number
$number = filter_var($number, FILTER_SANITIZE_NUMBER_INT);
$number = preg_replace("/[^0-9,.]/", "", $number);
//Line 40 adds a 1 before the number if its not there already...
//You can remove this if you already added this into your outbound route or you dont need a 1.
//if(substr($number,0,1) != 1){$number = "1".$number;}
$pos=strpos ($number,"local");
if ($number == null) :
exit() ;
endif ;
if ($pos===false) :
$errno=0 ;
$errstr=0 ;
//OPEN CNAM LOOKUP
$callerid = file_get_contents("https://api.opencnam.com/v2/phone/".$number);
$strCallerId = $callerid." <$number>";
$oSocket = fsockopen ("localhost", 5038, $errno, $errstr, 20);
if (!$oSocket) {
echo "$errstr ($errno)<br>\n";
} else {
fputs($oSocket, "Action: login\r\n");
fputs($oSocket, "Events: off\r\n");
fputs($oSocket, "Username: $strUser\r\n");
fputs($oSocket, "Secret: $strSecret\r\n\r\n");
fputs($oSocket, "Action: originate\r\n");
fputs($oSocket, "Channel: $strChannel\r\n");
fputs($oSocket, "WaitTime: $strWaitTime\r\n");
fputs($oSocket, "CallerId: $strCallerId\r\n");
fputs($oSocket, "Exten: $number\r\n");
fputs($oSocket, "Context: $strContext\r\n");
fputs($oSocket, "Priority: $strPriority\r\n\r\n");
fputs($oSocket, "Action: Logoff\r\n\r\n");
sleep(2);
fclose($oSocket);
}
echo "Extension $strChannel should be calling $number." ;
else :
exit() ;
endif ;
?>