Skip to content

Instantly share code, notes, and snippets.

@zed9h
Created October 10, 2009 23:28
Show Gist options
  • Save zed9h/207239 to your computer and use it in GitHub Desktop.
Save zed9h/207239 to your computer and use it in GitHub Desktop.
DreamHost Dynamic DNS script for OpenWRT
#!/bin/sh
# DreamHost Dynamic DNS script for OpenWRT
# by Rodrigo Damazio <rodrigo@damazio.org>
# updated by Kyle Bassett <kylebassett@gmail.com>
# ported by Carlo 'zED' Caputo <carlo.caputo@gmail.com>
USER=carlo.caputo@gmail.com
PASS=xxxxxx
ACCOUNT=123456
HOST=www
DOMAIN=9hells.org
RECTYPE=A
IFACE=ppp0
# to use this record update script, first create a record at:
# https://panel.dreamhost.com/index.cgi?tree=domain.manage&current_step=Index&next_step=ShowZone&domain=$DOMAIN
RECVAL=`ifconfig $IFACE | sed -n 's/.*inet addr: *\([0-9.]*\) .*/\1/p'`
ACTVAL=`nslookup $HOST.$DOMAIN | sed -n 's/Address.*: *//p' | tail -1`
test "$RECVAL" = "$ACTVAL" && exit
HEADER=`mktemp -t`
rm /var/tmp.* # XXX hardcoded, cleanup loose mktemp
CURL_OPT="-m 15 --retry 3"
curl $CURL_OPT -s -k -D $HEADER "https://panel.dreamhost.com/" >/dev/null || exit
COOKIE="`sed -n 's/.*\(Cookie:.*\)/\1/p' $HEADER`"
echo "$COOKIE"
rm $HEADER
curl $CURL_OPT -s -k -H "$COOKIE" -d "Nscmd=Nlogin&username=$USER&password=$PASS" "https://panel.dreamhost.com/index.cgi" >/dev/null || exit
curl $CURL_OPT -s -k -H "$COOKIE" "https://panel.dreamhost.com/index.cgi?active_account=$ACCOUNT" >/dev/null || exit
curl $CURL_OPT -s -k -H "$COOKIE" "https://panel.dreamhost.com/index.cgi?tree=domain.manage&current_step=Index&next_step=ShowZone&domain=$DOMAIN" |
grep "next_step=ShowRecord&editname=$HOST&editzone=$DOMAIN&edittype=$RECTYPE" | # grep -v `echo $RECVAL | sed 's/\./%2E/g'` |
sed 's/"><img.*//' | sed 's/.*href="//' | xargs curl $CURL_OPT -s -k -D $HEADER -H "$COOKIE" >/dev/null || exit
curl $CURL_OPT -s -k -H "$COOKIE" \
-d "tree=domain.manage&current_step=ShowRecord&next_step=EditRecord&newname=$HOST&newtype=$RECTYPE&newvalue=$RECVAL&newcomment=" \
"https://panel.dreamhost.com/" | sed -n 's/.*\(Success!\).*/\1/p' || exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment