wardmundy
Nerd Uno
- Joined
- Oct 12, 2007
- Messages
- 19,168
- Reaction score
- 5,199
UPDATED: Oct. 29 at 4:30 pm EDT (special thanks to adamgoldberg for elegant code addition)
Found something interesting on the FreePBX Forum this morning. It was a link to a new FCC Robocall Blacklist which apparently will be updated weekly. With help, we've turned this into a few little scripts that will import the list into Asterisk automatically with the following caveat: ALL existing BlackList entries are ALWAYS erased before the import begins. If you want to preserve your personally-added BlackList entries from FreePBX or Incredible GUI, be sure you enter them with a Description value of 1. That's the FreePBX default value. Using a value that sorts higher than FCC will mean they won't get exported in Step #1 below. Using this 1 methodology, your personal BlackList entries can be parsed and preserved while the FCC entries will be replaced weekly and have a unique Description of FCC.
HOW IT WORKS. First, we export your personal BlackList entries from the Asterisk DB. Next, we erase ALL BlackList entries from the Asterisk DB. Then, we import the latest FCC BlackList into the Asterisk DB (10-digit numbers only). Finally, we restore your personal BlackList entries to the Asterisk DB.
You can run these 3 scripts weekly or whenever you like to keep the FCC BlackList current in Asterisk. Here is the correct procedure. The scripts MUST be run in the correct order. It only takes a minute or two to complete the 3-step procedure. If you don't have any personal BlackList entries, just skip steps 1 and 3. How can you review your personal BlackList entries?
Code:
sqlite3 /var/lib/asterisk/astdb.sqlite3 'SELECT key FROM astdb where KEY LIKE "/blacklist%" and value="1"'
TO GET STARTED: Download import-fcc-blacklist.tar.gz and untar it into /root: tar zxvf import-fcc-blacklist.tar.gz
1. Save your existing personal BlackList entries by running: ./export-my-blacklist
2. Import the new FCC BlackList after deleting ALL existing Asterisk blacklist entries: ./import-fcc-blacklist
3. Restore your existing personal BlackList entries by running: ./import-my-blacklist
The script also blocks ANONYMOUS calls so, if you don't want that, comment out line 38 in the import-fcc-blacklist script:
Code:
#asterisk -rx "database put blacklist blocked FCC"
WARNING: This makes a BIG BLACKLIST... currently 6889 non-duplicate entries. No idea how well Asterisk is going to handle this although Asterisk 11 and 13 astdb now use a modern, indexed, lightning-fast SQLITE 3 database so you should be fine. Doesn't seem to blow up the GUI either.
DO NOT USE WITH OLDER ASTERISK VERSIONS, before Asterisk 11 or DISASTER AWAITS!
OTHER HELPFUL COMMANDS
Add Personal Entry to BlackList: asterisk -rx "database put blacklist 4045551212 1"
Add the Anonymous Call Blocker to BlackList: asterisk -rx "database put blacklist blocked 1" (NOTE: This is done automatically in Step #2 above)
List and Count the entries in your current BlackList: asterisk -rx "database show blacklist"