-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
959 lines (938 loc) · 51.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
# -*- coding: utf-8 -*-
# Written by Rune Johannesen, (c)2021-2023
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from tkinter.filedialog import askopenfilename
from PIL import Image, ImageTk
from os.path import splitext, basename, dirname, realpath, join, exists
from os import getcwd, chdir, mkdir
from subprocess import Popen
from threading import Thread
from Configurator_Object import Configurator
from sys import version_info, platform
from asyncio import set_event_loop, set_event_loop_policy, get_event_loop, sleep, gather
from re import search, findall
from itertools import chain
from datetime import datetime
from concurrent.futures import ThreadPoolExecutor
from ScrollableFrame import ScrollableFrame
from CredentialHandler import CredentialHandler
class Main(ttk.Frame):
def __init__(self, parent):
if version_info[0] == 3 and version_info[1] >= 8 and platform.startswith('win'):
from asyncio import ProactorEventLoop, WindowsSelectorEventLoopPolicy
set_event_loop(ProactorEventLoop())
set_event_loop_policy(WindowsSelectorEventLoopPolicy())
super().__init__(parent)
self.place(x=0, y=0, relwidth=1, relheight=1)
self.loop = get_event_loop()
self.script_name: str = splitext(basename(__file__))[0]
self.script_dir: str = dirname(realpath(__file__))
self.current_dir: str = getcwd()
if self.current_dir != self.script_dir:
chdir(self.script_dir)
self.current_dir: str = self.script_dir
device_show_config: str = "SHOW_CONFIGURATIONS"
device_check_config: str = "CHECK_CONFIGURATIONS"
device_config: str = "DEVICE_CONFIGURATIONS"
self.show_config_dir: str = join(self.current_dir, device_show_config)
self.check_config_dir: str = join(self.current_dir, device_check_config)
self.device_config_dir: str = join(self.current_dir, device_config)
if not exists(self.show_config_dir):
mkdir(self.show_config_dir)
if not exists(self.check_config_dir):
mkdir(self.check_config_dir)
if not exists(self.device_config_dir):
mkdir(self.device_config_dir)
self.txt_file_icon: ImageTk.PhotoImage = ImageTk.PhotoImage(Image.open(join(self.current_dir, "txt-file-icon.png")).resize((15,15), Image.ANTIALIAS))
self.folder_file_icon: ImageTk.PhotoImage = ImageTk.PhotoImage(Image.open(join(self.current_dir, "folder-open-icon.png")).resize((15,15), Image.ANTIALIAS))
self.reload_file_icon: ImageTk.PhotoImage = ImageTk.PhotoImage(Image.open(join(self.current_dir, "reload-file-icon.png")).resize((20,20), Image.ANTIALIAS))
self.preview_folder: ImageTk.PhotoImage = ImageTk.PhotoImage(Image.open(join(self.current_dir, "folder-open-icon.png")).resize((20,20), Image.ANTIALIAS))
self.device_help: str = "devices.help"
self.show_check_help: str = "show_check.help"
self.global_config_help: str = "global_config.help"
self.port_config_help: str = "port.help"
self.about_help: str = "about.help"
self.help_help: str = "help.help"
self.shorten_int: dict = {"FastEthernet": "Fa", "GigabitEthernet": "Gi", "TwoGigabitEthernet": "Tw", "TenGigabitEthernet": "Te", "TwentyFiveGigE": "Twe", "FortyGigabitEthernet": "Fo", "HundredGigE": "Hu", "FourHundredGigE": "F", "Loopback": "Lo"}
self.devices: list = []
self.show_cmd: list = []
self.check_cmd: list = []
self.global_config: list = []
self.port_include: list = []
self.port_exclude: list = []
self.port_config: list = []
self.widgets: list = []
self.title_width: list = [20,40,84,10]
self.title_placement: list = [0.01,0.139,0.391,0.914]
self.credHandler = CredentialHandler(join(self.current_dir, "Configurator_GUI.db"))
self.create_menu()
self.create_main()
def menu_item_selected(self, action):
if action == "Exit": self.quit()
if action == "About": self.msgBox(self.about_help)
if action == "Help": self.msgBox(self.help_help)
def get_creds(self) -> None:
device_path, username, password = self.credHandler.load_creds()
if device_path and username and password:
self.reset_menu()
self.open_devices(loaded=device_path)
self.menu_username.delete(0,"end")
self.menu_username.insert(0,username)
self.menu_password.delete(0,"end")
self.menu_password.insert(0,password)
else: self.menu_error.set("No credential session found.")
def msgBox(self, filename: str) -> None:
win = ttk.Toplevel(title=filename, resizable=(False,False))
win.geometry("800x800")
win.position_center()
frame1 = ttk.Frame(master=win)
frame1.place(x=0, y=0, relwidth=1, relheight=1)
ttk.Button(frame1, text="OK", command=win.destroy).place(relx=0.939, rely=0.935)
v=ttk.Scrollbar(frame1, orient='vertical')
v.place(relx=0.989, rely=0.02, relheight=0.9)
textbox = ttk.Text(master=frame1, font='Calibri 14', wrap=WORD, yscrollcommand=v.set)
textbox.place(relx=0.015, rely=0.02, relheight=0.9, relwidth=0.974)
with open(join(self.current_dir, filename)) as msg:
textbox.insert(END,msg.read())
v.config(command=textbox.yview)
textbox.config(state='disabled')
def open_file(self, path: str) -> None:
if platform.startswith('win'):
from os import startfile
startfile(path)
else:
opener: str = "open" if platform == "darwin" else "xdg-open"
Popen([opener, path])
def open_devices(self, reload: bool = False, loaded: str = "") -> None:
if reload and ("\\" in self.device_path.get() or "/" in self.device_path.get()):
path: str = self.device_path.get()
if (self.device_reload_counter.get() % 2) == 0:
self.menu_device_reload.config(bootstyle='success')
else: self.menu_device_reload.config(bootstyle='info')
self.device_reload_counter.set(self.device_reload_counter.get()+1)
else:
if loaded: path: str = loaded
else: path: str = askopenfilename(title='Select Device list')
self.menu_device_reload.config(bootstyle='secondary')
if path:
self.devices: list = []
with open(path) as r:
self.devices: list = [[search(r"(^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", x.strip()).group(1)] for x in r.readlines() if x.strip() and search(r"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", x.strip())]
if self.devices:
self.device_path.set(path)
self.device_preview.set(", ".join([x for i,x in enumerate(chain(*self.devices)) if i <= 4]))
self.menu_device1.config(foreground='lime')
self.menu_device2.config(foreground="lime")
self.device_total.set(f"Total devices: {len(self.devices)}")
self.menu_check_btn.config(state='normal')
self.menu_device_reload.config(state='normal')
self.menu_device_preview.config(state='normal')
else:
path_file: str = path.split("/")[-1]
self.device_path.set(f"No devices found in file: {path_file}")
self.device_preview.set(f"No devices found in file: {path_file}")
self.menu_device_reload.config(state='disabled', bootstyle='secondary')
self.menu_device_preview.config(state='disabled')
self.menu_device1.config(foreground='orange')
self.menu_device2.config(foreground="orange")
else:
if not "\\" in self.device_path.get() and not "/" in self.device_path.get():
self.device_path.set("No device file selected yet.")
self.device_preview.set("No device file selected yet.")
self.device_total.set("Total devices: 0")
self.menu_device_reload.config(state='disabled', bootstyle='secondary')
self.menu_device_preview.config(state='disabled')
self.menu_device1.config(foreground='')
self.menu_device2.config(foreground='')
def open_show_check(self, reload: bool = False) -> None:
if reload and ("\\" in self.show_check_path.get() or "/" in self.show_check_path.get()):
path: str = self.show_check_path.get()
if (self.show_reload_counter.get() % 2) == 0:
self.menu_show_reload.config(bootstyle='success')
else: self.menu_show_reload.config(bootstyle='info')
self.show_reload_counter.set(self.show_reload_counter.get()+1)
else:
path: str = askopenfilename(title='Select Show/Check Commands list')
self.menu_show_reload.config(bootstyle='secondary')
if path:
self.show_cmd: list = []
self.check_cmd: list = []
with open(path) as r:
line: str = r.readline().strip()
while line:
if not line.strip() or line.startswith("#") or line.startswith("!"):
line: str = r.readline().strip()
continue
if line.lower() == ";; show ;;":
line: str = r.readline().strip()
while line:
if not line.strip() or line.startswith("#") or line.startswith("!"):
line: str = r.readline().strip()
continue
if line.lower() == ";; check ;;": break
self.show_cmd.append(line.strip())
line: str = r.readline().strip()
if line.lower() == ";; check ;;":
line: str = r.readline().strip()
while line:
if not line.strip() or line.startswith("#") or line.startswith("!"):
line: str = r.readline().strip()
continue
if line.lower() == ";; show ;;": break
self.check_cmd.append(line.strip())
line: str = r.readline().strip()
if line.lower() == ";; show ;;" or line.lower() == ";; check ;;":
continue
try: line: str = r.readline().strip()
except: break
if self.show_cmd or self.check_cmd:
if self.show_cmd: self.show_cmd = ["terminal length 0"]+self.show_cmd
self.show_check_path.set(path)
self.menu_show.config(foreground='lime')
self.menu_show_text.set("Task Enabled.")
self.menu_show_btn.config(state='normal')
self.menu_show_reload.config(state='normal')
self.menu_show_preview.config(state='normal')
self.menu_show_config.set(1)
else:
path_file: str = path.split("/")[-1]
self.show_check_path.set(f"No Show/Check commands (;; SHOW ;; or ;; CHECK ;;) found in file: {path_file}")
self.menu_show.config(foreground='orange')
self.menu_show_text.set("Task Disabled.")
self.menu_show_btn.config(state='disabled')
self.menu_show_reload.config(state='disabled', bootstyle='secondary')
self.menu_show_preview.config(state='disabled')
self.menu_show_config.set(0)
else:
if not "\\" in self.show_check_path.get() and not "/" in self.show_check_path.get():
self.show_check_path.set("No Show/Check commands file selected yet.")
self.menu_show_text.set("Task Disabled.")
self.menu_show_btn.config(state='disabled')
self.menu_show_reload.config(state='disabled', bootstyle='secondary')
self.menu_show_preview.config(state='disabled')
self.menu_show_config.set(0)
self.menu_show.config(foreground='')
def open_global(self, reload: bool = False) -> None:
if reload and ("\\" in self.global_path.get() or "/" in self.global_path.get()):
path: str = self.global_path.get()
if (self.global_reload_counter.get() % 2) == 0:
self.menu_global_reload.config(bootstyle='success')
else: self.menu_global_reload.config(bootstyle='info')
self.global_reload_counter.set(self.global_reload_counter.get()+1)
else:
path: str = askopenfilename(title='Select Global Configuration list')
self.menu_global_reload.config(bootstyle='secondary')
if path:
self.global_config: list = []
with open(path) as r:
self.global_config: list = [x.strip() for x in r.readlines() if x.strip() and not x.strip().startswith("#") and not x.strip().startswith("!")]
if self.global_config:
self.menu_check_config.set(1)
self.global_path.set(path)
self.menu_global.config(foreground='lime')
self.menu_global_text.set("Task Enabled.")
self.menu_global_btn.config(state='normal')
self.menu_global_reload.config(state='normal')
self.menu_global_preview.config(state='normal')
self.menu_global_config.set(1)
else:
path_file: str = path.split("/")[-1]
self.global_path.set(f"No Global Configurations found in file: {path_file}")
self.menu_global_text.set("Task Disabled.")
self.menu_global_btn.config(state='disabled')
self.menu_global_reload.config(state='disabled', bootstyle='secondary')
self.menu_global_preview.config(state='disabled')
self.menu_global_config.set(0)
self.menu_global.config(foreground='orange')
else:
if not "\\" in self.global_path.get() and not "/" in self.global_path.get():
self.global_path.set("No Global configuration file selected yet.")
self.menu_global_text.set("Task Disabled.")
self.menu_global_btn.config(state='disabled')
self.menu_global_reload.config(state='disabled', bootstyle='secondary')
self.menu_global_preview.config(state='disabled')
self.menu_global_config.set(0)
self.menu_global.config(foreground='')
def open_port(self, reload: bool = False) -> None:
if reload and ("\\" in self.port_path.get() or "/" in self.port_path.get()):
path: str = self.port_path.get()
if (self.port_reload_counter.get() % 2) == 0:
self.menu_port_reload.config(bootstyle='success')
else: self.menu_port_reload.config(bootstyle='info')
self.port_reload_counter.set(self.port_reload_counter.get()+1)
else:
path: str = askopenfilename(title='Select Port Configuration list')
self.menu_port_reload.config(bootstyle='secondary')
if path:
self.port_config: list = []
self.port_include: list = []
self.port_exclude: list = []
with open(path) as r:
if not ";; config ;;" in r.read().lower():
path_file: str = path.split("/")[-1]
self.port_path.set(f"No Port Configuration commands (;; CONFIG ;;) found in file: {path_file}")
self.menu_port_text.set("Task Disabled.")
self.menu_port_btn.config(state='disabled')
self.menu_port_reload.config(state='disabled', bootstyle='secondary')
self.menu_port_preview.config(state='disabled')
self.menu_port_config.set(0)
self.menu_port.config(foreground="orange")
return
else:
r.seek(0)
line: str = r.readline().strip()
while line:
if not line.strip() or line.startswith("#") or line.startswith("!"):
line: str = r.readline().strip()
continue
if line.lower() == ";; include ;;":
line: str = r.readline().strip()
while line:
if not line.strip() or line.startswith("#") or line.startswith("!"):
line: str = r.readline().strip()
continue
if line.lower() == ";; exclude ;;" or line.lower() == ";; config ;;":
break
self.port_include.append(line.strip())
line: str = r.readline().strip()
if line.lower() == ";; exclude ;;":
line: str = r.readline().strip()
while line:
if not line.strip() or line.startswith("#") or line.startswith("!"):
line: str = r.readline().strip()
continue
if line.lower() == ";; include ;;" or line.lower() == ";; config ;;":
break
self.port_exclude.append(line.strip())
line: str = r.readline().strip()
if line.lower() == ";; config ;;":
line: str = r.readline().strip()
while line:
if not line.strip() or line.startswith("#") or line.startswith("!"):
line: str = r.readline().strip()
continue
if line.lower() == ";; include ;;" or line.lower() == ";; exclude ;;":
break
self.port_config.append(line.strip())
line: str = r.readline().strip()
if line.lower() == ";; include ;;" or line.lower() == ";; exclude ;;" or line.lower() == ";; config ;;":
continue
try: line: str = r.readline().strip()
except: break
if self.port_config:
self.menu_check_config.set(1)
self.port_path.set(path)
self.menu_port.config(foreground="lime")
self.menu_port_text.set("Task Enabled.")
self.menu_port_btn.config(state='normal')
self.menu_port_reload.config(state='normal')
self.menu_port_preview.config(state='normal')
self.menu_port_config.set(1)
else:
path_file: str = path.split("/")[-1]
self.port_path.set(f"No Port Configuration commands found in file: {path_file}")
self.menu_port_text.set("Task Disabled.")
self.menu_port_btn.config(state='disabled')
self.menu_port_reload.config(state='disabled', bootstyle='secondary')
self.menu_port_preview.config(state='disabled')
self.menu_port_config.set(0)
self.menu_port.config(foreground="orange")
else:
if not "\\" in self.port_path.get() and not "/" in self.port_path.get():
self.menu_port_text.set("Task Disabled.")
self.menu_port_btn.config(state='disabled')
self.menu_port_reload.config(state='disabled', bootstyle='secondary')
self.menu_port_preview.config(state='disabled')
self.menu_port_config.set(0)
self.port_path.set("No Port configuration file selected yet.")
def reset_menu(self) -> None:
self.menu_error.set("")
self.menu_username.delete(0,"end")
self.menu_username.insert(0,"Enter TACACS SSH credentials to use for logging into devices.")
self.menu_password.delete(0,"end")
self.devices: list = []
self.device_path.set("No device file selected yet.")
self.device_preview.set("No device file selected yet.")
self.device_total.set("Total devices: 0")
self.show_cmd: list = []
self.check_cmd: list = []
self.show_check_path.set("No Show/Check commands file selected yet.")
self.menu_show_text.set("Task Disabled.")
self.menu_show_btn.config(state='disabled')
self.menu_show_config.set(0)
self.menu_global_text.set("Task Disabled.")
self.menu_global_btn.config(state='disabled')
self.menu_global_config.set(0)
self.menu_device_reload.config(state='disabled', bootstyle='secondary')
self.menu_show_reload.config(state='disabled', bootstyle='secondary')
self.menu_global_reload.config(state='disabled', bootstyle='secondary')
self.menu_port_reload.config(state='disabled', bootstyle='secondary')
self.menu_port_text.set("Task Disabled.")
self.menu_port_btn.config(state='disabled')
self.menu_port_config.set(0)
self.global_config: list = []
self.global_path.set("No Global configuration file selected yet.")
self.port_config: list = []
self.port_include: list = []
self.port_exclude: list = []
self.port_path.set("No Port configuration file selected yet.")
self.menu_port.config(foreground="")
self.menu_device1.config(foreground="")
self.menu_device2.config(foreground="")
self.menu_show.config(foreground="")
self.menu_global.config(foreground="")
self.menu_error_label.config(foreground="orange")
self.menu_check_btn.config(state='disabled')
self.menu_check_config.set(0)
self.menu_device_preview.config(state='disabled')
self.menu_show_preview.config(state='disabled')
self.menu_global_preview.config(state='disabled')
self.menu_port_preview.config(state='disabled')
def build_save_results(self, frame: ttk.Frame, results: list) -> None:
def place_objects(frame: ttk.Frame, entry: list, style: str, row: float) -> None:
error: str = ""
for i, value in enumerate(entry):
if isinstance(value, list):
if not any("Error" in x for x in value):
_ = ttk.Label(frame, text="OK", bootstyle=style, width=self.title_width[i], font='Calibri 11', foreground='lime')
else:
for err in value:
if search(r"Error:\s.+?(\s\[ SKIPPED \]|\n|$)", err):
error: str = search(r"Error:\s(.+?)(\s\[ SKIPPED \]|\n|$)", err).group(1)
_ = ttk.Label(frame, text=error, bootstyle=style, width=self.title_width[i], font='Calibri 11', foreground='orange')
break
else: _ = ttk.Label(frame, text="FAILED", bootstyle=style, width=self.title_width[i], font='Calibri 11', foreground='orange')
else:
_ = ttk.Label(frame, text=value, bootstyle=style, width=self.title_width[i], font='Calibri 11')
self.widgets.append(_)
_.place(relx=self.title_placement[i], rely=row)
row: float = 0.05
for index, entry in enumerate(["IP Address","Hostname","Write Memory Status"]):
_ = ttk.Label(frame, text=entry, bootstyle="inverse-secondary", width=self.title_width[index], font='Calibri 11 bold')
self.widgets.append(_)
_.place(relx=self.title_placement[index], rely=row)
for index, entry in enumerate(results):
row += 0.0255
if (index % 2) == 0:
place_objects(frame, entry, "inverse-secondary", row)
else:
place_objects(frame, entry, "inverse-dark", row)
def build_show_results(self, frame: ttk.Frame, results: list) -> None:
def place_objects(frame: ttk.Frame, entry: list, style: str, row: float) -> None:
error: str = ""
for i, value in enumerate(entry):
if isinstance(value, list):
if not any("Error" in x for x in value):
_ = ttk.Label(frame, text="OK", bootstyle=style, width=self.title_width[i], font='Calibri 11', foreground='lime')
else:
for err in value:
if search(r"Error:\s.+?(\s\[ SKIPPED \]|\n|$)", err):
error: str = search(r"Error:\s(.+?)(\s\[ SKIPPED \]|\n|$)", err).group(1)
_ = ttk.Label(frame, text=error, bootstyle=style, width=self.title_width[i], font='Calibri 11', foreground='orange')
break
else: _ = ttk.Label(frame, text="FAILED", bootstyle=style, width=self.title_width[i], font='Calibri 11', foreground='orange')
else:
if "\\" in r"%r" % value or "/" in value:
_ = ttk.Button(frame, image=self.txt_file_icon, compound='top', bootstyle='secondary-outline', padding=0, command=lambda j=value: self.open_file(j))
self.widgets.append(_)
_.place(relx=self.title_placement[i], rely=row, height=20, width=35)
_ = ttk.Button(frame, image=self.folder_file_icon, compound='top', bootstyle='secondary-outline', padding=0, command=lambda: self.open_file(self.show_config_dir))
self.widgets.append(_)
_.place(relx=self.title_placement[i]+0.033, rely=row, height=20, width=35)
continue
else: _ = ttk.Label(frame, text=value, bootstyle=style, width=self.title_width[i], font='Calibri 11')
self.widgets.append(_)
_.place(relx=self.title_placement[i], rely=row)
row: float = 0.05
for index, entry in enumerate(["IP Address","Hostname","Command Status","Actions"]):
_ = ttk.Label(frame, text=entry, bootstyle="inverse-secondary", width=self.title_width[index], font='Calibri 11 bold')
if entry == "Actions": _ = ttk.Label(frame, text=entry, bootstyle="inverse-secondary", width=self.title_width[index], font='Calibri 11 bold', anchor='center')
self.widgets.append(_)
_.place(relx=self.title_placement[index], rely=row)
for index, entry in enumerate(results):
row += 0.0255
if (index % 2) == 0:
place_objects(frame, entry, "inverse-secondary", row)
else:
place_objects(frame, entry, "inverse-dark", row)
def build_device_results(self, frame: ttk.Frame, reload_start: list, scp_ena: list, scp_transfer: list, copy: list, scp_dis: list, reload_cancel: list, results: list) -> None:
def place_objects(frame: ttk.Frame, entry: list, style: str, row: float, title_width: list, title_placement: list, subjects: list, sub_results: list) -> None:
error: str = ""
if not any("Error" in x for x in entry[2]):
_ = ttk.Label(frame, text=entry[0], bootstyle=style, width=title_width[0], font='Calibri 10')
self.widgets.append(_)
_.place(relx=title_placement[0], rely=row)
_ = ttk.Label(frame, text=entry[1].rstrip("#"), bootstyle=style, width=title_width[1], font='Calibri 10')
self.widgets.append(_)
_.place(relx=title_placement[1], rely=row)
for i in range(len(subjects)):
if i > 1:
for data in sub_results[i]:
if entry[0] == data[0]:
if not any("Error" in x for x in data[2]):
if i == 4:
flash: str = data[2].split(":")[1] if ":" in data[2] else data[2]
_ = ttk.Label(frame, text=flash, bootstyle=style, width=title_width[i], font='Calibri 10', foreground='lime')
else: _ = ttk.Label(frame, text="OK", bootstyle=style, width=title_width[i], font='Calibri 10', foreground='lime')
self.widgets.append(_)
_.place(relx=title_placement[i], rely=row)
break
else:
if i == 4:
flash: str = data[2].split(":")[1] if ":" in data[2] else data[2]
_ = ttk.Label(frame, text=flash, bootstyle=style, width=title_width[i], font='Calibri 10', foreground='orange')
else: _ = ttk.Label(frame, text="FAILED", bootstyle=style, width=title_width[i], font='Calibri 10', foreground='orange')
self.widgets.append(_)
_.place(relx=title_placement[i], rely=row)
else:
_ = ttk.Label(frame, text=entry[0], bootstyle=style, width=title_width[0], font='Calibri 10')
self.widgets.append(_)
_.place(relx=title_placement[0], rely=row)
for err in entry[2]:
if search(r"Error:\s.+?(\s\[ SKIPPED \]|\n|$)", err):
error: str = search(r"Error:\s(.+?)(\s\[ SKIPPED \]|\n|$)", err).group(1)
_ = ttk.Label(frame, text=error, bootstyle=style, width=136, font='Calibri 10', foreground='orange')
break
else: _ = ttk.Label(frame, text="FAILED", bootstyle=style, width=136, font='Calibri 10', foreground='orange')
self.widgets.append(_)
_.place(relx=title_placement[1], rely=row)
sub_results: list = [None, None, reload_start, scp_ena, scp_transfer, copy, scp_dis, reload_cancel]
row: float = 0.05
title_width: list = [20,30,16,10,35,15,11,13]
title_placement: list = [0.01,0.139,0.3295,0.434,0.502,0.7235,0.822,0.8955]
subjects: list = ["IP Address","Hostname","Reload in 30 Mins","SCP Enable","SCP Transfer","Config->Running","SCP Disable","Reload Cancel"]
for index, entry in enumerate(subjects):
_ = ttk.Label(frame, text=entry, bootstyle="inverse-secondary", width=title_width[index], font='Calibri 10 bold')
self.widgets.append(_)
_.place(relx=title_placement[index], rely=row)
btn1 = ttk.Button(frame, text='Open Device Config', bootstyle="success", command=lambda: self.open_file(self.device_config_dir))
btn1.place(relx=0.85, rely=0.95)
self.widgets.append(btn1)
for index, entry in enumerate(results):
row += 0.0235
if (index % 2) == 0:
place_objects(frame, entry, "inverse-secondary", row, title_width, title_placement, subjects, sub_results)
else:
place_objects(frame, entry, "inverse-dark", row, title_width, title_placement, subjects, sub_results)
def build_check_results(self, frame: ttk.Frame, results: list) -> None:
def place_objects(frame: ttk.Treeview, results: list) -> None:
for result in results:
commands: tuple = tuple(["OK" if "OK" in x else "NOT FOUND" if "NOT FOUND" in x else x for x in result[2]])
frame.insert('', END, values=(result[0], result[1])+commands, )
self.widgets.append(frame)
columns: tuple = ("IP_Address","Hostname")+tuple([x.replace(" ","_") for x in self.check_cmd])
my_tree = ttk.Treeview(frame, style='primary.Treeview', columns=columns, show='headings')
my_tree.place(relx=0.01, rely=0.05, width=1105, height=848)
my_scroll = ttk.Scrollbar(frame, orient=HORIZONTAL, command=my_tree.xview)
my_scroll.place(relx=0.01, rely=0.98, height=22, width=1105)
self.widgets.append(my_scroll)
my_tree.configure(xscrollcommand=my_scroll.set)
for index, column in enumerate(columns):
my_tree.heading(column, text=column.replace("_", " "), anchor='w')
if index == 0: my_tree.column(column, minwidth=0, width=105, anchor='w', stretch=False)
elif index == 1: my_tree.column(column, minwidth=0, width=150, anchor='w', stretch=False)
else: my_tree.column(column, minwidth=0, anchor='w', stretch=False)
file_path: str = results[0][-1]
btn1 = ttk.Button(frame, text='Open CSV', bootstyle="success", command=lambda: self.open_file(file_path))
btn1.place(relx=0.913, rely=0.94)
self.widgets.append(btn1)
btn2 = ttk.Button(frame, text='Open Dir', bootstyle="success", command=lambda: self.open_file(self.check_config_dir))
btn2.place(relx=0.83, rely=0.94)
self.widgets.append(btn2)
place_objects(my_tree, results)
async def save_files(self, results: list, operation: str = "show") -> list:
def normalizefilename(fn: str) -> str:
validchars: str = "-_.() "
out: str = ""
for c in fn:
if str.isalpha(c) or str.isdigit(c) or (c in validchars):
out += c
return out
returnResults: list = []
today: str = datetime.now().strftime("%d-%m-%Y_%H-%M")
try:
with ThreadPoolExecutor() as executor:
if operation == "check":
filename: str = f"Check_Configurations_{today}.csv"
with open(join(self.check_config_dir, filename), "w") as w:
for device in results:
cmd_found: list = []
cmd_gui: list = []
if not "Error" in device[2][0]:
show_run: str = device[2][0].replace("show run","").strip()
interfaces: list = findall(r"(interface [A-Z].+[\S\n ]+?!)", show_run)
for check in self.check_cmd:
tmpint: list = []
found: bool = False
for interface in interfaces:
if check.lower() in interface.lower():
i: str = interface.splitlines()[0].split(" ")[1]
for key, value in self.shorten_int.items():
if i.startswith(key):
i: str = i.replace(key,value)
tmpint.append(i)
if tmpint:
tmpstr: str = ",".join(tmpint)
cmd_found.append(f"OK ({tmpstr})")
cmd_gui.append(f"OK ({tmpstr})")
continue
for line in show_run.splitlines():
if check.lower() in line.lower():
cmd_found.append(f"OK ({line.strip()})")
found: bool = True
for line in show_run.splitlines():
if check.lower() in line.lower():
cmd_gui.append(f"OK ({line.strip()})")
break
if not found:
cmd_found.append(f"NOT FOUND ({check})")
cmd_gui.append(f"NOT FOUND ({check})")
else: cmd_found.append(search(r"Error:\s(.+?)(\s\[ SKIPPED \]|\n|$)", device[2][0]).group(1))
await self.loop.run_in_executor(executor, w.write, f"{device[0]};{device[1].rstrip('#')};{';'.join(cmd_found)}\n")
if len(cmd_found) > len(self.check_cmd):
returnResults.append([device[0], device[1].rstrip("#"), cmd_gui, join(self.check_config_dir, filename)])
else: returnResults.append([device[0], device[1].rstrip("#"), cmd_found, join(self.check_config_dir, filename)])
else:
for device in results:
filename: str = f"{device[0]}_{normalizefilename(device[1])}_{today}.txt"
with open(join(self.show_config_dir, filename), "w") as w:
for command in device[2]:
await self.loop.run_in_executor(executor, w.write, f"{command}\n\n")
returnResults.append([device[0], device[1].rstrip("#"), device[2], join(self.show_config_dir, filename)])
except Exception as e:
self.menu_error_label.config(foreground='orange')
self.menu_error.set(f"Program Exception: {e}")
return(returnResults)
async def create_device_configurations(self, config_prechecks: list) -> tuple:
scp_transfer: list = []; scp_ena: list = []; scp_dis: list = []; copy: list = []; reload_start: list = []; reload_cancel: list = []
today: str = datetime.now().strftime("%d-%m-%Y_%H-%M")
with ThreadPoolExecutor() as executor:
for device in config_prechecks:
if any("Error" in x for x in device[2]):
continue
show_run: str = ""; flash: str = ""
enableScp: list = []; disableScp: list = []; interfaces: list = []; interfacelist: list = []
for config in device[2]:
if "show run" in config:
show_run: str = config.replace("show run","").strip()
elif "dir all-filesystems" in config:
flash: str = config.replace("dir all-filesystems | in (Directory of flash|Directory of bootflash)","").strip().splitlines()[0].split(" ")[-1].replace("/","")
if "ip scp server enable" not in show_run:
enableScp: list = ["conf t", "ip scp server enable", "end"]
disableScp: list = ["conf t", "no ip scp server enable", "end"]
interfaces: list = findall(r"(interface G.+[\S\n ]+?!|interface F.+[\S\n ]+?!|interface T.+[\S\n ]+?!|interface H.+[\S\n ]+?!)", show_run)
if self.port_include:
interfacelist: list = [x for x in interfaces if any(y.lower() in x.lower() for y in self.port_include)]
if self.port_exclude:
if interfacelist: interfacelist: list = [x for x in interfacelist if not any(y.lower() in x.lower() for y in self.port_exclude)]
else: interfacelist: list = [x for x in interfaces if not any(y.lower() in x.lower() for y in self.port_exclude)]
if not interfacelist:
interfacelist: list = interfaces
filename: str = f"{device[0]}_{today}.cfg"
flash_copy: str = f"copy {flash}{filename} running-config\n\n"
with open(join(self.device_config_dir, filename), "w") as w:
if self.menu_global_config.get():
if self.global_config:
for globalcfg in self.global_config:
await self.loop.run_in_executor(executor, w.write, f"{globalcfg}\n")
if self.menu_port_config.get():
if self.port_config:
for interface in interfacelist:
if any(";; default ;;" in x.lower() for x in self.port_config):
await self.loop.run_in_executor(executor, w.write, f"default {interface.splitlines()[0]}\n")
await self.loop.run_in_executor(executor, w.write, f"{interface.splitlines()[0]}\n")
for portcfg in self.port_config:
if portcfg.lower() != ";; default ;;":
await self.loop.run_in_executor(executor, w.write, f"{portcfg}\n")
await self.loop.run_in_executor(executor, w.write, f"end")
with open(join(self.device_config_dir, f"{device[0]}_{today}_backup.cfg"), "w") as w:
await self.loop.run_in_executor(executor, w.write, show_run)
reload_start.append([device[0], ["reload in 30\ny\n\n"]])
scp_transfer.append([device[0], join(self.device_config_dir, filename), flash+filename])
copy.append([device[0], [flash_copy]])
reload_cancel.append([device[0], ["reload cancel\n\n"]])
if enableScp:
scp_ena.append([device[0], enableScp])
scp_dis.append([device[0], disableScp])
return(reload_start, scp_ena, scp_transfer, copy, scp_dis, reload_cancel)
async def do_work(self) -> None:
self.menu_error_label.config(foreground='lime')
Config = Configurator(self.menu_username.get(), self.menu_password.get())
show_results: list = []
check_results: list = []
run: bool = False
sleep_time: float = 1.5
if self.menu_show_config.get():
if self.show_cmd and self.check_cmd:
self.menu_error.set("Show & Check Commands: Execution started...")
show_results, check_results = await gather(Config.InitiateExecution(self.devices, self.show_cmd), Config.InitiateExecution(self.devices, ["terminal length 0", "show run"]),)
self.menu_error.set("Show & Check Commands: Execution completed!")
run: bool = True
if self.show_cmd:
if not show_results:
self.menu_error.set("Show Commands: Execution started...")
show_results: list = await Config.InitiateExecution(self.devices, self.show_cmd)
self.menu_error.set("Show Commands: Execution completed!")
run: bool = True
if show_results:
save_show_results: list = await self.save_files(show_results)
self.main_show_config.set("Show Configurations:")
self.build_show_results(self.main_show, save_show_results)
else:
self.main_show_label.config(foreground='orange')
self.main_show_config.set(f"No results returned or operation failed, check the logs under: {self.current_dir}")
if self.check_cmd:
if not check_results:
self.menu_error.set("Check Commands: Execution started...")
check_results: list = await Config.InitiateExecution(self.devices, ["terminal length 0", "show run"])
self.menu_error.set("Check Commands: Execution completed!")
run: bool = True
if check_results:
save_check_results: list = await self.save_files(check_results, "check")
self.main_check_config.set("Check Configurations:")
self.build_check_results(self.main_check, save_check_results)
else:
self.main_check_label.config(foreground='orange')
self.main_check_config.set(f"No results returned or operation failed, check the logs under: {self.current_dir}")
if self.menu_global_config.get() or self.menu_port_config.get():
if not self.menu_global_config.get():
self.menu_error.set("Global Task disabled, skipping...")
await sleep(sleep_time)
elif not self.menu_port_config.get():
self.menu_error.set("Port Task disabled, skipping...")
await sleep(sleep_time)
if self.global_config or self.port_config:
self.menu_error.set("Device configurations started...")
scp_ena_result: list = []; scp_dis_result: list = []
if run: await sleep(sleep_time)
self.config_prechecks: list = await Config.InitiateExecution(self.devices, ["terminal length 0", "show run", "dir all-filesystems | in (Directory of flash|Directory of bootflash)"])
reload_start, scp_ena, scp_transfer, copy, scp_dis, reload_cancel = await self.create_device_configurations(self.config_prechecks)
await sleep(sleep_time)
self.menu_error.set("Device configurations: setting reload in 30 mins...")
reload_start_result: list = await Config.InitiateExecution(reload_start)
if scp_ena:
await sleep(sleep_time)
self.menu_error.set(f"Device configurations: enabling SCP transfer...")
scp_ena_result: list = await Config.InitiateExecution(scp_ena)
await sleep(sleep_time)
self.menu_error.set("Device configurations: Starting SCP transfers...")
scp_transfer_result: list = await Config.InitiateScpTransfer(scp_transfer)
await sleep(sleep_time)
self.menu_error.set("Device configurations: copying config to running-config...")
copy_result: list = await Config.InitiateExecution(copy)
if scp_dis:
await sleep(sleep_time)
self.menu_error.set(f"Device configurations: disabling SCP transfer...")
scp_dis_result: list = await Config.InitiateExecution(scp_dis)
await sleep(sleep_time)
self.menu_error.set("Device configurations: cancelling reloads...")
reload_cancel_result: list = await Config.InitiateExecution(reload_cancel)
self.menu_error.set("Device configurations completed!")
run: bool = True
self.main_global_config.set("Device Configurations:")
self.build_device_results(self.main_global, reload_start_result, scp_ena_result, scp_transfer_result, copy_result, scp_dis_result, reload_cancel_result, self.config_prechecks)
if self.menu_check_config.get():
if run: await sleep(sleep_time)
self.menu_error.set("Saving configurations (write memory) started...")
write_mem: list = await Config.InitiateExecution(self.devices, ["write memory"])
self.menu_error.set("Saving configurations (write memory) completed!")
if write_mem:
self.main_save_config.set("Save Configurations Status:")
self.build_save_results(self.main_save, write_mem)
else:
self.main_save_label.config(foreground='orange')
self.main_save_config.set(f"No results returned or operation failed, check the logs under: {self.current_dir}")
await sleep(sleep_time)
self.menu_error.set("")
self.menu_error_label.config(foreground='orange')
def _asyncio_thread(self) -> None:
self.loop.run_until_complete(self.do_work())
def do_tasks(self) -> None:
show: bool = False
if not self.devices or self.menu_username.get() == "Enter TACACS SSH credentials to use for logging into devices." or not self.menu_password.get():
self.menu_error.set("You must select devices, enter username and password and at least select one configuration option.")
return
if self.show_cmd or self.check_cmd:
show: bool = True
if show or self.global_config or self.port_config or self.menu_check_config.get():
self.menu_error.set("")
if self.widgets:
for x in self.widgets:
x.destroy()
self.main_show_label.config(foreground='')
self.main_check_label.config(foreground='')
self.main_global_label.config(foreground='')
self.main_save_label.config(foreground='')
self.main_show_config.set("No Show Configurations to display.")
self.main_check_config.set("No Check Configurations to display.")
self.main_global_config.set("No Device Configurations to display.")
self.main_save_config.set("No Configurations have been saved yet.")
self.widgets: list = []
self.credHandler.save_creds(self.device_path.get(), self.menu_username.get(), self.menu_password.get())
Thread(target=self._asyncio_thread, name="tkinter_thread").start()
else:
self.menu_error.set("You must select at least one configuration option: Show/Check, Global or Port.")
def create_menu(self) -> None:
# Init Notebook
my_notebook = ttk.Notebook(self)
my_notebook.place(x=4, y=0, relwidth=0.395, relheight=0.994)
# Init menu Frame
menu_button = ttk.Menubutton(my_notebook, text='Menu', style='info.TMenubutton')
my_menu = ttk.Menu(menu_button)
for option in ('Help', 'About', 'Exit'):
my_menu.add_command(label=option, command=lambda j=option:self.menu_item_selected(j))
menu_button["menu"] = my_menu
menu_button.place(relx=0.0, rely=0.0)
menu = ttk.Frame(my_notebook)
# Devices
self.device_path = ttk.StringVar(value='No device file selected yet.')
self.device_preview = ttk.StringVar(value='No device file selected yet.')
self.device_total = ttk.StringVar(value='Total devices: 0')
ttk.Label(menu, text='Select devices to execute on:', font='Calibri 18 bold').place(relx=0.02, rely=0.02)
ttk.Label(menu, text='Loaded File:', font='Calibri 12').place(relx=0.02, rely=0.10)
self.menu_device_reload = ttk.Button(menu, image=self.reload_file_icon, compound='center', bootstyle='secondary-outline', padding=1, command=lambda: self.open_devices(reload=True), takefocus=0)
self.menu_device_reload.place(relx=0.27, rely=0.10)
self.menu_device_reload.config(state='disabled')
self.menu_device_preview = ttk.Button(menu, image=self.preview_folder, compound='center', bootstyle='secondary-outline', padding=1, command=lambda: self.open_file(self.device_path.get()), takefocus=0)
self.menu_device_preview.place(relx=0.225, rely=0.10)
self.menu_device_preview.config(state='disabled')
self.device_reload_counter = ttk.IntVar(value=0)
ttk.Label(menu, text='Device preview (First 5 devices):', font='Calibri 12').place(relx=0.02, rely=0.14)
ttk.Button(menu, text='Select Devices...', bootstyle="light", command=lambda:self.open_devices(), padding=2).place(relx=0.02, rely=0.06)
ttk.Button(menu, text='Device Help', bootstyle="light", command=lambda:self.msgBox(self.device_help), padding=2).place(relx=0.32, rely=0.06)
ttk.Label(menu, textvariable=self.device_total, font='Calibri 11').place(relx=0.80, rely=0.06)
self.menu_device1 = ttk.Entry(menu, state='readonly', textvariable=self.device_path)
self.menu_device1.place(relx=0.32, rely=0.10, relwidth=0.65)
self.menu_device2 = ttk.Entry(menu, state='readonly', textvariable=self.device_preview)
self.menu_device2.place(relx=0.32, rely=0.14, relwidth=0.65)
# Separator
ttk.Separator(menu).place(relx=0, rely=0.19, relwidth=1)
# TACACS
ttk.Label(menu, text='Enter TACACS Credentials to use:', font='Calibri 18 bold').place(relx=0.02, rely=0.20)
ttk.Label(menu, text='Username:', font='Calibri 12').place(relx=0.02, rely=0.25)
self.menu_username = ttk.Entry(menu)
self.menu_username.insert(0,"Enter TACACS SSH credentials to use for logging into devices.")
self.menu_username.bind("<FocusIn>", lambda event: self.menu_username.delete(0,"end") if self.menu_username.get() == "Enter TACACS SSH credentials to use for logging into devices." else None)
self.menu_username.bind("<FocusOut>", lambda event: self.menu_username.insert(0,"Enter TACACS SSH credentials to use for logging into devices.") if not self.menu_username.get() else None)
self.menu_username.place(relx=0.32, rely=0.25, relwidth=0.65)
ttk.Label(menu, text='Password:', font='Calibri 12').place(relx=0.02, rely=0.29)
self.menu_password = ttk.Entry(menu, show='*')
self.menu_password.place(relx=0.32, rely=0.29, relwidth=0.65)
# Separator
ttk.Separator(menu).place(relx=0, rely=0.34, relwidth=1)
# Show/Check config
self.show_check_path = ttk.StringVar(value='No Show/Check commands file selected yet.')
ttk.Label(menu, text='Show Configuration/Check Commands (Optional):', font='Calibri 18 bold').place(relx=0.02, rely=0.35)
self.menu_show_config = ttk.IntVar(value=0)
self.menu_show_text = ttk.StringVar(value="Task Disabled.")
self.menu_show_btn = ttk.Checkbutton(menu, textvariable=self.menu_show_text, style='Roundtoggle.Toolbutton', variable=self.menu_show_config, onvalue=1, offvalue=0)
self.menu_show_btn.place(relx=0.80, rely=0.35)
self.menu_show_btn.config(state='disabled')
ttk.Button(menu, text='Select Show/Check Commands...', bootstyle="light", command=lambda:self.open_show_check(), padding=2).place(relx=0.02, rely=0.39)
ttk.Button(menu, text='Show/Check Help', bootstyle="light", command=lambda:self.msgBox(self.show_check_help), padding=2).place(relx=0.32, rely=0.39)
ttk.Label(menu, text='Loaded File:', font='Calibri 12').place(relx=0.02, rely=0.43)
self.menu_show_reload = ttk.Button(menu, image=self.reload_file_icon, compound='center', bootstyle='secondary-outline', padding=1, command=lambda: self.open_show_check(reload=True), takefocus=0)
self.menu_show_reload.place(relx=0.27, rely=0.43)
self.menu_show_reload.config(state='disabled')
self.menu_show_preview = ttk.Button(menu, image=self.preview_folder, compound='center', bootstyle='secondary-outline', padding=1, command=lambda: self.open_file(self.show_check_path.get()), takefocus=0)
self.menu_show_preview.place(relx=0.225, rely=0.43)
self.menu_show_preview.config(state='disabled')
self.show_reload_counter = ttk.IntVar(value=0)
self.menu_show = ttk.Entry(menu, state='readonly', textvariable=self.show_check_path)
self.menu_show.place(relx=0.32, rely=0.43, relwidth=0.65)
# Separator
ttk.Separator(menu).place(relx=0, rely=0.48, relwidth=1)
# Global Configuration
self.global_path = ttk.StringVar(value='No Global configuration file selected yet.')
ttk.Label(menu, text='Global Configuration (Optional):', font='Calibri 18 bold').place(relx=0.02, rely=0.49)
self.menu_global_config = ttk.IntVar(value=0)
self.menu_global_text = ttk.StringVar(value="Task Disabled.")
self.menu_global_btn = ttk.Checkbutton(menu, textvariable=self.menu_global_text, style='Roundtoggle.Toolbutton', variable=self.menu_global_config, onvalue=1, offvalue=0)
self.menu_global_btn.place(relx=0.80, rely=0.49)
self.menu_global_btn.config(state='disabled')
ttk.Button(menu, text='Select Global Config...', bootstyle="light", command=lambda:self.open_global(), padding=2).place(relx=0.02, rely=0.53)
ttk.Button(menu, text='Global Config Help', bootstyle="light", command=lambda:self.msgBox(self.global_config_help), padding=2).place(relx=0.32, rely=0.53)
ttk.Label(menu, text='Loaded File:', font='Calibri 12').place(relx=0.02, rely=0.57)
self.menu_global_reload = ttk.Button(menu, image=self.reload_file_icon, compound='center', bootstyle='secondary-outline', padding=1, command=lambda: self.open_global(reload=True), takefocus=0)
self.menu_global_reload.place(relx=0.27, rely=0.57)
self.menu_global_reload.config(state='disabled')
self.menu_global_preview = ttk.Button(menu, image=self.preview_folder, compound='center', bootstyle='secondary-outline', padding=1, command=lambda: self.open_file(self.global_path.get()), takefocus=0)
self.menu_global_preview.place(relx=0.225, rely=0.57)
self.menu_global_preview.config(state='disabled')
self.global_reload_counter = ttk.IntVar(value=0)
self.menu_global = ttk.Entry(menu, state='readonly', textvariable=self.global_path)
self.menu_global.place(relx=0.32, rely=0.57, relwidth=0.65)
# Separator
ttk.Separator(menu).place(relx=0, rely=0.62, relwidth=1)
# Port Configuration
self.port_path = ttk.StringVar(value='No Port configuration file selected yet.')
ttk.Label(menu, text='Port Configuration (Optional):', font='Calibri 18 bold').place(relx=0.02, rely=0.63)
self.menu_port_config = ttk.IntVar(value=0)
self.menu_port_text = ttk.StringVar(value="Task Disabled.")
self.menu_port_btn = ttk.Checkbutton(menu, textvariable=self.menu_port_text, style='Roundtoggle.Toolbutton', variable=self.menu_port_config, onvalue=1, offvalue=0)
self.menu_port_btn.place(relx=0.80, rely=0.63)
self.menu_port_btn.config(state='disabled')
ttk.Button(menu, text='Select Port Config...', bootstyle="light", command=lambda:self.open_port(), padding=2).place(relx=0.02, rely=0.67)
ttk.Button(menu, text='Port Config Help', bootstyle="light", command=lambda:self.msgBox(self.port_config_help), padding=2).place(relx=0.32, rely=0.67)
ttk.Label(menu, text='Loaded File:', font='Calibri 12').place(relx=0.02, rely=0.71)
self.menu_port_reload = ttk.Button(menu, image=self.reload_file_icon, compound='center', bootstyle='secondary-outline', padding=1, command=lambda: self.open_port(reload=True), takefocus=0)
self.menu_port_reload.place(relx=0.27, rely=0.71)
self.menu_port_reload.config(state='disabled')
self.menu_port_preview = ttk.Button(menu, image=self.preview_folder, compound='center', bootstyle='secondary-outline', padding=1, command=lambda: self.open_file(self.port_path.get()), takefocus=0)
self.menu_port_preview.place(relx=0.225, rely=0.71)
self.menu_port_preview.config(state='disabled')
self.port_reload_counter = ttk.IntVar(value=0)
self.menu_port = ttk.Entry(menu, state='readonly', textvariable=self.port_path)
self.menu_port.place(relx=0.32, rely=0.71, relwidth=0.65)
# Separator
ttk.Separator(menu).place(relx=0, rely=0.76, relwidth=1)
# Load previous session
ttk.Label(menu, text='Load previous session (devices, username and password):', font='Calibri 12').place(relx=0.02, rely=0.77)
ttk.Button(menu, text='Load', bootstyle="success", command=lambda:self.get_creds()).place(relx=0.835, rely=0.77)
# Separator
ttk.Separator(menu).place(relx=0, rely=0.81, relwidth=1)
# Error messaging
self.menu_error = ttk.StringVar(value='')
self.menu_error_label = ttk.Label(menu, textvariable=self.menu_error, font='Calibri 12 bold', foreground='orange')
self.menu_error_label.place(relx=0.02, rely=0.87)
# Separator
ttk.Separator(menu).place(relx=0, rely=0.925, relwidth=1)
# Execute
self.menu_check_config = ttk.IntVar(value=0)
self.menu_check_btn = ttk.Checkbutton(menu, text='Save device configuration.', style='Roundtoggle.Toolbutton', variable=self.menu_check_config, onvalue=1, offvalue=0)
self.menu_check_btn.place(relx=0.02, rely=0.955)
self.menu_check_btn.config(state='disabled')
ttk.Button(menu, text='Reset Options', bootstyle="info", command=lambda:self.reset_menu()).place(relx=0.650, rely=0.945)
ttk.Button(menu, text='Start Execution', bootstyle="danger", command=lambda:self.do_tasks()).place(relx=0.835, rely=0.945)
# Add tabs
my_notebook.add(menu)
def create_main(self) -> None:
my_notebook = ttk.Notebook(self)
my_notebook.place(relx=0.4, y=0, relwidth=0.598, relheight=0.994)
# Init main Frame
self.main_show = ScrollableFrame(my_notebook)
self.main_check = ScrollableFrame(my_notebook)
self.main_global = ScrollableFrame(my_notebook)
self.main_save = ScrollableFrame(my_notebook)
# Show Config pane
self.main_show_config = ttk.StringVar(value='No Show Configurations to display.')
self.main_show_label = ttk.Label(self.main_show, textvariable=self.main_show_config, font='Calibri 14', wraplength=550)
self.main_show_label.place(relx=0.01, rely=0.01)
# Check Config pane
self.main_check_config = ttk.StringVar(value='No Check Configurations to display.')
self.main_check_label = ttk.Label(self.main_check, textvariable=self.main_check_config, font='Calibri 14', wraplength=550)
self.main_check_label.place(relx=0.01, rely=0.01)
# Device Config pane
self.main_global_config = ttk.StringVar(value='No Device Configurations to display.')
self.main_global_label = ttk.Label(self.main_global, textvariable=self.main_global_config, font='Calibri 14', wraplength=550)
self.main_global_label.place(relx=0.01, rely=0.01)
# Save Config pane
self.main_save_config = ttk.StringVar(value='No Configurations have been saved yet.')
self.main_save_label = ttk.Label(self.main_save, textvariable=self.main_save_config, font='Calibri 14', wraplength=550)
self.main_save_label.place(relx=0.01, rely=0.01)
# Add tabs
my_notebook.add(self.main_show, text="Show Config")
my_notebook.add(self.main_check, text="Check Config")
my_notebook.add(self.main_global, text="Device Config")
my_notebook.add(self.main_save, text="Save Config")