First of all, thanks all for your answers. Here is how I achieved to do this, in case someone need this:
#!/bin/bash
vacio="`ls -lrt /var/lib/asterisk/blacklist/ | wc -l`"
if [ "$vacio" != "1" ]; then
if [ "$1" == "" ]; then
VALUE=0;
echo "Sin argumento de entrada" >> /var/log/asterisk/log_blacklist_SERVICE1
else
IsBlackListed="`grep $1 /var/lib/asterisk/blacklist/SERVICE1`"
if [ "$IsBlackListed" != "" ]; then
VALUE=0;
echo "LLAMADA BLOQUEADA: " $1 >> /var/log/asterisk/log_blacklist_SERVICE1
else
VALUE=1;
fi
fi
else
VALUE=1;
echo "FICHERO VACIO" >> /var/log/asterisk/log_blacklist_SERVICE1
fi
echo -e "SET VARIABLE answer $VALUE"
export answer=$VALUE
I stored this script here /var/lib/asterisk/agi-bin/blacklist_SERVICE.sh
You have to put a list of numbers to block in files like this one
/var/lib/asterisk/blacklist/SERVICE
101
102
Give script permissions to execute:
chmod +x /var/lib/asterisk/agi-bin/blacklist_SERVICE.sh
If you have generated the script in Windows, you will need to reformat it with this command:
dos2unix /var/lib/asterisk/agi-bin/blacklist_SERVICE.sh
In order to execute the script each time that a call hits a queue, I overrided Freepbx dialplan config using /etc/asterisk/extensions_override_freepbx.conf
This is the default config for a queue in /etc/asterisk/extensions_additional.conf
[ext-queues]
include => ext-queues-custom
exten => 100,1,Macro(user-callerid,)
exten => 100,n,Answer
exten => 100,n,Macro(blkvm-set,reset)
So in /etc/asterisk/extensions_override_freepbx.conf you need to put this in order to execute the script and if the answer of it is equal to 0, go to “gotodest” which is the last command for a queue in the context:
[ext-queues]
exten => 100,3,agi(/var/lib/asterisk/agi-bin/blacklist_SERVICE1.sh,${CALLERID(num)})
exten => 100,4,Gotoif($[“${answer}”=“0”]?gotodest)
Then, enter to asterisk cli
asterisk -rvvv
And make a reload of the dialplan
dialplan reload
Hope that this can help someone
Cheers!