Skip to content

Instantly share code, notes, and snippets.

@verawatk
Created January 31, 2017 08:59
Show Gist options
  • Save verawatk/93b248a27affcbe82eb7be7a96f86a49 to your computer and use it in GitHub Desktop.
Save verawatk/93b248a27affcbe82eb7be7a96f86a49 to your computer and use it in GitHub Desktop.
#!/usr/bin/php -q
<?php
/**
* Created by JetBrains PhpStorm.
* User: verawatk
* Date: 1/5/14
* Time: 13:21
* To change this template use File | Settings | File Templates.
*/
//set_time_limit(30);
include(dirname(__FILE__) . "/phpagi.php");
error_reporting(E_ALL);
/*
$agi = new AGI();
$agi->exec("Progress");
$agi->stream_file("connect_failed","#");
$agi->hangup();
exit();
*/
function urlsafe_b64encode($string)
{
$data = base64_encode($string);
$data = str_replace(array('+','/','='),array('-','_','.'),$data);
return $data;
}
$agi = new AGI();
$calleridnum = $agi->request['agi_callerid'];
$callerid = $agi->request['agi_callerid'];
$callidname = $agi->request['agi_calleridname'];
$phoneno = $agi->request['agi_dnid'];
$channel = $agi->request['agi_channel'];
$uniqueid = $agi->request['agi_uniqueid'];
$ch = curl_init();
$key = "4fbb348f0cc531e670e0b0145c69ac24";
$phoneno = substr($phoneno,1);
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $phoneno, MCRYPT_MODE_CBC, md5(md5($key))));
$safe_en = urlsafe_b64encode($encrypted);
$post = "username=hello_abc";
$post = $post."&number=";
$post = $post.$safe_en;
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($ch,CURLOPT_TIMEOUT,2);
curl_setopt($ch,CURLOPT_URL,"http://192.168.1.10/index.php/check_no");
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$server_output = curl_exec($ch);
$server_status = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
$agi->verbose($server_output,1);
if( !$server_status){
$agi->exec("Progress");
$agi->stream_file("connect_failed","#");
$agi->hangup();
exit();
}
if($server_status != 401 and $server_status !=200 ){
$agi->exec("Progress");
$agi->stream_file("connect_failed","#");
$agi->hangup();
exit();
}
if( $server_status == 401){
$agi->exec("Progress");
$agi->stream_file("unauthorized","#");
$agi->hangup();
exit();
}
if( $server_status == 200){
$result = json_decode($server_output,true);
if($result['provider'] == 1){
$agi->exec("Progress");
$agi->stream_file("ais","#");
$agi->exec_dial("SIP","openvox64/1".$phoneno);
}else if($result['provider'] == 2){
$agi->exec("Progress");
$agi->stream_file("dtac","#");
$agi->exec_dial("SIP","openvox64/2".$phoneno);
}else if($result['provider'] == 3){
$agi->exec("Progress");
$agi->stream_file("truemove","#");
$agi->exec_dial("SIP","openvox64/3".$phoneno);
}else if($result['provider'] == 0){
$agi->exec("Progress");
$agi->stream_file("unidentified","#");
}else{
$agi->exec("Progress");
$agi->stream_file("unidentified","#");
}
$agi->hangup();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment