I will offer my latest efforts, first the script ("var/lib/asterisk/bin/fcc.sh"):-
#!/bin/bash
# by dicko
# Licensed under the MIT (
http://creativecommons.org/licenses/MIT/) license.
LOGDIR="/var/log/asterisk"
LOGFILE="${LOGDIR}/fcc.log"
#LOGFILE="/dev/stdout"
PIDFILE="/var/run/asterisk/fcc.pid"
if [ -f ${PIDFILE} ];then echo "$0 already running, pid $(cat ${PIDFILE}), run rm ${PIDFILE} if you are sure it is not";exit;fi
echo -n "$(date +'%Y/%m/%d %H:%M:%S')" >> $LOGFILE
echo $$ > ${PIDFILE}
SP=3 # spam level, 1 should be fine also
if [ $1 ]; then SP=$1;fi
WGET="wget -q
https://opendata.fcc.gov/api/views/t3tq-usu8/rows.csv -O -"
PRE= # Prefix to add to NXXNXXXXXX to suit your carriers CID
SQL="sqlite3 /var/lib/asterisk/astdb.sqlite3"
MYSQL="mysql -u root -pyourpassword"
ASTPID=$(pidof asterisk)
START=$(date +%s)
CURRENT=$($SQL "select value from astdb where key like '/fcc/%'")
ASTDBFCC=$($SQL "select * from astdb where key like '/fcc/%'")
$SQL " select substr(substr(key,12),-10) from astdb where key like '/whitelist/%'"|sort >${LOGDIR}/fcc.whitelist
$MYSL -ss -D asteriskcdrdb -e "select distinct substr(dst,-9) from cdr where length(dst) >= 10 order by calldate desc limit 100000" > ${LOGDIR}/fcc.calls
${WGET}|sed -e '1d' -e 's/-//g'|sort -n|tee ${LOGDIR}/fcc.numbers|uniq -c|tee ${LOGDIR}/fcc.unique |awk '{print "/blacklist/"$2"|FCC-"$1}'|sed -e "/-[$(seq -s '' 0 ${SP})]$/d" -e "s|list/|list/${PRE}|" > ${LOGDIR}/fcc.sp${SP}
#grep -vwF -f ${LOGDIR}/fcc.whitelist ${LOGDIR}/fcc.sp${SP} > ${LOGDIR}/fcc.import
grep -vF -f ${LOGDIR}/fcc.whitelist ${LOGDIR}/fcc.sp${SP}|grep -vF ${LOGDIR}/fcc.calls - > ${LOGDIR}/fcc.import
FCC=$(cat ${LOGDIR}/fcc.numbers|wc -l)
SPCNT=$(cat ${LOGDIR}/fcc.sp${SP}|wc -l)
WLCNT=$(cat ${LOGDIR}/fcc.import|wc -l)
echo -n " (wget in $(($(date +%s) - ${START})) secs) " >> $LOGFILE
if [ "$1" == "" ] && [ "$CURRENT" == "$FCC" ] ;
then
echo "No new records, FCC=${FCC} astdb=${ASTDBFCC}" >>${LOGFILE}
else
if [ ${ASTPID} ] ; then /usr/sbin/rasterisk -x 'core stop when convenient' >/dev/null 2>&1;fi
$SQL "DELETE from astdb WHERE key LIKE '/blacklist/%' AND value like 'FCC%'"
$SQL "DELETE from astdb WHERE key LIKE '/fcc/%' "
$SQL ".import ${LOGDIR}/fcc.import astdb"
$SQL "insert into astdb values( strftime('/fcc/%Y-%m-%d--%H-%M','now','localtime') , ${FCC})"
echo "FCC/${SP}=${SPCNT} of ${FCC} BL-WL=${WLCNT} Time ($(($(date +%s) - ${START})) secs) " >> $LOGFILE
if [ ${ASTPID} ];then /usr/sbin/service asterisk start > /dev/null;fi
fi
rm -rf ${PIDFILE}
exit 0
Hopefully this is self documented and a little less obtuse.
Then the context you can send calls to:-
[from-nanp-trunks-susceptible-to-being-on-the-fcc-list]
exten => _X.,1,Set(CALLERID(number)=${CALLERID(number):-10})
same => n,Set(VALUE=${DB(blacklist/${CALLERID(num)})})
same => n,Set(LEVEL=${CUT(VALUE,-,2)})
same => n,gotoif($["${LEVEL}" = ""]?from-pstn,${EXTEN},1)
same => n,Playback(custom/fccsorry)
same => n,SayDigits(${CALLERID(num)})
same => n,Playback(custom/fccisblacklisted)
same => n,Set(PASSCODE=${RAND(100,999)})
same => n,SayNumber(${level})
same => n,Playback(custom/fccruhuman)
same => n,SayDigits(${PASSCODE}
same => n,PlayBack(custom/fccafterbeep)
same => n,read(HUMAN,beep,3,,,5)
same => n,gotoif($["${HUMAN}" = "${PASSCODE}" ]?voicemail:hangup)
same => n(voicemail),PlayBack(custom/fccconfirmedcode)
same => n,Voicemail(3101,s) ; WHERE 3101 is the the voicemail box of your sentient adult in charge
same => n(hangup),hangup
You get to record the custom/fcc*prompts, maybe something like
fccsorry: . . . . . .We are sorry, but your callerID . . .
fccisblacklisted: is on the fcc blacklist of robocallers and spammers for a count of
fccruhuman: To prove you are a human please dial
fccafterbeep: After the beep.
fccconfirmcode: Thank you. Please leave a message after the beep, include your phone number,
who you are and what your call is about.
It covers the ongoing conversations at the other site that got fahrenheit 451'ed , first off it t confuses the machines, then it covers the FedEX guys to actually let you know they are regular, and you can whitelist them as soon as you get the email. You don't need Superfecta and it should cover the whitelist/blacklist contretemps as the traditionally the Asterisk blacklist just looks at the "value" this script filters on the existance of FCC in value,
Also note that the context
from-nanp-trunks-susceptible-to-being-on-the-fcc-list
falls through to from-pstn "very quickly" if not needed. Those quick enough will notice that DB(blacklist*) could easily be replace with DB(fccblacklist*) making this whole snippet completely transparent to FreePBX yet attentive at level 1 to the FCC list (Please watch the logs, the list is NOT realtime, as some have stated, it updates at about every 25 to 28 hours, but might be real-time sometime real-soon (maybe) so please adjust down your cron job appropriately perhaps is sufficient (yes this is a little grumpy for root to do it
)
1 4,20 * * * su asterisk -c /"var/lib/asterisk/bin/fcc.sh"
)
Any peer comments would be much appreciated, especially if you have actual tried it