-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjacops.py
More file actions
executable file
·2122 lines (1817 loc) · 102 KB
/
jacops.py
File metadata and controls
executable file
·2122 lines (1817 loc) · 102 KB
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
#!/usr/bin/env python3
"""
JacOps Security Suite v.1.0
Een uitgebreide cybersecurity multitool suite met verschillende professionele security tools.
"""
import os
import sys
import subprocess
import shutil
import re
from pathlib import Path
from typing import Optional
class ReturnToMenuException(Exception):
"""Custom exception to signal return to main menu"""
pass
# Try to import readline for tab completion
try:
import readline
READLINE_AVAILABLE = True
except ImportError:
READLINE_AVAILABLE = False
# ANSI color codes voor terminal output
class Colors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
DIM = '\033[2m'
BRIGHT_CYAN = '\033[1;96m'
BRIGHT_GREEN = '\033[1;92m'
BRIGHT_RED = '\033[1;91m'
def clear_screen():
"""Clear the terminal screen"""
os.system('clear' if os.name != 'nt' else 'cls')
def center_text(text, width=None):
"""Center text in terminal, ignoring ANSI color codes"""
if width is None:
try:
width = shutil.get_terminal_size().columns
except:
width = 80
# Remove ANSI codes to get actual text length
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
text_without_codes = ansi_escape.sub('', text)
text_length = len(text_without_codes)
# Calculate padding
padding = (width - text_length) // 2
return ' ' * padding + text
def print_banner():
"""Print the JacOps Security Suite banner"""
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
# ASCII art lines for JacOps - original format
ascii_lines = [
" _ ___ ",
" | | __ _ ___ / _ \\ _ __ ___ ",
" _ | |/ _` |/ __| | | | '_ \\/ __|",
"| |_| | (_| | (__| |_| | |_) \\__ \\",
" \\___/ \\__,_|\\___|\\___/| .__/|___/",
" |_| "
]
# Center each ASCII art line
centered_ascii = []
for line in ascii_lines:
centered_ascii.append(center_text(line, term_width))
# Create banner - all elements centered
banner = f"""
{Colors.BRIGHT_CYAN}{Colors.BOLD}{chr(10).join(centered_ascii)}{Colors.ENDC}
{center_text(Colors.OKCYAN + Colors.BOLD + "════════════════════════════════════════" + Colors.ENDC, term_width)}
{center_text(Colors.BRIGHT_CYAN + Colors.BOLD + "Security Suite v.1.0" + Colors.ENDC, term_width)}
{center_text(Colors.OKCYAN + Colors.BOLD + "════════════════════════════════════════" + Colors.ENDC, term_width)}
{center_text(Colors.DIM + "10 Professional Security Tools" + Colors.ENDC, term_width)}
"""
print(banner)
def print_menu():
"""Print the main menu"""
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
menu_items = [
("[1]", "", "File Type Identifier (Magic Numbers)"),
("[2]", "", "Phishing Email Simulator"),
("[3]", "", "Network Device Scanner"),
("[4]", "", "Live Threat Intelligence Dashboard"),
("[5]", "", "Password Policy Analyzer"),
("[6]", "", "Caesar Cipher Frequency Analyzer"),
("[7]", "", "DoS Attack Detector"),
("[8]", "", "Secure File Sharing System"),
("[9]", "", "Intrusion Detection Monitor"),
("[10]", "", "Web Vulnerability Scanner"),
]
# Menu box width - make it wider for better alignment
box_width = 75 # Increased from 61 to 75
box_padding = (term_width - box_width) // 2
border_line = "═" * 73 # 75 - 2 border chars
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
content_width = 73 # Fixed content width inside box (box_width - 2 border chars)
# Top border - ensure perfect alignment
print(f"\n{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
# Header line - fixed width formatting
header_text = "Selecteer een tool:"
header_with_colors = f" {Colors.BOLD}{header_text}{Colors.ENDC}"
header_clean = ansi_escape.sub('', header_with_colors)
header_padding = max(0, content_width - len(header_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{header_with_colors}{' ' * header_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╠{border_line}╣{Colors.ENDC}")
for number, icon, description in menu_items:
# Normalize number formatting: [1]-[9] get extra space to match [10]
if len(number) == 3: # [1] through [9]
formatted_number = f"{Colors.OKCYAN}{Colors.BOLD}{number}{Colors.ENDC} "
else: # [10]
formatted_number = f"{Colors.OKCYAN}{Colors.BOLD}{number}{Colors.ENDC} "
# Build content string - no emojis, simpler formatting
# Format: " [number] description"
content = f" {formatted_number}{description}"
# Remove ANSI codes to get actual display width
content_clean = ansi_escape.sub('', content)
# Calculate exact padding to fill content_width exactly
padding_needed = content_width - len(content_clean)
# Ensure padding is non-negative and correct
if padding_needed < 0:
padding_needed = 0
# Print with exact padding - right border will always align perfectly
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{content}{' ' * padding_needed}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╠{border_line}╣{Colors.ENDC}")
# Exit option - fixed width formatting
exit_content = f" {Colors.OKCYAN}{Colors.BOLD}[0]{Colors.ENDC} {Colors.BRIGHT_RED}{Colors.BOLD}Exit{Colors.ENDC}"
exit_clean = ansi_escape.sub('', exit_content)
exit_padding = max(0, content_width - len(exit_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{exit_content}{' ' * exit_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}")
def get_user_choice() -> str:
"""Get user's menu choice"""
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
# Center the prompt - align with menu box
box_width = 75 # Increased from 61 to 75
box_padding = (term_width - box_width) // 2
# Prompt starts at same position as menu box content
print()
choice = input(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}➜{Colors.ENDC} {Colors.BOLD}Select a tool:{Colors.ENDC} ").strip()
return choice
def ask_cli_or_gui(tool_name: str) -> str:
"""Ask user if they want CLI or GUI version"""
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
# Use same box dimensions as main menu
box_width = 75
box_padding = (term_width - box_width) // 2
border_line = "═" * 73 # 75 - 2 border chars
content_width = 73 # Fixed content width inside box
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
# Title line
title_with_colors = f" {Colors.BOLD}{tool_name}{Colors.ENDC}"
title_clean = ansi_escape.sub('', title_with_colors)
title_padding = max(0, content_width - len(title_clean))
# Option 1: CLI versie
option1 = f" {Colors.OKCYAN}{Colors.BOLD}[1]{Colors.ENDC} CLI versie"
option1_clean = ansi_escape.sub('', option1)
option1_padding = max(0, content_width - len(option1_clean))
# Option 2: GUI versie
option2 = f" {Colors.OKCYAN}{Colors.BOLD}[2]{Colors.ENDC} GUI versie"
option2_clean = ansi_escape.sub('', option2)
option2_padding = max(0, content_width - len(option2_clean))
# Print centered box
print(f"\n{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{title_with_colors}{' ' * title_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╠{border_line}╣{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{option1}{' ' * option1_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{option2}{' ' * option2_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}")
# Prompt aligned with box
print()
choice = input(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}➜{Colors.ENDC} {Colors.BOLD}Keuze (1-2):{Colors.ENDC} ").strip()
return choice
def print_fti_result(result_data):
"""Print File Type Identifier result in a nice formatted box"""
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
box_width = 75
box_padding = (term_width - box_width) // 2
border_line = "═" * 73
content_width = 73
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
if "error" in result_data:
error_msg = f"Error: {result_data['error']} — {result_data.get('filepath', '')}"
error_clean = ansi_escape.sub('', error_msg)
error_padding = max(0, content_width - len(error_clean))
print(f"\n{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC} {Colors.BRIGHT_RED}{Colors.BOLD}{error_msg}{Colors.ENDC}{' ' * error_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}\n")
return
# Title
title = "File Type Identifier - Resultaten"
title_with_colors = f" {Colors.BOLD}{title}{Colors.ENDC}"
title_clean = ansi_escape.sub('', title_with_colors)
title_padding = max(0, content_width - len(title_clean))
print(f"\n{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{title_with_colors}{' ' * title_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╠{border_line}╣{Colors.ENDC}")
# File path
filepath_line = f" {Colors.OKCYAN}File:{Colors.ENDC} {result_data.get('filepath', '—')}"
filepath_clean = ansi_escape.sub('', filepath_line)
filepath_padding = max(0, content_width - len(filepath_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{filepath_line}{' ' * filepath_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
# Size
size_line = f" {Colors.OKCYAN}Size:{Colors.ENDC} {result_data.get('file_size_formatted', '—')}"
size_clean = ansi_escape.sub('', size_line)
size_padding = max(0, content_width - len(size_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{size_line}{' ' * size_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
# Raw hex
hex_line = f" {Colors.OKCYAN}Raw hex:{Colors.ENDC} {result_data.get('raw_hex', '—')}"
hex_clean = ansi_escape.sub('', hex_line)
hex_padding = max(0, content_width - len(hex_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{hex_line}{' ' * hex_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
# Detected type
detected_line = f" {Colors.OKCYAN}Detected:{Colors.ENDC} {Colors.BRIGHT_GREEN}{result_data.get('detected_type', '—')}{Colors.ENDC}"
detected_clean = ansi_escape.sub('', detected_line)
detected_padding = max(0, content_width - len(detected_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{detected_line}{' ' * detected_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
# File extension
ext_line = f" {Colors.OKCYAN}File extension:{Colors.ENDC} {result_data.get('file_extension', '—')}"
ext_clean = ansi_escape.sub('', ext_line)
ext_padding = max(0, content_width - len(ext_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{ext_line}{' ' * ext_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
# Mismatch warning
if result_data.get('mismatch'):
mismatch_line = f" {Colors.BRIGHT_RED}{Colors.BOLD}⚠ Warning:{Colors.ENDC} {Colors.WARNING}Extension mismatch detected!{Colors.ENDC}"
mismatch_clean = ansi_escape.sub('', mismatch_line)
mismatch_padding = max(0, content_width - len(mismatch_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╠{border_line}╣{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{mismatch_line}{' ' * mismatch_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
# Additional info if available
if result_data.get('md5'):
md5_line = f" {Colors.OKCYAN}MD5:{Colors.ENDC} {result_data['md5']}"
md5_clean = ansi_escape.sub('', md5_line)
md5_padding = max(0, content_width - len(md5_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{md5_line}{' ' * md5_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
if result_data.get('sha256'):
sha_line = f" {Colors.OKCYAN}SHA256:{Colors.ENDC} {result_data['sha256']}"
sha_clean = ansi_escape.sub('', sha_line)
sha_padding = max(0, content_width - len(sha_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{sha_line}{' ' * sha_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
if result_data.get('entropy') is not None:
entropy_val = result_data['entropy']
entropy_note = " (high — possibly encrypted/obfuscated)" if entropy_val > 7.5 else ""
entropy_line = f" {Colors.OKCYAN}Entropy:{Colors.ENDC} {entropy_val:.2f}{entropy_note}"
entropy_clean = ansi_escape.sub('', entropy_line)
entropy_padding = max(0, content_width - len(entropy_clean))
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{entropy_line}{' ' * entropy_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}\n")
def path_completer(text, state):
"""Tab completer for file paths"""
# Expand ~ to home directory
if text.startswith('~'):
text = os.path.expanduser(text)
# Determine separator (Unix uses /, Windows can use both)
sep = '/' if '/' in text else os.sep
# Get directory and base name
if sep in text:
# Path with directory
parts = text.rsplit(sep, 1)
if len(parts) == 2:
directory = parts[0] if parts[0] else '.'
base = parts[1]
else:
directory = '.'
base = text
else:
directory = '.'
base = text
# Handle absolute paths
if directory.startswith('/') or (len(directory) > 1 and directory[1] == ':'):
# Absolute path
abs_dir = directory
else:
# Relative path - resolve from current directory
abs_dir = os.path.abspath(directory)
try:
if not os.path.exists(abs_dir) or not os.path.isdir(abs_dir):
return None
# List files in directory
files = os.listdir(abs_dir)
matches = [f for f in files if f.startswith(base)]
# Sort: directories first, then files
matches.sort(key=lambda x: (not os.path.isdir(os.path.join(abs_dir, x)), x.lower()))
if state < len(matches):
match = matches[state]
match_path = os.path.join(abs_dir, match)
# Build return path maintaining original format
if directory == '.':
result = match
else:
# Preserve original directory format
result = directory + sep + match
# Add separator if it's a directory
if os.path.isdir(match_path):
result += sep
return result
except (OSError, PermissionError):
pass
return None
def setup_tab_completion():
"""Setup tab completion for file paths"""
if READLINE_AVAILABLE:
readline.set_completer(path_completer)
readline.parse_and_bind("tab: complete")
# Set delimiters to allow path completion
readline.set_completer_delims(readline.get_completer_delims().replace('/', '').replace('\\', ''))
def print_tool_header(tool_name, mode):
"""Print a nice header for a tool in CLI or GUI mode"""
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
box_width = 75
box_padding = (term_width - box_width) // 2
border_line = "═" * 73
content_width = 73
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
title = f"{tool_name} - {mode}"
title_with_colors = f" {Colors.BRIGHT_CYAN}{Colors.BOLD}{title}{Colors.ENDC}"
title_clean = ansi_escape.sub('', title_with_colors)
title_padding = max(0, content_width - len(title_clean))
print(f"\n{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}{title_with_colors}{' ' * title_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}\n")
def run_file_type_identifier():
"""Run File Type Identifier tool"""
choice = ask_cli_or_gui("File Type Identifier")
fti_dir = Path(__file__).parent / "FTI"
if choice == "1":
# CLI versie
print_tool_header("File Type Identifier", "CLI")
# Setup tab completion for file paths
setup_tab_completion()
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
box_width = 75
box_padding = (term_width - box_width) // 2
file_path = input(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}➜{Colors.ENDC} {Colors.BOLD}Voer bestandspad in ('q' om terug te gaan):{Colors.ENDC} ").strip()
# Check if user wants to go back to main menu - only 'q' works
if file_path.lower() == 'q':
return True # Return True to skip "press Enter" prompt in main()
# Require a file path - empty input shows warning and returns
if not file_path:
print(f"{Colors.WARNING}{Colors.BOLD}⚠{Colors.ENDC} {Colors.WARNING}Geen bestandspad opgegeven. Gebruik 'q' om terug te gaan.{Colors.ENDC}")
return True # Return True to skip "press Enter" prompt in main()
if file_path:
fti_src_path = fti_dir / "src"
if fti_src_path.exists():
# Import and use the identify function directly
sys.path.insert(0, str(fti_src_path))
try:
from identifier import identify
result = identify(Path(file_path))
print_fti_result(result)
except Exception as e:
print(f"\n{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}Fout bij analyseren: {str(e)}{Colors.ENDC}\n")
else:
print(f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}FTI tool niet gevonden!{Colors.ENDC}")
# If we get here and file_path is empty, user already returned (handled above)
elif choice == "2":
# GUI versie
print_tool_header("File Type Identifier", "GUI")
# Get terminal width for centering
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
box_width = 75
box_padding = (term_width - box_width) // 2
fti_gui_path = fti_dir / "src" / "gui_web.py"
if fti_gui_path.exists():
# Create a nice box for the server info
border_line = "═" * 73
content_width = 73
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
# Print nice box with server info
print(f"\n{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
# "Starten van web interface..." line
start_msg = f"{Colors.BRIGHT_GREEN}{Colors.BOLD}→{Colors.ENDC} {Colors.OKGREEN}Starten van web interface...{Colors.ENDC}"
start_clean = ansi_escape.sub('', start_msg)
# Account for the space after ║
start_padding = max(0, content_width - len(start_clean) - 1)
# Ensure total length matches exactly
total_length = 1 + len(start_clean) + start_padding
if total_length != content_width:
start_padding = max(0, content_width - len(start_clean) - 1)
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC} {start_msg}{' ' * start_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}\n")
os.chdir(fti_gui_path.parent)
try:
# Import and run the GUI main function directly to catch KeyboardInterrupt
sys.path.insert(0, str(fti_gui_path.parent))
from gui_web import main as gui_main
gui_main()
except KeyboardInterrupt:
# User pressed Ctrl+C in GUI, return to main menu
raise ReturnToMenuException()
else:
# Center the error message
error_msg = f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}FTI GUI tool niet gevonden!{Colors.ENDC}"
error_clean = ansi_escape.sub('', error_msg)
error_padding = (box_width - len(error_clean)) // 2
print(f"{' ' * (box_padding + error_padding)}{error_msg}")
else:
error_msg = f"{Colors.WARNING}{Colors.BOLD}⚠{Colors.ENDC} {Colors.WARNING}Ongeldige keuze.{Colors.ENDC}"
print(center_text(error_msg))
def run_phishing_email_simulator():
"""Run Phishing Email Simulator tool"""
print(f"\n{Colors.BRIGHT_CYAN}{Colors.BOLD}╔═══════════════════════════════════════════════════════════════╗{Colors.ENDC}")
print(f"{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC} {Colors.BOLD}Phishing Email Simulator{' ' * 42}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{Colors.BRIGHT_CYAN}{Colors.BOLD}╚═══════════════════════════════════════════════════════════════╝{Colors.ENDC}")
print(f"{Colors.BRIGHT_GREEN}{Colors.BOLD}→{Colors.ENDC} {Colors.OKGREEN}Starten van web interface...{Colors.ENDC}\n")
pes_path = Path(__file__).parent / "PES" / "app.py"
if pes_path.exists():
os.chdir(pes_path.parent)
subprocess.run([sys.executable, "app.py"])
else:
print(f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}PES tool niet gevonden!{Colors.ENDC}")
def run_network_device_scanner():
"""Run Network Device Scanner tool"""
choice = ask_cli_or_gui("Network Device Scanner")
ndt_dir = Path(__file__).parent / "NDT"
if choice == "1":
# CLI versie
print_tool_header("Network Device Scanner", "CLI")
ndt_cli_path = ndt_dir / "cli.py"
if ndt_cli_path.exists():
original_dir = os.getcwd()
try:
# Change to NDT directory and run CLI
os.chdir(ndt_cli_path.parent)
sys.path.insert(0, str(ndt_cli_path.parent))
from cli import main as cli_main
cli_main()
except KeyboardInterrupt:
# User pressed Ctrl+C, return to main menu
raise ReturnToMenuException()
except Exception as e:
print(f"\n{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}Fout bij uitvoeren: {str(e)}{Colors.ENDC}\n")
finally:
try:
os.chdir(original_dir)
except:
pass
else:
print(f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}NDT CLI tool niet gevonden!{Colors.ENDC}")
elif choice == "2":
# GUI versie
print_tool_header("Network Device Scanner", "GUI")
# Get terminal width for centering
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
box_width = 75
box_padding = (term_width - box_width) // 2
ndt_path = ndt_dir / "app.py"
if ndt_path.exists():
# Create a nice box for the server info
border_line = "═" * 73
content_width = 73
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
# Print nice box with server info
print(f"\n{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
# "Starten van web interface..." line
start_msg = f"{Colors.BRIGHT_GREEN}{Colors.BOLD}→{Colors.ENDC} {Colors.OKGREEN}Starten van web interface...{Colors.ENDC}"
start_clean = ansi_escape.sub('', start_msg)
# Calculate padding: content_width includes the space after ║, so subtract 1 for that space
# Total width should be: space(1) + message + padding = content_width
start_padding = max(0, content_width - len(start_clean) - 1)
# Ensure total length matches exactly - recalculate if needed
total_length = 1 + len(start_clean) + start_padding # space + message + padding
if total_length != content_width:
start_padding = max(0, content_width - len(start_clean) - 1)
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC} {start_msg}{' ' * start_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}\n")
os.chdir(ndt_path.parent)
try:
# Set environment variable to suppress Flask output
os.environ['JACOPS_RUNNING'] = '1'
# Import and run the Flask app directly to catch KeyboardInterrupt
sys.path.insert(0, str(ndt_path.parent))
from app import app
# Suppress Flask/Werkzeug logging and output
import logging
import warnings
from contextlib import redirect_stderr, redirect_stdout
from io import StringIO
import sys as sys_module
# Suppress all Flask/Werkzeug output BEFORE importing Flask
logging.getLogger('werkzeug').setLevel(logging.CRITICAL)
logging.getLogger('flask').setLevel(logging.CRITICAL)
warnings.filterwarnings("ignore")
# Disable Flask's default startup messages
os.environ['WERKZEUG_RUN_MAIN'] = 'true'
# Run Flask app with KeyboardInterrupt handling
port = 5001
try:
# Print server info in a nice box before starting Flask
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
server_msg = f"{Colors.OKGREEN}{Colors.BOLD}Server draait op{Colors.ENDC} {Colors.BRIGHT_CYAN}{Colors.BOLD}http://localhost:{port}{Colors.ENDC}"
server_clean = ansi_escape.sub('', server_msg)
# Calculate padding: content_width includes the space after ║, so subtract 1 for that space
# Total width should be: space(1) + message + padding = content_width
server_padding = max(0, content_width - len(server_clean) - 1)
# Ensure total length matches exactly - recalculate if needed
total_length = 1 + len(server_clean) + server_padding # space + message + padding
if total_length != content_width:
server_padding = max(0, content_width - len(server_clean) - 1)
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC} {server_msg}{' ' * server_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}\n")
# Suppress Flask output completely by redirecting stdout/stderr
# Save original streams
original_stdout = sys_module.stdout
original_stderr = sys_module.stderr
# Redirect to devnull
devnull = StringIO()
sys_module.stdout = devnull
sys_module.stderr = devnull
# Also suppress werkzeug logging completely
werkzeug_logger = logging.getLogger('werkzeug')
werkzeug_logger.setLevel(logging.CRITICAL)
werkzeug_logger.disabled = True
try:
# Use werkzeug's make_server for better control and no startup messages
from werkzeug.serving import make_server
# Create server silently
server = make_server('0.0.0.0', port, app, threaded=True, processes=1)
server.serve_forever()
finally:
# Restore original streams
sys_module.stdout = original_stdout
sys_module.stderr = original_stderr
werkzeug_logger.disabled = False
except KeyboardInterrupt:
# User pressed Ctrl+C, return to main menu
raise ReturnToMenuException()
except ReturnToMenuException:
raise
except Exception as e:
error_msg = f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}Fout bij starten: {str(e)}{Colors.ENDC}"
error_clean = ansi_escape.sub('', error_msg)
error_padding = (box_width - len(error_clean)) // 2
print(f"{' ' * (box_padding + error_padding)}{error_msg}")
finally:
# Clean up environment variable
if 'JACOPS_RUNNING' in os.environ:
del os.environ['JACOPS_RUNNING']
else:
# Center the error message
error_msg = f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}NDT tool niet gevonden!{Colors.ENDC}"
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
error_clean = ansi_escape.sub('', error_msg)
error_padding = (box_width - len(error_clean)) // 2
print(f"{' ' * (box_padding + error_padding)}{error_msg}")
else:
error_msg = f"{Colors.WARNING}{Colors.BOLD}⚠{Colors.ENDC} {Colors.WARNING}Ongeldige keuze.{Colors.ENDC}"
print(center_text(error_msg))
def run_threat_intelligence_dashboard():
"""Run Live Threat Intelligence Dashboard"""
choice = ask_cli_or_gui("Live Threat Intelligence Dashboard")
ltid_dir = Path(__file__).parent / "LTID"
if choice == "1":
# CLI versie
print_tool_header("Live Threat Intelligence Dashboard", "CLI")
ltid_cli_path = ltid_dir / "cli.py"
if ltid_cli_path.exists():
original_dir = os.getcwd()
try:
# Change to LTID directory and run CLI
os.chdir(ltid_cli_path.parent)
sys.path.insert(0, str(ltid_cli_path.parent))
# Add virtual environment to path if it exists
venv_site_packages = ltid_cli_path.parent / ".venv" / "lib" / f"python{sys.version_info.major}.{sys.version_info.minor}" / "site-packages"
if not venv_site_packages.exists():
import glob
venv_lib = ltid_cli_path.parent / ".venv" / "lib"
if venv_lib.exists():
python_dirs = glob.glob(str(venv_lib / "python*"))
if python_dirs:
venv_site_packages = Path(python_dirs[0]) / "site-packages"
if venv_site_packages.exists():
sys.path.insert(0, str(venv_site_packages))
from cli import main as cli_main
cli_main()
except KeyboardInterrupt:
# User pressed Ctrl+C, return to main menu
raise ReturnToMenuException()
except Exception as e:
print(f"\n{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}Fout bij uitvoeren: {str(e)}{Colors.ENDC}\n")
finally:
try:
os.chdir(original_dir)
except:
pass
else:
print(f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}LTID CLI tool niet gevonden!{Colors.ENDC}")
elif choice == "2":
# GUI versie
print_tool_header("Live Threat Intelligence Dashboard", "GUI")
# Get terminal width for centering
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
box_width = 75
box_padding = (term_width - box_width) // 2
border_line = "═" * 73
content_width = 73
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
ltid_path = ltid_dir / "dashboard.py"
if ltid_path.exists():
# Print nice box with server info
print(f"\n{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
# "Starten van web dashboard..." line
start_msg = f"{Colors.BRIGHT_GREEN}{Colors.BOLD}→{Colors.ENDC} {Colors.OKGREEN}Starten van web dashboard...{Colors.ENDC}"
start_clean = ansi_escape.sub('', start_msg)
# Account for the space after ║
start_padding = max(0, content_width - len(start_clean) - 1)
# Ensure total length matches exactly
total_length = 1 + len(start_clean) + start_padding
if total_length != content_width:
start_padding = max(0, content_width - len(start_clean) - 1)
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC} {start_msg}{' ' * start_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}\n")
os.chdir(ltid_path.parent)
try:
# Set environment variable to suppress output
os.environ['JACOPS_RUNNING'] = '1'
# Suppress logging and warnings before importing
import logging
import warnings
from contextlib import redirect_stderr, redirect_stdout
from io import StringIO
import sys as sys_module
# Suppress all logging output
logging.basicConfig(level=logging.CRITICAL)
logging.getLogger('uvicorn').setLevel(logging.CRITICAL)
logging.getLogger('uvicorn.access').setLevel(logging.CRITICAL)
logging.getLogger('fastapi').setLevel(logging.CRITICAL)
logging.getLogger('collectors').setLevel(logging.CRITICAL)
warnings.filterwarnings("ignore")
# Check if virtual environment exists and add it to path
venv_site_packages = ltid_path.parent / ".venv" / "lib" / f"python{sys.version_info.major}.{sys.version_info.minor}" / "site-packages"
if not venv_site_packages.exists():
# Try alternative Python version paths
import glob
venv_lib = ltid_path.parent / ".venv" / "lib"
if venv_lib.exists():
python_dirs = glob.glob(str(venv_lib / "python*"))
if python_dirs:
venv_site_packages = Path(python_dirs[0]) / "site-packages"
if venv_site_packages.exists():
sys.path.insert(0, str(venv_site_packages))
# Import and run the dashboard
sys.path.insert(0, str(ltid_path.parent))
from dashboard import run as dashboard_run
# Get port from config
try:
from config import Config
port = Config.PORT
except:
port = 8001 # Changed from 8000 to avoid conflict with FTI
# Print server info in a nice box before starting
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
server_msg = f"{Colors.OKGREEN}{Colors.BOLD}Server draait op{Colors.ENDC} {Colors.BRIGHT_CYAN}{Colors.BOLD}http://localhost:{port}{Colors.ENDC}"
server_clean = ansi_escape.sub('', server_msg)
# Account for the space after ║
server_padding = max(0, content_width - len(server_clean) - 1)
# Ensure total length matches exactly
total_length = 1 + len(server_clean) + server_padding
if total_length != content_width:
server_padding = max(0, content_width - len(server_clean) - 1)
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC} {server_msg}{' ' * server_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}\n")
# Suppress stdout and stderr
original_stdout = sys_module.stdout
original_stderr = sys_module.stderr
devnull = StringIO()
sys_module.stdout = devnull
sys_module.stderr = devnull
try:
# Run dashboard
dashboard_run()
finally:
# Restore original streams
sys_module.stdout = original_stdout
sys_module.stderr = original_stderr
if 'JACOPS_RUNNING' in os.environ:
del os.environ['JACOPS_RUNNING']
except KeyboardInterrupt:
# User pressed Ctrl+C, return to main menu
raise ReturnToMenuException()
except ReturnToMenuException:
raise
except Exception as e:
error_msg = f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}Fout bij starten: {str(e)}{Colors.ENDC}"
error_clean = ansi_escape.sub('', error_msg)
error_padding = (box_width - len(error_clean)) // 2
print(f"{' ' * (box_padding + error_padding)}{error_msg}")
else:
error_msg = f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}LTID tool niet gevonden!{Colors.ENDC}"
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
error_clean = ansi_escape.sub('', error_msg)
error_padding = (box_width - len(error_clean)) // 2
print(f"{' ' * (box_padding + error_padding)}{error_msg}")
else:
error_msg = f"{Colors.WARNING}{Colors.BOLD}⚠{Colors.ENDC} {Colors.WARNING}Ongeldige keuze!{Colors.ENDC}"
print(center_text(error_msg))
def run_password_policy_analyzer():
"""Run Password Policy Analyzer tool"""
choice = ask_cli_or_gui("Password Policy Analyzer")
if choice == "1":
# CLI versie
print_tool_header("Password Policy Analyzer", "CLI")
ppa_cli_path = Path(__file__).parent / "PPA" / "cli.py"
if ppa_cli_path.exists():
original_dir = os.getcwd()
try:
# Change to PPA directory and run CLI
os.chdir(ppa_cli_path.parent)
sys.path.insert(0, str(ppa_cli_path.parent))
from cli import main as cli_main
cli_main()
except KeyboardInterrupt:
# User pressed Ctrl+C, return to main menu
raise ReturnToMenuException()
except Exception as e:
print(f"\n{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}Fout bij uitvoeren: {str(e)}{Colors.ENDC}\n")
finally:
try:
os.chdir(original_dir)
except:
pass
else:
print(f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}PPA CLI tool niet gevonden!{Colors.ENDC}")
elif choice == "2":
# GUI versie
print_tool_header("Password Policy Analyzer", "GUI")
# Get terminal width for centering
try:
term_width = shutil.get_terminal_size().columns
except:
term_width = 80
box_width = 75
box_padding = (term_width - box_width) // 2
border_line = "═" * 73
content_width = 73
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
ppa_app_path = Path(__file__).parent / "PPA" / "app.py"
if ppa_app_path.exists():
# Print nice box with server info
print(f"\n{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╔{border_line}╗{Colors.ENDC}")
# "Starten van web interface..." line
start_msg = f"{Colors.BRIGHT_GREEN}{Colors.BOLD}→{Colors.ENDC} {Colors.OKGREEN}Starten van web interface...{Colors.ENDC}"
start_clean = ansi_escape.sub('', start_msg)
# Account for the space after ║
start_padding = max(0, content_width - len(start_clean) - 1)
# Ensure total length matches exactly
total_length = 1 + len(start_clean) + start_padding
if total_length != content_width:
start_padding = max(0, content_width - len(start_clean) - 1)
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC} {start_msg}{' ' * start_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}║{Colors.ENDC}")
print(f"{' ' * box_padding}{Colors.BRIGHT_CYAN}{Colors.BOLD}╚{border_line}╝{Colors.ENDC}\n")
original_dir = os.getcwd()
try:
os.chdir(ppa_app_path.parent)
sys.path.insert(0, str(ppa_app_path.parent))
# Check if virtual environment exists and add it to path
venv_site_packages = ppa_app_path.parent / ".venv" / "lib" / f"python{sys.version_info.major}.{sys.version_info.minor}" / "site-packages"
if not venv_site_packages.exists():
# Try alternative Python version paths
import glob
venv_lib = ppa_app_path.parent / ".venv" / "lib"
if venv_lib.exists():
python_dirs = glob.glob(str(venv_lib / "python*"))
if python_dirs:
venv_site_packages = Path(python_dirs[0]) / "site-packages"
if venv_site_packages.exists():
sys.path.insert(0, str(venv_site_packages))
# Check for required dependencies before starting
missing_deps = []
try:
import flask
except ImportError:
missing_deps.append("flask")
try:
import flask_cors
except ImportError:
missing_deps.append("flask_cors")
if missing_deps:
deps_str = ", ".join(missing_deps)
error_msg = f"{Colors.BRIGHT_RED}{Colors.BOLD}✗{Colors.ENDC} {Colors.FAIL}Ontbrekende dependencies: {deps_str}{Colors.ENDC}"
error_clean = ansi_escape.sub('', error_msg)
error_padding = (box_width - len(error_clean)) // 2
print(f"{' ' * (box_padding + error_padding)}{error_msg}")
print()
python_exe = sys.executable
install_msg = f"{Colors.WARNING}Installeer dependencies met:{Colors.ENDC} {Colors.OKCYAN}cd PPA && python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt{Colors.ENDC}"
print(center_text(install_msg))
print()
alt_msg = f"{Colors.DIM}Of: cd PPA && pip3 install -r requirements.txt --break-system-packages{Colors.ENDC}"
print(center_text(alt_msg))
print()
return
# Set environment variable to suppress output
os.environ['JACOPS_RUNNING'] = '1'
# Suppress logging and warnings before importing
import logging
import warnings
from contextlib import redirect_stderr, redirect_stdout
from io import StringIO
import sys as sys_module
# Suppress all logging output
logging.basicConfig(level=logging.CRITICAL)