-
Notifications
You must be signed in to change notification settings - Fork 153
/
jumpcloud_test_utility.sh
executable file
·1016 lines (796 loc) · 19.8 KB
/
jumpcloud_test_utility.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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
###############################################################################
#
# jumpcloud_test_utility.sh - This is a menu driven utility for testing common
# common protocols via command line, icluding LDAP, General Access API
# and Events API
#
# Questions or issues with the operation of the script, please contact
#
# Author: Rob Holden | [email protected]
#
###############################################################################
clear
#
# Help screen
#
help() {
cat << EOF
###################################################################
# #
# JumpCloud command line testing utility #
# #
###################################################################
Enter q to exit
This utility is meant to assist in testing and configuring LDAP
with JumpCloud using the native ldapsearch command and API
interaction.
Step 1. Enter LDAP account variables
LDAP Binding User account name: If you do not know this, please
refer to
https://support.jumpcloud.com/customer/portal/articles/2439911
Password: This is the password for the LDAP Binding User
Organization ID
Step 2. Pick a port using option 2 or 3
Step 3. Option 4 will allow you to connect to LDAP and search
using the defined account variables
Option 5 will list common strings used by the applications
that will athenticate to JumpCloud LDAP.
Option 6 will access API options
Option 9 displays this help screen
Option 0 will exit the utility
EOF
}
#
# ldapsearch
#
# Check for ldapsearch command
ldapsearch=`which ldapsearch`
which ldapsearch &>/dev/null;
if [ $? != 0 ]
then
echo "ldapsearch is not in your path or not installed. Please correct and rerun this script";
exit 1;
fi
# To make it a little bit easier to test against other than production.
CONSOLE_URL="https://console.jumpcloud.com"
if [ ! -z "${JUMPCLOUD_CONSOLE_URL_OVERRIDE}" ]
then
CONSOLE_URL=${JUMPCLOUD_CONSOLE_URL_OVERRIDE}
fi
echo "CONSOLE_URL=${CONSOLE_URL}"
LDAP_DOMAIN="ldap.jumpcloud.com"
if [ -n "${JUMPCLOUD_LDAP_DOMAIN_OVERRIDE}" ]
then
LDAP_DOMAIN=${JUMPCLOUD_LDAP_DOMAIN_OVERRIDE}
fi
EVENTS_URL="https://events.jumpcloud.com"
if [ -n "${JUMPCLOUD_EVENTS_URL_OVERRIDE}" ]
then
EVENTS_URL=${JUMPCLOUD_EVENTS_URL_OVERRIDE}
fi
# Check account vars have been entered
check_ldap_config() {
if [ -z "$port" ]
then
echo "Port Undefined, using default 636";
port=636;
read -rsp $'press key to continue \n' -n1 key
fi
if [ "$port" = "389 -ZZ" ]
then
uri=ldap
else
uri=ldaps
fi
if [ -z "$user" ]
then
echo -e "\nAccount variables undefined, enter information and reselect\n";
read_account;
fi
}
# Define ldapsearch
ldsearch() {
check_ldap_config
$ldapsearch -H ${uri}://${LDAP_DOMAIN}:${port} -x -b "ou=Users,o=${oid},dc=jumpcloud,dc=com" -D "uid=${user},ou=Users,o=${oid},dc=jumpcloud,dc=com" -w "${pass}" "(objectClass=${search_param})" | less
}
#
# Display common configuration strings
#
echo_ldap_config() {
cat << EOF
###################################################################
# Common LDAP Configuration Settings #
###################################################################
### URI/LDAP Server ###
ldaps://ldap.jumpcloud.com:636
ldap://ldap.jumpcloud.com:389
### BIND DN ###
uid=${user},ou=Users,o=${oid},dc=jumpcloud,dc=com
### Search DN/Base Search DN ###
ou=Users,o=${oid},dc=jumpcloud,dc=com
### LDAP Search Example ###
$ldapsearch -H ${uri}://${LDAP_DOMAIN}:${port} -x -b "ou=Users,o=${oid},dc=jumpcloud,dc=com" -D "uid=${user},ou=Users,o=${oid},dc=jumpcloud,dc=com" -w "${pass}" "(objectClass=inetOrgPerson)"
**If the above ldapsearch command results in invalid credentials, and the password contains special characters (!,@,#,etc...), replace the double quotes (") around the password with single quotes (') and retry
EOF
}
# Display the settings
ldap_config() {
check_ldap_config
echo_ldap_config | less
}
#
# read in oid, ldap service account and password
#
# read username, check for null input
read_user() {
echo -n "Enter LDAP Binding User account name: "
read user;
if [ -z "$user" ]
then
echo "Input cannot be null"; read_user;
else
read_pass;
fi
}
# read password, check for null input
read_pass() {
echo -n "Enter password: "
read -s pass;
echo
if [ -z "$pass" ]
then
echo "Input cannot be null"; read_pass;
else
read_oid;
fi
}
# read oid, check for null input
read_oid() {
echo -n "Enter the organization ID: "
read oid;
if [ -z "$oid" ]
then
echo "Input cannot be null"; read_oid;
else continue;
fi
}
read_account() {
read_user
read_pass
read_oid
}
# Single Record Get, enter _id, check for null input
single_get() {
echo -n "Enter the _id value: "
read id;
if [ -z "$id" ]
then
echo "Input cannot be null"; single_get;
else
id=/${id};
get_api | python -m json.tool | less;
continue;
fi
}
# API Call
get_api() {
if [ -z "${org_id}" ]
then
curl \
-X 'GET' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: ${api_key}" \
"${CONSOLE_URL}/api/${api_object}${id}"
else
curl \
-X 'GET' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: ${api_key}" \
-H "x-org-id: ${org_id}" \
"${CONSOLE_URL}/api/${api_object}${id}"
fi
}
# read apikey, check for null input
read_api_key() {
echo -n "Enter your API Key: "
read api_key;
if [ -z "$api_key" ]
then
echo "Input cannot be null"; read_api_key;
else continue;
fi
}
read_org_id() {
echo -n "Enter the Org ID: "
read org_id;
if [ -z "${org_id}" ]
then
echo "Input cannot be null"; read_org_id;
else continue;
fi
}
#
# Define LDAP menu
#
ldap_menu() {
clear
cat << EOF
###### LDAP Search Options ######"
1. List Users
2. List POSIX Groups
3. List Groups of Names
4. List all Objects
0. Main Menu
EOF
}
#
# Read LDAP menu
#
read_ldap_menu() {
echo -ne "\nSelect an option: "
read ldap_option
case $ldap_option in
1) search_param=inetOrgPerson; ldsearch;;
2) search_param=posixGroup; ldsearch;;
3) search_param=groupOfNames; ldsearch;;
4) search_param=*; ldsearch;;
0) break;;
*)
if [ -z "$ldap_option" ]
then
echo "Input cannot be null"; sleep .5;
else
echo -e "\n${ldap_option} is not a valid option"; sleep .5;
fi;;
esac
}
#
# Launch LDAP search menu
#
ldap_search_menu() {
while true
do
ldap_menu
read_ldap_menu
done
}
#
# set_system_search_field
#
set_system_search_field() {
clear
cat << EOF
###########################
## Valid Search Fields ##
###########################
This list shows the search field name and valid
search parameters. There is no error correction for
invalid field or the parameter. Invalid data will
produce null results.
displayName - Alpha/numeric, the value of the System Name in list
view, Display Name in system details
hostname - Alpha/numeric, the hostname of the system
os - Alpha, the base OS type of the system
version - Alpha/numeric, the specific version of the OS
EOF
if [ -z "$system_search_param" ]
then
echo "Current search parameter is undefined"
else
echo "Current Search parameter is \"${system_search_param}"\"
fi
echo -ne "\nSelect a search field: "
read system_search_field
if [ -z "$system_search_field" ]
then
echo "Search field cannot be null"; sleep .5; set_system_search_field
else
continue
fi
}
# Set system_search_param
set_system_search_param() {
clear
cat << EOF
##########################
## Set Search Parameter ##
##########################
The user search parameter is case *insensitive*
by default. Regex is accepted.
EOF
if [ -z "$system_search_field" ]
then
echo "Currnet search field is undefined"
else
echo "Current search field is \"${system_search_field}"\"
fi
echo -ne "\nEnter a search string: "
read system_search_param
if [ -z "$system_search_param" ]
then
echo "Search string undefined"; sleep .5; set_system_search_param
else
continue
fi
}
#
# System search
#
system_search() {
if [ -z "${org_id}" ]
then
curl \
-d '{ "filter" : [{ "'"${system_search_field}"'" : { "$regex" : "(?i)'"${system_search_param}"'" }}]}' \
-X 'POST' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: ${api_key}" \
"${CONSOLE_URL}/api/search/systems?limit=100&skip=10"
else
curl \
-d '{ "filter" : [{ "'"${system_search_field}"'" : { "$regex" : "(?i)'"${system_search_param}"'" }}]}' \
-X 'POST' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: ${api_key}" \
-H "x-org-id: ${org_id}" \
"${CONSOLE_URL}/api/search/systems?limit=100&skip=10"
fi
}
#
# Define system_search_menu
#
system_search_menu() {
clear
cat << EOF
##########################
### System Search ###
##########################
1. Set Search Field
2. Set Search Parameter
3. Run Search
0. System Menu
EOF
}
#
# Read system_search_menu
#
read_system_search_menu() {
echo -ne "\nSelect an option: "
read system_search_option
case $system_search_option in
1) set_system_search_field;;
2) set_system_search_param;;
3) system_search | python -m json.tool | less;;
0) break;;
*)
if [ -z "$system_search_option" ]
then
echo "Input cannot be null"; sleep .5;
else
echo -e "\n${system_search_option} is not a valid option"; sleep .5;
fi;;
esac
}
launch_system_search_menu() {
while true
do
system_search_menu
read_system_search_menu
done
}
#
# set_user_search_field
#
set_user_search_field() {
clear
cat << EOF
###########################
## Valid Search Fields ##
###########################
This list shows the search field name and valid
search parameters. There is no error correction for
invalid field or the parameter. Invalid data will
produce null results.
email - Alpha/numeric, the email address associated with the user
firstname - Alpha/numeric, the first name associated with the user
lastname - Alpha/numeric, the last name associated with the user
username - Alpha/numeric, the unique username associated with the user
EOF
if [ -z "$user_search_param" ]
then
echo "Current search parameter is undefined"
else
echo "Current Search parameter is \"${user_search_param}"\"
fi
echo -ne "\nSelect a search field: "
read user_search_field
if [ -z "$user_search_field" ]
then
echo "Search field cannot be null"; sleep .5; set_user_search_field
else
continue
fi
}
# Set user_search_param
set_user_search_param() {
clear
cat << EOF
##########################
## Set Search Parameter ##
##########################
The user search parameter is case *insensitive*
by default. Regex is accepted.
EOF
if [ -z "$user_search_field" ]
then
echo "Currnet search field is undefined"
else
echo "Current search field is \"${user_search_field}"\"
fi
echo -ne "\nEnter a search string: "
read user_search_param
if [ -z "$user_search_param" ]
then
echo "Search string undefined"; sleep .5; set_user_search_param
else
continue
fi
}
#
# User search
#
user_search() {
#call_type=POST
#search=" -d '{ \"filter\" : [{\"${user_search_field}\" : { \"\\$regex\" : \"(?i)${user_search_param}\"}}]}'"
#get_api | python -m json.tool | less
if [ -z "${org_id}" ]
then
curl \
-d '{ "filter" : [{ "'"${user_search_field}"'" : { "$regex" : "(?i)'"${user_search_param}"'" }}]}' \
-X 'POST' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: ${api_key}" \
"${CONSOLE_URL}/api/search/systemusers?limit=100"
else
curl \
-d '{ "filter" : [{ "'"${user_search_field}"'" : { "$regex" : "(?i)'"${user_search_param}"'" }}]}' \
-X 'POST' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: ${api_key}" \
-H "x-org-id: ${org_id}" \
"${CONSOLE_URL}/api/search/systemusers?limit=100"
fi
}
#
# Define user_search_menu
#
user_search_menu() {
clear
cat << EOF
##########################
### User Search ###
##########################
1. Set Search Field
2. Set Search Parameter
3. Run Search
0. User Menu
EOF
}
#
# Read user_search_menu
#
read_user_search_menu() {
echo -ne "\nSelect an option: "
read user_search_option
case $user_search_option in
1) set_user_search_field;;
2) set_user_search_param;;
3) user_search | python -m json.tool | less;;
0) break;;
*)
if [ -z "$user_search_option" ]
then
echo "Input cannot be null"; sleep .5;
else
echo -e "\n${user_search_option} is not a valid option"; sleep .5;
fi;;
esac
}
launch_user_search_menu() {
while true
do
user_search_menu
read_user_search_menu
done
}
#
# Define command_menu
#
command_menu() {
clear
cat << EOF
##########################
### Commands ###
##########################
1. Commands multi record GET (limit 100)
2. Commands single record GET
3. Command results multi record GET (limit 100)
4. Command results single record GET
0. API Menu
EOF
}
#
# Read command menu
#
read_command_menu() {
api_object=commands
echo -ne "\nSelect an option: "
read command_option
case $command_option in
1) api_object=$api_object?limit=100; get_api | python -m json.tool | less;;
2) single_get;;
3) api_object=commandresults?limit=100; get_api | python -m json.tool | less;;
4) api_object=commandresults; single_get;;
0) break;;
*)
if [ -z "$commmand_option" ]
then
echo "Input cannot be null"; sleep .5;
else
echo -e "\n${command_option} is not a valid option"; sleep .5;
fi;;
esac
}
launch_command_menu() {
while true
do
command_menu
read_command_menu
done
}
#
# Define system_menu
#
system_menu() {
clear
cat << EOF
##########################
### Systems ###
##########################
1. Multi record GET (limit 100)
2. Single record GET
3. Search
0. API Menu
EOF
}
#
# Read system menu
#
read_system_menu() {
api_object=systems
echo -ne "\nSelect an option: "
read system_option
case $system_option in
1) api_object=$api_object?limit=100; get_api | python -m json.tool | less;;
2) single_get;;
3) launch_system_search_menu;;
0) break;;
*)
if [ -z "$system_option" ]
then
echo "Input cannot be null"; sleep .5;
else
echo -e "\n${system_option} is not a valid option"; sleep .5;
fi;;
esac
}
launch_system_menu() {
while true
do
system_menu
read_system_menu
done
}
#
# Define user_menu
#
user_menu() {
clear
cat << EOF
##########################
### Users ###
##########################
1. Multi record GET (limit 100)
2. Single record GET
3. Search
0. API Menu
EOF
}
#
# Read user menu
#
read_user_menu() {
api_object=systemusers;
echo -ne "\nSelect an option: "
read user_option
case $user_option in
1) api_object=$api_object?limit=100; get_api | python -m json.tool | less;;
2) single_get;;
3) launch_user_search_menu;;
0) break;;
*)
if [ -z "$user_option" ]
then
echo "Input cannot be null"; sleep .5;
else
echo -e "\n${user_option} is not a valid option"; sleep .5;
fi;;
esac
}
launch_user_menu() {
while true
do
user_menu
read_user_menu
done
}
#
# Get Events for prev 24 hrs
#
set_date() {
end_date=`date -u +%Y-%m-%dT%H:%M:%SZ`
months=(0 31 28 31 30 31 30 31 31 30 31 30 31)
today=`date -u +%d`
yesterday=`expr $today - 1`
month=`date -u +%m`
yestermonth=${month}
year=`date -u +%Y`
yesteryear=${year}
if ((${yesterday} < 10))
then
if ((${yesterday} == 0))
then
yestermonth=`expr $month - 1`
if ((${yestermonth} == 0))
then
yesteryear=`expr $year - 1`
yestermonth=12
yesterday=31
else
yesterday=${months[${yestermonth}]}
yesteryear=${year}
fi
else
yesterday=0${yesterday}
fi
fi
start_date=`date -u +${yesteryear}-${yestermonth}-${yesterday}T%H:%M:%SZ`
}
call_events() {
if [ -z "${org_id}" ]
then
curl \
-G \
-H "x-api-key: ${api_key}" \
-H "Content-Type:application/json" \
--data-urlencode "startDate=${start_date}" \
"${EVENTS_URL}/events"
else
curl \
-G \
-H "x-api-key: ${api_key}" \
-H "x-org-id: ${org_id}" \
-H "Content-Type:application/json" \
--data-urlencode "startDate=${start_date}" \
"${EVENTS_URL}/events"
fi
}
#
# Define API menu
#
api_menu() {
clear
cat << EOF
##########################
### API Access ###
##########################
1. Enter API Key (Required)
2. Enter OrgId (Required for multi-tenant admin)
3. Users
4. Systems
5. Commands
6. Events (Prev 24 hrs UTC)
0. Main Menu
EOF
}
#
# Read API menu
#
read_api_menu() {
echo -ne "\nSelect an option: "
read api_option
case $api_option in
1) read_api_key;;
2) read_org_id;;
3) launch_user_menu;;
4) launch_system_menu;;
5) launch_command_menu;;
6) set_date;call_events | python -m json.tool | less;;
0) break;;
*)
if [ -z "$api_option" ]
then
echo "Input cannot be null"; sleep .5;
else
echo -e "\n${api_option} is not a valid option"; sleep .5;
fi;;
esac
}
#
# Launch API menu
#
launch_api_menu() {
while true
do
api_menu
read_api_menu
done
}
#
# Define main menu
#
main_menu() {
clear
cat << EOF
###########################
#### Main Menu #####
###########################
1. Enter LDAP account variables
2. Set LDAP port 389 (STARTTLS)
3. Set LDAP port 636 (SSL)
4. LDAP Search Menu
5. Display Common LDAP settings
6. API access
9. Help
0. Exit
EOF
}
#
# Read main menu options
#
read_main_menu() {
echo -ne "\nSelect an option: "
read option
case $option in
1) read_account;;
2) port="389 -ZZ"; echo -e "\n**Port set to 389\n";;
3) port=636; echo -e "\n**Port set to 636\n";;
4) ldap_search_menu;;
5) ldap_config;;
6) launch_api_menu;;
9) help | less;;
0) exit 0;;
*)
if [ -z "$option" ]
then
echo "Input cannot be null"; sleep .5;