mirror of
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker.git
synced 2025-09-03 11:10:47 +00:00
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
This commit is contained in:
parent
a607f88838
commit
ebb515c5ac
1 changed files with 26 additions and 2 deletions
|
@ -34,6 +34,7 @@ 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 ##############################################################
|
||||||
|
|
||||||
|
@ -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