#!/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 '&amp;record_id.*[^>]</a>' | awk -F'=' '{print $2}' | awk -F'&amp;' '{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}&amp;state=logged_in&amp;mode=records&amp;record_mode=edit_record_now&amp;record_id=${RECORD_ID}&amp;domain=${TARGET_DOMAIN}&amp;type=${NEW_TARGET_TYPE}&amp;name=${NEW_TARGET_RECORD}&amp;address=${NEW_TARGET_IP}&amp;distance=${NEW_TARGET_DISTANCE}&amp;weight=${NEW_TARGET_WEIGHT}&amp;port=${NEW_TARGET_PORT}&amp;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}&amp;state=logged_in&amp;mode=records&amp;record_mode=edit_record&amp;record_id=${RECORD_ID}&amp;domain=${TARGET_DOMAIN}" | grep -Eo "${POST_UPDATE_STRING}"`
if [ "$POST_UPDATE_STRING" != "$POST_UPDATE_CHECK" ] then 
exit 0 
else 
exit 1 
fi

Kommentar schreiben


Sicherheitscode
Aktualisieren