cloudflare-cli
cloudflare-cli copied to clipboard
Add command to ban IPs (account)
I'm doing add and removing of blocked IPs from fail2ban. The code is somewhat complicated and I'd love if I could just issue a command to ban and unban IPs. Here is how its done:
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": "<cfmode>", "configuration": { "target": "ip", "value": "<ip>" }, "notes": "Fail2Ban on '`date "+%%Y-%%m-%%d %%H:%%M:%%S"`'" }' \
https://api.cloudflare.com/client/v4/accounts/<cfaccount>/firewall/access_rules/rules
actionunban = curl -s -o /dev/null -X DELETE -H 'X-Auth-Email: <cfuser>' -H 'X-Auth-Key: <cftoken>' \
https://api.cloudflare.com/client/v4/accounts/<cfaccount>/firewall/access_rules/rules/$(curl -s -X GET -H 'X-Auth-Email: <cfuser>' -H 'X-Auth-Key: <cftoken>' \
'https://api.cloudflare.com/client/v4/accounts/<cfaccount>/firewall/access_rules/rules?mode=<cfmode>&configuration_target=ip&configuration_value=<ip>&page=1&per_page=1' | awk -F '"' '/id":/{print $4; exit}')
Would this be an easy addition so it'd be easier to just issue something like cfcli -u ban-ip <ip> and cfcli -h unban-ip <ip>, or cfcli -u unban $(cfcli get-banned-ip <ip>) or something alike?