apache-ultimate-bad-bot-blocker icon indicating copy to clipboard operation
apache-ultimate-bad-bot-blocker copied to clipboard

[BUG] Mailing of messages is inconsistent (with patch)

Open NickJH opened this issue 9 months ago • 0 comments

Sendmail is used to send emails in 5 different locations, but if the blacklist is already up to date, a simple echo is used which will send a mail to cron's MAILTO parameter instead of the script's EMAIL parameter

To Reproduce Run script when it is already up to date.

Expected behavior I would expect all messages to be sent using the sendmail parameter

Server (please complete the following information):

  • OS: Debian 12
  • Apache Version 2.4.62 (Debian)

Additional information I wanted to run the script from cron.daily, so I have also added a -l to the shebang and a note at the end to rename the updater.

** Proposed patch **

--- /etc/cron.daily/update-apacheblocker.sh.orig        2025-02-24 11:24:20.000000000 +0000
+++ /etc/cron.daily/update-apacheblocker        2025-02-28 08:43:44.000000000 +0000
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -l
 # Bash Script for Auto Updating the Apache Bad Bot Blocker for Apache 2.2 > 2.4
 # Copyright - https://github.com/mitchellkrogza
 # Project Url: https://github.com/mitchellkrogza/apache-ultimate-bad-bot-blocker
@@ -52,6 +52,7 @@
 SERVER_NAME=$(hostname)
 UPDATE_FAIL="Bad bot failed to update globalblacklist on ${SERVER_NAME}"
 UPDATE_SUCCESS="Bad bot globalblacklist successfully updated on ${SERVER_NAME}"
+UPDATE_NOT_NEEDED="Bad bot globalblacklist update not needed on ${SERVER_NAME}"
 CURL_FAIL="Bad bot curl tests have failed on ${SERVER_NAME}."
 WGET_FAIL="Unable to obtain updated globalblacklist. Wget failed on ${SERVER_NAME}."
 CONF_ERROR="Bad bot globalblacklist not present. Does not appear to be setup properly. Aborting update on ${SERVER_NAME}"
@@ -62,11 +63,11 @@
   echo -e "To: ${EMAIL}\\nSubject: Bad bot not installed properly \\n\\n ${CONF_ERROR}\\n" | sendmail -t;
   exit 1;
 else
-  diff <(wget -q -O - ${BLACKLIST_URL}) ${APACHE_CONF}/globalblacklist.conf;
+  cmp -s <(wget -q -O - ${BLACKLIST_URL}) ${APACHE_CONF}/globalblacklist.conf;
   DIFF_CHECK=$?
   if [ ${DIFF_CHECK} -eq 0 ] ; then
-    #Nothing changed
-    echo "Bad bot globalblacklist is already up to date";
+    #Nothing changed. Comment out the next line to stop the not needed email
+    echo -e "To: ${EMAIL}\\nSubject: Bad bot globalblacklist is already up to date \\n\\n ${UPDATE_NOT_NEEDED}\\n" | sendmail -t
     exit 0;
   else
     if [ ${MAKE_BACKUP} = true ] ; then
@@ -105,3 +106,6 @@
 # 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 * * * /usr/sbin/update-apacheblocker.sh
+#
+# If you want to run the updater from cron.daily, on some distros you need to rename it
+# from update-apacheblocker.sh to update-apacheblocker

Note the script could be tarted up further with an additional parameter to enable or disable the new message rather than a comment to comment out the line.

NickJH avatar Feb 28 '25 08:02 NickJH