bhmail.py
version: 1.0.0
usage: bhmail.py [options]
Send email regarding BlockHosts blocked IP addresses
options:
--version show program's version number and exit
-h, --help show this help message and exit
-q, --quiet Be as quiet as possible - only print out error
messages
-v, --verbose Be verbose - print errors, warnings, and info messages
-g, --debug Be chatty - print out debug level messages also
--dry-run Don't send any email, just print out email body to
stdout instead (False)
--check-ip=IPADDRESS Instead of mailing entire list of blocked address,
just send email if given IP address is being blocked
("")
--echo=TAG Prints TAG on stderr and syslog, may be used to
identify a run of bhmail ()
Configuration Options:
Hard-coded defaults can be overridden by the values in the config file
- if it exists at /etc/blockhosts.cfg, and those values can be
overriden by using the command-line options. The current values are
shown in () below. This program uses a section in the block file
(/etc/hosts.allow) to find blockhosts data. This section is demarcated
by two identical marker lines, with this text - without the quotes:
"#---- BlockHosts Additions". Also see the "INSTALL" file in the
blockhosts source package for a detailed example of the block file.
--blockfile=FILE Name of hosts-block-file to read (/etc/hosts.allow)
--notify-address=ADDRESS
Address to send notification emails to
("root@localhost.localdomain")
--sender-address=ADDRESS
Address appearing as sender address in notification
emails ("BlockHosts
")
--smtp-server=HOST SMTP server to send notification emails through
("localhost")
--smtp-user=USERNAME
If SMTP authentication is required, use this username
("")
--smtp-passwd=PASSWORD
If SMTP authentication is required, use this password
("")
DETAILS
Sends email if a given IP address is being blocked by blockhosts,
and includes all currently blocked IP addresses in the email message.
Will not send email if given IP address is not yet blocked, or if not a
single address is being blocked.
SMTP is required, it is used for sending email; email header data can be
specified as arguments at run-time, or in the same config file as used by
blockhosts. Defaults can be seen by running with the --help argument, if
you have email setup to receive at root@localhost.localdomain, with
SMTP available at localhost, the defaults might be sufficient to make
this work. Otherwise, edit the section named [bhmail] in the blockhosts.cfg
config file.
This script can be run sequentially after each run of blockhosts.py (to
get notification if currently connecting IP address will be blocked in
future), or can be run periodically using cron (to get list of all
blocked addresses).
Example hosts.allow script:
(/usr/bin/blockhosts.py --echo "%c-%s" ; /usr/bin/bhmail.py --check-ip "%h" --echo "%h")
Example cron run:
/usr/bin/bhmail.py --echo "cron"
====
Based on 29/12/06 patch by Erik Ljungström erik [-at-] ibiblio dot 0rg
http://www.aczoom.com/cms/forums/blockhosts/patch-enabling-email-alerts
====
bhmail.py Script License
This work is hereby released into the Public Domain.
To view a copy of the public domain dedication, visit
http://creativecommons.org/licenses/publicdomain/ or send a letter to
Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
Author: Avinash Chopde
Created: February 2007
http://www.aczoom.com/cms/blockhosts/
See file INSTALL for installation instructions.
See file blockhosts.cfg for site configuration parameters.
Visit blockhosts home page and forum for details and discussions.