Skip to content

Instantly share code, notes, and snippets.

@benmmurphy
Created April 21, 2015 13:48
Show Gist options
  • Save benmmurphy/724e52aff8229d221d50 to your computer and use it in GitHub Desktop.
Save benmmurphy/724e52aff8229d221d50 to your computer and use it in GitHub Desktop.
# app.rb
require 'sinatra'
require 'securerandom'
require 'aws-sdk'
set :protection, :except => :frame_options
HOSTED_ZONE_ID = "HOLLAID"
DOMAIN = "holla.net"
SUFFIX = "-bad.#{DOMAIN}"
get '/' do
if !request.host.end_with?(SUFFIX)
subdomain = SecureRandom.hex(16)
@server = "#{subdomain}#{SUFFIX}"
erb :index
else
if request.host.end_with?(SUFFIX)
domain_sufix = ".#{DOMAIN}"
update_domain(request.host)
end
erb :subdomain
end
end
def update_domain(subdomain)
puts "updating domain..#{subdomain}"
route53 = Aws::Route53::Client.new(
region: 'eu-west-1'
)
resp = route53.change_resource_record_sets(
# required
hosted_zone_id: HOSTED_ZONE_ID,
# required
change_batch: {
# required
changes: [
{
# required
action: "UPSERT",
# required
resource_record_set: {
# required
name: "#{subdomain}",
# required
type: "A",
ttl: 60,
resource_records: [
{
# required
value: "127.0.0.1",
},
]
},
},
],
},
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment