This repository has been archived by the owner on Jan 22, 2018. It is now read-only.
/
geoipupdate.sh
162 lines (143 loc) · 5.27 KB
/
geoipupdate.sh
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/sh
#
# pfBlockerNG MaxMind GeoLite GeoIP Updater Script - By BBcan177@gmail.com
# Copyright (C) 2014 BBcan177@gmail.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License Version 2 as
# published by the Free Software Foundation. You may not use, modify or
# distribute this program under any other version of the GNU General
# Public License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# The GeoLite databases by MaxMind Inc., are distributed under the Creative Commons
# Attribution-ShareAlike 3.0 Unported License. The attribution requirement
# may be met by including the following in all advertising and documentation
# mentioning features of or use of this database.
# Folder Locations
pathfetch=/usr/bin/fetch
pathtar=/usr/bin/tar
pathgunzip=/usr/bin/gunzip
# File Locations
pathdb=/var/db/pfblockerng
pathlog=/var/log/pfblockerng
errorlog=$pathlog/geoip.log
pathgeoipdatgz=$pathdb/GeoIP.dat.gz
pathgeoipdatgzv6=$pathdb/GeoIPv6.dat.gz
pathgeoipdat=$pathdb/GeoIP.dat
pathgeoipdatv6=$pathdb/GeoIPv6.dat
pathgeoipcc=$pathdb/country_continent.csv
pathgeoipcsv4=$pathdb/GeoIPCountryCSV.zip
pathgeoipcsvfinal4=$pathdb/GeoIPCountryWhois.csv
pathgeoipcsv6=$pathdb/GeoIPv6.csv.gz
pathgeoipcsvfinal6=$pathdb/GeoIPv6.csv
if [ ! -d $pathdb ]; then mkdir $pathdb; fi
if [ ! -d $pathlog ]; then mkdir $pathlog; fi
now=$(date)
echo; echo "$now - Updating pfBlockerNG - Country Database Files"
echo "pfBlockerNG uses GeoLite data created by MaxMind, available from http://www.maxmind.com"; echo
#Function to update MaxMind GeoIP Binary (For Reputation Process)
binaryupdate() {
# Download Part 1 - GeoLite IPv4 Binary Database
echo " ** Downloading MaxMind GeoLite IPv4 Binary Database (For Reputation/Alerts Processes) **"; echo
URL="http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz"
$pathfetch -v -o $pathgeoipdatgz -T 20 $URL
if [ "$?" -eq "0" ]; then
$pathgunzip -f $pathgeoipdatgz
echo; echo " ( MaxMind IPv4 GeoIP.dat has been updated )"; echo
echo "Current Date/Timestamp:"
/bin/ls -alh $pathgeoipdat
echo
else
echo; echo " => MaxMind IPv4 GeoIP.dat Update [ FAILED ]"; echo
echo "MaxMind IPV4 Binary Update FAIL [ $now ]" >> $errorlog
fi
# Download Part 2 - GeoLite IPv6 Binary Database
echo; echo " ** Downloading MaxMind GeoLite IPv6 Binary Database (For Reputation/Alerts Processes) **"; echo
URL="http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz"
$pathfetch -v -o $pathgeoipdatgzv6 -T 20 $URL
if [ "$?" -eq "0" ]; then
$pathgunzip -f $pathgeoipdatgzv6
echo; echo " ( MaxMind IPv6 GeoIPv6.dat has been updated )"; echo
echo "Current Date/Timestamp:"
/bin/ls -alh $pathgeoipdatv6
echo
else
echo; echo " => MaxMind IPv6 GeoIPv6.dat Update [ FAILED ]"; echo
echo "MaxMind IPv6 Binary Update FAIL [ $now ]" >> $errorlog
fi
}
#Function to update MaxMind Country Code Files
csvupdate() {
# Download Part 1 - CSV IPv4 Database
echo; echo " ** Downloading MaxMind GeoLite IPv4 CSV Database **"; echo
URL="http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip"
$pathfetch -v -o $pathgeoipcsv4 -T 20 $URL
if [ "$?" -eq "0" ]; then
$pathtar -zxvf $pathgeoipcsv4 -C $pathdb
if [ "$?" -eq "0" ]; then
echo; echo " ( MaxMind GeoIPCountryWhois has been updated )"; echo
echo "Current Date/Timestamp:"
/bin/ls -alh $pathgeoipcsvfinal4
echo
else
echo; echo " => MaxMind IPv4 GeoIPCountryWhois [ FAILED ]"; echo
echo "MaxMind CSV Database Update FAIL - Tar extract [ $now ]" >> $errorlog
fi
else
echo; echo " => MaxMind IPv4 CSV Download [ FAILED ]"; echo
echo "MaxMind CSV Database Update FAIL [ $now ]" >> $errorlog
fi
# Download Part 2 - Country Definitions
echo; echo " ** Downloading MaxMind GeoLite Database Country Definition File **"; echo
URL="http://dev.maxmind.com/static/csv/codes/country_continent.csv"
$pathfetch -v -o $pathgeoipcc -T 20 $URL
if [ "$?" -eq "0" ]; then
echo; echo " ( MaxMind ISO 3166 Country Codes has been updated. )"; echo
echo "Current Date/Timestamp:"
/bin/ls -alh $pathgeoipcc
echo
else
echo; echo " => MaxMind ISO 3166 Country Codes Update [ FAILED ]"; echo
echo "MaxMind ISO 3166 Country Code Update FAIL [ $now ]" >> $errorlog
fi
# Download Part 3 - Country Definitions IPV6
echo " ** Downloading MaxMind GeoLite IPv6 CSV Database **"; echo
URL="http://geolite.maxmind.com/download/geoip/database/GeoIPv6.csv.gz"
$pathfetch -v -o $pathgeoipcsv6 -T 20 $URL
if [ "$?" -eq "0" ]; then
$pathgunzip -f $pathgeoipcsv6
echo; echo " ( MaxMind GeoIPv6.csv has been updated )"; echo
echo "Current Date/Timestamp:"
/bin/ls -alh $pathgeoipcsvfinal6
echo
else
echo; echo " => MaxMind GeoLite IPv6 Update [ FAILED ]"; echo
echo "MaxMind GeoLite IPv6 Update FAIL [ $now ]" >> $errorlog
fi
}
# CALL APPROPRIATE PROCESSES using Script Argument $1
case $1 in
bu)
binaryupdate
;;
cu)
csvupdate
;;
all)
binaryupdate
csvupdate
;;
*)
exit
;;
esac
exit