Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to ban IPs (account) #70

Open
elgeorge2k opened this issue Aug 5, 2021 · 0 comments
Open

Add command to ban IPs (account) #70

elgeorge2k opened this issue Aug 5, 2021 · 0 comments

Comments

@elgeorge2k
Copy link

elgeorge2k commented Aug 5, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant