FreePBX | Register | Issues | Wiki | Portal | Support

Limit monthly outbound calls with AGI script


(South Africa) #1

Good day,

I have an agi script that limits the total minutes a user is able to dial out per month. The script stopped working 2 months or so ago (possibly from an update or accidental change).

My questions are:

  1. How do I check if the extension is executing the AGI script? I do not see the agi script called billsec.php beign triggered on outbound calls so where would I need to check this?

  2. Please review AGI script, maybe there are something silly like a typo (I doubt but you never know) and if the AGI script is setup correctly

    #!/usr/bin/php -q
    <?php
    ob_implicit_flush(false);
     error_reporting(0);
     set_time_limit(30);
    require('/var/lib/asterisk/agi-bin/phpagi.php');
    $username = "root";
    $password = "st1nk13";
    $hostname = "localhost";

    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password)
     or die("Unable to connect to MySQL");

    $selected = mysql_select_db("asteriskcdrdb",$dbhandle)
      or die("Could not select examples");

    $ext = $argv[1];
    $agi = new AGI();
    //$agi -> answer();

    $MONTH=date("m"); //we just need the moth for now.
    $YEAR=date("Y");

    if ($ext != 728) {


    $agi->verbose("No Limit Set for Extension");
    exit;
    }

    $query = mysql_query("SELECT sum(billsec) AS totalminute from cdr WHERE disposition = 'ANSWERED' AND dst like '0%' and src='$ext' and month(calldate) = $MONTH and year(calldate) = $YEAR LIMIT 1");

    if ($query) {

    if($row = mysql_fetch_array($query)) {

    $agi->verbose($row['calldate']);
    $agi->verbose($row['disposition']);


    if($row['totalminute']>16800) {
    $agi->verbose($row['totalminute']);
    $agi->stream_file("prepaid-account-has-locked","#");
    $agi->hangup();
    }
    }
    }
    mysql_close($dbhandle);

    ?>

(South Africa) #2

Thank you for the edit


(system) closed #3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.