Updated DNS Zone Update tool for Hostmonster

  • Posted August 21, 2014. Last modified March 23, 2017 by

A couple years ago I posted a slightly modified script for hostmonster to update the dns zone entries for subdomains. It used mechanize and ruby. However, since then my script broke as hostmonster made some changes to their backend. Another guy made some changes that seemed to work for a while, but again it has broken. My previous post about this is here.

The culprit seems to be the mixture of javascript / ajax and the fact that hostmonster returns an empty page when you append the /ajax onto the dnszone url. No worries though, I found another way to do it.

Using Watir and Headless, it is possible to achieve the same functionality.

You need to add a few things to ubuntu to make it work:
sudo apt-get install ruby ruby-dev xvfb
sudo gem install watir
sudo gem install headless

Here’s the updated script (note, you can still use the same cron jobs and ip scripts etc. from the previous two techniques.:

#!/usr/bin/ruby

#http://watirwebdriver.com/headless/

require “rubygems”
require “watir-webdriver”
require “headless”

IPLINK = “http://www.jasonernst.com/ip.php”
HOSTMONSTERLOGIN = “https://my.hostmonster.com/web-hosting/cplogin”
DOMAIN = “YOURDOMAIN.COM”
USER = “YOURUSERNAME”
PASS = “YOURPASS”
SUBDOMAIN = “YOUR SUBDOMAIN”

headless = Headless.new
headless.start

browser = Watir::Browser.new

browser.goto IPLINK
ip = browser.text
puts ip

puts “Logging in…”
browser.goto HOSTMONSTERLOGIN

browser.text_field(:name => ‘ldomain’).set USER
browser.text_field(:name => ‘lpass’).set PASS

browser.button(:value => ‘Submit’).click

puts “Done. Getting Zone Info…”

browser.goto ‘https://my.hostmonster.com/cgi/dm/zoneedit’
browser.select_list(:name => ‘domain_selected’).select DOMAIN

Watir::Wait.until { browser.div(:id => “dns_zone_table”).visible? }

puts “Done. Updating IP…”

id = browser.span(:text, /#{SUBDOMAIN}/).id

cleanid = id.delete(“^0-9”)

browser.span(:id => /#{cleanid}/, :class => “action_edit_link btn”).click
browser.text_field(:id => /rec_sp_#{cleanid}_address/).set ip
browser.span(:id => /#{cleanid}/, :class => “action_save_link btn”).click

puts “Done. Success.”

headless.destroy

6 comments on “Updated DNS Zone Update tool for Hostmonster”

  1.  

    Very helpful, thank you! I couldn’t get it to work initially but adding a sleep(10) just before the headless.destroy did the trick.

    There’s probably a better way – waiting for the “save” button to switch back to “edit” springs to mind – but i’m not a ruby-head so the quick and dirty hack will do for now…

  2. Pingback: BLOGS ON COMPUTER SCIENCE | CS SECTION 6B 2013

  3. Pingback: Top 30 Computer Science and Programming Blogs | Yoo Worlds

Leave a Reply

Your email address will not be published. Required fields are marked *