From c3624d2d895542f64ad8b8f5e1ad2b09698ec92e Mon Sep 17 00:00:00 2001 From: Stuart Cardall Date: Thu, 8 Feb 2018 09:44:58 +0000 Subject: [PATCH 1/2] fix service command for cron jobs the cron environment usually does not contain $PATH. This fixes cases where users do not use full paths in their crontabs. fixes https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/issues/120#issuecomment-364028147 --- update-ngxblocker | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/update-ngxblocker b/update-ngxblocker index 30984c2eb..0e59557c3 100755 --- a/update-ngxblocker +++ b/update-ngxblocker @@ -140,15 +140,24 @@ update_paths() { service_cmd() { # arch linux does not have a 'service' command - local svc= svc_list="service systemctl rc-service" + local x= svc= svc_list="service systemctl rc-service" - for svc in $svc_list; do + for x in $svc_list; do svc=$(which $svc 2>/dev/null) if [ -n "$svc" ]; then - echo $svc - exit 0 + case "$x" in + service) svc="$svc nginx reload";; + systemctl) svc="$svc reload nginx.service";; + rc-service) svc="$svc nginx reload";; + esac + break + else + # centos does not have 'which' by default + svc="/usr/sbin/service nginx reload" fi done + + echo $svc } sanitize_path() { @@ -259,8 +268,7 @@ get_options() { main() { local REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master local file=globalblacklist.conf remote_dir=conf.d url= output= update= status= tmp= retval= - # default to service (centos does not have 'which' by default) - local service=${service_cmd:-"service"} + local reload_service=$(service_cmd) # require root if [ "$(id -u)" != "0" ]; then @@ -307,7 +315,7 @@ main() { # re-read nginx configuration if [ $retval = 0 ]; then - $service nginx reload 2>&1 >/dev/null + $reload_service 2>&1 >/dev/null if [ $? = 0 ]; then status="${BOLDGREEN}[OK]${RESET}" print_message "\nReloading NGINX configuration...$status\n" From fa873a3e208bc8e3c75996af8ec06d9c36a20a91 Mon Sep 17 00:00:00 2001 From: Stuart Cardall Date: Thu, 8 Feb 2018 09:56:34 +0000 Subject: [PATCH 2/2] install to /usr/local/sbin by default fixes https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/issues/133 --- install-ngxblocker | 10 +++++----- setup-ngxblocker | 2 +- update-ngxblocker | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/install-ngxblocker b/install-ngxblocker index d9884adc1..03ba620e0 100755 --- a/install-ngxblocker +++ b/install-ngxblocker @@ -23,18 +23,18 @@ ### You can also now use a setup script contributed by Stuart Cardall to automatically insert the includes for you ### See - https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/setup-ngxblocker -# Save this file as /usr/sbin/install-ngxblocker -# sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/install-ngxblocker -O /usr/sbin/install-ngxblocker +# Save this file as /usr/local/sbin/install-ngxblocker +# sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/install-ngxblocker -O /usr/local/sbin/install-ngxblocker # Make it Executable: -# chmod 700 /usr/sbin/install-ngxblocker +# chmod 700 /usr/local/sbin/install-ngxblocker # Run it from the command line: -# sudo /usr/sbin/install-ngxblocker [ -h ] +# sudo /usr/local/sbin/install-ngxblocker [ -h ] ######## LETS INSTALL NOW ############################### CONF_DIR=/etc/nginx/conf.d BOTS_DIR=/etc/nginx/bots.d -SCRIPT_DIR=/usr/sbin +SCRIPT_DIR=/usr/local/sbin REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master ####### end user configuration ########################## diff --git a/setup-ngxblocker b/setup-ngxblocker index de9643193..32ab5b01b 100755 --- a/setup-ngxblocker +++ b/setup-ngxblocker @@ -12,7 +12,7 @@ VHOST_DIR=/etc/nginx/sites-available BOTS_DIR=/etc/nginx/bots.d CONF_DIR=/etc/nginx/conf.d MAIN_CONF=/etc/nginx/nginx.conf -INSTALLER=/usr/sbin/install-ngxblocker +INSTALLER=/usr/local/sbin/install-ngxblocker # setting Y / yes will whitelist only directories in $www # that look like domain.names DOT_NAMES="Y" diff --git a/update-ngxblocker b/update-ngxblocker index 0e59557c3..c78243bd4 100755 --- a/update-ngxblocker +++ b/update-ngxblocker @@ -20,10 +20,10 @@ # PLEASE READ UPDATED CONFIGURATION INSTRUCTIONS BEFORE USING THIS -# Save this file as /usr/sbin/update-ngxblocker -# cd /usr/sbin +# Save this file as /usr/local/sbin/update-ngxblocker +# cd /usr/local/sbin # sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/update-ngxblocker -O update-ngxblocker -# Make it Executable chmod 700 /usr/sbin/update-ngxblocker +# Make it Executable chmod 700 /usr/local/sbin/update-ngxblocker # RUN THE UPDATE # Here our script runs, pulls the latest update, reloads nginx and emails you a notification @@ -32,7 +32,7 @@ EMAIL="me@myemail.com" SEND_EMAIL="N" CONF_DIR=/etc/nginx/conf.d BOTS_DIR=/etc/nginx/bots.d -INSTALLER=/usr/sbin/install-ngxblocker +INSTALLER=/usr/local/sbin/install-ngxblocker ##### end user configuration ############################################################## @@ -359,13 +359,13 @@ exit $? # Add this as a cron to run daily / weekly as you like # Here's a sample CRON entry to update every day at 10pm -# 00 22 * * * sudo /usr/sbin/update-ngxblocker -q +# 00 22 * * * sudo /usr/local/sbin/update-ngxblocker -q # Here's another example to run it daily at midday using a command line switch to set the email address for the notification -# 00 12 * * * sudo /usr/sbin/update-ngxblocker -e yourname@youremailprovider.com +# 00 12 * * * sudo /usr/local/sbin/update-ngxblocker -e yourname@youremailprovider.com # Less verbose logging to a system alias mail address (root crontab) -# 00 12 * * * /usr/sbin/update-ngxblocker -q -m webmaster +# 00 12 * * * /usr/local/sbin/update-ngxblocker -q -m webmaster # better logging for cron jobs: # https://serverfault.com/questions/137468/better-logging-for-cronjobs-send-cron-output-to-syslog