-
Notifications
You must be signed in to change notification settings - Fork 0
/
azbastion
executable file
·286 lines (254 loc) · 9.32 KB
/
azbastion
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
#
# Open a tunnel with a server through Azure Bastion
# https://github.com/luisbunuel/aztools
VERSION="1.1"
azuser="admbunuel"
if [ -z "$azuser" ]; then
echo "Error: The 'azuser' variable is not set. Please edit this script and set it."
exit 1
fi
# LIST OF AZURE TENANTS
IIIM_tenant="iiimprod.onmicrosoft.com"
IIIM_config_dir="$HOME/.azure_IIIM"
UNDP_tenant="iccundp.onmicrosoft.com"
UNDP_config_dir="$HOME/.azure_UNDP"
UNDPBIO_tenant="iccundp.onmicrosoft.com"
UNDPBIO_config_dir="$HOME/.azure_UNDPBIO"
UNWOMEN_tenant="unwomen.onmicrosoft.com"
UNWOMEN_config_dir="$HOME/.azure_WOMEN"
export AZURE_CONFIG_DIR=$IIIM_config_dir
if az account get-access-token &>/dev/null; then
iiim="\Zu\Z1IIIM"
else
iiim="IIIM"
fi
export AZURE_CONFIG_DIR=$UNDP_config_dir
if az account get-access-token &>/dev/null; then
undp="\Zu\Z1UNDP"
else
undp="UNDP"
fi
export AZURE_CONFIG_DIR=$UNWOMEN_config_dir
if az account get-access-token &>/dev/null; then
unwomen="\Zu\Z1UNWOMEN"
else
unwomen="UNWOMEN"
fi
export AZURE_CONFIG_DIR=$UNDPBIO_config_dir
if az account get-access-token &>/dev/null; then
undpbio="\Zu\Z1UNDPBIO"
else
undpbio="UNDPBIO"
fi
check_ssh() {
az extension list | grep name | grep ssh &>/dev/null
if [ $? -ne 0 ]; then
az extension add -n ssh &>/dev/null
fi
}
tenant="$(dialog --colors --backtitle "Azure Bastion tunnel connection" --title "\Zb\Z0AZBASTION v.$VERSION" --stdout --default-item 1 --menu "Select Tenant" 0 0 6 \
1 "$iiim" \
2 "$undp" \
3 "$unwomen" \
4 "$undpbio" )"
case $tenant in
1)
export AZURE_CONFIG_DIR=$IIIM_config_dir
az config set extension.use_dynamic_install=yes_without_prompt &>/dev/null
if ! az account get-access-token &>/dev/null; then
az login --tenant $IIIM_tenant &>> /tmp/azbastion_$USER.log
fi
az account set --subscription 'IIIM - Connectivity Hub'
check_ssh;;
2)
export AZURE_CONFIG_DIR=$UNDP_config_dir
az config set extension.use_dynamic_install=yes_without_prompt &>/dev/null
if ! az account get-access-token &>/dev/null; then
az login --tenant $UNDP_tenant &>> /tmp/azbastion_$USER.log
fi
az account set --subscription 'ICCUNDP - Production'
check_ssh;;
3)
export AZURE_CONFIG_DIR=$UNWOMEN_config_dir
az config set extension.use_dynamic_install=yes_without_prompt &>/dev/null
if ! az account get-access-token &>/dev/null; then
az login --tenant $UNWOMEN_tenant &>> /tmp/azbastion_$USER.log
fi
az account set --subscription 'UNICC'
check_ssh;;
4)
export AZURE_CONFIG_DIR=$UNDPBIO_config_dir
az config set extension.use_dynamic_install=yes_without_prompt &>/dev/null
if ! az account get-access-token &>/dev/null; then
az login --tenant $UNDPBIO_tenant &>> /tmp/azbastion_$USER.log
fi
az account set --subscription 'UNDP - UN Biodiversity Lab Hosting - ELSA'
check_ssh;;
esac
################## IIIM MENU ##################
if [[ $tenant == 1 ]] ; then
bastion="iiim-conn-dw-bastion"
rg="RG-IIIM-ConnHub-Datawalk"
environment="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Environment:" 0 0 5 \
1 "Production" \
2 "Test")"
if [[ $environment == 1 ]] ; then
server="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Server:" 0 0 10 \
1 "iiim-dw-p-appsrv-01" \
2 "iiim-dw-p-appsrv-02" \
3 "iiim-dw-p-intsrv-01" \
4 "iiim-dw-p-intsrv-02" \
5 "iiim-dw-p-compsrv-01" \
6 "iiim-dw-p-compsrv-02" \
7 "iiim-dw-p-compsrv-03" \
8 "iiim-dw-p-monsrv-01")"
case $server in
1)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.62.4 --auth-type password --username $azuser ;;
2)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.62.25 --auth-type password --username $azuser ;;
3)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.62.36 --auth-type password --username $azuser ;;
4)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.62.37 --auth-type password --username $azuser ;;
5)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.62.68 --auth-type password --username $azuser ;;
6)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.62.69 --auth-type password --username $azuser ;;
7)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.62.70 --auth-type password --username $azuser ;;
8)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.62.38 --auth-type password --username $azuser ;;
esac
fi
if [[ $environment == 2 ]] ; then
server="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Server:" 0 0 10 \
1 "iiim-dw-t-appsrv-01" \
2 "iiim-dw-t-appsrv-02" \
3 "iiim-dw-t-intsrv-01" \
4 "iiim-dw-t-intsrv-02" \
5 "iiim-dw-t-compsrv-01" \
6 "iiim-dw-t-compsrv-02" \
7 "iiim-dw-t-compsrv-03")"
case $server in
1)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.61.4 --auth-type password --username $azuser ;;
2)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.61.5 --auth-type password --username $azuser ;;
3)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.61.36 --auth-type password --username $azuser ;;
4)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.61.37 --auth-type password --username $azuser ;;
5)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.61.68 --auth-type password --username $azuser ;;
6)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.61.69 --auth-type password --username $azuser ;;
7)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.61.70 --auth-type password --username $azuser ;;
esac
fi
fi
###############################################
################## UNDP MENU ##################
if [[ $tenant == 2 ]] ; then
bastion="UNDP-PRD-AZRWEU-BASTION-VNET-01"
rg="UNDP-PRD-AZRWEU-HUB"
environment="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Environment:" 0 0 5 \
1 "Production" \
2 "Test")"
if [[ $environment == 1 ]] ; then
server="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Server:" 0 0 10 \
1 "DPLPRODCF02" \
2 "DPSPRODCF02")"
case $server in
1)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.1.46 --auth-type password --username $azuser ;;
2)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.1.47 --auth-type password --username $azuser ;;
esac
fi
if [[ $environment == 2 ]] ; then
server="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Server:" 0 0 10 \
1 "DPLNONPRODCF02")"
case $server in
1)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.1.42 --auth-type password --username $azuser ;;
esac
fi
fi
###############################################
################## UNWOMEN ####################
if [[ $tenant == 3 ]] ; then
bastion="UNWOMEN-EAST-US-bastion"
rg="UNWOMEN-EAST-US-Migrated"
environment="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Environment:" 0 0 5 \
1 "Production" \
2 "Test")"
if [[ $environment == 1 ]] ; then
server="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Server:" 0 0 10 \
1 "UNWMEUSSENBFWD01 - BUY FROM WOMEN" \
2 "UNWMEUSELPRDWEB01 - TRAINING CENTRE" \
3 "UNWMEUSLMSP01 - WEPS")"
case $server in
1)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.2.2.5 --auth-type password --username $azuser ;;
2)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.135.164 --auth-type password --username $azuser ;;
3)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.0.0.4 --auth-type password --username $azuser ;;
esac
fi
if [[ $environment == 2 ]] ; then
server="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Server:" 0 0 10 \
1 "UNWMEUSDEVBFWD01 - BUY FROM WOMEN" \
2 "UNWMEUSLMSD01 - WEPS")"
case $server in
1)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.3.1.132 --auth-type password --username $azuser ;;
2)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.0.1.4 --auth-type password --username $azuser ;;
esac
fi
fi
###############################################
################## UNDP BIO ###################
if [[ $tenant == 4 ]] ; then
bastion="undp-elsa-bastion"
rg="RG-undp-elsa-prod"
environment="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Environment:" 0 0 5 \
1 "Production")"
if [[ $environment == 1 ]] ; then
server="$(dialog --backtitle "Azure Bastion tunnel connection" --stdout --default-item 1 --menu "Select Server:" 0 0 10 \
1 "undpbio")"
case $server in
1)
clear
az network bastion ssh -n $bastion -g $rg --target-ip-address 10.88.2.68 --auth-type password --username $azuser ;;
esac
fi
fi
###############################################