示例#1
0
	To:	variables_order = "EGPCS"
The order forthe value of variables_order is IMPORTANT!

In features.conf under [applicationmap] you need to add:
log_call_caller => *#,self/caller,agi,/var/lib/asterisk/agi-bin/log_bad_call.php
log_call_callee => *#,self/callee,agi,/var/lib/asterisk/agi-bin/log_bad_call.php

Then in the dial plan you need to add in your dial plan something like:
Exten => _X.,1,set(__DYNAMIC_FEATURES=log_call_caller#log_call_callee)
*/
$email_contact = '*****@*****.**';
//seperate them by ,
$agi = new AGI();
$sip_callid = get_var('SIPCALLID');
$peername = get_channel_var('peername');
$agi->verbose("WE NEED TO LOG CALL WITH SIP CALL ID {$sip_callid} FROM VOIPMONITOR AS PEER {$peername} IS COMPLAINING");
$values_to_get = array('audioreadformat', 'audionativeformat', 'audiowriteformat', 'peerip', 'recvip', 'from', 'uri', 'useragent', 'peername', 'peerip', 'peername', 'channeltype', 'rtpdest');
$email_msg = '';
$email_msg .= "Hi there,\n\n";
$email_msg .= "The peer {$peername} just dialed *# to indicate that they may have a quality issue. Below is the details of the call.\n\n\n";
foreach ($values_to_get as $item) {
    $var = get_channel_var($item);
    $email_msg .= "{$item}: {$var}\n";
}
$email_msg .= "PCAP URL: http://voipmonitor.example.org/?callid={$sip_callid}\n";
$email_msg .= "\n\n\n";
//Output the message so we have it in our logs.
$agi->verbose($email_msg);
$parent_email = explode(',', $email_contact);
foreach ($parent_email as $email) {
    $subject = "Call quality complaint from {$peername}";
    $PK_Extension = $row['PK_Extension'];
    $query = "INSERT INTO Ext_Queue_Members_Status (FK_Extension, `From`) VALUES({$PK_Extension}, '{$agent_phone_number}')";
    $mysqli->query($query) or die($mysqli->error);
}
while (true) {
    // Get agent number if we shoud request it else use calling extension al agent number
    if ($AgentLogin['EnterExtension']) {
        $agent_number = read_agent_number();
    } else {
        $agent_number = $caller_ext;
    }
    // Request password for this agent
    if ($AgentLogin['RequirePassword']) {
        $agent_password = read_agent_password();
        if (agent_auth_ok($agent_number, $agent_password)) {
            $agi->verbose('---------------------------------------HERE');
            break;
        }
    } else {
        break;
    }
}
// Agent phone number = extension from this agentlogin was called
$agent_phone_number = $caller_ext;
if ($AgentLogin['LoginToggle']) {
    if (agent_logout($agent_number)) {
        $agi->stream_file('agent-loggedoff');
    } else {
        agent_login($agent_number, $agent_phone_number);
        $agi->stream_file('agent-loginok');
    }
示例#3
0
}
// Get Called Extension informations
$called_ext = $agi->request['agi_extension'];
// Get Caller Extension infomation
$cid = $agi->parse_callerid();
$caller_ext = $cid['username'];
$Extension_S = DB_Extension($caller_ext);
//CDR: Set caller information
$cdr->set_caller($Extension_S['PK_Extension'], $Extension_S['Type'], DB_Extension_Name($caller_ext), $caller_ext);
//CDR: Set called information
$cdr->set_called(0, '', '', $called_ext);
// CDR: Push dial event
$cdr->push_event("DIAL", $called_ext);
// See if we can match any outgoing rule
$query = "SELECT * FROM OutgoingRules ORDER BY RuleOrder";
$result = $mysqli->query($query) or $agi->verbose($mysqli->error . $query);
while ($rule = $result->fetch_assoc()) {
    // Check if rule matches
    $regex = "/^{$rule['BeginWith']}[0-9]{{$rule['RestBetweenLow']},{$rule['RestBetweenHigh']}}\$/";
    if (!preg_match($regex, $called_ext)) {
        continue;
    }
    // Create new_number
    $new_number = substr($called_ext, $rule['TrimFront']);
    $new_number = $new_number . $rule['PrependDigits'];
    break;
}
// Exit if no rule was matched
if ($new_number == "") {
    $agi->verbose('Cannot match any outgoing rule for number :' . $called_ext);
    exit(0);
示例#4
0
#!/usr/bin/php -q 
<?php 
require 'phpagi.php';
include_once 'netsds.inc';
$agi = new AGI();
if (isset($argv[1])) {
    $msisdn = $argv[1];
} else {
    $agi->verbose("MSISDN does not exist.");
    exit(0);
}
$pgdbh = netsds_connect();
$query = "select operator from primary_operators where number='" . $msisdn . "'";
$res = pg_query($pgdbh, $query) or die("Query failed.");
$a = pg_fetch_array($res);
$listed = $a[0];
pg_close($pgdbh);
if ($listed) {
    $agi->verbose("OPERATOR: " . $listed);
    $agi->set_variable("PRIMARY_OPERATOR", trim($listed));
}
$cdr = new AGI_CDR($agi);
// Get Called Extension informations
$called_ext = $agi->request['agi_extension'];
$Extension_D = DB_Extension($called_ext);
// Get 'Intercom' Parameters
$Intercom = Database_Entry('Ext_Intercom', $Extension_D['PK_Extension']);
// Get the extension of the caller
$cid = $agi->parse_callerid();
$caller_ext = $cid['username'];
// See if the caller is allowed to use this extension
if ($Intercom['Use_Admins_ByAccount']) {
    $query = "\n\t\tSELECT\n\t\t\tExtension\n\t\tFROM\n\t\t\tExt_Intercom_Admins\n\t\t\tINNER JOIN Extensions ON PK_Extension = FK_Ext_Admin\n\t\tWHERE\n\t\t\tFK_Extension = {$Intercom['PK_Extension']}\n\t\t\tAND\n\t\t\tExtensions.Extension = {$caller_ext}\n\t\tLIMIT 1\n\t";
} else {
    $query = "\n\t\tSELECT\n\t\t\tExtension\n\t\tFROM\n\t\t\tExt_Intercom_Admins\n\t\t\tINNER JOIN Extension_Groups ON Extension_Groups.FK_Group = Ext_Intercom_Admins.FK_Ext_Group\n\t\t\tINNER JOIN Extensions       ON Extensions.PK_Extension   = Extension_Groups.FK_Extension\n\t\tWHERE\n\t\t\tExt_Intercom_Admins.FK_Extension = {$Intercom['PK_Extension']}\n\t\t\tAND\n\t\t\tExtensions.Extension = {$caller_ext}\n\t\tLIMIT 1\n\t";
}
$result = $mysqli->query($query) or $agi->verbose($mysqli->error . $query);
if ($mysqli->numrows($result) != 1) {
    $agi->stream_file('beeperr');
    $agi->hangup();
    exit(0);
}
//CDR: Set called info
$cdr->set_called("{$Intercom['PK_Extension']}", "Intercom", "Intercom", "{$Extension_D['Extension']}");
$agi->set_variable('__SIP_URI_OPTIONS', 'intercom=true');
$agi->set_variable('SIPURI', 'intercom=true');
$agi->set_variable('_VXML_URL', 'intercom=true');
$agi->exec('AbsoluteTimeout', $Intercom['Timeout']);
$agi->exec('SipAddHeader', $Intercom['Header']);
$agi->exec('SipAddHeader', '"Call Info: Answer-After=0"');
$agi->exec('SipAddHeader', '"Alert-Info: Ring Answer"');
$agi->exec('SipAddHeader', '"Call-Info: <uri>\\;answer-after=0"');
示例#6
0
#!/usr/bin/php -q 
<?php 
// IVR history. Version 0.2.0.
// It requires netsds.inc to connect to the database
// It requires phpagi to work with Asterisk.
/* Usage: 
	cdr(calldate),cdr(src),custom destination, 
	dtmf, previous context, current_context, 
	previous ID, seconds (integer) in previous context. 

*/
include_once 'netsds.inc';
/* navigation and taps logs */
$agi = new AGI();
if (!isset($argv[1]) or !isset($argv[2]) or !isset($argv[3]) or !isset($argv[4]) or !isset($argv[5]) or !isset($argv[6]) or !isset($argv[7]) or !isset($argv[8])) {
    $agi->verbose("Usage: cdr(calldate) cdr(src) custom_dst dtmf previous_context current_context previous_id previous_seconds");
    exit(0);
}
$cdr_calldate = $argv[1];
$cdr_src = $argv[2];
$custom_dst = $argv[3];
// $moment = now();
$dtmf = $argv[4];
$previous_context = $argv[5];
$current_context = $argv[6];
$previous_id = $argv[7];
$previous_seconds = $argv[8];
$pgdbh = netsds_connect();
$agi->verbose("Previous id is {$previous_id}");
if ($previous_id > 0) {
    // We have previous ID.
示例#7
0
 * We would be happy to list your phpagi based application on the phpagi
 * website.  Drop me an Email if you'd like us to list your program.
 *
 * @package phpAGI
 * @version 2.0
 * @example docs/fastagi.xinetd Example xinetd config file
 */
/**
 * Written for PHP 4.3.4, should work with older PHP 4.x versions.
 * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/
 * Gracias. :)
 *
 */
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpagi.php';
$fastagi = new AGI();
$fastagi->verbose(print_r($fastagi, true));
if (!isset($fastagi->config['fastagi']['basedir'])) {
    $fastagi->config['fastagi']['basedir'] = dirname(__FILE__);
}
// perform some security checks
$script = $fastagi->config['fastagi']['basedir'] . DIRECTORY_SEPARATOR . $fastagi->request['agi_network_script'];
// in the same directory (or subdirectory)
$mydir = dirname($fastagi->config['fastagi']['basedir']) . DIRECTORY_SEPARATOR;
$dir = dirname($script) . DIRECTORY_SEPARATOR;
if (substr($dir, 0, strlen($mydir)) != $mydir) {
    $fastagi->conlog("{$script} is not allowed to execute.");
    exit;
}
// make sure it exists
if (!file_exists($script)) {
    $fastagi->conlog("{$script} does not exist.");
示例#8
0
文件: IVR.php 项目: wdoyle/phpivr
#!/usr/bin/php -q
<?php 
/*
 *  IVR.php
 *  
 *  IVR AGI приложение для Asterisk PBX
 *  
 *  Григорий Майстренко (Grygorii Maistrenko)
 *  grygoriim@gmail.com
 */
include dirname(__FILE__) . "/lib/Class.IVR.php";
include dirname(__FILE__) . "/lib/phpagi-2.14/phpagi.php";
$agi = new AGI();
//$agi->verbose(basename(__FILE__).":".__LINE__." - Входящие параметры ".print_r($argv, true));
if (isset($argv[1]) && $argv[1] != "") {
    $MENUID = $argv[1];
    //$agi->verbose(basename(__FILE__).":".__LINE__." - Передан параметр".print_r($resrun, true));
} else {
    $MENUID = "common";
}
$ivr = new IVR($agi);
$resrun = $ivr->Run($MENUID);
if ($resrun != '-1') {
    // делаем трансфер
    $resrun = $agi->exec("TRANSFER {$resrun}");
    $agi->verbose(basename(__FILE__) . ":" . __LINE__ . " - " . print_r($resrun, true));
}
示例#9
0
list: The list of strings separated by a character (example: 1&2&3)
item: The value of the item to remove
varname: The variable to return the new list in
listseparator: The separator.  This defaults to "&" if it is not specified.
*/
/* --------WARNING---------
 * 
 * This script is auto-copied from an included module and will get overwritten.
 * If you modify it, you must change it to write only, in the agi-bin directory,
 * to keep it from getting changed.
 */
include "phpagi.php";
$agi = new AGI();
if (!isset($argv[1])) {
    $agi->verbose("Missing list");
    exit(1);
}
if (!isset($argv[2])) {
    $agi->verbose("Missing item");
    exit(1);
}
if (!isset($argv[3])) {
    $agi->verbose("Missing return var name");
    exit(1);
}
$arglist = $argv[1];
$argitem = $argv[2];
$argvarname = $argv[3];
if (isset($argv[4])) {
    $argsep = "&";
$agi->answer();
//wait a minute to give everything a chance to settle
sleep(2);


//I had it set up to check the callerid against a set of valid peeps - but i decided i was tired of that. and it made it too complex.
//get caller id. 
$cid = $agi->parse_callerid();
$cid= $cid[username];

//streamfile that says "Enter number to spoof"
$agi->stream_file('enter_spoof');
//beep then get the resulting 10 digits - set it to spoofnumber
$result = $agi->get_data('beep', 3000, 10);
$spoofnumber= $result['result'];
$agi->verbose("Spoof Number:".$spoofnumber);
//streamfile that says "enter number to call"
$agi->stream_file('call_spoof');
//beep then get the resulting 10 digits - set it to callnumber
$result = $agi->get_data('beep', 3000, 10);
$callnumber= $result['result'];
$agi->verbose("Number to call:".$callnumber);
// set caller id to the spoofnumber
$agi->set_callerid($spoofnumber);

//call the number using whatever you got
//notice i have placed the 1 before the callnumber. this is so that i can keep everything ten digits. and cuz i am lazy
$agi->exec("Dial IAX2/yourpassword@provider/1".$callnumber);


// That is it. simple.. scary and easy
示例#11
0
#!/usr/bin/php -q 
<?php 
// It requires netsds.inc to connect to the database
// It requires phpagi
include_once 'netsds.inc';
/* navigation and taps logs */
$agi = new AGI();
if (!isset($argv[1]) or !isset($argv[2]) or !isset($argv[3]) or !isset($argv[4]) or !isset($argv[5]) or !isset($argv[6])) {
    $agi->verbose("Usage: cdr(calldate) cdr(src) custom_dst dtmf previous_context current_context");
    exit(0);
}
$cdr_calldate = $argv[1];
$cdr_src = $argv[2];
$custom_dst = $argv[3];
// $moment = now();
$dtmf = $argv[4];
$previous_context = $argv[5];
$current_context = $argv[6];
$pgdbh = netsds_connect();
$query = sprintf("insert into ivr.navigation_taps_logs (cdr_calldate, cdr_src, custom_dst, dtmf, previous_context, current_context ) values ('%s','%s','%s','%s','%s','%s');", $cdr_calldate, $cdr_src, $custom_dst, $dtmf, $previous_context, $current_context);
pg_query($pgdbh, $query);
pg_close($pgdbh);
$agi->verbose("Navigation logs saved", 3);
exit(0);
#!/usr/bin/php -q 
<?php 
// IVR history. Version 0.2.0.
// It requires netsds.inc to connect to the database
// It requires phpagi to work with Asterisk.
/* Usage: 
	cdr(calldate),cdr(src),custom destination, 
	dtmf, previous context, current_context, 
	previous ID, seconds (integer) in previous context. 

*/
include_once 'netsds.inc';
/* navigation and taps logs */
$agi = new AGI();
if (!isset($argv[1]) or !isset($argv[2]) or !isset($argv[3]) or !isset($argv[4])) {
    $agi->verbose("Usage: cdr(calldate) cdr(src) custom_dst seconds");
    exit(0);
}
$cdr_calldate = $argv[1];
$cdr_src = $argv[2];
$custom_dst = $argv[3];
$seconds = $argv[4];
$pgdbh = netsds_connect();
$select = pg_query($pgdbh, "select id from ivr.navigation_taps_logs where cdr_calldate='" . $cdr_calldate . "' and cdr_src='" . $cdr_src . "' and custom_dst='" . $custom_dst . "' order by id desc limit 1");
$row = pg_fetch_row($select);
$agi->verbose("ID is " . $row[0]);
pg_query($pgdbh, "update ivr.navigation_taps_logs set seconds={$seconds} where id=" . $row[0]);
pg_close($pgdbh);
exit(0);
示例#13
0
$peer = get_channel_var('peername');
$email_msg = '';
$email_msg .= "Hi there,\n\n";
$email_msg .= "The peer {$peer} just dialed *222 to indicate that they may have a quality issue. Below is the details of the connection as well as a trace.\n\n\n";
foreach ($values_to_get as $item) {
    $var = get_channel_var($item);
    $email_msg .= "{$item}: {$var}\n";
}
$email_msg .= "\n\n\n";
$rtp_ip = get_channel_var('rtpdest');
$rtp_ip = explode(':', $rtp_ip);
$rtp_ip = $rtp_ip[0];
$output = shell_exec("/usr/sbin/mtr -o \"L SRD NBAW JMXI\" --report --report-cycles 5 --no-dns {$rtp_ip}");
$email_msg .= $output;
//Output the message so we have it in our logs.
$agi->verbose($email_msg);
$parent_email = explode(',', $email_contact);
foreach ($parent_email as $email) {
    $subject = "Call quality complaint from {$peername}";
    $headers = 'From: no-reply@example.org' . "\r\n" . 'Reply-To: no-reply@example.org' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
    mail($email, $subject, $email_msg, $headers);
}
$agi->exec('PlayBack', 'privacy-thankyou');
function get_channel_var($var)
{
    global $agi;
    $chann_var_to_get = 'CHANNEL(' . $var . ')';
    $my_channel_var = $agi->get_variable($chann_var_to_get);
    $my_channel_var = $my_channel_var['data'];
    return $my_channel_var;
}
示例#14
0
        } else {
            return false;
        }
    }
    if (strncmp($str, $prefix, $len) == 0) {
        return substr($str, $len);
    } else {
        return false;
    }
}
require "cardfns.inc.php";
require "dialfns.inc.php";
include "voucher.inc.php";
require "dialstring.inc.php";
require "dialspecial.inc.php";
switch ($mode) {
    case 'standard':
        require "mode-standard.inc.php";
        break;
    case 'voucher':
        require "mode-voucher.inc.php";
        break;
    case 'did':
        require "mode-did.inc.php";
        break;
    default:
        @syslog(LOG_ERR, "A2Billing AGI: cannot handle mode {$mode}");
        $agi->verbose("Cannot handle mode {$mode}", 1);
        exit(1);
}
//exit();