-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
2013 lines (1785 loc) · 105 KB
/
Copy pathmain.py
File metadata and controls
2013 lines (1785 loc) · 105 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
import os
import json
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
import threading
import time
import importlib
current_dir = os.path.dirname(os.path.abspath(__file__))
if current_dir not in sys.path:
sys.path.append(current_dir)
from config.config import config
from utils.rest_client import RestClient
from modules_optional.opt_group import OptGroup
from modules_optional.opt_context import OptContext
from modules_optional.opt_permgroup import OptPermGroup
from modules_optional.opt_siptrunk import OptSipTrunk
from modules_optional.opt_outboundrouting import OptOutboundRouting
from modules_optional.opt_inboundrouting import OptInboundRouting
from modules_optional.opt_calleridmanipulation import OptCallerIdManipulation
from modules_optional.opt_aclgroup import OptAclGroup
from modules_optional.opt_userprofile import OptUserProfile
from modules_optional.opt_user import OptUser
from modules_optional.opt_acluser import OptAclUser
from modules_optional.opt_numberstrip import OptNumberStrip
from modules_optional.opt_siptrunkstatus import OptSipTrunkStatus
from modules_optional.opt_callpickup import OptCallPickup
from modules_optional.opt_huntgroup import OptHuntGroup
from modules_optional.opt_voiceprompt import OptVoicePrompt
from modules_optional.opt_ivr import OptIVR
from modules_optional.opt_callforward import OptCallForward
from modules_optional.opt_agents import OptAgents
from modules_optional.opt_agentgroups import OptAgentGroups
from modules_optional.opt_queue import OptQueue
import styles as st
class DeltapathAutomator:
def _set_window_icon(self):
icon_path = os.path.join(current_dir, "resources", "app.ico")
if os.path.exists(icon_path):
try:
self.root.iconbitmap(icon_path)
except Exception:
try:
icon = tk.PhotoImage(file=icon_path)
self.root.iconphoto(False, icon)
except Exception:
pass
def __init__(self):
self.root = tk.Tk()
self.root.title("AnderOng Deltapath Automation (REST API)")
screen_h = self.root.winfo_screenheight()
req_h = 1000
if screen_h < req_h:
req_h = screen_h - 60
self.root.geometry(f"1400x{req_h}+50+10")
self.root.configure(bg=st.C["bg"])
self._set_window_icon()
self.stop_event = threading.Event()
self.pipeline_running = False
self.rest_client = None
self.last_session = self._load_last_session()
self.std_session = self._load_global_session("standard")
self.cplx_session = self._load_global_session("complex")
self.api_available = {
"task1_group": True,
"task2_context": True,
"task3_perm": True,
"task4_sip_trunk": True,
"task5_outbound_routing": True,
"task6_inbound_routing": True,
"task7_caller_id_manipulation": True,
"task8_acl_group": True,
"task9_user_profile": True,
"task10_user": True,
"task10b_user_htek": True,
"task11_acl_user": True,
"task12_number_strip": True,
"task12_number_strip": True,
}
self.task_definitions = [
("Group", "task1_group", "run_group_task"),
("Context", "task2_context", "run_context_task"),
("Permission Group", "task3_perm", "run_perm_task"),
("SIP Trunk", "task4_sip_trunk", "run_sip_task"),
("Outbound Routing", "task5_outbound_routing", "run_outbound_task"),
("Inbound Routing", "task6_inbound_routing", "run_inbound_task"),
("Caller ID Manipulation", "task7_caller_id_manipulation", "run_caller_id_task"),
("ACL Group", "task8_acl_group", "run_acl_task"),
("User Profile", "task9_user_profile", "run_profile_task"),
("User (Mobility Apps Only)", "task10_user", "run_user_task"),
("User (Htek Mac based Only)", "task10b_user_htek", "run_user_htek_task"),
("ACL User", "task11_acl_user", "run_acl_user_task"),
("Number (Strip Digits)", "task12_number_strip", "run_number_strip_task")
]
self.custom_ob_list = self.last_session.get("custom_ob_list", [])
self.custom_api_payloads = {}
self.api_json_samples = {
"Group": '{\n "code": "GROUP_CODE",\n "engName": "GROUP_NAME",\n "chiName": "",\n "email": "",\n "greeting": "",\n "instruction": "",\n "locationAddress": "",\n "locationName": "e",\n "staff_value": "",\n "customer_value": "",\n "maxConcurrentCalls": "10",\n "registerUserCount": "10",\n "CCAgentCount": "0",\n "OCCAgentCount": "0",\n "SFBAccountCount": "0",\n "PTTGroupCount": "0"\n}',
"Context (Auto suffix _Fixed,Internal,Mobile&IDD)": '[\n {"contextID": "PREFIX_Internal", "contextTitle": "PREFIX_Internal", "group": "CUSTOMER_ID", "contextDesc": ""},\n {"contextID": "PREFIX_Fixed", "contextTitle": "PREFIX_Fixed", "group": "CUSTOMER_ID", "contextDesc": ""},\n {"contextID": "PREFIX_Mobile", "contextTitle": "PREFIX_Mobile", "group": "CUSTOMER_ID", "contextDesc": ""},\n {"contextID": "PREFIX_IDD", "contextTitle": "PREFIX_IDD", "group": "CUSTOMER_ID", "contextDesc": ""}\n]\n\n// Use JSON array to define exactly which contexts to create (edit items above)\n// Use JSON object to merge extra fields into the default 4 contexts',
"Permission Group (Auto suffix _Class_1 to _Class_4)": '[\n {"contextTitle": "PREFIX_Class_1", "contextInclude_value": "PREFIX_Internal"},\n {"contextTitle": "PREFIX_Class_2", "contextInclude_value": "PREFIX_Internal,PREFIX_Fixed"},\n {"contextTitle": "PREFIX_Class_3", "contextInclude_value": "PREFIX_Internal,PREFIX_Fixed,PREFIX_Mobile"},\n {"contextTitle": "PREFIX_Class_4", "contextInclude_value": "PREFIX_Internal,PREFIX_Fixed,PREFIX_Mobile,PREFIX_IDD"}\n]\n\n// Use JSON array to define exactly which permission groups to create\n// Use JSON object to merge extra fields into the default 4 classes',
"SIP Trunk": '{\n "allowcodec_value": "alaw,ulaw,g729",\n "group": "CUSTOMER_ID",\n "peerID": "GROUP_NAME",\n "pronunciation": "GROUP_NAME",\n "host": "HOST_IP",\n "port": "PORT",\n "frsipPBX": "0",\n "main_protocol": "udp",\n "nat": "0",\n "inviteRequireAuth": "0",\n "password": "",\n "registration_extension": "",\n "registration_expires": "",\n "reg_server_option": "0",\n "call_restrict": "no",\n "context": "PREFIX_Class_1",\n "dtmfmode": "rfc2833",\n "copyCidNameToNum": "no",\n "routingMethod": "VoIP+PSTN",\n "fromdomain": "",\n "insecure": "invite",\n "allowsipinfo": "1",\n "canreinvite": "0",\n "promiscredir": "0"\n}',
"Outbound Routing (10 rules)": '[\n {"number": "_+60[2-9]X.", "context": "PREFIX_Fixed", "sippeer_value": "GROUP_NAME"},\n {"number": "_+601X.", "context": "PREFIX_Mobile", "sippeer_value": "GROUP_NAME"},\n {"number": "_+X.", "context": "PREFIX_IDD", "sippeer_value": "GROUP_NAME"},\n {"number": "_0[2-9]X.", "context": "PREFIX_Fixed", "sippeer_value": "GROUP_NAME"},\n {"number": "_00X.", "context": "PREFIX_IDD", "sippeer_value": "GROUP_NAME"},\n {"number": "_01X.", "context": "PREFIX_Mobile", "sippeer_value": "GROUP_NAME"},\n {"number": "_1300X.", "context": "PREFIX_Fixed", "sippeer_value": "GROUP_NAME"},\n {"number": "_1800X.", "context": "PREFIX_Fixed", "sippeer_value": "GROUP_NAME"},\n {"number": "_ZXX", "context": "PREFIX_Fixed", "sippeer_value": "GROUP_NAME"},\n {"number": "_ZXXXX", "context": "PREFIX_Fixed", "sippeer_value": "GROUP_NAME"}\n]\n\n// Use JSON array to define exactly which routing rules to create\n// Use JSON object to merge extra fields into the default 10 rules',
"Inbound Routing": '{\n "peerID_value": "GROUP_NAME",\n "range_type": "incoming",\n "range_begin": "6032722300",\n "range_end": "6032722366",\n "internal_exten_range_begin": "032722300",\n "internal_exten_range_end": "032722366",\n "callerid_range_begin": "032722300",\n "callerid_range_end": "032722366",\n "callerid_prefix": ""\n}\n\n# Creates one per inbound range (comma-separated in Global Params)',
"Caller ID Manipulation": '{\n "peerID_value": "GROUP_NAME",\n "username_value": "",\n "manipulation_id": "",\n "manipulation_type": "default",\n "internal_exten_range_begin": "032722300",\n "internal_exten_range_end": "032722366",\n "callerid_strip": "",\n "callerid_prepend": "6"\n}\n\n# Creates one per inbound range (comma-separated in Global Params)',
"ACL Group (Copy Existing Profiles with Managers & Users Suffix)": '{\n "members_value": "",\n "profile_members_value": "",\n "name": "GROUPNAME_Managers",\n "description": "",\n "group_privilege": "manager",\n "customer_id": "CUSTOMER_ID",\n "allow_login_ip": "all",\n "default_permission": "deny",\n "permission": "[{\\"access\\":\\"allow\\",\\"module\\":\\"Switchboard\\",\\"category\\":\\"Switchboard-FaxPanel\\",\\"action\\":\\"export;use\\"}]"\n}\n\n# Note: Sent as form-urlencoded. permission field value must be a JSON string.\n# Creates two groups: GROUPNAME_Managers (manager) and GROUPNAME_Users (limited)',
"User Profile": '{\n "group": "CUSTOMER_ID",\n "profile_name": "GROUPNAME_Class_1",\n "profile_desc": "",\n "sfb_gateway_type": "video",\n "acl_group_id": "USERS_ACL_GROUP_ID",\n "user_acl_group_id": "USERS_ACL_GROUP_ID",\n "user_context": "PREFIX_Class_1",\n "user_dtmfmode": "rfc2833",\n "user_incominglimit": "0",\n "user_nat": "no",\n "user_call_restrict": "no",\n "user_callrecording": "0",\n "user_callrecording_quota": "0",\n "user_callrecording_policy": "0",\n "activated": 1,\n "idd_pin_auth": "off",\n "idd_permit_other": "on",\n "rewritecallerid": "autoresolve",\n "disa_status": "0",\n "disa_pin_auth": "N",\n "timezone": "global",\n "language": "GLOBAL",\n "number_context": "PREFIX_Internal",\n "user_maxmsg": "100",\n "user_maxsecs": "360",\n "nat": "yes",\n "main_protocol": "udp",\n "mobile_nat": "yes",\n "allowcodec_useGlobal": 1\n}\n\n# Each class does 4 POSTs: 1) JSON userprofile, 2) form numberstatus, 3) form set/status/mode, 4) form update/timeslot/overview.\n# Creates four profiles: GROUPNAME_Class_1 to GROUPNAME_Class_4',
"User (Mobility Apps Only)": '{\n "action": "newUser",\n "ext": "0101",\n "firstname": "User0101",\n "lastname": "API",\n "group": "CUSTOMER_ID",\n "profile": "CLASS3_PROFILE_ID",\n "callRecording_quota": "0",\n "callRecording_policy": "0",\n "deter": "0",\n "phoneLabel": "0101",\n "linenum": "1",\n "ip": "2",\n "nat": "yes",\n "hotdeskphone": "0",\n "autoAnswer": "2",\n "checknat": "yes",\n "sla": "0"\n}\n\n# Note: login_password/password NOT sent — server auto-generates.\n# Extracted from response: resp_json[\"pin\"][\"login_pw\"] and resp_json[\"pin\"][\"user_pin\"].\n# Ext range from UX, strips leading 6. Auto-generates user records.',
"ACL User": '{\n "action": "updateACLUser",\n "username": "032722300",\n "group": "CUSTOMER_ID",\n "aclgroup": "MANAGERS_ACL_ID",\n "privileges": "manager",\n "features": "[{\\"feature\\":\\"extension\\",\\"data\\":\\"032722300\\"},{\\"feature\\":\\"manager_allow\\",\\"data\\":\\"makeCall\\"}]",\n "monitor": "[\\"CUSTOMER_ID\\"]",\n "include_monitor_group": "[\\"CUSTOMER_ID\\"]",\n "firstname": "User2300",\n "lastname": "Manager",\n "company": "",\n "phone_number": "032722300"\n}\n\n# Sent as form-urlencoded via POST /put/configuration/acluser/{id}.\n# Auto-fetches: ACL group IDs via GET /v1/get/configuration/aclgroup/view/list.\n# Auto-fetches individual user details via GET /get/configuration/acluser/{ext}.\n# First ext from range = manager (full features), rest = limited (no features).',
"User (Htek Mac based Only)": '{\n "type": "Htek",\n "model": "UC902G",\n "mac": "001fc122acec",\n "mac_select": "001fc122acec",\n "deter": "1",\n "linenum": "1",\n "autoAnswer": "2",\n "hotdeskphone": "0",\n "ip": "2",\n "nat": "yes",\n "call_waiting": "0",\n "callRecording_type": "1",\n "disa_callerid": "EXT"\n}\n\n# MAC/mac_select/model come from the MAC Configuration popup.\n# Other fields (ext, firstname, group, profile, etc.) are auto-filled from Global Params.',
"Number (Strip Digits)": '{\n "action": "createNumber",\n "id": "",\n "crm": "0",\n "inbound": "0",\n "type": "Number",\n "number": "_230X",\n "number_static": "",\n "callerid_matching": "",\n "number_name": "GROUPNAME Strip Digit",\n "number_name_static": "",\n "number_desc": "",\n "group": "CUSTOMER_ID",\n "context": "PREFIX_Internal",\n "call_recording": "no",\n "idd_account": ""\n}\n\n# ===== 3-Step Flow =====\n# Step 1: POST JSON /numberingplan/number (above) -> returns id\n# Step 2: POST form /v1/post/numberingplan/numberstatus with number_id from step 1 -> returns status_id\n# Step 3: POST form /numberingplan/number/set/status/mode with id + number_status_id\n#\n# Number pattern auto-generated from last 4 digits of extension range.\n# Number name = \"{group_name} Strip Digit\". Context = \"{prefix}_Internal\".',
}
def create_gui(self):
st.config_ttk_styles()
# ========== Base Configuration ==========
login_frame = ttk.LabelFrame(self.root, text="Base Configuration", padding=5)
login_frame.pack(fill="x", padx=10, pady=5)
ttk.Label(login_frame, text="URL:").grid(row=0, column=0, sticky="e")
url_frame = ttk.Frame(login_frame)
url_frame.grid(row=0, column=1, padx=5, pady=2)
self.url_proto = ttk.Label(url_frame, text="https://")
self.url_proto.pack(side="left")
self.url_proto.bind("<Button-1>", lambda e: self.toggle_url_proto())
self.url_ent = ttk.Entry(url_frame, width=28)
self.url_ent.pack(side="left")
saved_url = self.last_session.get("base_url", config.base_url)
for p in ("https://", "http://"):
if saved_url.startswith(p):
saved_url = saved_url[len(p):]
self.url_proto.config(text=p)
break
self.url_ent.insert(0, saved_url)
ttk.Label(login_frame, text="Username:").grid(row=0, column=2, sticky="e")
self.user_ent = ttk.Entry(login_frame, width=15)
self.user_ent.insert(0, self.last_session.get("username", config.username))
self.user_ent.grid(row=0, column=3, padx=5, pady=2)
ttk.Label(login_frame, text="Password:").grid(row=0, column=4, sticky="e")
pw_frame = ttk.Frame(login_frame)
pw_frame.grid(row=0, column=5, padx=5, pady=2)
self.pw_ent = ttk.Entry(pw_frame, width=18, show="*")
self.pw_ent.pack(side="left")
self.pw_visible = False
self.pw_toggle_btn = tk.Button(pw_frame, text="👁", width=3, command=self.toggle_password,
relief="flat", padx=0, cursor="hand2", font=("Segoe UI", 10))
self.pw_toggle_btn.pack(side="left")
self.pw_ent.insert(0, "")
self.pw_ent.bind("<Return>", lambda e: self.threaded_login())
# Token indicator light
self.token_canvas = tk.Canvas(login_frame, width=20, height=20, bg="white", highlightthickness=0)
self.token_canvas.grid(row=0, column=7, padx=(10, 2))
self._draw_token_indicator(0)
# Login & Save Token button
self.login_btn = ttk.Button(login_frame, text="Login", style="Primary.TButton",
command=self.threaded_login)
self.login_btn.grid(row=0, column=8, padx=2, pady=2)
# Token status label
self.token_label = ttk.Label(login_frame, text="Not logged in", style="Token.TLabel")
self.token_label.grid(row=0, column=9, padx=(2, 5))
self.root.protocol("WM_DELETE_WINDOW", self.on_close)
# ========== Vertical PanedWindow: Notebook (top) + Log (bottom) ==========
outer_pw = ttk.PanedWindow(self.root, orient=tk.VERTICAL)
outer_pw.pack(fill="both", expand=True, padx=10)
# ========== Notebook: Standard Order | Complex Order | Search & Delete ==========
notebook = ttk.Notebook(outer_pw)
outer_pw.add(notebook, weight=2)
# ========== Tab 1: Standard Order ==========
tab1 = ttk.Frame(notebook)
notebook.add(tab1, text="Standard")
# ========== Horizontal PanedWindow: Task Pipeline | Global Params ==========
std_pw = ttk.PanedWindow(tab1, orient=tk.HORIZONTAL)
std_pw.pack(fill="both", expand=True)
left_side = ttk.Frame(std_pw)
std_pw.add(left_side, weight=1)
self._build_task_panel(left_side, [], "standard")
right_side = ttk.Frame(std_pw)
std_pw.add(right_side, weight=1)
self._build_global_params(right_side, "standard")
# ========== Tab 2: Complex Order ==========
tab2 = ttk.Frame(notebook)
notebook.add(tab2, text="Complex")
all_names = [name for name, _, _ in self.task_definitions]
complex_default = []
cmp_pw = ttk.PanedWindow(tab2, orient=tk.HORIZONTAL)
cmp_pw.pack(fill="both", expand=True)
tab2_left = ttk.Frame(cmp_pw)
cmp_pw.add(tab2_left, weight=1)
self._build_task_panel(tab2_left, complex_default, "complex")
tab2_right = ttk.Frame(cmp_pw)
cmp_pw.add(tab2_right, weight=1)
self._build_global_params(tab2_right, "complex")
# ========== Tab 3: Search & Delete ==========
tab3 = ttk.Frame(notebook)
notebook.add(tab3, text="Search & Delete")
# ========== Optional Task (Search / Delete) ==========
opt_frame = ttk.LabelFrame(tab3, text="Optional Task - Search & Delete", padding=4)
opt_frame.pack(fill="both", expand=True, pady=(5, 0))
opt_top = ttk.Frame(opt_frame)
opt_top.pack(fill="x", pady=(0, 2))
ttk.Label(opt_top, text="Group Name/ID Search:").pack(side="left")
self.opt_search_entry = ttk.Entry(opt_top, width=15)
self.opt_search_entry.pack(side="left", padx=5)
self.opt_search_entry.bind("<KeyRelease>", self._on_opt_search_key)
self.opt_group_combo = ttk.Combobox(opt_top, width=35, state="readonly")
self.opt_group_combo.pack(side="left")
self.opt_group_combo.bind("<<ComboboxSelected>>", self._on_opt_group_selected)
refresh_btn = tk.Button(opt_top, text="↻", font=("Segoe UI", 11), width=2, relief="flat",
cursor="hand2", command=self._populate_group_combo)
refresh_btn.pack(side="left", padx=(2, 6))
ttk.Button(opt_top, text="All Tasks", style="Outline.TButton", width=8, command=self.opt_select_all).pack(side="left", padx=(0, 2))
ttk.Button(opt_top, text="No Task", style="Outline.TButton", width=8, command=self.opt_deselect_all).pack(side="left")
ttk.Button(opt_top, text="Search", style="Primary.TButton", width=10, command=self.opt_threaded_search).pack(side="left", padx=(10, 2))
self.opt_delete_btn = ttk.Button(opt_top, text="Delete", style="Danger.TButton", width=10, command=self.opt_threaded_delete)
self.opt_delete_btn.pack(side="left")
# Scrollable area for module rows
opt_canvas = tk.Canvas(opt_frame, bg=st.C["bg"], highlightthickness=0)
opt_scrollbar = ttk.Scrollbar(opt_frame, orient="vertical", command=opt_canvas.yview)
opt_canvas.configure(yscrollcommand=opt_scrollbar.set)
opt_canvas.pack(side="left", fill="both", expand=True)
opt_scrollbar.pack(side="right", fill="y")
opt_inner = ttk.Frame(opt_canvas)
opt_canvas_window = opt_canvas.create_window((0, 0), window=opt_inner, anchor="nw")
def _config_opt_inner(event):
opt_canvas.configure(scrollregion=opt_canvas.bbox("all"))
opt_inner.bind("<Configure>", _config_opt_inner)
def _config_opt_canvas(event):
opt_canvas.itemconfig(opt_canvas_window, width=event.width)
opt_canvas.bind("<Configure>", _config_opt_canvas)
def _on_opt_wheel(event):
opt_canvas.yview_scroll(int(-1*(event.delta/120)), "units")
opt_canvas.bind("<Enter>", lambda e: opt_canvas.bind_all("<MouseWheel>", _on_opt_wheel))
opt_canvas.bind("<Leave>", lambda e: opt_canvas.unbind_all("<MouseWheel>"))
def _refresh_opt_scroll():
opt_canvas.configure(scrollregion=opt_canvas.bbox("all"))
self.opt_scroll_refresh = _refresh_opt_scroll
self.opt_group = OptGroup(opt_inner, self)
self.opt_context = OptContext(opt_inner, self)
self.opt_permgroup = OptPermGroup(opt_inner, self)
self.opt_siptrunk = OptSipTrunk(opt_inner, self)
self.opt_outboundrouting = OptOutboundRouting(opt_inner, self)
self.opt_inboundrouting = OptInboundRouting(opt_inner, self)
self.opt_calleridmanipulation = OptCallerIdManipulation(opt_inner, self)
self.opt_aclgroup = OptAclGroup(opt_inner, self)
self.opt_userprofile = OptUserProfile(opt_inner, self)
self.opt_user = OptUser(opt_inner, self)
self.opt_acluser = OptAclUser(opt_inner, self)
self.opt_numberstrip = OptNumberStrip(opt_inner, self)
self.opt_callforward = OptCallForward(opt_inner, self)
self.opt_callpickup = OptCallPickup(opt_inner, self)
self.opt_huntgroup = OptHuntGroup(opt_inner, self)
self.opt_voiceprompt = OptVoicePrompt(opt_inner, self)
self.opt_ivr = OptIVR(opt_inner, self)
# ========== Cinch Contact Center group ==========
cinch_frame = ttk.LabelFrame(opt_inner, text="Cinch Contact Center", padding=(0, 2, 0, 2))
cinch_frame.pack(fill="x", pady=(6, 0))
self.opt_agents = OptAgents(cinch_frame, self)
self.opt_agentgroups = OptAgentGroups(cinch_frame, self)
self.opt_queue = OptQueue(cinch_frame, self)
self.opt_modules = [
self.opt_group, self.opt_context, self.opt_permgroup,
self.opt_siptrunk, self.opt_outboundrouting, self.opt_inboundrouting,
self.opt_calleridmanipulation, self.opt_aclgroup, self.opt_userprofile,
self.opt_user, self.opt_acluser, self.opt_numberstrip, self.opt_callforward,
self.opt_callpickup, self.opt_huntgroup, self.opt_voiceprompt, self.opt_ivr,
self.opt_agents, self.opt_agentgroups, self.opt_queue,
]
# ========== Tab 4: SIP Trunk Status ==========
tab4 = ttk.Frame(notebook)
notebook.add(tab4, text="SIP Trunk Status")
self.opt_siptrunkstatus = OptSipTrunkStatus(tab4, self)
# ========== Log Area (shared across all tabs) ==========
log_frame = ttk.Frame(outer_pw)
outer_pw.add(log_frame, weight=1)
self.log_text = tk.Text(log_frame, bg=st.C["log_bg"], fg=st.C["log_fg"],
font=st.F["mono"], insertbackground=st.C["log_insert"],
relief="flat", borderwidth=0)
self.log_text.pack(side="left", fill="both", expand=True)
log_scrollbar = ttk.Scrollbar(log_frame, orient="vertical", command=self.log_text.yview)
log_scrollbar.pack(side="right", fill="y")
self.log_text.configure(yscrollcommand=log_scrollbar.set)
# ========== Footer ==========
footer = ttk.Frame(self.root)
footer.pack(fill="x", padx=10, pady=(2, 4))
ttk.Label(footer,
text="Author: Anderson OngCS | Email: anderson_ong84@hotmail.com | RestfulAPI Automation | Special Thanks to Chris Wong",
font=("Segoe UI", 8), foreground="#94a3b8").pack(side="right")
def _initial_scroll_fix():
h = self.root.winfo_height()
outer_pw.sashpos(0, max(h - 300, 350))
self.opt_scroll_refresh()
self.root.after(150, _initial_scroll_fix)
self.root.bind_all("<Control-MouseWheel>", self._on_ctrl_scroll)
self.root.mainloop()
def _on_ctrl_scroll(self, event):
new_scale = st.FONT_SCALE + (0.1 if event.delta > 0 else -0.1)
if new_scale < 0.5 or new_scale > 3.0:
return "break"
st.set_font_scale(new_scale)
self._rescale_widget_fonts()
self.log(f"Font scale: {st.FONT_SCALE:.1f}x")
return "break"
def _rescale_widget_fonts(self):
scale = st.FONT_SCALE
def _rescale_font_tuple(font):
if isinstance(font, tuple) and len(font) >= 2 and isinstance(font[1], int):
fam, size = font[0], max(int(font[1] * scale), 1)
rest = font[2:]
return (fam, size) + rest
if isinstance(font, str) and "{" in font:
try:
parts = font.split()
size_i = next(i for i, p in enumerate(parts) if p.lstrip("-").isdigit())
fam = " ".join(parts[:size_i]).strip("{}")
size = max(int(parts[size_i]) * scale, 1)
return (fam, size)
except Exception:
return font
return font
def walk(widget):
try:
cls = widget.winfo_class()
if cls not in ("Tk", "Toplevel", "Frame", "TFrame", "Labelframe", "TLabelframe",
"Canvas", "Scrollbar", "TScrollbar", "Notebook", "TNotebook"):
if isinstance(widget, (tk.Button, tk.Label, tk.Entry, tk.Text,
tk.Checkbutton, tk.Radiobutton)):
try:
cur = widget.cget("font")
if isinstance(cur, tuple):
widget.configure(font=_rescale_font_tuple(cur))
except Exception:
pass
except Exception:
pass
try:
for child in widget.winfo_children():
walk(child)
except Exception:
pass
walk(self.root)
# ========== Task Panel Builder ==========
def _build_task_panel(self, parent, default_checked, tag):
task_vars = {}
task_status = {}
task_canvas = {}
session = self.std_session if tag == "standard" else self.cplx_session
task_frame = ttk.LabelFrame(parent, text="Task Pipeline", padding=5)
task_frame.pack(fill="both", expand=True)
btn_frame = ttk.Frame(task_frame)
btn_frame.pack(anchor="w", pady=(0, 4), fill="x")
ttk.Button(btn_frame, text="All Tasks", style="Outline.TButton", width=10,
command=lambda: self.select_all_tasks(tag)).pack(side="left", padx=(0, 6))
ttk.Button(btn_frame, text="No Task", style="Outline.TButton", width=10,
command=lambda: self.deselect_all_tasks(tag)).pack(side="left")
run_btn = ttk.Button(btn_frame, text="Start", style="Success.TButton", width=10,
command=lambda: self.start_thread(tag))
run_btn.pack(side="left", padx=(10, 4))
stop_btn = ttk.Button(btn_frame, text="Stop", style="Danger.TButton", width=10,
command=lambda: self.stop_task(tag), state="disabled")
stop_btn.pack(side="left")
last_task_row = None
for idx, (name, mod, _) in enumerate(self.task_definitions):
task_vars[name] = tk.BooleanVar(value=name in default_checked)
task_status[name] = 0
if name == "User (Htek Mac based Only)":
task_canvas[name] = task_canvas["User (Mobility Apps Only)"]
mob_row = last_task_row
cb = ttk.Checkbutton(mob_row, text=name, variable=task_vars[name])
cb.pack(side="left", padx=(8, 0))
if mod in self.api_available and self.api_available[mod]:
badge = ttk.Label(mob_row, text="API", style="Api.TLabel", width=4)
badge.pack(side="right", padx=(4, 0))
if tag != "standard":
json_btn = tk.Button(mob_row, text="📄", font=("Segoe UI", 9), width=2, relief="flat",
command=lambda n=name: self.show_api_popup(n))
json_btn.pack(side="right", padx=(1, 2))
continue
task_row = ttk.Frame(task_frame)
task_row.pack(anchor="w", pady=0, fill="x")
task_canvas[name] = tk.Canvas(task_row, width=24, height=24, bg="white", highlightthickness=0)
task_canvas[name].pack(side="left", padx=6, pady=2)
cb = ttk.Checkbutton(task_row, text=name, variable=task_vars[name])
cb.pack(anchor="w", side="left")
if tag == "complex" and name == "Number (Strip Digits)":
cb.configure(state="disabled")
task_vars[name].set(False)
if mod in self.api_available and self.api_available[mod]:
badge = ttk.Label(task_row, text="API", style="Api.TLabel", width=4)
badge.pack(side="right", padx=(4, 0))
if tag != "standard":
json_btn = tk.Button(task_row, text="📄", font=("Segoe UI", 9), width=2, relief="flat",
command=lambda n=name: self.show_api_popup(n))
json_btn.pack(side="right", padx=(1, 2))
else:
badge = ttk.Label(task_row, text="N/A", style="Na.TLabel", width=4)
badge.pack(side="right", padx=4)
if name == "Group":
label = ttk.Label(task_row, text="", style="GroupId.TLabel")
label.pack(side="right", padx=(0, 4))
setattr(self, f"{tag}_group_id_label", label)
if tag == "complex" and name == "Outbound Routing":
outbound_var = task_vars[name]
custom_var = tk.BooleanVar(value=False)
custom_cb = ttk.Checkbutton(task_row, text="Custom Routing", variable=custom_var)
custom_cb.pack(side="left", padx=(8, 0))
setattr(self, f"{tag}_custom_routing_var", custom_var)
def _set_custom_enabled(*a):
on = custom_var.get()
state = "normal" if on else "disabled"
custom_ent = getattr(self, f"{tag}_custom_number_ent", None)
custom_ctx_cb = getattr(self, f"{tag}_custom_ctx_cb", None)
if custom_ent:
custom_ent.configure(state=state)
if custom_ctx_cb:
custom_ctx_cb.configure(state=state)
def _on_custom_changed(*a):
if custom_var.get():
outbound_var.set(False)
_set_custom_enabled()
def _on_outbound_changed(*a):
if outbound_var.get():
custom_var.set(False)
_set_custom_enabled()
custom_var.trace_add("write", _on_custom_changed)
outbound_var.trace_add("write", _on_outbound_changed)
last_task_row = task_row
mob_var = task_vars["User (Mobility Apps Only)"]
htek_var = task_vars["User (Htek Mac based Only)"]
def _mob_changed(*args):
if mob_var.get():
htek_var.set(False)
def _htek_changed(*args):
if htek_var.get():
mob_var.set(False)
fill_fn = getattr(self, f"{tag}_fill_htek_ext", None)
if fill_fn:
self.root.after(50, fill_fn)
mob_var.trace_add("write", _mob_changed)
htek_var.trace_add("write", _htek_changed)
setattr(self, f"{tag}_task_vars", task_vars)
setattr(self, f"{tag}_task_status", task_status)
setattr(self, f"{tag}_task_canvas", task_canvas)
setattr(self, f"{tag}_run_btn", run_btn)
setattr(self, f"{tag}_stop_btn", stop_btn)
for name in task_canvas:
self._draw_indicator(tag, name, 0)
def _bind_ctx_sub_options(self, tag, ctx_var):
suffix_vars = {}
custom_chk = tk.BooleanVar(value=False)
custom_var = tk.StringVar()
sub_frame = getattr(self, f"{tag}_ctx_sub_frame")
checkboxes = []
for i, sfx in enumerate(("_Internal", "_Fixed", "_Mobile", "_IDD")):
sv = tk.BooleanVar(value=False)
suffix_vars[sfx] = sv
cb = ttk.Checkbutton(sub_frame, text=sfx, variable=sv, state="disabled")
cb.pack(side="left", padx=(0, 8))
checkboxes.append(cb)
custom_cb = ttk.Checkbutton(sub_frame, text="Custom", variable=custom_chk, state="disabled")
custom_cb.pack(side="left")
custom_ent = ttk.Entry(sub_frame, width=14, textvariable=custom_var, state="disabled")
custom_ent.pack(side="left", padx=(4, 0))
def _set_enabled(state):
for cb in checkboxes:
cb.configure(state=state)
custom_cb.configure(state=state)
custom_ent.configure(state="disabled")
if state == "disabled":
for sv in suffix_vars.values():
sv.set(False)
custom_chk.set(False)
custom_var.set("")
def _on_ctx_changed(*args):
_set_enabled("normal" if ctx_var.get() else "disabled")
def _on_custom_changed(*args):
custom_ent.configure(state="normal" if custom_chk.get() else "disabled")
ctx_var.trace_add("write", _on_ctx_changed)
custom_chk.trace_add("write", _on_custom_changed)
_set_enabled("disabled")
setattr(self, f"{tag}_ctx_suffix_vars", suffix_vars)
setattr(self, f"{tag}_ctx_custom_chk", custom_chk)
setattr(self, f"{tag}_ctx_custom_var", custom_var)
setattr(self, f"{tag}_ctx_custom_ent", custom_ent)
def _bind_pg_sub_options(self, tag, pg_var):
front_items = [
("c_i", ["Custom", "_Internal"]),
("i_c", ["_Internal", "Custom"]),
("c", ["Custom"]),
("i", ["_Internal"]),
]
fixed_by_class = {1: [], 2: ["_Fixed"], 3: ["_Fixed", "_Mobile"], 4: ["_Fixed", "_Mobile", "_IDD"]}
labels = ["Class 1", "Class 2", "Class 3", "Class 4"]
sub_frame = getattr(self, f"{tag}_pg_sub_frame")
checks = []
for row_i in range(2):
row = ttk.Frame(sub_frame)
row.pack(anchor="w")
for col_i in range(2):
idx = row_i * 2 + col_i
class_num = idx + 1
fixed = fixed_by_class[class_num]
opts = [", ".join(front + fixed) for _, front in front_items]
default = ", ".join(["Custom", "_Internal"] + fixed)
cell = ttk.Frame(row)
cell.pack(side="left", padx=(0, 8))
chk = tk.BooleanVar(value=True)
ck = ttk.Checkbutton(cell, text=labels[idx], variable=chk, state="disabled")
ck.pack(side="left", padx=(0, 4))
var = tk.StringVar(value=default)
cb = ttk.Combobox(cell, textvariable=var, values=opts, state="disabled", width=36)
cb.pack(side="left")
checks.append((labels[idx], class_num, chk, var, cb, ck))
def _set_enabled(enabled):
cb_state = "readonly" if enabled else "disabled"
chk_state = "normal" if enabled else "disabled"
for _, _, chk, var, cb, ck in checks:
cb.configure(state=cb_state)
ck.configure(state=chk_state)
if not enabled:
for _, class_num, chk, var, cb, ck in checks:
chk.set(True)
var.set(", ".join(["Custom", "_Internal"] + fixed_by_class[class_num]))
def _on_pg_changed(*args):
_set_enabled(pg_var.get())
pg_var.trace_add("write", _on_pg_changed)
_set_enabled(False)
setattr(self, f"{tag}_pg_checks", checks)
setattr(self, f"{tag}_pg_front_items", front_items)
setattr(self, f"{tag}_pg_fixed_by_class", fixed_by_class)
def _bind_acl_sub_options(self, tag, acl_var):
sub_frame = getattr(self, f"{tag}_acl_sub_frame")
checks = []
for label in ("_Managers", "_Supervisors", "_Users"):
chk = tk.BooleanVar(value=True)
ck = ttk.Checkbutton(sub_frame, text=label, variable=chk, state="disabled")
ck.pack(side="left", padx=(0, 8))
checks.append((label, chk, ck))
def _set_enabled(enabled):
state = "normal" if enabled else "disabled"
for _, chk, ck in checks:
ck.configure(state=state)
if not enabled:
for _, chk, ck in checks:
chk.set(True)
def _on_acl_changed(*args):
_set_enabled(acl_var.get())
acl_var.trace_add("write", _on_acl_changed)
_set_enabled(False)
setattr(self, f"{tag}_acl_checks", checks)
def _bind_user_profile_sub_options(self, tag, profile_var):
sub_frame = getattr(self, f"{tag}_profile_sub_frame")
checks = []
for i, label in enumerate(("Class 1 (Internal)", "Class 2 (Fixed)", "Class 3 (Mobile)", "Class 4 (IDD)")):
chk = tk.BooleanVar(value=True)
ck = ttk.Checkbutton(sub_frame, text=label, variable=chk, state="disabled")
ck.pack(side="left", padx=(0, 8))
checks.append((i + 1, label, chk, ck))
def _set_enabled(enabled):
state = "normal" if enabled else "disabled"
for _, _, chk, ck in checks:
ck.configure(state=state)
if not enabled:
for _, _, chk, ck in checks:
chk.set(True)
def _on_profile_changed(*args):
_set_enabled(profile_var.get())
profile_var.trace_add("write", _on_profile_changed)
_set_enabled(False)
setattr(self, f"{tag}_profile_checks", checks)
# ========== Custom Routing Context Refresh (standalone) ==========
def threaded_refresh_custom_ctx(self, tag):
if not self.rest_client or not self.rest_client.authenticated:
self.log("Please login first!")
return
threading.Thread(target=lambda: self._refresh_custom_ctx(tag), daemon=True).start()
def _refresh_custom_ctx(self, tag):
try:
inputs = getattr(self, f"{tag}_inputs", {})
group_name = inputs["group_name"].get().strip()
if not group_name:
self.log("Fill Group Name before refreshing custom routing contexts.")
return
customer_id = getattr(self.rest_client, '_searched_customer_id', None) or ""
if not customer_id:
customer_id = self.rest_client.get_customer_id_by_name(group_name)
if customer_id:
self._set_customer_id_ui(customer_id)
found = self.rest_client.search_contexts_by_group(customer_id, group_name)
if found is None:
self.log(f"⚠️ Failed to fetch contexts: {self.rest_client.last_error}")
return
ctx_list = [c["contextID"] for c in found]
if not ctx_list:
self.log(f"⚠️ No contexts found for group '{group_name}'.")
return
cb = getattr(self, f"{tag}_custom_ctx_cb", None)
if cb:
cb.configure(values=ctx_list)
cb.set(ctx_list[0])
self.log(f"↻ Found {len(ctx_list)} context(s) for group '{group_name}': {ctx_list}")
except Exception as e:
self.log(f"⚠️ Refresh custom routing contexts error: {e}")
# ========== Permission Group Context Refresh (standalone) ==========
def threaded_refresh_pg(self, tag):
if not self.rest_client or not self.rest_client.authenticated:
self.log("Please login first!")
return
threading.Thread(target=lambda: self._refresh_pg_contexts(tag), daemon=True).start()
def _refresh_pg_contexts(self, tag):
try:
inputs = getattr(self, f"{tag}_inputs", {})
group_name = inputs["group_name"].get().strip()
ctx_prefix = inputs["context_prefix"].get().strip()
if not group_name or not ctx_prefix:
self.log("Fill Group Name and Context Prefix before refreshing Permission Group contexts.")
return
prefix = ctx_prefix[:-1] if ctx_prefix.endswith("_") else ctx_prefix
customer_id = self.rest_client.get_customer_id_by_name(group_name)
if not customer_id:
self.log(f"⚠️ Could not resolve group '{group_name}' to a customer ID.")
return
found = self.rest_client.search_contexts_by_prefix(prefix)
if found is None:
self.log(f"⚠️ Failed to fetch contexts: {self.rest_client.last_error}")
return
matched = [c["contextID"] for c in found
if str(c.get("groupName", "")) in (str(customer_id), group_name)]
if not matched:
matched = [c["contextID"] for c in found]
self.log(f"⚠️ Could not match contexts to group '{group_name}'; using all '{ctx_prefix}'* contexts.")
if not matched:
self.log(f"No contexts found with prefix '{ctx_prefix}'.")
return
std_suffixes = ["_Internal", "_Fixed", "_Mobile", "_IDD"]
std_order = {"_Internal": 0, "_Fixed": 1, "_Mobile": 2, "_IDD": 3}
def suffix_of(full):
return full[len(prefix):] if full.startswith(prefix) else full
custom_ctx = next((c for c in matched if suffix_of(c) not in std_suffixes), None)
std_found = [c for c in matched if suffix_of(c) in std_suffixes]
std_found.sort(key=lambda c: std_order.get(suffix_of(c), 99))
internal_ctx = next((c for c in std_found if suffix_of(c) == "_Internal"),
std_found[0] if std_found else None)
fixed = [c for c in std_found if c != internal_ctx]
server_data = {
"customer_id": customer_id,
"custom_ctx": custom_ctx,
"internal_ctx": internal_ctx,
"fixed": fixed,
"all": matched,
}
setattr(self, f"{tag}_pg_server_data", server_data)
self.log(f"↻ Found {len(matched)} context(s) for group '{group_name}': {matched}")
self._rebuild_pg_options(tag, server_data)
except Exception as e:
self.log(f"⚠️ Refresh Permission Group contexts error: {e}")
def _rebuild_pg_options(self, tag, server_data):
checks = getattr(self, f"{tag}_pg_checks", [])
for label, class_num, chk, var, cb, ck in checks:
keys = list(self._pg_options_for_class(tag, class_num, server_data).keys())
var.set(keys[0] if keys else "")
cb.configure(values=keys)
def _pg_options_for_class(self, tag, class_num, server_data):
front_items = getattr(self, f"{tag}_pg_front_items", [])
fixed_by_class = getattr(self, f"{tag}_pg_fixed_by_class", {})
fixed = fixed_by_class.get(class_num, [])
opts = []
if server_data:
custom_ctx = server_data.get("custom_ctx")
internal_ctx = server_data.get("internal_ctx")
srv_fixed = server_data.get("fixed", [])
for key, front in front_items:
parts = []
for name in front:
if name == "Custom":
if custom_ctx:
parts.append(custom_ctx)
elif name == "_Internal":
if internal_ctx:
parts.append(internal_ctx)
parts = parts + srv_fixed[:class_num - 1]
opts.append((key, ", ".join(parts)))
else:
for key, front in front_items:
opts.append((key, ", ".join(front + fixed)))
seen = {}
for key, disp in opts:
if disp not in seen:
seen[disp] = key
return seen
# ========== Global Parameters Builder ==========
def _build_global_params(self, parent, tag):
inputs = {}
session = self.std_session if tag == "standard" else self.cplx_session
frame_title = "Standard Parameter" if tag == "standard" else "Complex Parameter"
task_vars = getattr(self, f"{tag}_task_vars", {})
user_frame = None
if tag == "complex":
scroll_canvas = tk.Canvas(parent, highlightthickness=0, bg=st.C["bg"])
scroll_canvas.pack(side="left", fill="both", expand=True)
vbar = ttk.Scrollbar(parent, orient="vertical", command=scroll_canvas.yview)
vbar.pack(side="right", fill="y")
scroll_canvas.configure(yscrollcommand=vbar.set)
param_frame = ttk.LabelFrame(scroll_canvas, text=frame_title, padding=5)
win_id = scroll_canvas.create_window((0, 0), window=param_frame, anchor="nw")
param_frame.bind("<Configure>",
lambda e: scroll_canvas.configure(scrollregion=scroll_canvas.bbox("all")))
scroll_canvas.bind("<Configure>", lambda e: scroll_canvas.itemconfig(win_id, width=e.width))
def _wheel_enter(_e):
scroll_canvas.bind_all("<MouseWheel>",
lambda ev: scroll_canvas.yview_scroll(int(-ev.delta / 120), "units"))
def _wheel_leave(_e):
scroll_canvas.unbind_all("<MouseWheel>")
scroll_canvas.bind("<Enter>", _wheel_enter)
scroll_canvas.bind("<Leave>", _wheel_leave)
else:
param_frame = ttk.LabelFrame(parent, text=frame_title, padding=5)
param_frame.pack(fill="x")
if tag == "complex":
# ========== Frame 1: Group ==========
group_frame = ttk.LabelFrame(param_frame, text="Group:", padding=4)
group_frame.pack(fill="x", pady=(0, 4))
top_row = ttk.Frame(group_frame)
top_row.pack(fill="x")
left_t = ttk.Frame(top_row)
left_t.pack(side="left", fill="x", expand=True)
ttk.Label(left_t, text="Group Name (max 30 chars, space→_):").pack(anchor="w")
group_name_var = tk.StringVar(value=session.get("group_name", "CARSOME_Kajang"))
group_name_var.trace_add("write", lambda *a, v=group_name_var: self._on_underscore_input_var(v))
ent_gn = ttk.Entry(left_t, textvariable=group_name_var)
ent_gn.pack(fill="x", padx=(0, 4))
inputs["group_name"] = ent_gn
mid_t = ttk.Frame(top_row)
mid_t.pack(side="left", fill="x", expand=True)
ttk.Label(mid_t, text="Group Code:").pack(anchor="w")
ent_gc = ttk.Entry(mid_t)
ent_gc.insert(0, session.get("group_code", "MCBLL5248_MV_CARSOME_KJG"))
ent_gc.pack(fill="x", padx=(4, 4))
inputs["group_code"] = ent_gc
right_t = ttk.Frame(top_row)
right_t.pack(side="left", fill="x", expand=True)
ttk.Label(right_t, text="Max Concurrent Calls & Reg User (1-300):").pack(anchor="w")
unified_spin = ttk.Spinbox(right_t, from_=1, to=300)
unified_spin.set(session.get("unified_limit", 10))
unified_spin.pack(fill="x", padx=(4, 0))
inputs["_unified_limit"] = unified_spin
# ========== Frame 2: Context ==========
ctx_frame = ttk.LabelFrame(param_frame, text="Context:", padding=4)
ctx_frame.pack(fill="x", pady=(0, 4))
ctx_prefix_row = ttk.Frame(ctx_frame)
ctx_prefix_row.pack(fill="x")
ttk.Label(ctx_prefix_row, text="Context Prefix:").pack(side="left")
ctx_prefix_var = tk.StringVar(value=session.get("context_prefix", "CARSOME"))
ctx_prefix_var.trace_add("write", lambda *a, v=ctx_prefix_var: self._on_underscore_input_var(v))
ent_ctx = ttk.Entry(ctx_prefix_row, textvariable=ctx_prefix_var, width=14)
ent_ctx.pack(side="left", padx=(4, 8))
inputs["context_prefix"] = ent_ctx
ctx_sub_frame = ttk.Frame(ctx_prefix_row)
ctx_sub_frame.pack(side="left")
setattr(self, f"{tag}_ctx_sub_frame", ctx_sub_frame)
self._bind_ctx_sub_options(tag, task_vars["Context"])
# ========== Frame 3: Permission Group ==========
pg_frame = ttk.LabelFrame(param_frame, text="Permission Group:", padding=4)
pg_frame.pack(fill="x", pady=(0, 4))
pg_head = ttk.Frame(pg_frame)
pg_head.pack(fill="x")
ttk.Label(pg_head, text="Permision Group Prefix:").pack(side="left")
refresh_btn = tk.Button(pg_head, text="↻", font=("Segoe UI", 11), width=2, relief="flat",
cursor="hand2", command=lambda: self.threaded_refresh_pg(tag))
refresh_btn.pack(side="right", padx=(1, 2))
pg_prefix_var = tk.StringVar(value=session.get("perm_group_prefix", "CARSOME"))
pg_prefix_var.trace_add("write", lambda *a, v=pg_prefix_var: self._on_underscore_input_var(v))
ent_pg = ttk.Entry(pg_frame, textvariable=pg_prefix_var)
ent_pg.pack(fill="x", pady=(2, 0))
inputs["perm_group_prefix"] = ent_pg
pg_sub_frame = ttk.Frame(pg_frame)
pg_sub_frame.pack(fill="x", pady=(4, 0))
setattr(self, f"{tag}_pg_sub_frame", pg_sub_frame)
self._bind_pg_sub_options(tag, task_vars["Permission Group"])
# ========== Frame 4: SIP Trunk ==========
sip_frame = ttk.LabelFrame(param_frame, text="SIP Trunk:", padding=4)
sip_frame.pack(fill="x", pady=(0, 4))
sip_row = ttk.Frame(sip_frame)
sip_row.pack(fill="x")
left_sip = ttk.Frame(sip_row)
left_sip.pack(side="left", fill="x", expand=True)
ttk.Label(left_sip, text="SIP Trunk Host/IP Address:").pack(anchor="w")
ent_ip = ttk.Entry(left_sip)
ent_ip.insert(0, session.get("host_ip", "202.179.100.99"))
ent_ip.pack(fill="x", padx=(0, 5))
inputs["host_ip"] = ent_ip
right_sip = ttk.Frame(sip_row)
right_sip.pack(side="left", fill="x", expand=True)
ttk.Label(right_sip, text="SIP Trunk Port:").pack(anchor="w")
ent_port = ttk.Entry(right_sip)
ent_port.insert(0, session.get("port", "7978"))
ent_port.pack(fill="x", padx=(5, 0))
inputs["port"] = ent_port
# ========== Frame 5: Outbound Routing ==========
ob_frame = ttk.LabelFrame(param_frame, text="Outbound Routing:", padding=4)
ob_frame.pack(fill="x", pady=(0, 4))
custom_side = ttk.Frame(ob_frame)
custom_side.pack(fill="x")
ttk.Label(custom_side, text="Custom Number:").pack(side="left")
custom_ent = ttk.Entry(custom_side, width=16, state="disabled")
custom_ent.insert(0, self.last_session.get("custom_number", ""))
custom_ent.pack(side="left", padx=(3, 0))
ttk.Label(custom_side, text="Context:").pack(side="left", padx=(6, 0))
custom_ctx_var = tk.StringVar(value="_Fixed")
custom_ctx_cb = ttk.Combobox(custom_side, textvariable=custom_ctx_var,
values=["Custom", "_Internal", "_Fixed", "_Mobile", "_IDD"],
state="disabled", width=14)
custom_ctx_cb.pack(side="left", padx=(3, 0))
ctx_refresh = tk.Button(custom_side, text="↻", font=("Segoe UI", 11), width=2, relief="flat",
cursor="hand2",
command=lambda t=tag: self.threaded_refresh_custom_ctx(t))
ctx_refresh.pack(side="left", padx=(1, 2))
setattr(self, f"{tag}_custom_number_ent", custom_ent)
setattr(self, f"{tag}_custom_ctx_var", custom_ctx_var)
setattr(self, f"{tag}_custom_ctx_cb", custom_ctx_cb)
# ========== Frame 6: Inbound Routing & Caller ID Manipulation ==========
ibr_frame = ttk.LabelFrame(param_frame, text="Inbound Routing & Caller ID Manipulation:", padding=4)
ibr_frame.pack(fill="x", pady=(0, 4))
ttk.Label(ibr_frame, text="Inbound Ranges / CallerID (603xxx-603xxx,...):").pack(anchor="w")
ent_in = ttk.Entry(ibr_frame, width=20)
ent_in.insert(0, session.get("inbound_ranges", "60338314500-60338314509"))
ent_in.pack(fill="x", pady=(0, 4))
inputs["inbound_ranges"] = ent_in
# ========== Frame 7: ACL Group ==========
acl_frame = ttk.LabelFrame(param_frame, text="ACL Group:", padding=4)
acl_frame.pack(fill="x", pady=(0, 4))
acl_sub_frame = ttk.Frame(acl_frame)
acl_sub_frame.pack(fill="x")
setattr(self, f"{tag}_acl_sub_frame", acl_sub_frame)
self._bind_acl_sub_options(tag, task_vars["ACL Group"])
# ========== Frame 8: User Profiles ==========
profile_frame = ttk.LabelFrame(param_frame, text="User Profiles:", padding=4)
profile_frame.pack(fill="x", pady=(0, 4))
profile_sub_frame = ttk.Frame(profile_frame)
profile_sub_frame.pack(fill="x")
setattr(self, f"{tag}_profile_sub_frame", profile_sub_frame)
self._bind_user_profile_sub_options(tag, task_vars["User Profile"])
# ========== Frame 9: User ==========
user_frame = ttk.LabelFrame(param_frame, text="User:", padding=4)
user_frame.pack(fill="x", pady=(0, 4))
ttk.Label(user_frame, text="User Extension / Extension Range:").pack(anchor="w")
ent_ext = ttk.Entry(user_frame, width=20)
ent_ext.insert(0, session.get("user_ext", "60338314500-60338314503"))
ent_ext.pack(fill="x", pady=(0, 4))
inputs["user_ext"] = ent_ext
def _on_ext_changed(*args):
fill_fn = getattr(self, f"{tag}_fill_htek_ext", None)
if fill_fn:
fill_fn()
ent_ext.bind("<KeyRelease>", _on_ext_changed)
else:
top_row = ttk.Frame(param_frame)
top_row.pack(fill="x", pady=(0, 4))
left_t = ttk.Frame(top_row)
left_t.pack(side="left", fill="x", expand=True)
ttk.Label(left_t, text="Group Name (max 30 chars, space→_):").pack(anchor="w")
group_name_var = tk.StringVar(value=session.get("group_name", "CARSOME_Kajang"))
group_name_var.trace_add("write", lambda *a, v=group_name_var: self._on_underscore_input_var(v))
ent_gn = ttk.Entry(left_t, textvariable=group_name_var)
ent_gn.pack(fill="x", padx=(0, 4))
inputs["group_name"] = ent_gn
mid_t = ttk.Frame(top_row)
mid_t.pack(side="left", fill="x", expand=True)
ttk.Label(mid_t, text="Group Code:").pack(anchor="w")
ent_gc = ttk.Entry(mid_t)
ent_gc.insert(0, session.get("group_code", "MCBLL5248_MV_CARSOME_KJG"))
ent_gc.pack(fill="x", padx=(4, 4))
inputs["group_code"] = ent_gc
right_t = ttk.Frame(top_row)
right_t.pack(side="left", fill="x", expand=True)
ttk.Label(right_t, text="Max Concurrent Calls & Reg User (1-300):").pack(anchor="w")
unified_spin = ttk.Spinbox(right_t, from_=1, to=300)
unified_spin.set(session.get("unified_limit", 10))