Codebase list poshc2 / 39f6cef resources / modules / HealthInspector.js
39f6cef

Tree @39f6cef (Download .tar.gz)

HealthInspector.js @39f6cefraw · history · blame

   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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
//Author Cody Thomas, @its_a_feature_
//All of these functions use Objective C API calls to read PLIST files from an unauthenticated context
//Helper Functions -----------------------------------
function hex2a(hexx) {
    let hex = hexx.toString();//force conversion
    let str = '';
    for (let i = 0; (i < hex.length && hex.substr(i, 2) !== '00'); i += 2)
        str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
    return str;
}
function get_permissions(path){
	let fileManager = $.NSFileManager.defaultManager;
	attributes = ObjC.deepUnwrap(fileManager.attributesOfItemAtPathError($(path), $()));
	//return attributes;
    let trimmed_attributes = {};
    if(attributes === undefined){
    	return ["Failed to get permissions"];
    }
    trimmed_attributes['NSFileOwnerAccountID'] = attributes['NSFileOwnerAccountID'];
    trimmed_attributes['NSFileExtensionHidden'] = attributes['NSFileExtensionHidden'];
    trimmed_attributes['NSFileGroupOwnerAccountID'] = attributes['NSFileGroupOwnerAccountID'];
    trimmed_attributes['NSFileOwnerAccountName'] = attributes['NSFileOwnerAccountName'];
    trimmed_attributes['NSFileCreationDate'] = attributes['NSFileCreationDate'];
    let nsposix = attributes['NSFilePosixPermissions'];
    // we need to fix this mess to actually be real permission bits that make sense
    let posix = ((nsposix >> 6) & 0x7).toString() + ((nsposix >> 3) & 0x7).toString() + (nsposix & 0x7).toString();
    trimmed_attributes['NSFilePosixPermissions'] = posix;
    trimmed_attributes['NSFileGroupOwnerAccountName'] = attributes['NSFileGroupOwnerAccountName'];
    trimmed_attributes['NSFileModificationDate'] = attributes['NSFileModificationDate'];
    return trimmed_attributes;
}
function file_exists(path){
	let fileManager = $.NSFileManager.defaultManager;
	return fileManager.fileExistsAtPath($(path));
}
//-------------------------------------------------
function Persistent_Dock_Apps({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Preferences/com.apple.dock.plist")){
		if(json==false){
			return "**************************************\n" + "**** Persistent Dock Applications ****\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Persistent_Dock_Apps"});
		}
	}

	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Preferences/com.apple.dock.plist");
	let contents = ObjC.deepUnwrap(dict);
	output['persistent-dock-apps'] = [];
	for(let i = 0; i < contents['persistent-apps'].length; i++){
		output['persistent-dock-apps'].push({"label": contents['persistent-apps'][i]['tile-data']['file-label'],
											 "bundle": contents['persistent-apps'][i]['tile-data']['bundle-identifier']});
	}
	for(let i = 0; i < contents['persistent-others'].length; i++){
		output['persistent-dock-apps'].push({"label": contents['persistent-others'][i]['tile-data']['file-label'],
											 "bundle": contents['persistent-others'][i]['tile-data']['bundle-identifier']});
	}
	output['show-recents'] = contents['show-recents'];
	output['recent-apps'] = contents['recent-apps'];
	if(json==false){
		output = "**************************************\n" + "**** Persistent Dock Applications ****\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	} 
	else{
		output['HealthInspectorCommand'] = "Persistent_Dock_Apps";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function Spaces_Check({help=false, json=false, user=""} = {}){
	if(help){
		let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Preferences/com.apple.spaces.plist")){
		if(json==false){
			return "**************************************\n" + "******** Desktops Information ********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Spaces_Check"});
		}
	}
	
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Preferences/com.apple.spaces.plist");
	let contents = ObjC.deepUnwrap(dict);
	let monitors = contents['SpacesDisplayConfiguration']['Management Data']['Monitors'];
	for(let i = 0; i < monitors.length; i++){
		if(monitors[i]['Display Identifier'] == "Main"){
			let currentSpaceID = monitors[i]['Current Space']['ManagedSpaceID'];
			let currentSpacePlace = 0;
			let totalSpaces = monitors[i]['Spaces'].length;
			for(let j = 0; j < monitors[i]['Spaces'].length; j++){
				if(currentSpaceID == monitors[i]['Spaces'][j]['ManagedSpaceID']){
					currentSpacePlace = j + 1;
				}
			}
			output['Main Desktop'] = {};
			output['Main Desktop']['Current Space'] = currentSpacePlace;
			output['Main Desktop']['Total Spaces'] = totalSpaces;
		}
	}
	if(json==false){
		output = "**************************************\n" + "******** Desktops Information ********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}
	else{
		output['HealthInspectorCommand'] = "Spaces_Check";
		output = JSON.stringify(output, null, 1);
	}
	
	return output;}
function Get_Office_Email({help=false, json=false, user=""} = {}){
	if(help){
		let output = "";
		return output;
	}
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Preferences/com.microsoft.office.plist")){
		if(json==false){
			return "**************************************\n" + "****** Registered Office Email ******\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Get_Office_Email"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Preferences/com.microsoft.office.plist");
	let contents = ObjC.deepUnwrap(dict);
	let output = {};
	if(contents != {} && contents != undefined){
		output['email'] = contents['OfficeActivationEmailAddress'];
		if(json==false){
			output = "**************************************\n" + "****** Registered Office Email ******\n" + "**************************************\n" + JSON.stringify(output, null , 1);
		}else{
			output['HealthInspectorCommand'] = "Get_Office_Email";
			output = JSON.stringify(output, null, 1);
		}
	}
	return output;}
function Saved_Printers({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Preferences/org.cups.PrintingPrefs.plist")){
		if(json==false){
			return "**************************************\n" + "********* Last Used Printers *********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Saved_Printers"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Preferences/org.cups.PrintingPrefs.plist");
	let contents = ObjC.deepUnwrap(dict);
	output['LastUsedPrinters'] = [];
	if(contents != undefined){
		if(contents.hasOwnProperty('LastUsedPrinters')){
			for(let i = 0; i < contents['LastUsedPrinters'].length; i++){
				output['LastUsedPrinters'].push({"Network": contents['LastUsedPrinters'][i]['Network'],
												 "PrinterID": contents['LastUsedPrinters'][i]['PrinterID']});
			}
		}
		if(json==false){
			output = "**************************************\n" + "********* Last Used Printers *********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
		}else{
			output['HealthInspectorCommand'] = "Saved_Printers";
			output = JSON.stringify(output, null, 1);
		}
	}	
	return output;}
function Finder_Preferences({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Preferences/com.apple.finder.plist")){
		if(json==false){
			return "**************************************\n" + "** Recent Folders and Finder Prefs **\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Finder_Preferences"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Preferences/com.apple.finder.plist");
	let contents = ObjC.deepUnwrap(dict);
	output['Recent Move and Copy Destinations'] = contents['RecentMoveAndCopyDestinations'];
	output['Finder GoTo Folder Recents'] = contents['GoToFieldHistory'];
	output['Show All Files in Finder'] = contents['AppleShowAllFiles'];
	output['Show Removable Media on Desktop'] = contents['ShowRemovableMediaOnDesktop'];
	output['Tag Names'] = contents['FavoriteTagNames'];
	output['Recent Folders'] = [];
	if('FXRecentFolders' in contents){
		for(let i = 0; i < contents['FXRecentFolders'].length; i++){
			output['Recent Folders'].push(contents['FXRecentFolders'][i]['name']);
		}
	}
	if('FXDesktopVolumePositions' in contents){
		output['Prior Mounted Volumes'] = Object.keys(contents['FXDesktopVolumePositions']);
	}
	if(json==false){
		output = "**************************************\n" + "** Recent Folders and Finder Prefs **\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Finder_Preferences";
		output = JSON.stringify(output, null, 1);
	}
	
	return output;}
function Launch_Services({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist")){
		if(json==false){
			return "**************************************\n" + "*** Custom LaunchServices Handlers ***\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Launch_Services"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist");
	let contents = ObjC.deepUnwrap(dict);
	output['LSHandlers_FileExtensions'] = [];
	output['LSHandlers_URLSchemes'] = [];
	if(contents != undefined){
		for(let i = 0; i < contents['LSHandlers'].length; i++){
			if(contents['LSHandlers'][i].hasOwnProperty('LSHandlerContentTag')){
				output['LSHandlers_FileExtensions'].push({"file_extension": contents['LSHandlers'][i]['LSHandlerContentTag'],
														  "handler": contents['LSHandlers'][i]['LSHandlerRoleAll']});
			}
			else if(contents['LSHandlers'][i].hasOwnProperty('LSHandlerURLScheme')){
				output['LSHandlers_URLSchemes'].push({"URLScheme": contents['LSHandlers'][i]['LSHandlerURLScheme'],
														  "handler": contents['LSHandlers'][i]['LSHandlerRoleAll'],
														  "viewer": contents['LSHandlers'][i]['LSHandlerRoleViewer']});
			}
			else{
				output['LSHandlers_URLSchemes'].push({"ContentType": contents['LSHandlers'][i]['LSHandlerContentType'],
														  "handler": contents['LSHandlers'][i]['LSHandlerRoleAll'],
														"viewer": contents['LSHandlers'][i]['LSHandlerRoleViewer']});
			}
		}
	}
	if(json==false){
		output = "**************************************\n" + "*** Custom LaunchServices Handlers ***\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Launch_Services";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function Universal_Access_Auth_Warning({help=false, json=false, user=""} = {}){
	// information on all apps that macOS has ever thrown the ‘some.app would like permission to control your computer
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Preferences/com.apple.universalaccessAuthWarning.plist")){
		if(json==false){
			return "**************************************\n" + "**** UniversalAccess Auth Warning ****\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Universal_Access_Auth_Warning"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Preferences/com.apple.universalaccessAuthWarning.plist");
	let contents = ObjC.deepUnwrap(dict);
	if(contents != {}){
		output['Universal Access Auth Warning Applications'] = contents;
	}
	if(json==false){
		output = "**************************************\n" + "**** UniversalAccess Auth Warning ****\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Universal_Access_Auth_Warning";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function Relaunch_At_Login({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	let files = ObjC.deepUnwrap(fileManager.contentsOfDirectoryAtPathError(currentUserPath + "/Library/Preferences/ByHost", Ref()));
	output['Relaunch Apps'] = [];
	for(i in files){
		if(files[i].includes("com.apple.loginwindow") && files[i].endsWith(".plist")){
			let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Preferences/ByHost/" + files[i]);
			output['Relaunch Apps'] = ObjC.deepUnwrap(dict)['TALAppsToRelaunchAtLogin'];
			break;
		}
	}
	if(json==false){
		output = "**************************************\n" + "* Applications to Relaunch at Login *\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Relaunch_At_Login";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function Login_Items({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Preferences/com.apple.loginitems.plist")){
		if(json==false){
			return "**************************************\n" + "************ Login Items ************\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Login_Items"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Preferences/com.apple.loginitems.plist");
	let contents = ObjC.deepUnwrap(dict);
	if(contents != {}){
		output['Login_Items'] = contents;
	}
	if(json==false){
		output = "**************************************\n" + "************ Login Items ************\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Login_Items";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function User_Dir_Hidden_Files_Folders({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = [];
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	let files = ObjC.deepUnwrap(fileManager.contentsOfDirectoryAtPathError(currentUserPath, Ref()));
	for(i in files){
		if(files[i][0] == "."){
			output.push(files[i]);
		}
	}
	if(json==false){
		output = "**************************************\n" + "***** Hidden Files/Folders in ~ *****\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "User_Dir_Hidden_Files_Folders";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function User_Global_Preferences({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Preferences/.GlobalPreferences.plist")){
		if(json==false){
			return "**************************************\n" + "***** User's Global Preferences *****\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "User_Global_Preferences"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Preferences/.GlobalPreferences.plist");
	let contents = ObjC.deepUnwrap(dict);
	if(contents['NSPreferredWebServices'] !== undefined){
		output['Default Web Service'] = contents['NSPreferredWebServices']['NSWebServicesProviderWebSearch']['NSDefaultDisplayName'] + " - " + contents['NSPreferredWebServices']['NSWebServicesProviderWebSearch']['NSProviderIdentifier']	
	}
	output['Recent Places'] = contents['NSNavRecentPlaces'];
	if(contents['com.apple.finder.SyncExtensions'] !== undefined){	
		output['Finder Sync Extensions'] = Object.keys(contents['com.apple.finder.SyncExtensions']['dirMap']);
	}
	output['Show All Extensions'] = contents['AppleShowAllExtensions'];
	if(json==false){
		output = "**************************************\n" + "***** User's Global Preferences *****\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "User_Global_Preferences";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function User_Launchagents({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	let files = ObjC.deepUnwrap(fileManager.contentsOfDirectoryAtPathError(currentUserPath + "/Library/LaunchAgents/", Ref()));
	for(i in files){
		let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/LaunchAgents/" + files[i]);
		dict = ObjC.deepUnwrap(dict);
		if(dict !== undefined && dict.hasOwnProperty('ProgramArguments')){
            dict['Program Attributes'] = get_permissions(dict['ProgramArguments'][0]);
            program_dir = dict['ProgramArguments'][0].split("/");
            program_dir.pop();
            program_dir = "/" + program_dir.join("/");
            dict['Program Directory Attributes'] = get_permissions(program_dir);
		}
		else if(dict !== undefined && dict.hasOwnProperty('Program')){
			dict['Program Attributes'] = get_permissions(dict['Program']);
            program_dir = dict['Program'].split("/");
            program_dir.pop();
            program_dir = "/" + program_dir.join("/");
            dict['Program Directory Attributes'] = get_permissions(program_dir);
		}
		output[files[i]] = dict;
		
	}
	if(json==false){
		output = "**************************************\n" + "***** User's Launch Agents *****\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "User_Launchagents";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function User_Launchdaemons({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	let files = ObjC.deepUnwrap(fileManager.contentsOfDirectoryAtPathError(currentUserPath + "/Library/LaunchDaemons/", Ref()));
	for(i in files){
		let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/LaunchDaemons/" + files[i]);
		dict = ObjC.deepUnwrap(dict);
		if(dict != undefined && dict.hasOwnProperty('ProgramArguments') && dict['ProgramArguments'].length > 0){
            dict['Program Attributes'] = get_permissions(dict['ProgramArguments'][0]);
            program_dir = dict['ProgramArguments'][0].split("/");
            program_dir.pop();
            program_dir = "/" + program_dir.join("/");
            dict['Program Directory Attributes'] = get_permissions(program_dir);
		}
		else if(dict !== undefined && dict.hasOwnProperty('Program')){
			dict['Program Attributes'] = get_permissions(dict['Program']);
            program_dir = dict['Program'].split("/");
            program_dir.pop();
            program_dir = "/" + program_dir.join("/");
            dict['Program Directory Attributes'] = get_permissions(program_dir);
		}
		output[files[i]] = dict;
		 
	}
	if(json==false){
		output = "**************************************\n" + "***** User's Launch Daemons *****\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "User_Launchdaemons";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function System_Launchdaemons({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let files = ObjC.deepUnwrap(fileManager.contentsOfDirectoryAtPathError("/Library/LaunchDaemons/", Ref()));
	for(i in files){
		let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/LaunchDaemons/" + files[i]);
		dict = ObjC.deepUnwrap(dict);
		if(dict != undefined && dict.hasOwnProperty('ProgramArguments') && dict['ProgramArguments'].length > 0){
            dict['Program Attributes'] = get_permissions(dict['ProgramArguments'][0]);
            program_dir = dict['ProgramArguments'][0].split("/");
            program_dir.pop();
            program_dir = "/" + program_dir.join("/");
            dict['Program Directory Attributes'] = get_permissions(program_dir);
		}
		else if(dict !== undefined && dict.hasOwnProperty('Program')){
			dict['Program Attributes'] = get_permissions(dict['Program']);
            program_dir = dict['Program'].split("/");
            program_dir.pop();
            program_dir = program_dir.join("/");
            //console.log(program_dir);
            dict['Program Directory Attributes'] = get_permissions(program_dir);
		}
		output[files[i]] = dict;
		 
	}
	if(json==false){
		output = "**************************************\n" + "***** System Launch Daemons *****\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "System_Launchdaemons";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function Installed_Software_Versions({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	if(!file_exists("/Library/Receipts/InstallHistory.plist")){
		if(json==false){
			return "**************************************\n" + "********** Software Verions  *********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Installed_Software_Versions"});
		}
	}
	let dict = $.NSArray.alloc.initWithContentsOfFile("/Library/Receipts/InstallHistory.plist");
	let contents = ObjC.deepUnwrap(dict);
	for(let i in contents){
		if(!output.hasOwnProperty(contents[i]['displayName'])){
			output[contents[i]['displayName']] = {};
		}
		if(output[contents[i]['displayName']]['version'] == undefined ||
			output[contents[i]['displayName']]['version'] < contents[i]['displayVersion']){
			// update our information if we find a newer version listed
			output[contents[i]['displayName']]['date'] = contents[i]['date'];
			output[contents[i]['displayName']]['version'] = contents[i]['displayVersion'];
			output[contents[i]['displayName']]['processName'] = contents[i]['processName'];
		}
		
	}
	if(json==false){
		output = "**************************************\n" + "********** Software Verions  *********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Installed_Software_Versions";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
// ----------- user data mining functions -------------
function Unique_Bash_History_Sessions({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	let files = ObjC.deepUnwrap(fileManager.contentsOfDirectoryAtPathError(currentUserPath + "/.bash_sessions/", Ref()));
	let final_commands = new Set();
	for(i in files){
		let list = $.NSString.alloc.initWithContentsOfFileEncodingError(currentUserPath + "/.bash_sessions/" + files[i], $.NSUTF8StringEncoding, $()).js.split("\n");
		for(let j in list){
			final_commands.add(list[j]);
		}
	}
	let list = $.NSString.alloc.initWithContentsOfFileEncodingError(currentUserPath + "/.bash_history", $.NSUTF8StringEncoding, $()).js;
	if(list != undefined){
		list = list.split("\n");
		for(let j in list){
			final_commands.add(list[j]);
		}
	}
	list = $.NSString.alloc.initWithContentsOfFileEncodingError(currentUserPath + "/.zsh_history", $.NSUTF8StringEncoding, $()).js;
	if(list != undefined){
		list = list.split("\n");
		for(let j in list){
			final_commands.add(list[j]);
		}
	}
	output['commands'] = Array.from(final_commands);
	if(json==false){
		output = "**************************************\n" + "******* Unique Bash History *******\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Unique_Bash_History_Sessions";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function SSH_Keys({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	let files = ObjC.deepUnwrap(fileManager.contentsOfDirectoryAtPathError(currentUserPath + "/.ssh", Ref()));
	for(i in files){
		let dict = $.NSString.alloc.initWithContentsOfFileEncodingError(currentUserPath + "/.ssh/" + files[i], $.NSUTF8StringEncoding, $());
		dict = ObjC.deepUnwrap(dict);
		output[files[i]] = dict;
		
	}
	if(json==false){
		output = "**************************************\n" + "********* SSH Key Files *********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "SSH_Keys";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function Slack_Download_Cache_History({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Application Support/Slack/storage/slack-downloads")){
		if(json==false){
			return "**************************************\n" + "********* Slack Downloads *********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Slack_Download_Cache_History"});
		}
	}
	let dict = $.NSString.alloc.initWithContentsOfFileEncodingError(currentUserPath + "/Library/Application Support/Slack/storage/slack-downloads", $.NSUTF8StringEncoding, $()).js;
	if(dict != "" && dict != undefined){
		dict = JSON.parse(dict);
		team_keys = Object.keys(dict);
		output['slack download cache history'] = [];
		for(let team_key in team_keys){
			let file_keys = Object.keys(dict[team_keys[team_key]]);
			for(let file_key in file_keys){
				output['slack download cache history'].push({"url":dict[team_keys[team_key]][file_keys[file_key]]['url'], "download path": dict[team_keys[team_key]][file_keys[file_key]]['downloadPath']});
			}
		}
	}
	if(json==false){
		output = "**************************************\n" + "********* Slack Downloads *********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Slack_Download_Cache_History";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function Slack_Team_Information({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	if(!file_exists(currentUserPath + "/Library/Application Support/Slack/storage/slack-teams")){
		if(json==false){
			return "**************************************\n" + "********* Slack Team Info *********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Slack_Team_Information"});
		}
	}
	let dict = $.NSString.alloc.initWithContentsOfFileEncodingError(currentUserPath + "/Library/Application Support/Slack/storage/slack-teams", $.NSUTF8StringEncoding, $()).js;
	if(dict != "" && dict != undefined){
		dict = JSON.parse(dict);
		keys = Object.keys(dict);
		for(let key in keys){
			delete dict[keys[key]]['theme'];
			delete dict[keys[key]]['icons'];
		}
		output['slack team information'] = dict;
	}
	if(json==false){
		output = "**************************************\n" + "********* Slack Team Info *********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Slack_Team_Information";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function Recent_Files({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	let currentUserPath = ""; if(user === ""){currentUserPath = fileManager.homeDirectoryForCurrentUser.fileSystemRepresentation;}else{currentUserPath = "/Users/" + user;}
	output['Recent Applications'] = [];
	if(!file_exists(currentUserPath + "/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.RecentApplications.sfl2")){
		if(json==false){
			return "**************************************\n" + "***** User's recent applications *****\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Recent_Files"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile(currentUserPath + "/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.RecentApplications.sfl2");
	let contents = ObjC.deepUnwrap(dict);
	if(contents === undefined){
		if(json==false){
			return "**************************************\n" + "***** User's recent applications *****\n" + "**************************************\n" + "Blocked by TCC";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Recent_Files"});
		}
	}
	for(let i = 0; i < contents['$objects'].length; i++){
		if(typeof contents['$objects'][i] == "string" && contents['$objects'][i].includes(".app")){
			output['Recent Applications'].push(contents['$objects'][i]);
		}
	}
	if(json==false){
		output = "**************************************\n" + "***** User's recent applications *****\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Recent_Files";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
//------------ globally readable plists with interesting info ------------------
function Firewall({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/Library/Preferences/com.apple.alf.plist")){
		if(json==false){
			return "**************************************\n" + "******* Firewall Preferences *******\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Firewall"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/com.apple.alf.plist");
	let contents = ObjC.deepUnwrap(dict);
	output['Global State'] = contents['globalstate'];
	output['Stealth Enabled'] = contents['stealthenabled'];
	output['Logging'] = contents['loggingenabled'];
	dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/com.apple.ARDAgent.plist");
	output['ARDAgent'] = ObjC.deepUnwrap(dict);
	dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/com.apple.RemoteDesktop.plist");
	output['RemoteDesktop'] = ObjC.deepUnwrap(dict);
	dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/com.apple.RemoteManagement.plist");
	output['RemoteManagement'] = ObjC.deepUnwrap(dict);
	dict = $.NSString.alloc.initWithContentsOfFile("/Library/Preferences/com.apple.VNCSettings.txt");
	output['VNCSettings'] = ObjC.deepUnwrap(dict);
	if(json==false){
		output = "**************************************\n" + "******* Firewall Preferences *******\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Firewall";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function Airport_Preferences({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist")){
		if(json==false){
			return "**************************************\n" + "******** Airport Preferences ********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Airport_Preferences"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist");
	let contents = ObjC.deepUnwrap(dict);
	output['Known Networks'] = [];
	let wifi_keys = Object.keys(contents['KnownNetworks']);
	let hex_to_ssid = {};
	for(let i in wifi_keys){
		hex_to_ssid[wifi_keys[i]] = contents['KnownNetworks'][wifi_keys[i]]['SSIDString'];
	}
	for(let i in wifi_keys){
		let SSID = contents['KnownNetworks'][wifi_keys[i]]['SSIDString'];
		let SecurityType = contents['KnownNetworks'][wifi_keys[i]]['SecurityType'];
		let lastConnected = contents['KnownNetworks'][wifi_keys[i]]['LastConnected'];
		let wasCaptive = contents['KnownNetworks'][wifi_keys[i]]['NetworkWasCaptive'];
		let captiveBypass = contents['KnownNetworks'][wifi_keys[i]]['CaptiveBypass'];
		let collocatedGroup = [];
		for(let j = 0; j < contents['KnownNetworks'][wifi_keys[i]]['CollocatedGroup'].length; j++){
			collocatedGroup.push(hex_to_ssid[contents['KnownNetworks'][wifi_keys[i]]['CollocatedGroup'][j]]);
		}
		output['Known Networks'].push({"SSID": SSID, "Security": SecurityType, "Last Connection": lastConnected,
									   "Was Captive": wasCaptive, "Captive Bypass": captiveBypass,
									   "Nearby Networks": collocatedGroup})
	}
	if(json==false){
		output = "**************************************\n" + "******** Airport Preferences ********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Airport_Preferences";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function SMB_Server({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/Library/Preferences/SystemConfiguration/com.apple.smb.server.plist")){
		if(json==false){
			return "**************************************\n" + "******* SMB Server Preferences *******\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "SMB_Server"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/SystemConfiguration/com.apple.smb.server.plist");
	let contents = ObjC.deepUnwrap(dict);
	output['Local Kerberos Realm'] = contents['LocalKerberosRealm'];
	output['NETBIOS Name'] = contents['NetBIOSName'];
	output['Server Description'] = contents['ServerDescription'];
	if(json==false){
		output = "**************************************\n" + "******* SMB Server Preferences *******\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "SMB_Server";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function WiFi_Messages({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/Library/Preferences/SystemConfiguration/com.apple.wifi.message-tracer.plist")){
		if(json==false){
			return "**************************************\n" + "********* WiFi Associations *********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "WiFi_Messages"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/SystemConfiguration/com.apple.wifi.message-tracer.plist");
	let contents = ObjC.deepUnwrap(dict);
	if(contents != undefined){
		let associationKeys = Object.keys(contents['AssociationSSIDMap']);
		output['Association SSIDs'] = [];
		for(let i in associationKeys){
			let condensed = associationKeys[i].replace(/ /g, '');
			condensed = condensed.substring(1, condensed.length-1)
			output['Association SSIDs'].push(hex2a(condensed));
		}
		associationKeys = Object.keys(contents['InternalAssociationSSIDMap']);
		output['InternalAssociation SSIDs'] = [];
		for(let i in associationKeys){
			let condensed = associationKeys[i].replace(/ /g, '');
			condensed = condensed.substring(1, condensed.length-1)
			output['InternalAssociation SSIDs'].push(hex2a(condensed));
		}
		if(json==false){
			output = "**************************************\n" + "********* WiFi Associations *********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
		}else{
			output['HealthInspectorCommand'] = "WiFi_Messages";
			output = JSON.stringify(output, null, 1);
		}
		
	}
	return output;}
function Network_Interfaces({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist")){
		if(json==false){
			return "**************************************\n" + "********* Network Interfaces *********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Network_Interfaces"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist");
	let contents = ObjC.deepUnwrap(dict);
	output['Network Interfaces'] = {};
	for(let i = 0; i < contents['Interfaces'].length; i++){
		output['Network Interfaces'][contents['Interfaces'][i]['BSD Name']] = {};
		output['Network Interfaces'][contents['Interfaces'][i]['BSD Name']]['Active'] = contents['Interfaces'][i]['Active'];
		output['Network Interfaces'][contents['Interfaces'][i]['BSD Name']]['Built In'] = contents['Interfaces'][i]['IOBuiltin'];
		output['Network Interfaces'][contents['Interfaces'][i]['BSD Name']]['Network Type'] = contents['Interfaces'][i]['SCNetworkInterfaceType'];
		output['Network Interfaces'][contents['Interfaces'][i]['BSD Name']]['Info'] = contents['Interfaces'][i]['SCNetworkInterfaceInfo'];
	}
	if(json==false){
		output = "**************************************\n" + "********* Network Interfaces *********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Network_Interfaces";
		output = JSON.stringify(output, null, 1);
	}
	return output;}
function Bluetooth_Connections({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/Library/Preferences/com.apple.Bluetooth.plist")){
		if(json==false){
			return "**************************************\n" + "******* Bluetooth Connections *******\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Bluetooth_Connections"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/com.apple.Bluetooth.plist");
	let contents = ObjC.deepUnwrap(dict);
	if(contents != undefined && contents.hasOwnProperty('DeviceCache')){
		let Bluetooth_Keys = Object.keys(contents['DeviceCache']);
		let string_to_name = {};
		for(let i in Bluetooth_Keys){
			string_to_name[Bluetooth_Keys[i]] = contents['DeviceCache'][Bluetooth_Keys[i]]['Name'];
		}
		output['Device Cache'] = [];
		for(let i in Bluetooth_Keys){
			let  ClassOfDevice = undefined;
			if(contents['DeviceCache'][Bluetooth_Keys[i]].hasOwnProperty('ClassOfDevice')){
				ClassOfDevice = contents['DeviceCache'][Bluetooth_Keys[i]]['ClassOfDevice'].toString(16);
			}
			let displayName = contents['DeviceCache'][Bluetooth_Keys[i]]['displayName'];
			let name = contents['DeviceCache'][Bluetooth_Keys[i]]['Name'];
			let lastConnected = contents['DeviceCache'][Bluetooth_Keys[i]]['LastInquiryUpdate'];
			let lastNameUpdate = contents['DeviceCache'][Bluetooth_Keys[i]]['LastNameUpdate'];
			output['Device Cache'].push({"Name": name, "Class of Device": ClassOfDevice, "Last Connected": lastConnected, "Last Updated": lastNameUpdate, "Display Name": displayName})
		}
		output['Currently Paired Devices'] = [];
		if(contents.hasOwnProperty('PairedDevices')){
			for(let i = 0; i < contents['PairedDevices'].length; i++){
				output['Currently Paired Devices'].push(string_to_name[contents['PairedDevices'][i]]);
			}
		}
	}
	if(json==false){
		output = "**************************************\n" + "******* Bluetooth Connections *******\n" + "**************************************\n" + "Convert Class of Device with: http://domoticx.com/bluetooth-class-of-device-list-cod/\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Bluetooth_Connections";
		output = JSON.stringify(output, null, 1);
	}	
	return output;}
function OS_Version({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/System/Library/CoreServices/SystemVersion.plist")){
		if(json==false){
			return "**************************************\n" + "********** OS Version Info  **********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "OS_Version"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/System/Library/CoreServices/SystemVersion.plist");
	output = ObjC.deepUnwrap(dict);
	dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/com.apple.SoftwareUpdate.plist");
	output['SoftwareUpdate'] = ObjC.deepUnwrap(dict);
	if(json==false){
		output = "**************************************\n" + "********** OS Version Info  **********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "OS_Version";
		output = JSON.stringify(output, null, 1);
	}
	
	return output;}
function Krb5_AD_Config({help=false, json=false, user=""}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/etc/krb5.conf")){
		if(json==false){
			return "**************************************\n" + "********** AD Config  **********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Krb5_AD_Config"});
		}
	}
	let dict = $.NSString.alloc.initWithContentsOfFileEncodingError("/etc/krb5.conf", $.NSUTF8StringEncoding, $());
	output = {"config": dict};
	if(json==false){
		output = "**************************************\n" + "********** AD Config  **********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Krb5_AD_Config";
		output = JSON.stringify(output, null, 1);
	}
	
	return output;}
function Krb5_AD_Logging({help=false, json=false, user=""} = {}){
	if(help){
	    let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/Library/Preferences/com.apple.Kerberos.plist")){
		if(json==false){
			return "**************************************\n" + "********** Krb5 Logging  **********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Krb5_AD_Logging"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/com.apple.Kerberos.plist");
	output = ObjC.deepUnwrap(dict);
	if(json==false){
		output = "**************************************\n" + "********** Krb5 Logging  **********\n" + "**************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Krb5_AD_Logging";
		output = JSON.stringify(output, null, 1);
	}
	
	return output;}

function PaloaltoGlobalProtect({help=false, json=false, user=""} = {}){
	if(help){
		let output = "";
		return output;
    }
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/Library/Preferences/com.paloaltonetworks.GlobalProtect.settings.plist")){
		if(json==false){
			return "**************************************\n" + "********** PaloaltoGlobalProtect portal  **********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "PaloaltoGlobalProtect"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Preferences/com.paloaltonetworks.GlobalProtect.settings.plist");
	let contents = ObjC.deepUnwrap(dict);
	output['Global Protect Portal'] = contents['Palo Alto Networks']['GlobalProtect']['PanSetup']['Portal'];
	output['Prelogon'] = contents['Palo Alto Networks']['GlobalProtect']['PanSetup']['Prelogon'];
	if(json==false){
		output = "****************************************************\n" + "***** Paloalto Networks Global Protect Portal *****\n" + "****************************************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Check_PaloaltoGlobalProtect";
		output = JSON.stringify(output, null, 1);
	}

	return output;}

function Forcepoint_DLP_Information({help=false, json=false, user=""} = {}){
	if(help){
		let output = "";
		return output;
	}
	let output = {};
	let fileManager = $.NSFileManager.defaultManager;
	if(!file_exists("/Library/Application Support/Websense Endpoint/DLP/DLPClient.plist")){
		if(json==false){
			return "**************************************\n" + "********** Forcepoint DLP Information  **********\n" + "**************************************\n" + "Required file not found";
		}else{
			return JSON.stringify({"HealthInspectorCommand": "Forcepoint_DLP_Information"});
		}
	}
	let dict = $.NSMutableDictionary.alloc.initWithContentsOfFile("/Library/Application Support/Websense Endpoint/DLP/DLPClient.plist");
	let contents = ObjC.deepUnwrap(dict);
	output['Connection domain name'] = contents['Connection domain name'];
	output['Connection status'] = contents['Connection status'];
	output['Connection user name'] = contents['Connection user name'];
	output['Discovery status'] = contents['Discovery status'];
	output['Endpoint profile name'] = contents['Endpoint profile name'];
	output['Endpoint silent mode'] = contents['Endpoint silent mode'];
	output['Endpoint status'] = contents['Endpoint status'];
	output['Fingerprint version'] = contents['Fingerprint version'];
	output['Policy version'] = contents['Policy version'];
	output['Profile version'] = contents['Profile version'];
	output['Remote bypass'] = contents['Remote bypass'];
	if(json==false){
		output = "********************************\n" + "***** Forcepoint DLP Info *****\n" + "********************************\n" + JSON.stringify(output, null , 1);
	}else{
		output['HealthInspectorCommand'] = "Forcepoint_DLP_Information";
		output = JSON.stringify(output, null, 1);
	}

	return output;}

function AVEnum() {
var fileMan = $.NSFileManager.defaultManager;
var runapps = $.NSWorkspace.sharedWorkspace.runningApplications.js;
var applist = [];
for(let i = 0; i < runapps.length; i++){
        let info = {};
        info['name'] = runapps[i].localizedName.js;
        applist.push(info['name']);

}

var output = "";

var allapps = applist.toString();
var b = 0;
output += "**************************************\n";
output += "*********Security Tools Check*********\n";
output += "**************************************\n";
if ((allapps.includes("CbOsxSensorService")) || (fileMan.fileExistsAtPath("/Applications/CarbonBlack/CbOsxSensorService"))){
        output += "[+] Carbon Black Sensor installed.\n";
        b = 1;
}

if ((allapps.includes("CbDefense")) || (fileMan.fileExistsAtPath("/Applications/Confer.app"))){
        output += "[+] CB Defense A/V installed.\n";
        b = 1;
}

if ((allapps.includes("ESET")) || (allapps.includes("eset")) || (fileMan.fileExistsAtPath("Library/Application Support/com.eset.remoteadministrator.agent"))){
        output += "[+] ESET A/V installed.\n";
        b = 1;
}

if ((allapps.includes("Littlesnitch")) || (allapps.includes("Snitch")) || (fileMan.fileExistsAtPath("/Library/Little Snitch/"))){
        output += "[+] Littlesnitch firewall found.\n";
        b = 1;
}

if ((allapps.includes("xagt")) || (fileMan.fileExistsAtPath("/Library/FireEye/xagt"))){
        output += "[+] FireEye HX agent found.\n";
        b = 1;
}

if ((allapps.includes("falconctl")) || (fileMan.fileExistsAtPath("/Library/CS/falcond"))){
        output += "[+] Crowdstrike Falcon agent found.\n";
        b = 1;
}

if ((allapps.includes("OpenDNS")) || (allapps.includes("opendns")) || (fileMan.fileExistsAtPath("/Library/Application Support/OpenDNS Roaming Client/dns-updater"))){
        output += "[+] OpenDNS client found.\n";
        b = 1;
}

if ((allapps.includes("SentinelOne")) || (allapps.includes("sentinelone"))){
        output += "[+] Sentinel One agent found.\n";
        b = 1;
}

if ((allapps.includes("GlobalProtect")) || (allapps.includes("PanGPS")) || (fileMan.fileExistsAtPath("/Library/Logs/PaloAltoNetworks/GlobalProtect")) || (fileMan.fileExistsAtPath("/Library/PaloAltoNetworks"))){
        output += "[+] Global Protect PAN VPN client found.\n";
        b = 1;
}

if ((allapps.includes("HostChecker")) || (allapps.includes("pulsesecure")) || (fileMan.fileExistsAtPath("/Applications/Pulse Secure.app")) || (allapps.includes("Pulse-Secure"))){
        output += "[+] Pulse VPN client found.\n";
        b = 1;
}

if ((allapps.includes("AMP-for-Endpoints")) || (fileMan.fileExistsAtPath("/opt/cisco/amp"))){
        output += "[+] Cisco AMP for endpoints found.\n";
        b = 1;
}

if ((fileMan.fileExistsAtPath("/usr/local/bin/jamf")) || (fileMan.fileExistsAtPath("/usr/local/jamf"))){
        output += "[+] JAMF found on this host.\n";
        b = 1;
}

if (fileMan.fileExistsAtPath("/Library/Application Support/Malwarebytes")){
        output += "[+] Malwarebytes A/V found.\n";
        b = 1;
}

if (fileMan.fileExistsAtPath("/usr/local/bin/osqueryi")){
        output += "[+] osquery found.\n";
        b = 1;
}

if (fileMan.fileExistsAtPath("/Library/Sophos Anti-Virus/")){
        output += "[+] Sophos A/V found.\n";
        b = 1;
}

if ((allapps.includes("lulu")) || (fileMan.fileExistsAtPath("/Library/Objective-See/Lulu")) || (fileMan.fileExistsAtPath("/Applications/LuLu.app"))){
        output += "[+] LuLu firewall found.\n";
        b = 1;
}

if ((allapps.includes("dnd")) || (fileMan.fileExistsAtPath("/Library/Objective-See/DND")) || (fileMan.fileExistsAtPath("/Applications/Do Not Disturb.app/"))){
        output += "[+] LuLu firewall found.\n";
        b = 1;
}

if ((allapps.includes("WhatsYourSign")) || (fileMan.fileExistsAtPath("/Applications/WhatsYourSign.app"))){
        output += "[+] Whats Your Sign code signature info tool found.\n";
        b = 1;
}

if ((allapps.includes("KnockKnock")) || (fileMan.fileExistsAtPath("/Applications/KnockKnock.app"))){
        output += "[+] Knock Knock persistence detection tool found.\n";
        b = 1;
}

if ((allapps.includes("reikey")) || (fileMan.fileExistsAtPath("/Applications/ReiKey.app"))){
        output += "[+] ReiKey keyboard event taps detection tool found.\n";
        b = 1;
}

if ((allapps.includes("OverSight")) || (fileMan.fileExistsAtPath("/Applications/OverSight.app"))){
        output += "[+] OverSight microphone and camera monitoring tool found.\n";
        b = 1;
}

if ((allapps.includes("KextViewr")) || (fileMan.fileExistsAtPath("/Applications/KextViewr.app"))){
        output += "[+] KextViewr kernel module detection tool found.\n";
        b = 1;
}

if ((allapps.includes("blockblock")) || (fileMan.fileExistsAtPath("/Applications/BlockBlock Helper.app"))){
        output += "[+] Block Block persistence location monitoring tool found.\n";
        b = 1;
}

if ((allapps.includes("Netiquette")) || (fileMan.fileExistsAtPath("/Applications/Netiquette.app"))){
        output += "[+] Netiquette network monitoring tool found.\n";
        b = 1;
}

if ((allapps.includes("processmonitor")) || (fileMan.fileExistsAtPath("/Applications/ProcessMonitor.app"))){
        output += "[+] Objective See Process Monitor tool found.\n";
        b = 1;
}

if ((allapps.includes("filemonitor")) || (fileMan.fileExistsAtPath("/Applications/FileMonitor.app"))){
        output += "[+] Objective See File Monitor tool found.\n";
        b = 1;
}

if (b == 0){
        output += "[-] No security products found.";
}

output += "**************************************\n";
return output;}


//---------------------------------------------------------
function All_Checks({help=false, json=false, user=""} = {}){
	let output = "";
	let input_parameter = {"help":help, "json":json, "user": user};
	output += "\n" + Persistent_Dock_Apps(input_parameter);
	output += "\n" + Spaces_Check(input_parameter);
	output += "\n" + Get_Office_Email(input_parameter);
	output += "\n" + Saved_Printers(input_parameter);
	output += "\n" + Finder_Preferences(input_parameter);
	output += "\n" + Launch_Services(input_parameter);
	output += "\n" + Universal_Access_Auth_Warning(input_parameter);
	output += "\n" + Relaunch_At_Login(input_parameter);
	output += "\n" + Login_Items(input_parameter);
	output += "\n" + User_Dir_Hidden_Files_Folders(input_parameter);
	output += "\n" + User_Global_Preferences(input_parameter);
	output += "\n" + User_Launchagents(input_parameter);
	output += "\n" + User_Launchdaemons(input_parameter);
	output += "\n" + System_Launchdaemons(input_parameter);
	output += "\n" + Installed_Software_Versions(input_parameter);
	output += "\n" + Unique_Bash_History_Sessions(input_parameter);
	output += "\n" + SSH_Keys(input_parameter);
	output += "\n" + Slack_Download_Cache_History(input_parameter);
	output += "\n" + Slack_Team_Information(input_parameter);
	output += "\n" + Recent_Files(input_parameter);
	output += "\n" + Firewall(input_parameter);
	output += "\n" + Airport_Preferences(input_parameter);
	output += "\n" + SMB_Server(input_parameter);
	output += "\n" + WiFi_Messages(input_parameter);
	output += "\n" + Network_Interfaces(input_parameter);
	output += "\n" + Bluetooth_Connections(input_parameter);
	output += "\n" + OS_Version(input_parameter);
	output += "\n" + Krb5_AD_Config(input_parameter);
	output += "\n" + Krb5_AD_Logging(input_parameter);
	output += "\n" + PaloaltoGlobalProtect(input_parameter);
	output += "\n" + Forcepoint_DLP_Information(input_parameter);
	output += "\n" + AVEnum();
	return output;
}
function User_Preferences({help=false, json=false, user=""} = {}){
	let output = "";
	let input_parameters = {"help":help, "json":json, "user": user};
	output += "\n" + Persistent_Dock_Apps(input_parameters);
	output += "\n" + Spaces_Check(input_parameters);
	output += "\n" + Get_Office_Email(input_parameters);
	output += "\n" + Saved_Printers(input_parameters);
	output += "\n" + Finder_Preferences(input_parameters);
	output += "\n" + Launch_Services(input_parameters);
	output += "\n" + Universal_Access_Auth_Warning(input_parameters);
	output += "\n" + Relaunch_At_Login(input_parameters);
	output += "\n" + Global_Preferences(input_parameters);
	output += "\n" + OS_Version(input_parameters);
	output += "\n" + Installed_Software_Versions(input_parameters);
	output += "\n" + User_Launchagents(input_parameters);
	output += "\n" + User_Launchdaemons(input_parameters);
	output += "\n" + Slack_Download_Cache_History(input_parameters);
	output += "\n" + Slack_Team_Information(input_parameters);
	return output;
}
function Global_Preferences({help=false, json=false, user=""} = {}){
	let output = "";
	let input_parameters = {"help":help, "json":json, "user": user};
	output += "\n" + Firewall(input_parameters);
	output += "\n" + Airport_Preferences(input_parameters);
	output += "\n" + SMB_Server(input_parameters);
	output += "\n" + WiFi_Messages(input_parameters);
	output += "\n" + Network_Interfaces(input_parameters);
	output += "\n" + Bluetooth_Connections(input_parameters);
	output += "\n" + Krb5_AD_Config(input_parameters);
	output += "\n" + Krb5_AD_Logging(input_parameters);
	output += "\n" + PaloaltoGlobalProtect(input_parameters);
	output += "\n" + Forcepoint_DLP_Information(input_parameters);
	return output;
}