Skip to content

Instantly share code, notes, and snippets.

@matjack1
Created October 25, 2012 20:17
Show Gist options
  • Save matjack1/3955145 to your computer and use it in GitHub Desktop.
Save matjack1/3955145 to your computer and use it in GitHub Desktop.
mt_bot
require 'rubygems'
require 'mechanize'
domain = ''
email = ''
password = ''
deploy_domain = ''
deploy_server_id = ''
app_name = ''
new_domain = "{app_name}.welaika.com"
domain_creation = true
agent = Mechanize.new
# Mediatemple login
puts "Login"
page = agent.get('http://mediatemple.com')
page = agent.page.link_with(text: 'AccountCenter Login').click
login_form = page.form
login_form.domain = domain
login_form.login_email = email
login_form.password = password
page = agent.submit(login_form)
puts "Login sent"
if domain_creation
# New domain creation
puts "New service"
page = agent.page.link_with(href: '/services/add/start.mt').click
puts "New domain"
page = agent.page.link_with(href: '/services/add/index.mt?act=adddom').click
domain_form = page.form
domain_form.domain = new_domain
domain_form.radiobutton_with(name: 'new_server', value: '0').click
domain_form.radiobutton_with(name: 'regact', value: 'dontregister').click
page = agent.submit(domain_form)
puts "New domain without registration selected"
# if subdomain
domain_form = page.form
domain_form.domain = new_domain
domain_form.radiobutton_with(name: 'new_server', value: '0').click
domain_form.radiobutton_with(name: 'regact', value: 'dontregister').click
domain_form.checkbox_with(name: 'subdomain_confirm').check
page = agent.submit(domain_form)
puts "New domain without registration confirmed selected"
# server selection
puts "Grid server selection"
server_form = page.form
server_form.radiobutton_with(name: 'service', value: deploy_server_id).click
page = agent.submit(server_form)
puts "Grid server #{deploy_domain} / #{deploy_server_id} selected"
# DNS ack
dns_form = page.form
checkbox = dns_form.checkbox_with(name: 'administratively_disable_confirm')
if checkbox
puts "Ignoring DNS"
checkbox.check
page = agent.submit(dns_form)
end
puts "NEW DOMAIN #{new_domain} CREATED!"
end
# DB creation
puts "Creating new DB"
agent.page.link_with(href: "/services/manage/index.mt?domain=#{deploy_domain}&server=#{deploy_server_id}").click
agent.page.link_with(href: "/services/manage/grid/databases/index.mt?id=#{deploy_server_id}").click
page = agent.page.link_with(href: "add.mt?id=#{deploy_server_id}").click
db_form = page.form
db_form.dbname = app_name
page = agent.submit(db_form)
puts "DB #{app_name} created"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment