Implement command line option to specify the fail2ban jail to use.
This commit is contained in:
parent
d33c43030d
commit
e12361472b
1 changed files with 13 additions and 5 deletions
|
@ -68,6 +68,9 @@ Usage: $(basename $0) [OPTION...]
|
||||||
least LIMIT current connections.
|
least LIMIT current connections.
|
||||||
When LIMIT is omitted, assume LIMIT=1.
|
When LIMIT is omitted, assume LIMIT=1.
|
||||||
|
|
||||||
|
-j, --jail=JAIL Specify the JAIL to use for banning the IP addresses. If
|
||||||
|
not set, uses 'apache-auth'.
|
||||||
|
|
||||||
-n, --netmask=SIZE SIZE defines the subnet size in bytes to be analyzed.
|
-n, --netmask=SIZE SIZE defines the subnet size in bytes to be analyzed.
|
||||||
Valid values are:
|
Valid values are:
|
||||||
- 1 or 8 for class A networks (X.0.0.0/8)
|
- 1 or 8 for class A networks (X.0.0.0/8)
|
||||||
|
@ -86,7 +89,7 @@ ENDOFHELP
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCommandline() {
|
function parseCommandline() {
|
||||||
TEMP=$(getopt -o 'a::,n:,h' -l 'auto::,netmask:,help' -- "$@")
|
TEMP=$(getopt -o 'a::,j:,n:,h' -l 'auto::,jail:,netmask:,help' -- "$@")
|
||||||
|
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo 'Error parsing command line options. Terminating. Invoke with --help for help.' >&2
|
echo 'Error parsing command line options. Terminating. Invoke with --help for help.' >&2
|
||||||
|
@ -99,7 +102,7 @@ function parseCommandline() {
|
||||||
while true ; do
|
while true ; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
'-a'|'--auto')
|
'-a'|'--auto')
|
||||||
case $2 in
|
case "$2" in
|
||||||
'')
|
'')
|
||||||
autopilot=1
|
autopilot=1
|
||||||
;;
|
;;
|
||||||
|
@ -108,11 +111,15 @@ function parseCommandline() {
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
autopilot=$2
|
autopilot="$2"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
'-j'|'--jail')
|
||||||
|
jail="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
'-n'|'--netmask')
|
'-n'|'--netmask')
|
||||||
case "$2" in
|
case "$2" in
|
||||||
'1'|'8')
|
'1'|'8')
|
||||||
|
@ -154,6 +161,7 @@ function parseCommandline() {
|
||||||
# Parse the command line options
|
# Parse the command line options
|
||||||
autopilot=0
|
autopilot=0
|
||||||
netmask=0
|
netmask=0
|
||||||
|
jail="apache-auth"
|
||||||
|
|
||||||
parseCommandline "$@"
|
parseCommandline "$@"
|
||||||
|
|
||||||
|
@ -372,9 +380,9 @@ while read -r addr ; do
|
||||||
echo "Banning ${addr} ..."
|
echo "Banning ${addr} ..."
|
||||||
if [[ $(id -un) == "root" ]] ; then
|
if [[ $(id -un) == "root" ]] ; then
|
||||||
# Don't use sudo when we're running as root.
|
# Don't use sudo when we're running as root.
|
||||||
fail2ban-client set apache-auth banip "${addr}"
|
fail2ban-client set "${jail}" banip "${addr}"
|
||||||
else
|
else
|
||||||
sudo fail2ban-client set apache-auth banip "${addr}"
|
sudo fail2ban-client set "${jail}" banip "${addr}"
|
||||||
fi
|
fi
|
||||||
done < "${banlist}"
|
done < "${banlist}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue