mirror of
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker.git
synced 2025-09-05 12:09:57 +00:00
Merge pull request #220 from itoffshore/alpine
Add syslog (-l) option / fix email addresses
This commit is contained in:
commit
7c352424ee
1 changed files with 29 additions and 5 deletions
|
@ -28,12 +28,13 @@
|
||||||
# RUN THE UPDATE
|
# RUN THE UPDATE
|
||||||
# Here our script runs, pulls the latest update, reloads nginx and emails you a notification
|
# Here our script runs, pulls the latest update, reloads nginx and emails you a notification
|
||||||
|
|
||||||
EMAIL="me@myemail.com"
|
EMAIL="you@example.com"
|
||||||
SEND_EMAIL="N"
|
SEND_EMAIL="N"
|
||||||
SEND_EMAIL_UPDATE="N"
|
SEND_EMAIL_UPDATE="N"
|
||||||
CONF_DIR=/etc/nginx/conf.d
|
CONF_DIR=/etc/nginx/conf.d
|
||||||
BOTS_DIR=/etc/nginx/bots.d
|
BOTS_DIR=/etc/nginx/bots.d
|
||||||
INSTALLER=/usr/local/sbin/install-ngxblocker
|
INSTALLER=/usr/local/sbin/install-ngxblocker
|
||||||
|
LOGGING="N"
|
||||||
|
|
||||||
##### end user configuration ##############################################################
|
##### end user configuration ##############################################################
|
||||||
|
|
||||||
|
@ -66,9 +67,9 @@ Examples:
|
||||||
$script (Download globalblacklist.conf to: $CONF_DIR)
|
$script (Download globalblacklist.conf to: $CONF_DIR)
|
||||||
$script -c /my/custom/conf.d (Download globalblacklist.conf to a custom location)
|
$script -c /my/custom/conf.d (Download globalblacklist.conf to a custom location)
|
||||||
$script -b /my/custom/bots.d (Download globalblacklist.conf & update with your custom bots.d location)
|
$script -b /my/custom/bots.d (Download globalblacklist.conf & update with your custom bots.d location)
|
||||||
$script -e you@youremail.com (Download globalblacklist.conf specifying your email address for the notification)
|
$script -e you@example.com (Download globalblacklist.conf specifying your email address for the notification)
|
||||||
$script -q -m webmaster (Send mail to a system alias address & give less verbose messages for cron)
|
$script -q -m webmaster (Send mail to a system alias address & give less verbose messages for cron)
|
||||||
$script -o -e you@youremail.com (Send mail notification only on updates)
|
$script -o -e you@example.com (Send mail notification only on updates)
|
||||||
$script -i /path/to/install-ngxblocker (Use custom path to install-ngxblocker to update bots.d / conf.d include files)
|
$script -i /path/to/install-ngxblocker (Use custom path to install-ngxblocker to update bots.d / conf.d include files)
|
||||||
EOF
|
EOF
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -249,6 +250,23 @@ print_message() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_output() {
|
||||||
|
local logger=$(find_binary logger)
|
||||||
|
local script=$(basename $0)
|
||||||
|
|
||||||
|
if [ -n "$logger" ]; then
|
||||||
|
# remove ansi color codes
|
||||||
|
sed -i 's/\x1b\[[0-9;]*m//g' $EMAIL_REPORT
|
||||||
|
# remove blank lines
|
||||||
|
sed -i '/^\s*$/d' $EMAIL_REPORT
|
||||||
|
# log output
|
||||||
|
$logger -t $script -f $EMAIL_REPORT 2>&1
|
||||||
|
print_message "Output logged to syslog\n";
|
||||||
|
else
|
||||||
|
print_message "${BOLDRED}ERROR: cannot find logger${RESET}\n\n";
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
send_email() {
|
send_email() {
|
||||||
# email report
|
# email report
|
||||||
if check_mail_depends; then
|
if check_mail_depends; then
|
||||||
|
@ -256,14 +274,13 @@ send_email() {
|
||||||
# remove ansi colour codes
|
# remove ansi colour codes
|
||||||
sed -i 's/\x1b\[[0-9;]*m//g' $EMAIL_REPORT
|
sed -i 's/\x1b\[[0-9;]*m//g' $EMAIL_REPORT
|
||||||
cat $EMAIL_REPORT | mail -s "Nginx Bad Bot Blocker Updated" $EMAIL
|
cat $EMAIL_REPORT | mail -s "Nginx Bad Bot Blocker Updated" $EMAIL
|
||||||
rm -f $EMAIL_REPORT
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_options() {
|
get_options() {
|
||||||
local arg= opts=
|
local arg= opts=
|
||||||
|
|
||||||
while getopts :c:b:i:r:e:m:novqh opts "$@"
|
while getopts :c:b:i:r:e:m:lnovqh opts "$@"
|
||||||
do
|
do
|
||||||
if [ -n "${OPTARG}" ]; then
|
if [ -n "${OPTARG}" ]; then
|
||||||
case "$opts" in
|
case "$opts" in
|
||||||
|
@ -280,6 +297,7 @@ get_options() {
|
||||||
r) REPO=$arg; check_args $opts url $arg ;;
|
r) REPO=$arg; check_args $opts url $arg ;;
|
||||||
e) EMAIL=$arg; SEND_EMAIL=Y; check_args $opts email $arg ;;
|
e) EMAIL=$arg; SEND_EMAIL=Y; check_args $opts email $arg ;;
|
||||||
m) EMAIL=$arg; SEND_EMAIL=Y ;; # /etc/aliases no sanity checks
|
m) EMAIL=$arg; SEND_EMAIL=Y ;; # /etc/aliases no sanity checks
|
||||||
|
l) LOGGING=Y ;;
|
||||||
n) SEND_EMAIL=N ;;
|
n) SEND_EMAIL=N ;;
|
||||||
o) SEND_EMAIL_UPDATE=Y ;;
|
o) SEND_EMAIL_UPDATE=Y ;;
|
||||||
v) check_version; exit 0 ;;
|
v) check_version; exit 0 ;;
|
||||||
|
@ -380,11 +398,17 @@ main() {
|
||||||
case "$SEND_EMAIL" in
|
case "$SEND_EMAIL" in
|
||||||
y*|Y*) send_email;;
|
y*|Y*) send_email;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# log report
|
||||||
|
case "$LOGGING" in
|
||||||
|
y*|Y*) log_output;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
## start ##
|
## start ##
|
||||||
EMAIL_REPORT=$(mktemp)
|
EMAIL_REPORT=$(mktemp)
|
||||||
main $@ | tee $EMAIL_REPORT
|
main $@ | tee $EMAIL_REPORT
|
||||||
|
rm -f $EMAIL_REPORT
|
||||||
|
|
||||||
exit $?
|
exit $?
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue