Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Created June 19, 2019 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandfoy/8b6bf162a5eea7f11e1016273ecdbb14 to your computer and use it in GitHub Desktop.
Save briandfoy/8b6bf162a5eea7f11e1016273ecdbb14 to your computer and use it in GitHub Desktop.
A Mojo script to pause cloudflare sites
#!/usr/bin/perl
use v5.10;
use strict;
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
# Translate the first command-line argument to the Mojo::JSON method to use
my $pause = $ARGV[0] ? 'true' : 'false';
# Go through all of your domains and copy their Zone IDs into this hash.
# The key doesn't really matter.
my %api_keys = (
'some_site' => '..zone_id..',
...
);
foreach my $site ( sort keys %api_keys ) {
my $url = 'https://api.cloudflare.com/client/v4/zones/' . $api_keys{$site};
my $tx = $ua->patch( $url => {
'X-Auth-Email' => $ENV{CLOUDFLARE_EMAIL},
'X-Auth-Key' => $ENV{CLOUDFLARE_AUTH_KEY},
'Content-Type' => 'application/json'
},
json => { paused => Mojo::JSON->$pause() }
);
say $tx->result->code, ' ', $site;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment