-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheduroam-linux-KLA-KU_Leuven_Association_eduroam.sh
executable file
·482 lines (442 loc) · 14.8 KB
/
eduroam-linux-KLA-KU_Leuven_Association_eduroam.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
#!/usr/bin/env bash
if [ -z "$BASH" ] ; then
bash $0
exit
fi
my_name=$0
function setup_environment {
bf=""
n=""
ORGANISATION="KU Leuven Association"
URL="https://admin.kuleuven.be/icts/english/servicedesk"
SUPPORT="[email protected]"
if [ ! -z "$DISPLAY" ] ; then
if which zenity 1>/dev/null 2>&1 ; then
ZENITY=`which zenity`
elif which kdialog 1>/dev/null 2>&1 ; then
KDIALOG=`which kdialog`
else
if tty > /dev/null 2>&1 ; then
if echo $TERM | grep -E -q "xterm|gnome-terminal|lxterminal" ; then
bf="[1m";
n="[0m";
fi
else
find_xterm
if [ -n "$XT" ] ; then
$XT -e $my_name
fi
fi
fi
fi
}
function split_line {
echo $1 | awk -F '\\\\n' 'END { for(i=1; i <= NF; i++) print $i }'
}
function find_xterm {
terms="xterm aterm wterm lxterminal rxvt gnome-terminal konsole"
for t in $terms
do
if which $t > /dev/null 2>&1 ; then
XT=$t
break
fi
done
}
function ask {
T="eduroam CAT"
# if ! [ -z "$3" ] ; then
# T="$T: $3"
# fi
if [ ! -z $KDIALOG ] ; then
if $KDIALOG --yesno "${1}\n${2}?" --title "$T" ; then
return 0
else
return 1
fi
fi
if [ ! -z $ZENITY ] ; then
text=`echo "${1}" | fmt -w60`
if $ZENITY --no-wrap --question --text="${text}\n${2}?" --title="$T" 2>/dev/null ; then
return 0
else
return 1
fi
fi
yes=Y
no=N
yes1=`echo $yes | awk '{ print toupper($0) }'`
no1=`echo $no | awk '{ print toupper($0) }'`
if [ $3 == "0" ]; then
def=$yes
else
def=$no
fi
echo "";
while true
do
split_line "$1"
read -p "${bf}$2 ${yes}/${no}? [${def}]:$n " answer
if [ -z "$answer" ] ; then
answer=${def}
fi
answer=`echo $answer | awk '{ print toupper($0) }'`
case "$answer" in
${yes1})
return 0
;;
${no1})
return 1
;;
esac
done
}
function alert {
if [ ! -z $KDIALOG ] ; then
$KDIALOG --sorry "${1}"
return
fi
if [ ! -z $ZENITY ] ; then
$ZENITY --warning --text="$1" 2>/dev/null
return
fi
echo "$1"
}
function show_info {
if [ ! -z $KDIALOG ] ; then
$KDIALOG --msgbox "${1}"
return
fi
if [ ! -z $ZENITY ] ; then
$ZENITY --info --width=500 --text="$1" 2>/dev/null
return
fi
split_line "$1"
}
function confirm_exit {
if [ ! -z $KDIALOG ] ; then
if $KDIALOG --yesno "Really quit?" ; then
exit 1
fi
fi
if [ ! -z $ZENITY ] ; then
if $ZENITY --question --text="Really quit?" 2>/dev/null ; then
exit 1
fi
fi
}
function prompt_nonempty_string {
prompt=$2
if [ ! -z $ZENITY ] ; then
if [ $1 -eq 0 ] ; then
H="--hide-text "
fi
if ! [ -z "$3" ] ; then
D="--entry-text=$3"
fi
elif [ ! -z $KDIALOG ] ; then
if [ $1 -eq 0 ] ; then
H="--password"
else
H="--inputbox"
fi
fi
out_s="";
if [ ! -z $ZENITY ] ; then
while [ ! "$out_s" ] ; do
out_s=`$ZENITY --entry --width=300 $H $D --text "$prompt" 2>/dev/null`
if [ $? -ne 0 ] ; then
confirm_exit
fi
done
elif [ ! -z $KDIALOG ] ; then
while [ ! "$out_s" ] ; do
out_s=`$KDIALOG $H "$prompt" "$3"`
if [ $? -ne 0 ] ; then
confirm_exit
fi
done
else
while [ ! "$out_s" ] ; do
read -p "${prompt}: " out_s
done
fi
echo "$out_s";
}
function user_cred {
PASSWORD="a"
PASSWORD1="b"
if ! USER_NAME=`prompt_nonempty_string 1 "enter your userid"` ; then
exit 1
fi
while [ "$PASSWORD" != "$PASSWORD1" ]
do
if ! PASSWORD=`prompt_nonempty_string 0 "enter your password"` ; then
exit 1
fi
if ! PASSWORD1=`prompt_nonempty_string 0 "repeat your password"` ; then
exit 1
fi
if [ "$PASSWORD" != "$PASSWORD1" ] ; then
alert "passwords do not match"
fi
done
}
setup_environment
show_info "This installer has been prepared for ${ORGANISATION}\n\nMore information and comments:\n\nEMAIL: ${SUPPORT}\nWWW: ${URL}\n\nInstaller created with software from the GEANT project."
if ! ask "This installer will only work properly if you are a member of ${bf}KU Leuven Association${n} and the user group: ${bf}KU Leuven Association (eduroam).${n}" "Continue" 1 ; then exit; fi
if [ -d $HOME/.cat_installer ] ; then
if ! ask "Directory $HOME/.cat_installer exists; some of its files may be overwritten." "Continue" 1 ; then exit; fi
else
mkdir $HOME/.cat_installer
fi
# save certificates
echo "-----BEGIN CERTIFICATE-----
MIIE+zCCA+OgAwIBAgIQCHC8xa8/25Wakctq7u/kZTANBgkqhkiG9w0BAQsFADBl
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJv
b3QgQ0EwHhcNMTQxMTE4MTIwMDAwWhcNMjQxMTE4MTIwMDAwWjBkMQswCQYDVQQG
EwJOTDEWMBQGA1UECBMNTm9vcmQtSG9sbGFuZDESMBAGA1UEBxMJQW1zdGVyZGFt
MQ8wDQYDVQQKEwZURVJFTkExGDAWBgNVBAMTD1RFUkVOQSBTU0wgQ0EgMzCCASIw
DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMV2Dw/ZQyk7bG3RR63eEL8jwnio
Snc18SNb4EweQefCMQC9iDdFdd25AhCAHo/tZCMERaegOTuBTc9jP8JJ/yKeiLDS
lrlcinQfkioq8hLIt2hUtVhBgUBoBhpPhSn7tU08D08/QJYbzqjMXjX/ZJj1dd10
VAWgNhEEEiRVY++Udy538RV27tOkWUUhn6i+0SftCuirOMo/h9Ha8Y+5Cx9E5+Ct
85XCFk3shKM6ktTPxn3mvcsaQE+zVLHzj28NHuO+SaNW5Ae8jafOHbBbV1bRxBz8
mGXRzUYvkZS/RYVJ+G1ShxwCVgEnFqtyLvRx5GG1IKD6JmlqCvGrn223zyUCAwEA
AaOCAaYwggGiMBIGA1UdEwEB/wQIMAYBAf8CAQAwDgYDV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Ru838fYxAe
+o0bJW1sj6W3YQGx0qMmoRBxna3iw/nDmVG3KwcIzi7mULKn+gpFL6Lw8g==
-----END CERTIFICATE-----
" > $HOME/.cat_installer/ca.pem
function run_python_script {
PASSWORD=$( echo "$PASSWORD" | sed "s/'/\\\'/g" )
if python << EEE1 > /dev/null 2>&1
import dbus
EEE1
then
PYTHON=python
elif python3 << EEE2 > /dev/null 2>&1
import dbus
EEE2
then
PYTHON=python3
else
PYTHON=none
return 1
fi
$PYTHON << EOF > /dev/null 2>&1
#-*- coding: utf-8 -*-
import dbus
import re
import sys
import uuid
import os
class EduroamNMConfigTool:
def connect_to_NM(self):
#connect to DBus
try:
self.bus = dbus.SystemBus()
except dbus.exceptions.DBusException:
print("Can't connect to DBus")
sys.exit(2)
#main service name
self.system_service_name = "org.freedesktop.NetworkManager"
#check NM version
self.check_nm_version()
if self.nm_version == "0.9" or self.nm_version == "1.0":
self.settings_service_name = self.system_service_name
self.connection_interface_name = "org.freedesktop.NetworkManager.Settings.Connection"
#settings proxy
sysproxy = self.bus.get_object(self.settings_service_name, "/org/freedesktop/NetworkManager/Settings")
#settings intrface
self.settings = dbus.Interface(sysproxy, "org.freedesktop.NetworkManager.Settings")
elif self.nm_version == "0.8":
#self.settings_service_name = "org.freedesktop.NetworkManagerUserSettings"
self.settings_service_name = "org.freedesktop.NetworkManager"
self.connection_interface_name = "org.freedesktop.NetworkManagerSettings.Connection"
#settings proxy
sysproxy = self.bus.get_object(self.settings_service_name, "/org/freedesktop/NetworkManagerSettings")
#settings intrface
self.settings = dbus.Interface(sysproxy, "org.freedesktop.NetworkManagerSettings")
else:
print("This Network Manager version is not supported")
sys.exit(2)
def check_opts(self):
self.cacert_file = '${HOME}/.cat_installer/ca.pem'
self.pfx_file = '${HOME}/.cat_installer/user.p12'
if not os.path.isfile(self.cacert_file):
print("Certificate file not found, looks like a CAT error")
sys.exit(2)
def check_nm_version(self):
try:
proxy = self.bus.get_object(self.system_service_name, "/org/freedesktop/NetworkManager")
props = dbus.Interface(proxy, "org.freedesktop.DBus.Properties")
version = props.Get("org.freedesktop.NetworkManager", "Version")
except dbus.exceptions.DBusException:
version = "0.8"
if re.match(r'^1\.', version):
self.nm_version = "1.0"
return
if re.match(r'^0\.9', version):
self.nm_version = "0.9"
return
if re.match(r'^0\.8', version):
self.nm_version = "0.8"
return
else:
self.nm_version = "Unknown version"
return
def byte_to_string(self, barray):
return "".join([chr(x) for x in barray])
def delete_existing_connections(self, ssid):
"checks and deletes earlier connections"
try:
conns = self.settings.ListConnections()
except dbus.exceptions.DBusException:
print("DBus connection problem, a sudo might help")
exit(3)
for each in conns:
con_proxy = self.bus.get_object(self.system_service_name, each)
connection = dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
try:
connection_settings = connection.GetSettings()
if connection_settings['connection']['type'] == '802-11-wireless':
conn_ssid = self.byte_to_string(connection_settings['802-11-wireless']['ssid'])
if conn_ssid == ssid:
connection.Delete()
except dbus.exceptions.DBusException:
pass
def add_connection(self,ssid):
server_alt_subject_name_list = dbus.Array({'DNS:radius.kuleuven.be'})
server_name = 'radius.kuleuven.be'
if self.nm_version == "0.9" or self.nm_version == "1.0":
match_key = 'altsubject-matches'
match_value = server_alt_subject_name_list
else:
match_key = 'subject-match'
match_value = server_name
s_con = dbus.Dictionary({
'type': '802-11-wireless',
'uuid': str(uuid.uuid4()),
'permissions': ['user:$USER'],
'id': ssid
})
s_wifi = dbus.Dictionary({
'ssid': dbus.ByteArray(ssid.encode('utf8')),
'security': '802-11-wireless-security'
})
s_wsec = dbus.Dictionary({
'key-mgmt': 'wpa-eap',
'proto': ['rsn',],
'pairwise': ['ccmp',],
'group': ['ccmp', 'tkip']
})
s_8021x = dbus.Dictionary({
'eap': ['peap'],
'identity': '$USER_NAME',
'ca-cert': dbus.ByteArray("file://{0}\0".format(self.cacert_file).encode('utf8')),
match_key: match_value,
'password': '$PASSWORD',
'phase2-auth': 'mschapv2',
})
s_ip4 = dbus.Dictionary({'method': 'auto'})
s_ip6 = dbus.Dictionary({'method': 'auto'})
con = dbus.Dictionary({
'connection': s_con,
'802-11-wireless': s_wifi,
'802-11-wireless-security': s_wsec,
'802-1x': s_8021x,
'ipv4': s_ip4,
'ipv6': s_ip6
})
self.settings.AddConnection(con)
def main(self):
self.check_opts()
ver = self.connect_to_NM()
self.delete_existing_connections('eduroam')
self.add_connection('eduroam')
self.delete_existing_connections('campusroam')
self.add_connection('campusroam')
if __name__ == "__main__":
ENMCT = EduroamNMConfigTool()
ENMCT.main()
EOF
}
function create_wpa_conf {
cat << EOFW >> $HOME/.cat_installer/cat_installer.conf
network={
ssid="eduroam"
key_mgmt=WPA-EAP
pairwise=CCMP
group=CCMP TKIP
eap=PEAP
ca_cert="${HOME}/.cat_installer/ca.pem"
identity="${USER_NAME}"
domain_suffix_match="radius.kuleuven.be"
phase2="auth=MSCHAPV2"
password="${PASSWORD}"
}
network={
ssid="campusroam"
key_mgmt=WPA-EAP
pairwise=CCMP
group=CCMP TKIP
eap=PEAP
ca_cert="${HOME}/.cat_installer/ca.pem"
identity="${USER_NAME}"
domain_suffix_match="radius.kuleuven.be"
phase2="auth=MSCHAPV2"
password="${PASSWORD}"
}
EOFW
chmod 600 $HOME/.cat_installer/cat_installer.conf
}
#prompt user for credentials
user_cred
if run_python_script ; then
show_info "Installation successful"
else
show_info "Network Manager configuration failed, generating wpa_supplicant.conf"
if ! ask "Network Manager configuration failed, but we may generate a wpa_supplicant configuration file if you wish. Be warned that your connection password will be saved in this file as clear text." "Write the file" 1 ; then exit ; fi
if [ -f $HOME/.cat_installer/cat_installer.conf ] ; then
if ! ask "File $HOME/.cat_installer/cat_installer.conf exists; it will be overwritten." "Continue" 1 ; then confirm_exit; fi
rm $HOME/.cat_installer/cat_installer.conf
fi
create_wpa_conf
show_info "Output written to $HOME/.cat_installer/cat_installer.conf"
fi