I am new to freepbx and asterisk
I need to know how to write a application that check each outbound call to see if that extension have permission.
for example I have 2 extension 100,200 and each time the one of the extension try to make outbound call I need to check in my database to see if he has that permission and if not block that call
sorry my English not so good
I am assuming that you have Asterisk installed and have basic setup with SIP soft phones configured.
You may need to add following to your /etc/asterisk/extensions.conf
[internal]
exten => _XXXXXXXXXX,1,Answer()
same => n,Set(callerid=${CALLERID(num)})
same => n,Verbose(Your Callerid is ${callerid})
same => n,Saydigits(${callerid})
same => n,AGI(check_callerid.php,${callerid})
;same => n,Hangup()
[welcome]
exten => s,1,Playback(welcome)
same => n,Verbose(Allowed to call)
;same => n,Dial(SIP/trunkname/${EXTEN})
[good_bye]
exten => s,1,Playback(goodbye)
same => n,Verbose(Not Allowed to call)
same => n,Hangup()
After that reload Asterisk:
asterisk -rvvvv
reload
Download phpagi library, run following commands at your Asterisk console
cd /var/lib/asterisk/agi-bin
git clone https://github.com/welltime/phpagi
Then create check_callerid.php
script at /var/lib/asterisk/agi-bin
and give full permission to it. Below script you may copy,
#!/usr/bin/php
<?php
global $agi;
require 'phpagi/phpagi.php';
$agi = new AGI();
$agi->answer();
$callerid = $argv[1];
$agi->verbose("CallerID is: $callerid");
$check_in_db = checkDB($callerid); //check caller allowed to do call
if($check_in_db==1){$agi->exec("Goto","welcome,s,1");} //allowed to do call, go to dial plan
else{$agi->exec("Goto","good_bye,s,1");} //not allowed to do call, go to dial plan
function checkDB($callerid){
//check here callerid allowed to do call or not
return 1;
}
?>
Now try to dial from one of your registered soft phone any 10 digits number your call will land to exten => _XXXXXXXXXX,1,Answer()
in your dial plan