Skip to content

Instantly share code, notes, and snippets.

@anabelle
Forked from colinbm/cloudflare_control.rb
Created November 20, 2017 15:36
Show Gist options
  • Save anabelle/8baab5e0c24d80ce078bc9de3fa9a494 to your computer and use it in GitHub Desktop.
Save anabelle/8baab5e0c24d80ce078bc9de3fa9a494 to your computer and use it in GitHub Desktop.
Pause or resume all your CloudFlare sites at once. Useful if CloudFlare is misbehaving.
#!/usr/bin/env ruby
require 'cloudflare'
module CloudFlare
class Connection
public :send_req
end
end
if ARGV[0] != 'resume' && ARGV[0] != 'pause'
STDERR.puts "Pass 'pause' or 'resume as argument."
exit
end
action = ARGV[0] == 'pause' ? :zone_deactivate : :zone_reactivate
cloudflares = {
"[email protected]" => "APIKEY123456789",
"[email protected]" => "APIKEY123456789"
}
cloudflares.each do |email, key|
api = CloudFlare::connection(key, email)
api.zone_load_multi['response']['zones']['objs'].each do |zone|
print zone['zone_name'] + ': '
begin
result = api.send_req({
a: action,
z: zone['zone_name']
})
puts "complete"
rescue Exception => e
puts e.to_s.gsub /<\/?strong>/, ''
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment