forked from linickx/rsdns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsdns-export.sh
executable file
·138 lines (119 loc) · 3.74 KB
/
rsdns-export.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
#
# rsdns-export.sh - Used to export domains
#
# config file for variables.
if [ -e ~/.rsdns_config ]
then
. ~/.rsdns_config
fi
# load up our auth & funct library
if [ -n "$RSPATH" ]
then
. $RSPATH/lib/auth.sh
. $RSPATH/lib/func.sh
else
. lib/auth.sh
. lib/func.sh
fi
#prints out the usage information on error or request.
function usage () {
printf "\n"
printf "rsdns export -u username -a apiKey -d domain -o -O filename.txt \n"
printf "\t-k Use London/UK Servers.\n"
printf "\t-o Save export to local directory / text file. \n"
printf "\t-O Specify filename to save export to. \n"
printf "\t-h Show this.\n"
printf "\n"
}
#prints words for master rsdns script output
function words () {
printf "Export domains in bind format \n"
}
#
function get_export() {
check_domain
if [ $FOUND -eq 1 ]
then
DOMEXPORT=`curl -A "rsdns/$RSDNS_VERSION (https://github.com/linickx/rsdns)" -k -s -X GET -H X-Auth-Token:\ $TOKEN $DNSSVR/$USERID/domains/$DOMAINID/export|tr -s '[:cntrl:]' "\n"`
JQ_DOMEXPORT_STATUS=`echo $DOMEXPORT | jq .status | tr -d '"'`
echo "Job status is: $JQ_DOMEXPORT_STATUS"
JQ_DOMEXPORT_CALLBACK=`echo $DOMEXPORT | jq .callbackUrl | tr -d '"'`
if [ "$JQ_DOMEXPORT_STATUS" == "RUNNING" ]
then
while true; do
DOMEXPORT=`curl -A "rsdns/$RSDNS_VERSION (https://github.com/linickx/rsdns)" -k -s -X GET -H X-Auth-Token:\ $TOKEN $JQ_DOMEXPORT_CALLBACK?showDetails=true|tr -s '[:cntrl:]' "\n"`
JQ_DOMEXPORT_STATUS=`echo $DOMEXPORT | jq .status | tr -d '"'`
echo "Job status is: $JQ_DOMEXPORT_STATUS"
echo
if [ "$JQ_DOMEXPORT_STATUS" == "COMPLETED" ]
then
if [ -n "$OFILE" ]; then
printf "\n \t Export will be written to: $OFILE \n\n"
echo $DOMEXPORT | jq .response.contents | tr -d '"' | awk '{gsub(/\\n/,"\n")}1' | awk '{gsub(/\\t/,"\t")}1' | sed 's/\\//g' > $OFILE
fi
echo $DOMEXPORT | jq .response.contents | tr -d '"' | awk '{gsub(/\\n/,"\n")}1' | awk '{gsub(/\\t/,"\t")}1' | sed 's/\\//g'
break
elif [ "$JQ_DOMEXPORT_STATUS" == "ERROR" ]; then
echo $DOMEXPORT | jq .
break
else
echo "Sleeping...."
sleep 1
fi
done
else
echo echo $DOMEXPORT | jq .
fi
fi
}
#Get options from the command line.
while getopts ":u:a:c:d:O::hkqwo" option
do
case $option in
u ) RSUSER=$OPTARG ;;
a ) RSAPIKEY=$OPTARG ;;
c ) USERID=$OPTARG ;;
d ) DOMAIN=$OPTARG ;;
h ) usage;exit 0 ;;
q ) QUIET=1 ;;
k ) UKAUTH=1 ;;
w ) words;exit 0 ;;
o ) SOFILE=1 ;;
O ) SOFILE=1;OFILE=$OPTARG ;;
esac
done
#All actions require authentication, get it done first.
#If the authentication works this will return $TOKEN and $MGMTSVR for use by everything else.
get_auth $RSUSER $RSAPIKEY
if test -z $TOKEN
then
if [[ $QUIET -eq 0 ]]; then
echo Auth Token does not exist.
fi
exit 98
fi
if test -z "$MGMTSVR"
then
if [[ $QUIET -eq 0 ]]; then
echo Management Server does not exist.
fi
exit 97
fi
#if a domain is given, print records, else print domaints
if [ -z "$DOMAIN" ]
then
echo "Which domain do you want to export?"
echo "use the -d switch"
echo
print_domains
else
if [[ $SOFILE -eq 1 ]];then
if [ -z "$OFILE" ]; then
OFILE=${DOMAIN//./_}"_EXPORT.txt"
fi
fi
get_export
fi
#done
exit 0