#!/bin/bash
# (c) IP-Exchange.de
# written by Team AK47
# Version 0.2 - 05/04/2012

if [ $# -lt 1 ]
 then
 	echo "usage: $0 domainlist"
else
	for FQDN in $(cat $1 );
	do
		 if $(curl -s --user user@domain:password --insecure "https://intranet.ip-exchange.de/dns/domain_such_ergebnis.php?typ=Domainname&value=$FQDN" | grep -q "Keine Daten vorhanden")
			then 
			echo -e "$FQDN \t\t\t aus altem DNS Interface geloescht" >> `date +%d-%m-%Y`.log
			DOMAIN=$(echo $FQDN | awk -F . '{ printf $1 }' )
			TLD=$(echo $FQDN | awk -F . '{ printf $2 }' )
			DOMAINID=$(curl -s --user user@domain:password --insecure "https://intranet.ip-exchange.de/dns/domain_such_ergebnis.php?typ=Domainname&value=$FQDN" | egrep domainid\=[[:digit:]] | awk -F "=" '{ printf $5 }' | awk '{ printf $1 "\n"}')
			curl -s --user berger@ip-partner.de:password --insecure "https://intranet.ip-exchange.de/dns/domain_del_sql.php?Domainname=$DOMAIN&Toplevel=$TLD&userid=8089&domainid=$DOMAINID" 1> /dev/null
		 elif $(curl -s -k --digest --user noc:uxNC69BHwiqtvzW2 "https://dnsql01.ip-exchange.de/admin/index.php?action=search&query=$FQDN" | grep -q Serial )
			then
			echo -e "$FQDN \t\t\t aus neuem DNS Interface geloescht" >> `date +%d-%m-%Y`.log
			ZONEID=$(curl -s -k --digest --user user:password "https://dnsql01.ip-exchange.de/admin/index.php?action=search&query=$FQDN" | egrep -om1 zone\"\ value.*\" | awk -F \" '{ printf $3 }')
			curl -s -k --digest --user user:password "https://dnsql01.ip-exchange.de/admin/index.php" -d 'action=Really+delete+zone' -d zone=$ZONEID -d query=$FQDN. 1> /dev/null
         else
			echo -e "$FQDN \t\t\t nicht in unserem DNS" >> `date +%d-%m-%Y`.log
		fi
	done
fi
mpg123 -q /home/t4c/hotbutton/oops.mp3