-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
1194 lines (1011 loc) · 63.1 KB
/
main.py
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
#Custom modules
import other_funcs, es_funcs
from settings import *
from custom_widgets import *
#External modules
import re, customtkinter, json, os
from threading import Thread
from typing import Union
class Groppy(customtkinter.CTk):
def __init__(self, app_settings):
super().__init__()
self.initialize_main_window()
self.load_color_schema(app_settings)
self.declare_variables()
self.initialize_left_sidebar()
self.initialize_middle_components()
self.initialize_right_sidebar()
self.declare_default_states()
self.light_text_color, self.dark_text_color = self.application_title.cget("text_color")
self.fg_light_color, self.fg_dark_color = self.sidebar_frame_left.cget("fg_color")
self.border_light_color, self.border_dark_color = self.sidebar_frame_left.cget("border_color")
self.update_color_scheme()
if not app_settings['successful_load']:
CustomMessagebox(title='Load settings', label=RETURN_MESSAGES['unsuccessful_retrieval_of_jsonfile_data'], text=app_settings['failure_reason'], geometry=self.messagebox_geometry)
if app_settings['initial_start']:
CustomMessagebox(title='Welcome', label=RETURN_MESSAGES['welcome_msg'], text=RETURN_MESSAGES['welcome_info'], geometry=self.welcome_messagebox_geometry)
self.enable_settings(app_settings)
def load_color_schema(self, app_settings: dict):
self.main_color = app_settings['mode']
self.sub_color = app_settings['theme']
def enable_settings(self, app_settings: dict):
if app_settings['elastic_host']:
self.es_host_entry.insert(0, app_settings['elastic_host'])
if app_settings['elastic_port']:
self.es_port_entry.insert(0, app_settings['elastic_port'])
if app_settings['elastic_auth']:
self.toggle_es_auth()
if app_settings['elastic_user']:
self.es_username_entry.insert(0, app_settings['elastic_user'])
if app_settings['elastic_api_key_is_used']:
self.toggle_es_api()
if app_settings['elastic_api_key_value']:
self.api_key_entry.insert(0, app_settings['elastic_api_key_value'])
if app_settings['elastic_cert_is_used']:
self.toggle_es_cert()
if app_settings['elastic_cert_path']:
self.es_cert_entry.insert(0, app_settings['elastic_cert_path'])
def initialize_main_window(self):
"""
Initializes the window with components such as icon, title, geometry
"""
self.wm_iconbitmap(app_icon)
self.title(app_title+"/"+app_version)
self.geometry("%dx%d" % (window_width, window_height))
self.grid_columnconfigure((1,2,3,4,5,6,7,8,9,10,11,12,13,14), weight=1)
self.grid_columnconfigure((0,15,16), weight=0)
self.grid_rowconfigure((1), weight=3)
def declare_variables(self):
"""
Declares variables
"""
self.log_box_font=log_box_font
self.created_patterns = 1
self.auto_match = True
self.bg_highlight = False
self.es_indicies = []
self.es_fields = []
self.json_fields = []
self.include=[]
self.exclude=[]
self.include_sign="\U00002714"
self.exclude_sign="\U0000274C"
self.filter_list = [self.include, self.exclude]
self.table_list = set()
def initialize_left_sidebar(self):
"""
Initializes the left sidebar of the window and all of the components inside
"""
self.sidebar_frame_left = customtkinter.CTkFrame(self, corner_radius=0, width=left_sidebar_size)
self.sidebar_frame_left.grid(row=0, column=0, rowspan=4, sticky="nsew")
self.sidebar_frame_left.grid_rowconfigure(6, weight=1)
self.application_title = customtkinter.CTkLabel(self.sidebar_frame_left,
text=app_title,
font=large_font)
self.application_title.grid(row=0, column=0, columnspan=5, padx=10, pady=(5, 0), sticky="n")
### LOAD FIELD TABVIEW
self.load_data_tabview = CustomTabView(self.sidebar_frame_left,
width=220)
self.load_data_tabview.add(load_data_tabview_local_file)
self.load_data_tabview.add(load_data_tabview_es)
self.load_data_tabview.grid(row=1, column=0, columnspan=2, padx=(30,30), sticky="new")
self.load_data_tabview.tab(load_data_tabview_es).grid_columnconfigure((0,1), weight=0)
self.load_data_tabview.tab(load_data_tabview_local_file).grid_columnconfigure((0,1), weight=1)
#### Logg File Tabview
self.initialize_local_file_tabview()
#### Elasticsearch Tabview
self.initialize_es_tabview()
### APPEARANCE FRAME
self.sidebar_appearance_frame_left = customtkinter.CTkFrame(self.sidebar_frame_left, corner_radius=5)
self.sidebar_appearance_frame_left.grid(row=9, column=0,columnspan=2, padx=(30,30),pady=(10,10), sticky="new")
self.sidebar_appearance_frame_left.grid_columnconfigure((1,2,3), weight=1)
self.sidebar_appearance_frame_left.grid_rowconfigure((0,1,2,3), weight=1)
### APPEARANCE LABEL
self.appearance_label = customtkinter.CTkLabel(self.sidebar_appearance_frame_left,
text=appearance_frame_label,
font=medium_font)
self.appearance_label.grid(row=0, column=0, columnspan=3, padx=20, pady=(5, 0), sticky="n")
### PATTERNS SWITCH
self.patterns_frame_switch = customtkinter.CTkCheckBox(master=self.sidebar_appearance_frame_left,
command=self.toggle_patterns_frame,
text=patterns_appear_switch_label,
checkbox_width=checkbox_size,
checkbox_height=checkbox_size,
font=small_font)
self.patterns_frame_switch.grid(row=1, column=0,columnspan=2,padx=20, pady=(5, 0), sticky="w")
### STATS SWITCH
self.patterns_stats_frame_switch = customtkinter.CTkCheckBox(master=self.sidebar_appearance_frame_left,
command=self.toggle_stats_frame,
text=stats_appear_switch_label,
checkbox_width=checkbox_size,
checkbox_height=checkbox_size,
font=small_font)
self.patterns_stats_frame_switch.grid(row=2, column=0,columnspan=2,padx=20, pady=(5, 5), sticky="w")
### APPEARANCE SWITCH
self.switch_main_appearance = customtkinter.CTkSwitch(master=self.sidebar_appearance_frame_left,
command=self.change_appearance_main_color,
text=self.get_color_switch_label(),
font=medium_font)
self.switch_main_appearance.grid(row=3, column=0, columnspan=2,padx=20, pady=(0, 5), sticky="w")
def initialize_local_file_tabview(self):
### SIDEBAR BUTTON LOGFILE
self.sidebar_button_logfile = customtkinter.CTkButton(self.load_data_tabview.tab(load_data_tabview_local_file),
text=lfi_log_button_name,
command=self.read_log,
width=10,
font=small_font)
self.sidebar_button_logfile.grid(row=0, column=0, columnspan=4, padx=(10,0), pady=10, sticky="we")
### SIDEBAR SWITCH UNIQUE LINES
self.unique_logfile_lines_switch = customtkinter.CTkCheckBox(self.load_data_tabview.tab(load_data_tabview_local_file),
width=20,
command=self.toggle_get_unique_logfile_lines,
text=lfi_unique_fields_label,
checkbox_width=checkbox_size,
checkbox_height=checkbox_size,
font=small_font)
self.unique_logfile_lines_switch.grid(row=0, column=5, padx=(5,10), pady=(5, 0))
self.unique_logfile_lines_switch.select()
### SIDEBAR BUTTON GROK PATTERNS
self.sidebar_button_patternlocation = customtkinter.CTkButton(self.load_data_tabview.tab(load_data_tabview_local_file),
text=lfi_pattern_button_name,
command=self.read_patterns,
width=10,
font=small_font)
self.sidebar_button_patternlocation.grid(row=1, column=0, columnspan=6, padx=10, pady=(5,10), sticky="we")
### SIDERBAR BUTTON JSON LOCATION
self.sidebar_button_jsonlocation = customtkinter.CTkButton(self.load_data_tabview.tab(load_data_tabview_local_file),
text=lfi_json_file_button_name,
command=self.read_json,
width=10,
font=small_font)
self.sidebar_button_jsonlocation.grid(row=2, column=0, columnspan=4, padx=(10,0), pady=10, sticky="we")
### SIDEBAR JSONFILE SWITCH UNIQUE LINES
self.unique_jsonfile_lines_switch = customtkinter.CTkCheckBox(self.load_data_tabview.tab(load_data_tabview_local_file),
width=20,
command=self.toggle_get_unique_jsonfile_results,
text=lfi_unique_fields_label,
checkbox_width=checkbox_size,
checkbox_height=checkbox_size,
font=small_font)
self.unique_jsonfile_lines_switch.grid(row=2, column=5, padx=(5,10), pady=(5, 0))
self.unique_jsonfile_lines_switch.select()
### JSON FIELD LABEL
self.json_field_label = customtkinter.CTkLabel(self.load_data_tabview.tab(load_data_tabview_local_file),
text=es_field_label_text,
font=small_font)
self.json_field_label.grid(row=3, column=0, padx=(5,0))
### JSON FIELD ENTRY
self.json_field_entry_dv = customtkinter.StringVar()
self.json_field_entry_dv.trace_add("write", self.json_field_autocomplete_callback)
### JSON FIELD COMBOBOX
self.json_field_combobox = customtkinter.CTkComboBox(self.load_data_tabview.tab(load_data_tabview_local_file),
variable=self.json_field_entry_dv,
values=self.json_fields,
height=left_es_entry_height)
self.json_field_combobox.grid(row=3, column=1, columnspan=5, padx=(5,10),pady=5)
### JSON BUTTON GET FIELDS
self.sidebar_button_json_fields = customtkinter.CTkButton(self.load_data_tabview.tab(load_data_tabview_local_file),
text=getjsonfield_button_name,
command=lambda: self.compute(self.get_json_field_data),
font=small_font)
self.sidebar_button_json_fields.grid(row=4, column=0, columnspan=6, padx=10, pady=(5,10), sticky="we")
def initialize_es_tabview(self):
### ES HOST LABEL
self.es_host_label = customtkinter.CTkLabel(self.load_data_tabview.tab(load_data_tabview_es),
text=es_hostname_label_text,
font=small_font)
self.es_host_label.grid(row=0, column=0, padx=(5,0), sticky="we")
### ES HOST ENTRY
self.es_host_entry = customtkinter.CTkEntry(self.load_data_tabview.tab(load_data_tabview_es),
placeholder_text=es_bogus_hostname,
height=left_es_entry_height)
self.es_host_entry.grid(row=0, column=1, columnspan=2, padx=(5,10), sticky="w")
### ES PORT LABEL
self.es_port_label = customtkinter.CTkLabel(self.load_data_tabview.tab(load_data_tabview_es),
text=es_port_label_text,
font=small_font)
self.es_port_label.grid(row=1, column=0, padx=(5,0), sticky="we")
### ES PORT ENTRY
self.es_port_entry = customtkinter.CTkEntry(self.load_data_tabview.tab(load_data_tabview_es),
placeholder_text=es_bogus_port,
height=left_es_entry_height)
self.es_port_entry.grid(row=1, column=1, columnspan=2, padx=(5,10), sticky="w")
### ES AUTH SWITCH
self.auth_switch = customtkinter.CTkCheckBox(self.load_data_tabview.tab(load_data_tabview_es),
command=self.toggle_es_auth,
text=es_basic_auth_label,
checkbox_width=checkbox_size,
checkbox_height=checkbox_size,
font=small_font)
self.auth_switch.grid(row=2, column=0, columnspan=3, padx=20, pady=(5, 0), sticky="w")
### ES USERNAME LABEL
self.es_username_label = customtkinter.CTkLabel(self.load_data_tabview.tab(load_data_tabview_es),
text=es_username_label_text,
font=small_font)
self.es_username_label.grid(row=3, column=0, padx=(5,0), sticky="w")
### ES USERNAME ENTRY
self.es_username_entry = customtkinter.CTkEntry(self.load_data_tabview.tab(load_data_tabview_es),
height=left_es_entry_height,
placeholder_text=es_bogus_username)
self.es_username_entry.grid(row=3, column=1,columnspan=2, padx=(5,10), sticky="w")
### ES PASSWORD LABEL
self.es_password_label = customtkinter.CTkLabel(self.load_data_tabview.tab(load_data_tabview_es),
text=es_password_label_text,
font=small_font)
self.es_password_label.grid(row=4, column=0, padx=(5,0), sticky="w")
### ES PASSWORD ENTRY
self.es_password_entry = customtkinter.CTkEntry(self.load_data_tabview.tab(load_data_tabview_es),
height=left_es_entry_height,
placeholder_text=es_bogus_password)
self.es_password_entry.grid(row=4, column=1,columnspan=2, padx=(5,10), sticky="w")
### ES API KEY SWITCH
self.api_key_switch = customtkinter.CTkCheckBox(self.load_data_tabview.tab(load_data_tabview_es),
command=self.toggle_es_api,
text=es_api_key_label,
checkbox_width=checkbox_size,
checkbox_height=checkbox_size,
font=small_font)
self.api_key_switch.grid(row=5, column=0, columnspan=3, padx=20, pady=(5, 0), sticky="w")
### API KEY LABEL
self.api_key_label = customtkinter.CTkLabel(self.load_data_tabview.tab(load_data_tabview_es),
text=es_api_key_label_text,
font=small_font)
self.api_key_label.grid(row=6, column=0, padx=(5,0), sticky="w")
### API KEY ENTRY
self.api_key_entry = customtkinter.CTkEntry(self.load_data_tabview.tab(load_data_tabview_es),
height=left_es_entry_height,
placeholder_text=es_bogus_api_key)
self.api_key_entry.grid(row=6, column=1,columnspan=2, padx=(5,10), sticky="we")
### ES CERT SWITCH
self.es_cert_switch = customtkinter.CTkCheckBox(self.load_data_tabview.tab(load_data_tabview_es),
command=self.toggle_es_cert,
text=es_cert_label,
checkbox_width=checkbox_size,
checkbox_height=checkbox_size,
font=small_font)
self.es_cert_switch.grid(row=7, column=0, columnspan=3, padx=20, pady=(5, 0), sticky="w")
### CERT LABEL
self.es_cert_label = customtkinter.CTkLabel(self.load_data_tabview.tab(load_data_tabview_es),
text=es_cert_label_text,
font=small_font)
self.es_cert_label.grid(row=8, column=0, padx=(5,0), sticky="w")
### CERT ENTRY
self.es_cert_entry = customtkinter.CTkEntry(self.load_data_tabview.tab(load_data_tabview_es),
height=left_es_entry_height,
placeholder_text=es_bogus_cert)
self.es_cert_entry.grid(row=8, column=1,columnspan=2, padx=(5,10), sticky="we")
### ES TEST CONNECTION BUTTON
self.sidebar_button_es_conn = customtkinter.CTkButton(self.load_data_tabview.tab(load_data_tabview_es),
text=conn_test_button_name,
command=lambda: self.compute(self.test_es_connection),
font=small_font)
self.sidebar_button_es_conn.grid(row=9, column=0, columnspan=3,padx=5, pady=10)
### ES INDEX LABEL
self.es_index_label = customtkinter.CTkLabel(self.load_data_tabview.tab(load_data_tabview_es),
text=es_index_label_text,
font=small_font)
self.es_index_label.grid(row=10, column=0, padx=(5,0), sticky="w")
### ES INDEX ENTRY
self.es_index_entry_dv = customtkinter.StringVar()
self.es_index_entry_dv.trace_add("write", self.index_autocomplete_callback)
### ES INDEX COMBOBOX
self.es_index_combobox = customtkinter.CTkComboBox(self.load_data_tabview.tab(load_data_tabview_es),
variable=self.es_index_entry_dv,
values=self.es_indicies,
height=left_es_entry_height)
self.es_index_combobox.grid(row=10, column=1,columnspan=2, padx=(5,10),pady=5, sticky="we")
### ES FIELD LABEL
self.es_field_label = customtkinter.CTkLabel(self.load_data_tabview.tab(load_data_tabview_es),
text=es_field_label_text,
font=small_font)
self.es_field_label.grid(row=11, column=0, padx=(5,0), sticky="w")
### ES FIELD ENTRY
self.es_field_entry_dv = customtkinter.StringVar()
self.es_field_entry_dv.trace_add("write", self.es_field_autocomplete_callback)
### ES FIELD COMBOBOX
self.es_field_combobox = customtkinter.CTkComboBox(self.load_data_tabview.tab(load_data_tabview_es),
variable=self.es_field_entry_dv,
values=self.es_fields,
height=left_es_entry_height)
self.es_field_combobox.grid(row=11, column=1,columnspan=2, padx=(5,10),pady=5, sticky="we")
### ES QUERY LABEL
self.es_query_label = customtkinter.CTkLabel(self.load_data_tabview.tab(load_data_tabview_es),
text=es_query_label_text,
font=small_font)
self.es_query_label.grid(row=12, column=0, padx=(5,0), sticky="w")
### ES QUERY ENTRY
self.es_query_entry = customtkinter.CTkEntry(self.load_data_tabview.tab(load_data_tabview_es),
placeholder_text=es_bogus_query,
height=left_es_entry_height)
self.es_query_entry.grid(row=12, column=1,columnspan=2, padx=(5,10),pady=5, sticky="we")
### GET UNIQUE ENTRIES
self.es_unique_data_switch = customtkinter.CTkCheckBox(self.load_data_tabview.tab(load_data_tabview_es),
command=self.toggle_get_unique_es_results,
text=es_unique_lines_label,
checkbox_width=checkbox_size,
checkbox_height=checkbox_size,
font=small_font)
self.es_unique_data_switch.grid(row=13, column=0, columnspan=3, padx=20, pady=(5, 0), sticky="w")
self.es_unique_data_switch.select()
### ES BUTTON GET FIELDS
self.sidebar_button_es_fields = customtkinter.CTkButton(self.load_data_tabview.tab(load_data_tabview_es),
text=getesfield_button_name,
command=lambda: self.compute(self.get_es_field_data),
font=small_font)
self.sidebar_button_es_fields.grid(row=14, column=0, columnspan=3, padx=5, pady=10)
def initialize_middle_components(self):
"""
Initializes the components in the middle of the window
"""
self.textbox_log = CustomTextBox(self, font=self.log_box_font)
self.textbox_log.grid(row=1, column=1, columnspan=15, pady=(10,20), padx=20, sticky="nsew")
self.update_textbox(self.textbox_log, bogus_textbox_text, editable=True)
### MIDDLE FRAME - LOADING BOX
self.create_loading_frame()
### MIDDLE FRAME - REGEX ENTRY BOX
self.regexp_entry_dv = customtkinter.StringVar()
self.regexp_entry_dv.trace_add("write", self.highlight_callback)
self.regexp_entry = customtkinter.CTkEntry(self, textvariable=self.regexp_entry_dv, width=500)
self.regexp_entry.grid(row=0,column=1, columnspan=13, padx=(20, 0),pady=(20, 20), sticky="we")
### MIDDLE FRAME - MATCH BUTTON
self.match_entry_button = customtkinter.CTkButton(self,
text=match_button_name,
command=self.highlight,
width=20,
font=small_font)
self.match_entry_button.grid(row=0, column=14, padx=(5,5), pady=(5,5), sticky="we")
### MIDDLE FRAME - ENTRY FRAME
self.entry_frame_middle = customtkinter.CTkFrame(self, corner_radius=5, height=20, width=20)
self.entry_frame_middle.grid(row=0, column=15, padx=(0,20), pady=(10, 5), sticky="we")
self.entry_frame_middle.grid_rowconfigure((0,1), weight=1)
self.entry_frame_middle.grid_columnconfigure((0,1), weight=1)
### ENTRY FRAME - REGEX SWITCH
self.switch_regexp_match = customtkinter.CTkSwitch(self.entry_frame_middle,
command=self.toggle_auto_match,
font=small_font,
text=automatch_label)
self.switch_regexp_match.grid(row=0, column=0, pady=(5,0),padx=(10,10),sticky="we")
self.switch_regexp_match.select()
### ENTRY FRAME - HIGHLIGHT SWITCH
self.switch_bg_highlight = customtkinter.CTkSwitch(self.entry_frame_middle,
command=self.toggle_bg_highlight,
font=small_font,
text=bg_highlight_label)
self.switch_bg_highlight.grid(row=1, column=0, pady=(0,5), padx=(10,10),sticky="we")
### ENTRY FRAME - EXPORT BUTTON
self.save_entry_button = customtkinter.CTkButton(self.entry_frame_middle,
text=add_pattern_button_name,
command=self.add_pattern_to_table,
font=small_font)
self.save_entry_button.grid(row=0, rowspan=2, column=1, padx=(5,5), pady=(5,5), sticky="we")
### ENTRY FRAME - REGEX HELP BUTTON
self.re_help_button = customtkinter.CTkButton(self.entry_frame_middle,
width=20,
text=regex_help_button_name,
command=self.create_regex_help_msgbox,
font=small_font)
self.re_help_button.grid(row=0, rowspan=2, column=2, padx=(5,5), pady=(5,5), sticky="we")
### MIDDLE FRAME - TABVIEW
self.tabview = CustomTabView(self)
self.tabview.grid(row=2, column=1, columnspan=15, rowspan=2, padx=(20, 20), pady=(20, 20), sticky="nsew")
self.tabview.add("Stats")
self.tabview.add("Results")
self.tabview.tab("Stats").grid_columnconfigure((0,1), weight=1)
self.tabview.tab("Results").grid_columnconfigure(0, weight=1)
### MIDDLE FRAME - STATS TABLE
self.stats_sheet = CustomSheet(self.tabview.tab("Stats"),
theme=self.main_color+" "+self.sub_color,
show_x_scrollbar = True,
show_y_scrollbar = False,
empty_horizontal = False,
empty_vertical = False,
show_top_left = False,
show_row_index = True)
self.stats_sheet.grid(row = 0, column = 0, columnspan=2, sticky = "nswe")
self.table_list.add(self.stats_sheet)
self.stats_sheet.enable_filter_in_menue("Include",lambda: self.pattern_filter(self.stats_sheet, self.include, "include"))
self.stats_sheet.enable_filter_in_menue("Exclude",lambda: self.pattern_filter(self.stats_sheet, self.exclude, "exclude"))
### MIDDLE FRAME - RESULTS TABLE
self.results_sheet = CustomSheet(self.tabview.tab("Results"),
theme=self.main_color+" "+self.sub_color,
show_x_scrollbar = True,
show_y_scrollbar = False,
empty_horizontal = False,
empty_vertical = False,
show_top_left = False,
show_row_index = True)
self.results_sheet.grid(row = 0, column = 0, sticky = "nswe")
self.table_list.add(self.results_sheet)
self.results_sheet.enable_filter_in_menue("Include",lambda: self.pattern_filter(self.results_sheet, self.include, "include"))
self.results_sheet.enable_filter_in_menue("Exclude",lambda: self.pattern_filter(self.results_sheet, self.exclude, "exclude"))
def initialize_right_sidebar(self):
"""
Initializes the right frame and the components within
"""
### RIGHT FRAME
self.sidebar_frame_right = customtkinter.CTkFrame(self, corner_radius=5, width=100)
self.sidebar_frame_right.grid(row=0, column=16, rowspan=4, padx=(0,20), pady=(10, 20), sticky="nsew")
self.sidebar_frame_right.grid_rowconfigure((0,1,2,4,5,6), weight=1)
### RIGHT FRAME - PATTERNS LABEL
self.patterns_label = customtkinter.CTkLabel(self.sidebar_frame_right,
text=lfi_pattern_button_name,
font=large_font)
self.patterns_label.grid(row=0, column=0, padx=40, pady=(0, 10), sticky="s")
### RIGHT FRAME - PATTERNS TABLE
self.patterns_sheet = CustomSheet(self.sidebar_frame_right, width=100,
theme=self.main_color+" "+self.sub_color,
show_x_scrollbar = False,
show_y_scrollbar = False,
empty_horizontal = False,
empty_vertical = False,
show_top_left = False,
show_row_index = False,
show_header = False,
headers=["Pattern", "Regex"],
column_width=99)
self.patterns_sheet.grid(row=1, rowspan=2, column=0, padx=20, sticky="nsew")
self.table_list.add(self.patterns_sheet)
### RIGHT FRAME - PATTERNS TABLE FUNCTIONS
self.patterns_sheet.enable_filter_in_menue("Include",
lambda: self.pattern_filter(self.patterns_sheet, self.include, "include"))
self.patterns_sheet.enable_filter_in_menue("Exclude",
lambda: self.pattern_filter(self.patterns_sheet, self.exclude, "exclude"))
self.patterns_sheet.popup_menu_add_command("Delete",
lambda: self.delete_pattern_from_table(self.patterns_sheet),
index_menu = False,
header_menu = False)
self.patterns_sheet.disable_bindings("double_click_column_resize")
### RIGHT FRAME - EXPORT PATTERNS BUTTON
self.sidebar_button_export_patterns = customtkinter.CTkButton(self.sidebar_frame_right,
text=export_patterns_button_name,
command=self.export_patterns,
width=10,
font=small_font)
self.sidebar_button_export_patterns.grid(row=3, column=0, padx=20, pady=(10,0), sticky="n")
### RIGHT FRAME - FILTER LABEL
self.filter_label = customtkinter.CTkLabel(self.sidebar_frame_right,
text=filter_label,
font=large_font)
self.filter_label.grid(row=4, column=0, padx=40, pady=(0, 10), sticky="s")
### RIGHT FRAME - FILTER BOX
self.filter_box = customtkinter.CTkTextbox(self.sidebar_frame_right)
self.filter_box.grid(row=5, column=0, rowspan=2, padx=20, sticky="nsew")
self.filter_box.configure(state="disabled")
### RIGHT FRAME - CLEAR FILTER BUTTON
self.filter_button = customtkinter.CTkButton(self.sidebar_frame_right,
command=self.clear_filters,
width=10,
text=clear_patterns_button_name,
font=small_font)
self.filter_button.grid(row=7, column=0, padx=50, pady=10, sticky="n")
### RIGHT FRAME - TEST PATTERNS BUTTON
self.sidebar_button_get_matches = customtkinter.CTkButton(self.sidebar_frame_right,
height=20,
text=getmatches_button_name,
command=lambda: self.compute(self.get_pattern_matches),
font=large_font)
self.sidebar_button_get_matches.grid(row=8, rowspan=2,column=0, padx=20, pady=20, sticky="nsew")
def declare_default_states(self):
self.showing_patterns_frame = False
self.showing_patterns_stats_frame = False
self.showing_es_auth = False
self.showing_es_api = False
self.showing_es_cert = False
self.get_unique_es_results = True
self.get_unique_jsonfile_results = True
self.get_unique_logfile_lines = True
self.es_username_label.grid_forget()
self.es_username_entry.grid_forget()
self.es_password_label.grid_forget()
self.es_password_entry.grid_forget()
self.api_key_label.grid_forget()
self.api_key_entry.grid_forget()
self.es_cert_label.grid_forget()
self.es_cert_entry.grid_forget()
self.match_entry_button.grid_forget()
self.tabview.grid_forget()
self.sidebar_frame_right.grid_forget()
self.messagebox_geometry="%d+%d" % (self.winfo_x() + window_width/2, self.winfo_y() + window_height/2)
self.welcome_messagebox_geometry="%d+%d" % (self.winfo_x() + window_width/2, self.winfo_y() + window_height/2)
def toggle_get_unique_logfile_lines(self):
if self.get_unique_logfile_lines:
self.unique_logfile_lines_switch.deselect()
else:
self.unique_logfile_lines_switch.select()
self.get_unique_logfile_lines = not self.get_unique_logfile_lines
def toggle_get_unique_es_results(self):
if self.get_unique_es_results:
self.es_unique_data_switch.deselect()
else:
self.es_unique_data_switch.select()
self.get_unique_es_results = not self.get_unique_es_results
def toggle_get_unique_jsonfile_results(self):
if self.get_unique_jsonfile_results:
self.unique_jsonfile_lines_switch.deselect()
else:
self.unique_jsonfile_lines_switch.select()
self.get_unique_jsonfile_results = not self.get_unique_jsonfile_results
def toggle_es_cert(self):
if self.showing_es_cert:
self.es_cert_switch.deselect()
self.es_cert_label.grid_forget()
self.es_cert_entry.grid_forget()
else:
self.es_cert_label.grid(row=8, column=0, padx=(5,0), sticky="w")
self.es_cert_entry.grid(row=8, column=1,columnspan=2, padx=(5,0), sticky="w")
self.es_cert_switch.select()
self.showing_es_cert = not self.showing_es_cert
def toggle_es_api(self):
if self.showing_es_api:
self.api_key_switch.deselect()
self.api_key_label.grid_forget()
self.api_key_entry.grid_forget()
else:
self.api_key_entry.grid(row=6, column=1,columnspan=2, padx=(5,0), sticky="w")
self.api_key_label.grid(row=6, column=0, padx=(5,0), sticky="w")
self.api_key_switch.select()
self.showing_es_api = not self.showing_es_api
def toggle_es_auth(self):
if self.showing_es_auth:
self.es_username_label.grid_forget()
self.es_username_entry.grid_forget()
self.es_password_label.grid_forget()
self.es_password_entry.grid_forget()
self.auth_switch.deselect()
else:
self.es_password_entry.grid(row=4, column=1,columnspan=2, padx=(5,0), sticky="w")
self.es_password_label.grid(row=4, column=0, padx=(5,0), sticky="w")
self.es_username_entry.grid(row=3, column=1,columnspan=2, padx=(5,0), sticky="w")
self.es_username_label.grid(row=3, column=0, padx=(5,0), sticky="w")
self.auth_switch.select()
self.showing_es_auth = not self.showing_es_auth
def toggle_patterns_frame(self):
self.showing_patterns_frame = not self.showing_patterns_frame
if self.showing_patterns_frame:
self.sidebar_frame_right.grid(row=0, column=16, rowspan=4, padx=(0,20), pady=(10, 20), sticky="nsew")
self.patterns_frame_switch.select()
else:
self.sidebar_frame_right.grid_forget()
self.patterns_frame_switch.deselect()
def toggle_stats_frame(self):
self.showing_patterns_stats_frame = not self.showing_patterns_stats_frame
if self.showing_patterns_stats_frame:
self.tabview.grid(row=2, column=1, columnspan=15, rowspan=2, padx=(20, 20), pady=(20, 20), sticky="nsew")
self.patterns_stats_frame_switch.select()
else:
self.tabview.grid_forget()
self.patterns_stats_frame_switch.deselect()
def get_es_server_details(function: callable) -> callable:
def wrapper(*args: any) -> callable:
self = args[0]
self.es_hostname=es_bogus_hostname if self.es_host_entry.get().strip() == "" else self.es_host_entry.get().strip()
self.es_port=es_bogus_port if self.es_port_entry.get().strip() == "" else self.es_port_entry.get().strip()
if self.showing_es_auth:
self.es_username = es_bogus_username if self.es_username_entry.get().strip() == "" else self.es_username_entry.get().strip()
self.es_password = es_bogus_password if self.es_password_entry.get().strip() == "" else self.es_password_entry.get().strip()
self.es_auth=(self.es_username, self.es_password)
else:
self.es_auth=es_default_auth
if self.showing_es_api:
self.es_api_key = es_default_api_key if self.api_key_entry.get().strip() == "" else self.api_key_entry.get().strip()
else:
self.es_api_key = es_default_api_key
if self.showing_es_cert:
self.es_cert = es_default_cert if self.es_cert_entry.get().strip() == "" else self.es_cert_entry.get().strip()
else:
self.es_cert = es_default_cert
self.es_index=es_bogus_index if self.es_index_combobox.get().strip() == "" else self.es_index_combobox.get().strip()
self.es_field=es_bogus_field if self.es_field_combobox.get().strip() == "" else self.es_field_combobox.get().strip()
self.es_query=es_bogus_query if self.es_query_entry.get().strip() == "" else self.es_query_entry.get().strip()
function(*args)
return wrapper
def get_json_field_data(self):
try:
self.json_field = self.json_field_combobox.get().strip()
json_data = other_funcs.extract_jsonfile_field_data(self.json_data, self.json_field, unique=self.get_unique_jsonfile_results)
if json_data:
self.update_textbox(self.textbox_log, "\n".join(json_data), editable=True)
except Exception as error_msg:
CustomMessagebox(title=error_msg.__class__.__name__, label=RETURN_MESSAGES['unsuccessful_retrieval_of_jsonfile_data'], text=str(error_msg), geometry=self.messagebox_geometry)
finally:
self.hide_loading()
def compute(self, func: callable):
self.show_loading()
self.loading_thread = Thread(target=func)
self.loading_thread.start()
def show_loading(self):
self.sidebar_button_es_fields.configure(state="disabled")
self.sidebar_button_es_conn.configure(state="disabled")
self.sidebar_button_get_matches.configure(state="disabled")
self.sidebar_button_json_fields.configure(state="disabled")
self.textbox_log.grid_forget()
self.loading_frame.grid(row=1, column=1, columnspan=15, pady=(10,20), padx=20, sticky="nsew")
def hide_loading(self):
self.loading_frame.grid_forget()
self.textbox_log.grid(row=1, column=1, columnspan=15,pady=(10,20), padx=20, sticky="nsew")
self.sidebar_button_es_fields.configure(state="normal")
self.sidebar_button_es_conn.configure(state="normal")
self.sidebar_button_get_matches.configure(state="normal")
self.sidebar_button_json_fields.configure(state="normal")
def create_loading_frame(self):
self.loading_frame = customtkinter.CTkFrame(self, corner_radius=5)
self.loading_frame.grid_columnconfigure((0,1,2), weight=1)
self.loading_frame.grid_rowconfigure((2,3), weight=2)
loading_label = customtkinter.CTkLabel(self.loading_frame, text=loading_label_text, font=extra_large_font)
loading_label.grid(row=2, column=0, columnspan=3, padx=10, pady=(0,15), sticky="ews")
progressbar = customtkinter.CTkProgressBar(self.loading_frame, height=30,corner_radius=40,border_width=2)
progressbar.grid(row=3, column=0, columnspan=3, pady=(0), padx=100, sticky="enw")
progressbar.configure(mode="indeterminnate")
progressbar.start()
@get_es_server_details
def test_es_connection(self):
try:
es_funcs.get_request_elastic(url='http://{}:{}'.format(self.es_hostname, self.es_port),
credentials=self.es_auth,
cert=self.es_cert,
api_key=self.es_api_key)
CustomMessagebox(title="Connection", label=RETURN_MESSAGES['successful_connection'], geometry=self.messagebox_geometry)
except Exception as error_msg:
CustomMessagebox(title=error_msg.__class__.__name__, label=RETURN_MESSAGES['unsuccessful_connection'], text=str(error_msg), geometry=self.messagebox_geometry)
finally:
self.hide_loading()
try:
self.refresh_index_and_fields()
except:
pass
@get_es_server_details
def get_es_field_data(self):
try:
request_body = es_funcs.populate_json(self.es_field, self.es_query)
response = es_funcs.get_request_elastic(url='http://{}:{}/{}/_search'.format(self.es_hostname, self.es_port, self.es_index),
credentials=self.es_auth,
request_body=request_body,
cert=self.es_cert,
api_key=self.es_api_key).json()
es_data = es_funcs.extract_es_field_data(response, self.es_field,unique=self.get_unique_es_results)
self.update_textbox(self.textbox_log, "\n".join(es_data), editable=True)
except Exception as error_msg:
CustomMessagebox(title=error_msg.__class__.__name__, label=RETURN_MESSAGES['unsuccessful_retrieval_of_es_data'], text=str(error_msg), geometry=self.messagebox_geometry)
finally:
self.hide_loading()
try:
self.refresh_index_and_fields()
except:
pass
def refresh_index_and_fields(self):
self.get_indicies()
self.get_fields()
self.index_autocomplete_callback()
self.es_field_autocomplete_callback()
def get_indicies(self):
response = es_funcs.get_request_elastic(url='http://{}:{}/_cat/indices?format=json&pretty=true'.format(self.es_hostname,self.es_port),
credentials=self.es_auth,
cert=self.es_cert,
api_key=self.es_api_key).json()
self.es_indicies = self.retrieve_available_indicies(response)
if not self.es_indicies:
raise ValueError(RETURN_MESSAGES["unsuccessful_retrieval_of_index"])
def get_fields(self):
self.es_fields = []
for index in self.es_indicies:
response = es_funcs.get_request_elastic(url='http://{}:{}/{}/_mapping'.format(self.es_hostname, self.es_port, index),
credentials=self.es_auth,
cert=self.es_cert,
api_key=self.es_api_key)
fields = response.json()[index]['mappings']['properties']
field_list = es_funcs.get_field_names(fields)
if field_list:
for field in field_list:
if field not in self.es_fields:
self.es_fields.append(field)
if not self.es_fields:
raise ConnectionError(RETURN_MESSAGES["unsuccessful_retrieval_of_field"])
def retrieve_available_indicies(self, response: dict):
return set(index_nr['index'] for index_nr in response if index_nr['status'] == "open" and index_nr['health'] != "red")
def export_patterns(self):
if self.pattern_table_is_populated():
patterns = self.get_patterns()
filename = customtkinter.filedialog.asksaveasfilename()
if filename:
try:
with open(filename, "wt") as patfile:
for pattern in patterns:
patfile.write("{} {}\n".format(pattern, patterns[pattern]))
patfile.flush()
patfile.close()
CustomMessagebox(title="Export", label=RETURN_MESSAGES["successful_pattern_export"], geometry=self.messagebox_geometry)
except Exception as error_msg:
CustomMessagebox(title=error_msg.__class__.__name__, label=RETURN_MESSAGES["invalid_export_dest"], text=str(error_msg), geometry=self.messagebox_geometry)
else:
CustomMessagebox(title="Export", label=RETURN_MESSAGES["no_patterns_for_export"], geometry=self.messagebox_geometry)
def add_pattern_to_table(self):
regex = self.regexp_entry.get().strip()
if len(regex) > 0:
if not self.showing_patterns_frame:
self.toggle_patterns_frame()
pattern_name = "{}-{}".format(app_title.upper(),self.created_patterns)
self.patterns_sheet.insert_row(values = (pattern_name,regex), idx = 0,redraw = True)
self.created_patterns += 1
def delete_pattern_from_table(self, object: object):
self.filter_list = object.delete_pattern(self.filter_list)
def toggle_bg_highlight(self):
self.bg_highlight = not self.bg_highlight
if self.bg_highlight:
self.textbox_log.tag_config("match", background=highlight_bg_color)
else:
self.textbox_log.tag_config("match", background="")
def toggle_auto_match(self):
self.auto_match = not self.auto_match
if self.auto_match:
self.match_entry_button.grid_forget()
else:
self.match_entry_button.grid(row=0, column=14, padx=(5,5), pady=(5,5), sticky="we")
def get_filtered_patterns(self, converted_patterns: dict) -> list:
all_patterns = [pattern for pattern in converted_patterns]
if self.include:
return self.include
elif self.exclude:
for excluded_pattern in self.exclude:
all_patterns.remove(excluded_pattern)
return all_patterns
def clear_filters(self):
for list in self.filter_list:
list.clear()
self.update_textbox(self.filter_box, "", editable=False)
def highlight_callback(self, *_args: any):
if self.auto_match:
self.textbox_log.highlight_pattern(pattern=self.regexp_entry.get())
else:
self.textbox_log.clean_highlights(tag="match")
def index_autocomplete_callback(self, *_args: any):
search_str=self.es_index_combobox.get()
matching_index=[]
for index in self.es_indicies:
if(re.match(search_str,index,re.IGNORECASE)):
matching_index.append(index)
self.es_index_combobox.configure(values=matching_index[:maximum_matched_fields])
def es_field_autocomplete_callback(self, *_args: any):
search_str=self.es_field_combobox.get()
matching_fields=[]
for field in self.es_fields:
if(re.match(search_str,field,re.IGNORECASE)):
matching_fields.append(field)
self.es_field_combobox.configure(values=matching_fields[:maximum_matched_fields])
def json_field_autocomplete_callback(self, *_args: any):
search_str=self.json_field_combobox.get()
matching_fields=[]
for field in self.json_fields:
if(re.match(search_str,field,re.IGNORECASE)):
matching_fields.append(field)
self.json_field_combobox.configure(values=matching_fields[:maximum_matched_fields])
def highlight(self):
self.textbox_log.highlight_pattern(pattern=self.regexp_entry.get())
def pattern_filter(self, object: object, pattern_filter_list: list, filter_type: str):
pattern_filter_list = object.get_patterns(pattern_filter_list)
if filter_type == "exclude":
box_icon=self.exclude_sign
self.include.clear()
elif filter_type == "include":
box_icon=self.include_sign
self.exclude.clear()
self.update_textbox(self.filter_box, "", editable=False)
message = "{} ".format(box_icon)+"\n{} ".format(box_icon).join(pattern_filter_list)
self.update_textbox(self.filter_box, message, editable=False)
def change_appearance_main_color(self):
if self.main_color == "light":
self.main_color = "dark"
else:
self.main_color = "light"
self.switch_main_appearance.configure(text=self.get_color_switch_label())
self.update_color_scheme()
def update_color_scheme(self):
customtkinter.set_appearance_mode(self.main_color)
for object in self.table_list:
if self.main_color == "dark":
object.update_design(self.fg_dark_color,
self.dark_text_color,
self.border_dark_color,
self.dark_text_color)
else:
object.update_design(self.fg_light_color,
self.light_text_color,
self.border_light_color,
self.light_text_color)
def create_regex_help_msgbox(self):
if self.main_color == "dark":
RegexHelpMessagebox(mode=self.main_color,
theme=self.sub_color,
first_color=self.fg_dark_color,
second_color=self.dark_text_color,
third_color=self.border_dark_color,
text_color=self.dark_text_color)
else:
RegexHelpMessagebox(mode=self.main_color,
theme=self.sub_color,
first_color=self.fg_light_color,
second_color=self.light_text_color,
third_color=self.border_light_color,
text_color=self.light_text_color)
def get_color_switch_label(self) -> str:
return self.main_color.capitalize() + " Mode"
def read_patterns(self):
patternsfile = customtkinter.filedialog.askopenfilename(title="Please select a pattern file")
if patternsfile:
try:
self.pattern_file_raw = self.read_textfile(patternsfile)
self.extracted_patterns = other_funcs.extract_patterns(self.pattern_file_raw)
except Exception as error_msg:
CustomMessagebox(title=error_msg.__class__.__name__, label=RETURN_MESSAGES["unsuccessful_grok_file_load"], text=str(error_msg), geometry=self.messagebox_geometry)
table_format_patterns = other_funcs.get_pattern_table_format(self.extracted_patterns)
self.patterns_sheet.set_sheet_data(data=table_format_patterns)
if not self.showing_patterns_frame:
self.toggle_patterns_frame()
def read_json(self):
jsonfile = customtkinter.filedialog.askopenfilename(title="Please select a json file")
if jsonfile:
try: