2014-07-18 02:54:30 +00:00
|
|
|
#
|
|
|
|
# Author: Mike Rushton
|
|
|
|
#
|
2015-07-01 07:38:36 +00:00
|
|
|
# IMPORTANT
|
2014-07-18 03:49:35 +00:00
|
|
|
#
|
2015-07-01 07:38:36 +00:00
|
|
|
# Please set jail.local's permission to 640 because it contains your CF API key.
|
2014-07-18 02:54:30 +00:00
|
|
|
#
|
2018-05-27 06:15:33 +00:00
|
|
|
# This action depends on curl and jq.
|
2015-07-01 07:38:36 +00:00
|
|
|
# Referenced from http://www.normyee.net/blog/2012/02/02/adding-cloudflare-support-to-fail2ban by NORM YEE
|
|
|
|
#
|
|
|
|
# To get your CloudFlare API Key: https://www.cloudflare.com/a/account/my-account
|
2015-09-30 14:07:45 +00:00
|
|
|
#
|
|
|
|
# CloudFlare API error codes: https://www.cloudflare.com/docs/host-api.html#s4.2
|
2014-07-18 02:54:30 +00:00
|
|
|
|
|
|
|
[Definition]
|
|
|
|
|
|
|
|
# Option: actionstart
|
2018-09-12 14:00:40 +00:00
|
|
|
# Notes.: command executed on demand at the first ban (or at the start of Fail2Ban if actionstart_on_demand is set to false).
|
2014-07-18 02:54:30 +00:00
|
|
|
# Values: CMD
|
|
|
|
#
|
|
|
|
actionstart =
|
|
|
|
|
|
|
|
# Option: actionstop
|
2018-09-12 14:00:40 +00:00
|
|
|
# Notes.: command executed at the stop of jail (or at the end of Fail2Ban)
|
2014-07-18 02:54:30 +00:00
|
|
|
# Values: CMD
|
|
|
|
#
|
|
|
|
actionstop =
|
|
|
|
|
|
|
|
# Option: actioncheck
|
|
|
|
# Notes.: command executed once before each actionban command
|
|
|
|
# Values: CMD
|
|
|
|
#
|
|
|
|
actioncheck =
|
|
|
|
|
|
|
|
# Option: actionban
|
|
|
|
# Notes.: command executed when banning an IP. Take care that the
|
|
|
|
# command is executed with Fail2Ban user rights.
|
2014-07-18 03:49:35 +00:00
|
|
|
# Tags: <ip> IP address
|
|
|
|
# <failures> number of failures
|
|
|
|
# <time> unix timestamp of the ban time
|
2014-07-18 02:54:30 +00:00
|
|
|
# Values: CMD
|
|
|
|
#
|
2016-12-31 20:30:57 +00:00
|
|
|
# API v1
|
2017-08-09 14:27:53 +00:00
|
|
|
#actionban = curl -s -o /dev/null https://www.cloudflare.com/api_json.html -d 'a=ban' -d 'tkn=<cftoken>' -d 'email=<cfuser>' -d 'key=<ip>'
|
2016-12-31 20:30:57 +00:00
|
|
|
# API v4
|
2017-08-09 14:27:53 +00:00
|
|
|
actionban = curl -s -o /dev/null -X POST -H 'X-Auth-Email: <cfuser>' -H 'X-Auth-Key: <cftoken>' \
|
|
|
|
-H 'Content-Type: application/json' -d '{ "mode": "block", "configuration": { "target": "ip", "value": "<ip>" } }' \
|
|
|
|
https://api.cloudflare.com/client/v4/user/firewall/access_rules/rules
|
2015-07-01 07:38:36 +00:00
|
|
|
|
2014-07-18 02:54:30 +00:00
|
|
|
# Option: actionunban
|
|
|
|
# Notes.: command executed when unbanning an IP. Take care that the
|
|
|
|
# command is executed with Fail2Ban user rights.
|
2014-07-18 03:49:35 +00:00
|
|
|
# Tags: <ip> IP address
|
|
|
|
# <failures> number of failures
|
|
|
|
# <time> unix timestamp of the ban time
|
2014-07-18 02:54:30 +00:00
|
|
|
# Values: CMD
|
|
|
|
#
|
2016-12-31 20:30:57 +00:00
|
|
|
# API v1
|
2017-08-09 14:27:53 +00:00
|
|
|
#actionunban = curl -s -o /dev/null https://www.cloudflare.com/api_json.html -d 'a=nul' -d 'tkn=<cftoken>' -d 'email=<cfuser>' -d 'key=<ip>'
|
2016-12-31 20:30:57 +00:00
|
|
|
# API v4
|
2017-08-09 14:27:53 +00:00
|
|
|
actionunban = curl -s -o /dev/null -X DELETE -H 'X-Auth-Email: <cfuser>' -H 'X-Auth-Key: <cftoken>' \
|
|
|
|
https://api.cloudflare.com/client/v4/user/firewall/access_rules/rules/$(curl -s -X GET -H 'X-Auth-Email: <cfuser>' -H 'X-Auth-Key: <cftoken>' \
|
2018-05-27 06:15:33 +00:00
|
|
|
'https://api.cloudflare.com/client/v4/user/firewall/access_rules/rules?mode=block&configuration_target=ip&configuration_value=<ip>&page=1&per_page=1' | jq -r '.result[0].configuration.value')
|
2014-07-18 02:54:30 +00:00
|
|
|
|
|
|
|
[Init]
|
2015-07-01 12:48:44 +00:00
|
|
|
|
2015-07-03 17:17:50 +00:00
|
|
|
# If you like to use this action with mailing whois lines, you could use the composite action
|
|
|
|
# action_cf_mwl predefined in jail.conf, just define in your jail:
|
2015-07-01 12:48:44 +00:00
|
|
|
#
|
|
|
|
# action = %(action_cf_mwl)s
|
|
|
|
# # Your CF account e-mail
|
|
|
|
# cfemail =
|
|
|
|
# # Your CF API Key
|
|
|
|
# cfapikey =
|
|
|
|
|
|
|
|
cftoken =
|
|
|
|
|
|
|
|
cfuser =
|