[asterisk-users] Blacklist callers from file

Tim S tim.strommen at gmail.com
Mon Aug 29 17:29:25 CDT 2016


Sorry, Gmail took my conversation with John off-list somehow,  I'll repost
what I had set here (sorry, it's going to be a bit big now), and I will be
more careful in the future:

First part:

I'm using Grandstream phones, so I have XML soft-keys, what hardware do you
have and how good are you with dialplans?  You'll have to do some re-work
unless you have an exact match for my setup.  I'm doing my best to give you
the functional code, I have to change a bunch of stuff to not leak the
security things I do in my code and some of the way more involved stuff I
do.  this should at least get you running I think.  Portions between "CODE:
 /CODE" tags are the functional dialplan code, I tried to comment a lot
here to explain what's happening, but I may have broken something in the
process.  Also, be aware that I generate custom sound files, so if you try
to run the code and it throws an error about sound-file does not exists,
that's why.

For this, I am using the internal DB in Asterisk (https://wiki.asterisk.org/
wiki/display/AST/Asterisk+Internal+Database).

The first part is easy, but also very important - filter your Caller-ID
data (in computers, we NEVER trust data from a source we don't generate),
CODE:

[incommingcall]
exten => 15555551234,1,Set(CalledNumber=${15555551234})               ;
Primary incoming phone line, number changed to protect my phone number
same => Set(CallEventTime=${STRFTIME(${EPOCH},,%m-%d-%Y_%H.%M.%S)}
same => n,Set(CALLERID(name)=${FILTER(A-Z0-9\s,${CALLERID(name)})})
same => n,Set(CALLERID(num)=${FILTER(0-9,${CALLERID(num)})})
same => n,Verbose(Incomming call to main phone number)
same => n,Goto(IVR-Menu,IVRStart,1)

/CODE - Then you hit phone numbers that don't have caller ID with the
special three-tone application that sounds like a phone company message,
CODE:

[IVR-Menu]
exten => IVRStart,1,Zapateller(nocallerid)                 ; Before
answering we do the sound for no-caller ID calls
same => n,Zapateller(answer,nocallerid)                    ; This is where
the phone call gets answered, we hit no-caller ID calls again here
same => n,Wait(1)
same => n,Playback(call-recording-warning)              ; Legally required
message: "For quality control purposes, this call may be monitored."
same => n,Wait(2)
same => n,Monitor(wav,Inbound_to_${CalledNumber}_from_${CALLERID(num)}_${CallEventTime})
 ; Yes, I record every call in an out.
same => n,GotoIf($["${CalledNumber}" != "15555551234"]?BlacklistFilter)  ;
Number changed to protect my toll-free costs!!!

/CODE - I had a problem with political phone calls to my 855 number this
past spring, so I added this little routine to prompt the caller for a
single random digit to be entered to prove they could interact, that
stopped all the calls from getting through.  CODE:

; special human test for toll-free
same => n,Set(TOLLFREERAND=${RAND(0,9)})
same => n,Read(HUMANTEST,thank-you&human-test&${TOLLFREERAND}&now,1,,1,5)
; Says "Thank you. If you're a human, please press the number: {RANDOM},
now.", like a captcha.
same => n,GotoIf($["${HUMANTEST}" = "${TOLLFREERAND}"]?BlacklistFilter) ;
If the random number matches what they entered they move on in the dialplan
same => n,Playback(do-not-call-warning)
; I have a message that states when this number was added to the FTC
do-not-call list,
; requests removal of the number from the current list, and warns that the
call and information was recorded
; and will be turned over to the FTC if the calls continue.
same => n,Hangup()  ; Yes, if a human can't be bothered to press one button
when calling a number I pay the minutes for, I won't be bothered to talk to
them.

/CODE - now we can get into the stuff that handles the blacklists and
telemarketers.  CODE:

; return to regular program
same => n(BlacklistFilter), Verbose(Checking caller ID against blacklist)
same => n,GotoIf($[DB_EXISTS(blacklist\${CALLERID(num)})]?:TelemarketerFilter)
; If the caller ID is not in the blacklist DB family, it goes to the
telemarketer check
same => n,VoiceMail(Blacklist at OtherAccounts,s)
same => n,Hangup()
same => n(TelemarketerFilter), Verbose(Checking caller ID against
telemarketer list)
same => n,GotoIf($[DB_EXISTS(telemarketer\${CALLERID(num)})]?:IVRInteractiveStart)
; If the caller ID is not in the blacklist DB family, it goes to the
telemarketer check
same => n,VoiceMail(Telemarketer at OtherAccounts,s)
same => n,Hangup()

/CODE: Then if the caller ID is not on either list, they go into the start
of the IVR.  Everything up until now takes about 8 seconds, I limit
"appeal" voicemails to 30 seconds by account limit, so that if one managed
to come in through my toll-free number, it wouldn't finish the first minute
of billing.  CODE:

same => n(IVRInteractiveStart),Verbose(Dialplan continues here)
;
; ...redacted...
;
same => n,Hangup()

/CODE.


You'll have to tell me more about your phones to know what you are doing
with called user prompts.  You can enter the numbers into the DBs manually
from the console using the DB commands: https://wiki.
asterisk.org/wiki/display/AST/Asterisk+Internal+Database

I hope this makes sense...


Second part:


One more thing, I didn't mention when I cut down the code, which is good
food for thought - I also have a "whitelist" for friends and family.  This
is the better way for a public facing phone number, people you know who
will call you, you can skip most of the boring stuff if you "trust" the
source phone number.

I do call screening on all incoming calls, unless they are on the
whitelist.  How that works is similar, I screen once if it's a new number,
and the file-name of the name they said during the screening recording is
saved to the the whitelist DB as:

CODE:

same=>n,Set(DB(whitelist\${CALLERID(num)}=${FILENAMEASVALUE}))

/CODE

That way when I get connected the next time they call, I get a phone call
from the home phone system, and instead of playing the screening prompt, I
get: "Connecting you to {recorded name}"

For a custom find-me-follow-me function, I wrote a menu that uses the 5
options:
1 = Connect me
2 = Connect me, add to whitelist
5 = Send to my Voicemail
7 = Add to Telemarketer list
9 = Add to Blacklist

That's done in a Macro and you could do that with basically any phone.  So
my basic process (with several omissions) is:

* New Incoming call
* Set up and filter variables
* Start a recording
* If it's a toll-free, do a "captcha" human-test
* Check if they are on the whitelist, if they are skip to the IVR
* Get rid of the new "easy" telemarketers
* Check if they are on the blacklist, get rid of them if they are
* Check if they are a known Telemarketer, get rid of them if they are
* Ask for the extension/user
* On user answer, If on the whitelist connect, if not screen
* If no answer, take a message.
-T

END OF REPOST...

Thread should be caught back up now (again, very sorry!!!).

I hadn't gotten to the Macro, as John hasn't responded yet anyway.

Kevin what phones are you using?  Depending on how your phones work, there
are various way to get this to happen.

If your phones don't have hot keys, a quick and dirty way to "kiss-off"
unwanted callers is to create an extension that an internal-called-user can
transfer the caller to.  You can even use a "dumb" touch-tone phone that
way.

Best,

-Tim


On Mon, Aug 29, 2016 at 2:31 PM, <kc6ovd at gmail.com> wrote:

> Tim, I would like to see the code for this. I also am a home user and I
> have been thinking of how I would do this same type of thing. Right now I
> have a black list db and it is manual. When the unwanted caller calls they
> go to a no one is here go away message and splash they are gone.  Your
> method and hot keys sounds very cool.
>
>
>
> -Kevin
>
>
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
> Windows 10
>
>
>
> *From: *Tim S <tim.strommen at gmail.com>
> *Sent: *Monday, August 29, 2016 12:40 PM
> *To: *Asterisk Users Mailing List - Non-Commercial Discussion
> <asterisk-users at lists.digium.com>
> *Subject: *[asterisk-users] Blacklist callers from file
>
>
>
> I'm a home user (not business), but I implemented a blacklist function too
> after a harassing call to my wife.
>
>
>
> Using the Asterisk DB functions, I have a caller ID look-up function
> before my IVR-tree starts, a simple if then.  Lookup caller ID in
> blocked-caller DB, if found then I kick them to a short dialplan the plays
> a message telling them they've been blocked, then lets them record an
> "appeal" message.  If a user put someone in the Blocked DB, by accident,
> I'd want to have a way for someone to report it to me via phone.
>
>
>
> To add a number to the Blocked DB, the caller internal user is allowed a
> hot-key on the phone to block the caller in-call, or with screening they
> are given an option in the prompt.  When a new number is added to the
> Blocked DB, the call recording for the session is retained to be able to
> remember why it was blocked.  The Blocked DB will automatically unblock an
> entry after a year, to account for number changes, but the entry can be
> extended before it expires via an email response.
>
>
>
> I did a similar thing for Telemarketers, the phone numbers also
> automatically unblock, but only after a month, as most of the worst
> offenders I've come across don't stay with a phone number longer than a few
> weeks to avoid enforcement by the FTC.  For that I also have a hot key on
> the phones for "Telemarketer Goodbye", which adds to the DB while playing a
> "Remove me from your list and stop bothering me" message.  This gives my
> users a bit of power as they don't have to be polite, or think of an
> evasion to the sales person, they just need to push a button and hang up
> the phone when they realize is a sales call.
>
>
>
> I didn't want to publish code for this since it's a bit long winded, but
> it should give you some ideas of things you want to consider.
>
>
>
> Best,
>
>
>
> -Tim
>
>
>
>
>
> On Mon, Aug 29, 2016 at 9:20 AM, John Kiniston <johnkiniston at gmail.com>
> wrote:
>
> Here is a quick and dirty bash script to do it that I wrote you.
>
> #!/bin/bash
> if ( asterisk -rx "database deltree blacklist")
>         then
>                 echo "Blacklist Cleared"
>         else
>                 err "ERROR Failed to clear Blacklist, Exiting."
>                 exit 1;
> fi
>
> while IFS=, read TN REASON
> do
> if ( asterisk -rx "database put blacklist \"${TN}\" \"${REASON}\"")
>    then
>            echo "Inserted $TN $REASON to Blacklist"
>    else
>          err "ERROR Insert Failed on $TN."
>          exit 1;
> fi
>
> done < blacklist.csv
> unset IFS
>
> It reads from the file blacklist.csv in the same directory with the format
> of NUMBER,"DESCRIPTION/REASON"
>
>
>
> On Sat, Aug 27, 2016 at 8:59 AM, tux john <atux at null.net> wrote:
>
> Hi. I would like to blacklist a few callers and I have been using the
> *CLI> database put blacklist 1234 "annoying callers". Instead of putting
> the same command for every user is there any way to have a file? Ideally a
> file in /opt that I would update the blacklisted numbers (add,remove). Is
> there anything like that, please?
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> Join the Asterisk Community at the 13th AstriCon, September 27-29, 2016
>       http://www.asterisk.org/community/astricon-user-conference
>
> New to Asterisk? Start here:
>       https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-users
>
>
>
>
> --
>
> A human being should be able to change a diaper, plan an invasion, butcher
> a hog, conn a ship, design a building, write a sonnet, balance accounts,
> build a wall, set a bone, comfort the dying, take orders, give orders,
> cooperate, act alone, solve equations, analyze a new problem, pitch manure,
> program a computer, cook a tasty meal, fight efficiently, die gallantly.
> Specialization is for insects.
> ---Heinlein
>
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> Join the Asterisk Community at the 13th AstriCon, September 27-29, 2016
>       http://www.asterisk.org/community/astricon-user-conference
>
> New to Asterisk? Start here:
>       https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-users
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20160829/c27ca7d2/attachment.html>


More information about the asterisk-users mailing list