asteriskdialplanphpagi

add pin conformation for outgoing call in asterisk 13


i want to add pin conformation for outgoing call in asterisk 13 before i implement this dial plan with asterisk 11. now i try it with asterisk 13. asterisk 13 in call always hangup

/etc/asterisk/extensions_custom.conf

[from-outgoinpin]
exten => _.,1,NoOp(CALLERID - ${EXTEN} | ${CALLERID(num)} | UNIQUEID - ${UNIQUEID} | ${CHANNEL} | ${CALLERID(RDNIS)} "--****************--")
exten => _.,2,AGI(outGoinPin.php,${EXTEN},${CALLERID(num)},${CHANNEL},${CALLERID(RDNIS)})
exten => _.,n,Hangup()

/var/lib/asterisk/agi-bin/outGoinPin.php

#!/usr/bin/php -q
<?
require('phpagi.php');
include('dbconn.php');
$agi = new AGI();
$agi->answer();
$number = $argv[1];
$exten = $argv[2];
$channel = $argv[3];
$dialedexten = $argv[4];
    if(strlen($number) >= 7 ){
        # try 1
        $result = $agi->get_data('enter-conf-pin-number', 3000, 4);
        $keys = $result['result'];
        $getPinValidate = getPinValidate($keys,$exten,$number);
        if(strlen($getPinValidate) > 0){
            $agi->exec_goto('from-internal',$number,1);
        }else{
            $agi->stream_file('pin-invalid');
            # try 2
            $result = $agi->get_data('enter-conf-pin-number', 3000, 4);
            $keys = $result['result'];
            $getPinValidate = getPinValidate($keys,$exten,$number);
            if(strlen($getPinValidate) > 0){
                    $agi->exec_goto('from-internal',$number,1);
            }else{
                $agi->stream_file('pin-invalid');
                    # try 3
                    $result = $agi->get_data('enter-conf-pin-number', 3000, 4);
                    $keys = $result['result'];
                    $getPinValidate = getPinValidate($keys,$exten,$number);
                if(strlen($getPinValidate) > 0){
                               $agi->exec_goto('from-internal',$number,1);
                }else{
                    $agi->stream_file('pin-invalid');
                    $agi->hangup();
                }
            }
        }
    }else{
        $agi->exec_goto('from-internal',$number,1);
    }   
function getPinValidate($keys,$exten,$number){
    $sql = "select `ext` from `asterisk`.`exten` where `pin`='$keys';";
    $PinResult = sendquery($sql);    
    $user = "";

    if(mysql_num_rows($PinResult) > 0){
        while($row = mysql_fetch_assoc($PinResult)){
                    $user = $row['ext'];
            }
        $sql = "insert into `asterisk`.`exten_log`(`date`,`ext`,`dst`,`user`,`type`) value (NOW(),'$exten','$number','$user','1');";
        $Result = sendquery($sql);
    }
    else{
        $sql = "insert into `asterisk`.`exten_log`(`date`,`ext`,`dst`,`user`,`type`) value (NOW(),'$exten','$number','$user','0');";
        $Result = sendquery($sql);
    }

    return $user;
}   
?>

/var/lib/asterisk/agi-bin/dbconn.php

#!/usr/bin/php -q

<?php
# connect to the database server
$link = mysql_connect('localhost','root','') or die('Could not connect: ' . mysql_error());

# select database
if(!mysql_select_db('phonikip_db')){
    echo 'DB init failed';
}

function sendquery($sql){
    return mysql_query($sql,$GLOBALS['link']);
}
?>

this is the error when i try to run this

error with debugging

how i fix this error or another way to do this


Solution

  • I'm not a PHP expert, so I won't fix your script, but I think I have a workaround. You can use "Authenticate" application to achieve that. It basically ask caller to introduce a key to continue with the dialplan. [from-outgoinpin]

    exten => _.,1,Authenticate(<YOUR PIN HERE>) same => n,whatever you want

    Here the docs: https://wiki.asterisk.org/wiki/display/AST/Application_Authenticate

    Hope it helped :)