Skip to content

Add command to ban IPs (account) #70

Description

@elgeorge2k

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions