From ebb515c5aca2dd5a927785905bd18a69f6a23dfd Mon Sep 17 00:00:00 2001 From: Stuart Cardall Date: Mon, 8 Oct 2018 21:32:09 +0000 Subject: [PATCH 1/2] add syslog (-l) option based on the original PR from https://github.com/ScrewLooseDan * fixes https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/pull/217 --- update-ngxblocker | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/update-ngxblocker b/update-ngxblocker index f8a9ad617..f7337e20c 100755 --- a/update-ngxblocker +++ b/update-ngxblocker @@ -34,6 +34,7 @@ SEND_EMAIL_UPDATE="N" CONF_DIR=/etc/nginx/conf.d BOTS_DIR=/etc/nginx/bots.d INSTALLER=/usr/local/sbin/install-ngxblocker +LOGGING="N" ##### end user configuration ############################################################## @@ -249,6 +250,23 @@ print_message() { 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() { # email report if check_mail_depends; then @@ -256,14 +274,13 @@ send_email() { # remove ansi colour codes sed -i 's/\x1b\[[0-9;]*m//g' $EMAIL_REPORT cat $EMAIL_REPORT | mail -s "Nginx Bad Bot Blocker Updated" $EMAIL - rm -f $EMAIL_REPORT fi } get_options() { local arg= opts= - while getopts :c:b:i:r:e:m:novqh opts "$@" + while getopts :c:b:i:r:e:m:lnovqh opts "$@" do if [ -n "${OPTARG}" ]; then case "$opts" in @@ -280,6 +297,7 @@ get_options() { r) REPO=$arg; check_args $opts url $arg ;; e) EMAIL=$arg; SEND_EMAIL=Y; check_args $opts email $arg ;; m) EMAIL=$arg; SEND_EMAIL=Y ;; # /etc/aliases no sanity checks + l) LOGGING=Y ;; n) SEND_EMAIL=N ;; o) SEND_EMAIL_UPDATE=Y ;; v) check_version; exit 0 ;; @@ -380,11 +398,17 @@ main() { case "$SEND_EMAIL" in y*|Y*) send_email;; esac + + # log report + case "$LOGGING" in + y*|Y*) log_output;; + esac } ## start ## EMAIL_REPORT=$(mktemp) main $@ | tee $EMAIL_REPORT +rm -f $EMAIL_REPORT exit $? From 53d8a08fac30c82e9d002cd9a1158a2b45b6c833 Mon Sep 17 00:00:00 2001 From: Stuart Cardall Date: Mon, 8 Oct 2018 21:35:58 +0000 Subject: [PATCH 2/2] use example.com for email addresses --- update-ngxblocker | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/update-ngxblocker b/update-ngxblocker index f7337e20c..cb07feb5c 100755 --- a/update-ngxblocker +++ b/update-ngxblocker @@ -28,7 +28,7 @@ # RUN THE UPDATE # 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_UPDATE="N" CONF_DIR=/etc/nginx/conf.d @@ -67,9 +67,9 @@ Examples: $script (Download globalblacklist.conf to: $CONF_DIR) $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 -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 -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) EOF exit 0