{jcomments on}
#!/bin/bash
# This script is used to update VEGADNS (frontend for tinydns).
# Author: Matthias Drobny, info@ drobny.it
# License: GPL, Feel free to copy and alter.
USER=$1
PASS=$2
VEGADNS_URL=$3
NEW_TARGET_IP=$6
TARGET_DOMAIN=$4
TARGET_RECORD=$5
TARGET_TYPE="A"
NEW_TARGET_TYPE=${TARGET_TYPE}
NEW_TARGET_RECORD=${TARGET_RECORD}
NEW_TARGET_DISTANCE=0
NEW_TARGET_WEIGHT=
NEW_TARGET_PORT=
NEW_TARGET_TTL=600
# Login
SESSIONID=`curl -s --head "${VEGADNS_URL}?state=login&email=${USER}&password=${PASS}" | grep Location | awk -F'=' '{ print $2 }' | awk -F'&' '{print $1}'` #echo ${SESSIONID} if [ -z "$SESSIONID" ] then
exit 0
fi
# get record
RESULT=`curl -s "${VEGADNS_URL}?VDNSSessid=${SESSIONID}&state=logged_in&mode=records&domain=${TARGET_DOMAIN}&search=${TARGET_RECORD}"`
#echo ${RESULT} if [ -z "$RESULT" ] then
exit 0
fi
# extract record_id
RECORD_ID=`echo ${RESULT} | grep -Eo '&record_id.*[^>]</a>' | awk -F'=' '{print $2}' | awk -F'&' '{print $1}'`
if [ -z "$RECORD_ID" ] then
exit 0
fi
# check record type
FOUND_TARGET_TYPE=`echo ${RESULT} | grep -Eo ${TARGET_RECORD}'</a></td> <td width="5%" nowrap>'${TARGET_TYPE}'</td>'`
if [ -z "$FOUND_TARGET_TYPE" ] then
exit 0
fi
# update
ACTION=`curl -s "${VEGADNS_URL}?VDNSSessid=${SESSIONID}&state=logged_in&mode=records&record_mode=edit_record_now&record_id=${RECORD_ID}&domain=${TARGET_DOMAIN}&type=${NEW_TARGET_TYPE}&name=${NEW_TARGET_RECORD}&address=${NEW_TARGET_IP}&distance=${NEW_TARGET_DISTANCE}&weight=${NEW_TARGET_WEIGHT}&port=${NEW_TARGET_PORT}&ttl=${NEW_TARGET_TTL}"`
POST_UPDATE_STRING=`echo '<td><input type="text" name="address" value="'${NEW_TARGET_IP}'"></td>'`
# post update check
POST_UPDATE_CHECK=`curl -s "${VEGADNS_URL}?VDNSSessid=${SESSIONID}&state=logged_in&mode=records&record_mode=edit_record&record_id=${RECORD_ID}&domain=${TARGET_DOMAIN}" | grep -Eo "${POST_UPDATE_STRING}"`
if [ "$POST_UPDATE_STRING" != "$POST_UPDATE_CHECK" ] then
exit 0
else
exit 1
fi