1#!/bin/bash
2# Generator Script for NGinx Ultimate Bad Bot Blocker
3# REPO: https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker
4# Copyright Mitchell Krog - mitchellkrog@gmail.com
5
6# ------------------------------------------------------------------------------
7# MIT License
8# ------------------------------------------------------------------------------
9# Copyright (c) 2017 Mitchell Krog - mitchellkrog@gmail.com
10# https://github.com/mitchellkrogza
11# ------------------------------------------------------------------------------
12# Permission is hereby granted, free of charge, to any person obtaining a copy
13# of this software and associated documentation files (the "Software"), to deal
14# in the Software without restriction, including without limitation the rights
15# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16# copies of the Software, and to permit persons to whom the Software is
17# furnished to do so, subject to the following conditions:
18# ------------------------------------------------------------------------------
19# The above copyright notice and this permission notice shall be included in all
20# copies or substantial portions of the Software.
21# ------------------------------------------------------------------------------
22# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28# SOFTWARE.
29# ------------------------------------------------------------------------------
30
31# ------------------------
32# Set Terminal Font Colors
33# ------------------------
34
35bold=$(tput bold)
36red=$(tput setaf 1)
37green=$(tput setaf 2)
38yellow=$(tput setaf 3)
39blue=$(tput setaf 4)
40magenta=$(tput setaf 5)
41cyan=$(tput setaf 6)
42white=$(tput setaf 7)
43defaultcolor=$(tput setaf default)
44
45# ---------
46# Variables
47# ---------
48
49outputfile=${TRAVIS_BUILD_DIR}/_generator_lists/bad-ip-addresses.list
50tmp=${TRAVIS_BUILD_DIR}/_generator_lists/tmp.list
51
52# ---------
53# FUNCTIONS
54# ---------
55
56fetchBadIPs () {
57    sudo wget https://hosts.ubuntu101.co.za/ngxubbb/bad-ips.list -O ${outputfile}
58echo "${bold}${green}----------------------------"
59echo "${bold}${green}Fetching Latest BAD IPs List"
60echo "${bold}${green}----------------------------"
61printf "\n"
62}
63
64prepareBadIPs () {
65    sudo sort -u ${outputfile} -o ${outputfile}
66    grep '[^[:blank:]]' < ${outputfile} > ${tmp}
67    sudo mv ${tmp} ${outputfile}
68	sudo dos2unix ${outputfile}
69echo "${bold}${green}-----------------------------"
70echo "${bold}${green}Preparing Latest BAD IPs List"
71echo "${bold}${green}-----------------------------"
72printf "\n"
73}
74
75# -----------------
76# Trigger Functions
77# -----------------
78
79fetchBadIPs
80prepareBadIPs
81
82# ----------------------
83# Exit With Error Number
84# ----------------------
85
86exit ${?}
87
88# ------------------------------------------------------------------------------
89# MIT License
90# ------------------------------------------------------------------------------
91# Copyright (c) 2017 Mitchell Krog - mitchellkrog@gmail.com
92# https://github.com/mitchellkrogza
93# ------------------------------------------------------------------------------
94# Permission is hereby granted, free of charge, to any person obtaining a copy
95# of this software and associated documentation files (the "Software"), to deal
96# in the Software without restriction, including without limitation the rights
97# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
98# copies of the Software, and to permit persons to whom the Software is
99# furnished to do so, subject to the following conditions:
100# ------------------------------------------------------------------------------
101# The above copyright notice and this permission notice shall be included in all
102# copies or substantial portions of the Software.
103# ------------------------------------------------------------------------------
104# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
105# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
106# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
107# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
108# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
109# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
110# SOFTWARE.
111# ------------------------------------------------------------------------------
112