-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphical_domain_script.sh
164 lines (151 loc) · 5.7 KB
/
graphical_domain_script.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/local/bin/bash
############################
# The following script is used for a GUI interface
# built upon the previous CLI version.
#############################
#Import user account details
source "account_details"
#Login Loop
LOGIN=false
while [ $LOGIN = false ]
do
username=$(zenity --entry --text="Enter Username")
password=$(zenity --entry --text="Enter Password")
#Test login details against existing accounts
if [ "$username" = "$FIRST_ACCOUNT_USERNAME" ] && [ "$password" = "$FIRST_ACCOUNT_PASSWORD" ]
then
LOGIN=true
elif [ "$username" = "$SECOND_ACCOUNT_USERNAME" ] && [ "$password" = "$SECOND_ACCOUNT_PASSWORD" ]
then
LOGIN=true
else
zenity --info --text "Incorrect Details..."
continue
fi
done
#Select a Zone depending on the user chosen.
while :
do
if [ "$username" == "$FIRST_ACCOUNT_USERNAME" ]
then
zone=$(zenity --list --title="Choose Your Zone" --column="0" "minecraft.com." "unix." --width=100 --height=200 --hide-header)
else
zone=$(zenity --list --title="Choose Your Zone" --column="0" "bigbrick.com." "littleegg.net." --width=100 --height=200 --hide-header)
fi
option=$(zenity --list --title="Pick Your Command" --column="0" "Add Record" "Delete Record" "Update Record" "Nslookup" "List All Records" --width=100 --height=200 --hide-header)
#CRUD actions of records, different details required depending on action
#Utilises Python scripts as DNSPython is required
#
# Add a Record.
# Simple validation implemented, -> Check record does not current exist, no spaces in subdomain and IP is valid IP if MX or A record.
#
regex_pattern=" |'"
if [ "$option" = "Add Record" ]
then
type=$(zenity --list --title="Choose the Type of Record" --column="0" "A" "CNAME" "MX" --width=100 --height=200 --hide-header)
fqdn=$(zenity --entry --text="Enter the subdomain wanted")
#Ask different questions depending on the type of Record created
if [ "$type" = "CNAME" ]
then
ip=$(zenity --entry --text="Enter Subdomain To Point To: ")
else
ip=$(zenity --entry --text="Enter IP")
fi
#Validation, first, check if record exists
python3 doesRecordExist "$fqdn" "$type" "$zone"
containsRecord="`cat ./getRecordsFromZoneContainsKey.txt`"
if [ ${#fqdn} -eq 0 ] || [ ${#ip} -eq 0 ]
then
zenity --info --text "Valid Data must be Inputted" --width=800
#Add to namedb database if validation is completed and passed.
elif [[ "$type" = "A" ]] || [[ "$type" = "MX" ]] && [[ ! $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
then
zenity --info --text "IP was not a valid IP" --width=800
elif [[ "$containsRecord" = "False" ]] && [[ ! $fqdn =~ $regex_pattern ]]
then
python3 site-add-record.py "$fqdn" "$ip" "$zone" "$type"
zenity --info --text "Successfully added $fqdn to $zone" --width=800
else
zenity --info --text "Record already Exists, OR, spaces are in subdomain." --width=800
fi
elif [ "$option" = "Delete Record" ]
then
#
# Delete a Record.
#
#
#
type=$(zenity --list --title="Choose the Type of Record That You wish To Delete" --column="0" "A" "CNAME" "MX" --width=200 --height=200 --hide-header)
fqdn=$(zenity --entry --text="Enter the subdomain you want deleted")
#Validation, first, check if record exists
python3 doesRecordExist "$fqdn" "$type" "$zone"
containsRecord="`cat ./getRecordsFromZoneContainsKey.txt`"
if [[ "$containsRecord" = "False" ]] || [[ ${#fqdn} -eq 0 ]]
then
zenity --info --text "No Record no Remove from the Zone" --width=800
else
python3 site-delete-record.py "$fqdn" "$zone" "$type"
zenity --info --text "Successfully deleted $fqdn from $zone" --width=800
fi
elif [ "$option" = "Update Record" ]
then
#
# Update a Record,
#
#
#
type=$(zenity --list --title="Choose the Type of Record" --column="0" "A" "CNAME" "MX" --width=100 --height=200 --hide-header)
old_fqdn=$(zenity --entry --text="Enter the current subdomain")
fqdn=$(zenity --entry --text="Enter the new subdomain")
ip=$(zenity --entry --text="Enter New IP")
#Validation, first, check if record exists
python3 doesRecordExist "$old_fqdn" "$type" "$zone"
containsOldRecord="`cat ./getRecordsFromZoneContainsKey.txt`"
python3 doesRecordExist "$fqdn" "$type" "$zone"
containsNewRecord="`cat ./getRecordsFromZoneContainsKey.txt`"
#Add to namedb database if validation is completed and passed.
if [[ "$containsOldRecord" = "False" ]]
then
zenity --info --text "No Record to Update" --width=800
elif [[ "$type" = "A" ]] || [[ "$type" = "MX" ]] && [[ ! $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
then
zenity --info --text "IP was not a valid IP" --width=800
elif [[ "$containsNewRecord" = "True" ]] && [[ "$old_fqdn" = "$fqdn" ]] || [[ $containsNewRecord == *"False"* ]]
then
python3 site-update-record.py "$old_fqdn" "$fqdn" "$ip" "$zone" "$type"
zenity --info --text "Successfully updated $fqdn from $zone" --width=800
else
zenity --info --text "Record already Exists, OR, spaces are in subdomain." --width=800
fi
elif [ "$option" = "Nslookup" ]
then
#
# Lookup a Hostname via. nslookup
#
#
#
hostname=$(zenity --entry --text="Enter Full Hostname")
python3 site-lookup.py "$hostname"
result=`cat ./lookup_result.txt`
zenity --info --text="$result" --width=800
else
#
# List the Records existing in the current zone.
# Relies on a CGI script made in Python as DNSPython was required
#
python3 site-list-record.py "$zone"
result=`cat ./list_records.txt`
zenity --info --text="$result" --height=500 --width=800
fi
# Allowing exiting the application
#
#
#Exit the terminal (parent process) if user does not wish to continue
ans=$(zenity --list --title="Do you Wish to Continue" --column="0" "No" "Yes" --width=100 --height=200 --hide-header)
if [ "$ans" = "No" ]
then
kill -9 $PPID
else
:
fi
done