|
Line 0
Link Here
|
|
|
1 |
#!/sbin/runscript |
| 2 |
# Copyright 1999-2015 Gentoo Foundation |
| 3 |
# Distributed under the terms of the GNU General Public License v2 |
| 4 |
# $Header: $ |
| 5 |
|
| 6 |
extra_commands="dumpcfg" |
| 7 |
extra_started_commands="reload short detailed" |
| 8 |
|
| 9 |
description="Scans log files and bans IPs that show malicious signs" |
| 10 |
description_dumpcfg="dump configuration. For debugging" |
| 11 |
description_reload="reloads the configuration" |
| 12 |
description_short="short status" |
| 13 |
description_detailed="detailed status about all jails" |
| 14 |
|
| 15 |
: ${pidfile:=/run/fail2ban/fail2ban.pid} |
| 16 |
: ${FAIL2BAN_SOCKFILE:=/run/fail2ban/fail2ban.sock} |
| 17 |
: ${FAIL2BAN_CONFDIR:=/etc/fail2ban} |
| 18 |
FAIL2BAN_OPTIONS="-c '${FAIL2BAN_CONFDIR}' -s '${FAIL2BAN_SOCKFILE}' -p '${pidfile}'" |
| 19 |
|
| 20 |
required_files="${FAIL2BAN_CONFDIR}/fail2ban.conf" |
| 21 |
command="/usr/bin/fail2ban-client" |
| 22 |
command_args="${FAIL2BAN_OPTIONS} -b -x start" |
| 23 |
|
| 24 |
depend() { |
| 25 |
need net logger iptables |
| 26 |
} |
| 27 |
|
| 28 |
start_pre() { |
| 29 |
mkdir -p "$(dirname "${pidfile}")" "$(dirname "${FAIL2BAN_SOCKFILE}")" |
| 30 |
} |
| 31 |
|
| 32 |
stop() { |
| 33 |
ebegin "Stopping fail2ban" |
| 34 |
eval ${command} ${FAIL2BAN_OPTIONS} stop |
| 35 |
eend $? "Failed to stop fail2ban" |
| 36 |
} |
| 37 |
|
| 38 |
reload() { |
| 39 |
ebegin "Reloading fail2ban" |
| 40 |
eval ${command} ${FAIL2BAN_OPTIONS} reload |
| 41 |
eend $? "Failed to reload fail2ban" |
| 42 |
} |
| 43 |
|
| 44 |
dumpcfg(){ |
| 45 |
eval ${command} ${FAIL2BAN_OPTIONS} -d |
| 46 |
} |
| 47 |
|
| 48 |
short(){ |
| 49 |
LANG= eval ${command} ${FAIL2BAN_OPTIONS} status |
| 50 |
} |
| 51 |
|
| 52 |
detailed(){ |
| 53 |
local _j |
| 54 |
for _j in $(short | sed -e 's/,//g' -nre 's/\S\S Jail list:[[:space:]]+(.*)$/\1/p'); do |
| 55 |
eval ${command} ${FAIL2BAN_OPTIONS} status $_j |
| 56 |
done |
| 57 |
} |