asterisk-livecalls-mysql
Asterisk Livecalls with mysql
step1 : Create table livecalls(clid varchar(20),did varchar(20),uniqueid varchar(12),channel varchar(50),call_date timestamp);
Step 2 : Open extensions.conf and write the following code
exten => _X.,1,Answer
exten => _X.,2,Agi(livecall.php,${CDR(uniqueid)},${CHANNEL},${CALLERID(num)},${CALLERID(dnid)},NEWCALL)
exten => _X.,3,Playback(welcome)
exten => _X.,4,Hangup
exten => h,1,Agi(livecall.php,${CDR(uniqueid)},${CHANNEL},${CALLERID(num)},${CALLERID(dnid)},HANGUP)
Step 3 : Reload Asterisk (Core reload)
Step 4 : Create a PHP file call livecalls.php and put the PHP file under /var/lib/asterisk/agi-bin/
Step 5 : Open Terminal and use the following commands to make the file executable.
a) chmod +x livecalls.php
Step 6: Now that the call in is DB you can easily display that.
Following is the contents of the livecalls.php
-----------------------------------------------------------------------------------------
#!/usr/bin/php
<?php
error_reporting(0);
$uniqueid=$argv[1];
$action=$argv[3];
$channels=$argv[4];
$clid=$argv[5];
$did=$argv[7];
$conn=mysql_connect("localhost","root",'password') or die(mysql_error());
$db=mysql_select_db("livecall", $conn);
if(strtoupper($action)=='NEWCALL')
{
$sql="insert into livecalls (uniqueid,channel,clid,did,call_date) values('$uniqueid','$channels','$clid','$did',now())";
}
else if(strtoupper($action)=='HANGUP')
{
//Deleteing calls from live calls
$sql="delete from livecalls where uniqueid='".$uniqueid."'";
}
$results = mysql_query($sql,$conn);
mysql_close($conn);
?>
Note : Sometimes Asterisk doesn't get hangup events in those case this system can cause problem