-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathimport-fcc-blacklist
executable file
·85 lines (82 loc) · 4.43 KB
/
import-fcc-blacklist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# import-fcc-blacklist, adapted for freeSWITCH by Bill Dengler <[email protected]>.
#Based on import-fcc-blacklist (for Asterisk) v2.0 Copyright (C) 2015-2016, Ward Mundy & Associates LLC. Licensed under GPL2.
# Special thanks to Adam Goldberg for the awk one-liner! http://nerd.bz/1PVUfhr
# This program imports the current FCC Telemarketing RoboCall Blacklist into freeSWITCH
clear
echo "This program imports the current FCC Telemarketing RoboCall Blacklist into freeSWITCH."
echo "When the script is run, it overwrites ALL existing FCC Blacklist numbers!"
echo " "
echo "BY USING THIS SCRIPT, YOU AGREE TO ASSUME ALL RESPONSIBILITY"
echo "FOR USE OF THE PROGRAM INCLUDED IN THIS INSTALLATION. NO WARRANTIES"
echo "EXPRESS OR IMPLIED INCLUDING MERCHANTABILITY AND FITNESS FOR PARTICULAR"
echo "USE ARE PROVIDED. YOU ASSUME ALL RISKS KNOWN AND UNKNOWN AND AGREE TO"
echo "HOLD BILL DENGLER, WARD MUNDY, WARD MUNDY & ASSOCIATES LLC, NERD VITTLES, AND THE PBX"
echo "IN A FLASH DEVELOPMENT TEAM HARMLESS FROM ANY AND ALL LOSS OR DAMAGE"
echo "WHICH RESULTS FROM YOUR USE OF THIS SOFTWARE. IF ANY OF THESE TERMS"
echo "AND CONDITIONS ARE RULED TO BE UNENFORCEABLE, YOU AGREE TO ACCEPT ONE"
echo "DOLLAR IN U.S. CURRENCY AS COMPENSATORY AND PUNITIVE LIQUIDATED DAMAGES"
echo "FOR ANY AND ALL CLAIMS YOU AND ANY USERS OF THIS SOFTWARE MIGHT HAVE."
echo " "
if [ ! -f "config" ]; then
echo "If you do not agree with these terms and conditions of use, press Ctrl-C now."
read -p "Otherwise, press Enter to proceed at your own risk..."
echo
fi
cd $(dirname "$0")
# Check for config
if [ ! -f config ]; then
echo "Detecting freeSWITCH settings..."
if [ -d /usr/local/freeswitch/conf ]; then
echo "Standard install found; blacklist will be saved to /usr/local/freeswitch/conf/blacklists/FCC.list."
BLACKLISTPATH=/usr/local/freeswitch/conf/blacklists/FCC.list
fi
if [ -d /etc/freeswitch ]; then
echo "Debian-style install found; blacklist will be saved to /etc/freeswitch/blacklists/FCC.list."
BLACKLISTPATH=/etc/freeswitch/blacklists/FCC.list
fi
echo "Please make sure either a standard (/usr/local/freeswitch/conf) or Debian-style (/etc/freeswitch) configuration directory was found above; if not you will need to define BLACKLISTPATH manually."
if [ -d /var/www/fusionpbx ]; then
echo "Fusionpbx install found; blacklist will be owned by user www-data"
FSUSER=www-data
else
echo "Fusionpbx install not found; assuming freeSWITCH runs under user freeswitch. Blacklist will be owned by user freeswitch."
FSUSER=freeswitch
fi
echo "BLACKLISTPATH=$BLACKLISTPATH" > config
echo "FSUSER=$FSUSER" >> config
echo "Your script configuration is as follows:"
cat config
echo "If auto-detection got something wrong please edit the file $(pwd)/config NOW!"
read -p "Please make any changes in another terminal if necessary, then press enter to continue..." continue
echo
echo "Creating $(dirname $BLACKLISTPATH)..."
mkdir -p "$(dirname $BLACKLISTPATH)"
echo "Reading settings..."
source config
FSROOT="$(dirname $(dirname $BLACKLISTPATH))"
echo "Generating $(pwd)/FCC.txt..."
# Generate $BLACKLISTXML
BLACKLISTXML="<list name=\"FCC\" filename=\"$BLACKLISTPATH\"/>"
echo "To enable the FCC blacklist, you must add the following snippet somewhere between the <lists> and </lists> tags in $FSROOT/autoload_configs/blacklist.conf.xml:" > FCC.txt
echo "$BLACKLISTXML" >> FCC.txt
fi
if [ -f "FCC.txt" ]; then
echo "Your FCC blacklist configuration is NOT complete!"
cat FCC.txt
echo "For your convenience, the above information has been saved to $(pwd)/FCC.txt. Please update your FreeSWITCH configuration and delete $(pwd)/FCC.txt when you're done."
echo "Once $(pwd)/fcc.txt is deleted, this script will be non-interactive. You may want to create a Cron or Systemd job to keep your system's blacklist up to date."
read -p "Press enter to continue..." continue
fi
echo "Reading settings..."
source config
echo "Processing FCC blacklist..."
wget --no-check-certificate https://opendata.fcc.gov/api/views/vakf-fz8e/rows.csv?accessType=DOWNLOAD -O Telemarketing_RoboCall_Weekly_Data.csv
echo "Extracting RoboCall numbers from FCC .csv data and writing blacklist..."
cat Telemarketing_RoboCall_Weekly_Data.csv | awk -F"," '{print $8}' | sort -u | grep "[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]" | sed "s|-||g" > "$BLACKLISTPATH"
echo "Changing user and group ownership to $FSUSER"
chown $FSUSER:$FSUSER $BLACKLISTPATH
echo "reloading mod_blacklist..."
fs_cli -x "load mod_blacklist"
fs_cli -x "blacklist reload"
echo "Done."