This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoScript.py
2528 lines (2109 loc) · 116 KB
/
AutoScript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# AutoScript for Windows OS
#
import re
import os
import sys
import time
import serial
class Tools:
"""This class contains functions for checks and validations"""
def __init__(self):
self.cent_message = ''
self.sear_tick_tag = ''
self.sear_tick_data = ''
self.sear_tick_pattern = ''
self.sear_tick_string = ''
self.sear_tick_found = ''
self.valid_octe_ip = ''
self.valid_octe_count = 0
self.valid_octe_int = 0
self.calc_netw_band = ''
self.calc_netw_fOcteto = ''
self.calc_netw_sOcteto = ''
self.calc_netw_tOcteto = ''
self.calc_netw_qOcteto_mask = ''
self.calc_netw_qOcteto = ''
self.calc_netw_cidr = ''
self.calc_netw_check = ''
self.calc_netw_first = ''
self.calc_netw = 0
self.calc_netw_last = ''
self.calc_netw_qOctetoGateway = ''
self.calc_netw_broadcast = ''
self.calc_netw_mask = ''
self.calc_netw_fband = ''
self.calc_netw_lband = ''
self.calc_netw_ipGateway = ''
self.vali_rang_bits = 0
self.vali_rang_qOcteto = ''
self.vali_rang_step = 0
self.vali_rang_int = 0
self.vali_rang_bands = []
self.sear_temp_tag = ''
self.sear_temp_string = ''
self.sear_temp_data = []
self.sear_temp_linenumber = 0
self.vali_rang_exten = ''
self.vali_rang_gama = ''
self.vali_rang_begin = ''
self.vali_rang_end = ''
self.vali_rang_size = 0
self.vali_rang_qOcteto = ''
self.run_ran_ext_tag = ''
self.run_ran_ext_new_extension = 0
self.run_ran_ext_extension = ''
self.run_ran_ext_template = []
self.run_ran_ext_prefix = ''
self.run_ran_ext_suffix = ''
self.run_ran_ext_line_number = 0
self.run_key_ext_tag = ''
self.run_key_ext_extension = ''
self.run_key_ext_template = []
self.run_key_ext_line_number = 0
self.comp_rang_exten = ''
self.comp_rang_gama = ''
self.comp_rang_begin = ''
self.comp_rang_end = ''
self.comp_rang_check = ''
self.comp_rang_prefix = ''
self.comp_rang_suffix = ''
def centralize_message(self, message):
"""Center with 80 pixels on each side of the character <\n>"""
self.cent_message = message
center = '\n'.join('{:^80}'.format(s) for s in message.split('\n'))
return center
def validate_octets(self, ip):
"""Receives an IPv4 IP and checks if it is valid"""
self.valid_octe_ip = ip
self.valid_octe_ip = self.valid_octe_ip.split('.')
for self.valid_octe_int in self.valid_octe_ip:
self.valid_octe_int = int(self.valid_octe_int)
if 1 <= self.valid_octe_int <= 254:
self.valid_octe_count += 1
else:
return None
pass
pass
if self.valid_octe_count == 4:
self.valid_octe_ip = '.'.join(self.valid_octe_ip)
return self.valid_octe_ip
else:
return None
pass
def validate_range_ip(self, bit, qocteto):
"""Receives the fourth octet (Ex. 10.0.0.4/30 - fourth octet = 4) of the IPV4 range and the bit value (CIDR)
of the netmask (Ex. 10.0.0.4/30 - CIDR = 30) and performs a comparison to identify whether the mask conforms
to the reported IP range."""
self.vali_rang_qOcteto = qocteto
self.vali_rang_bits = int(bit)
self.vali_rang_qOcteto = int(self.vali_rang_qOcteto)
if self.vali_rang_bits == 30:
self.vali_rang_step = 4
elif self.vali_rang_bits == 29:
self.vali_rang_step = 8
elif self.vali_rang_bits == 28:
self.vali_rang_step = 16
elif self.vali_rang_bits == 27:
self.vali_rang_step = 32
elif self.vali_rang_bits == 26:
self.vali_rang_step = 64
elif self.vali_rang_bits == 25:
self.vali_rang_step = 128
elif self.vali_rang_bits == 24:
self.vali_rang_step = 254
else:
return False
for self.vali_rang_int in range(0, 255, self.vali_rang_step):
self.vali_rang_bands.append(self.vali_rang_int)
if self.vali_rang_qOcteto in self.vali_rang_bands:
return True
else:
return False
def calculate_network_mask(self, band):
"""Receives a range of IPv4 (Ex. 192.168.0.0/24) separates the IP by octets and bit of the mask and performs
the calculations to identify which are the valid IPs and the Broadcast, returns the first available IP of the
range, the last available IP of the range, the last valid IP assigned as Gateway, IP Broadcast, and the
Calculated Network Mask."""
self.calc_netw_band = band
self.calc_netw_fOcteto, self.calc_netw_sOcteto, self.calc_netw_tOcteto, self.calc_netw_qOcteto_mask = \
self.calc_netw_band.split('.')
self.calc_netw_qOcteto, self.calc_netw_cidr = self.calc_netw_qOcteto_mask.split('/')
self.calc_netw_check = tools.validate_range_ip(self.calc_netw_cidr, self.calc_netw_qOcteto)
if self.calc_netw_check:
self.calc_netw = int(self.calc_netw_qOcteto)
if self.calc_netw_cidr == '30':
self.calc_netw_first = str(self.calc_netw + 1)
self.calc_netw_last = str(self.calc_netw + 2)
self.calc_netw_qOctetoGateway = str(self.calc_netw + 2)
self.calc_netw_broadcast = str(self.calc_netw + 3)
self.calc_netw_mask = '255.255.255.252'
elif self.calc_netw_cidr == '29':
self.calc_netw_first = str(self.calc_netw + 1)
self.calc_netw_last = str(self.calc_netw + 5)
self.calc_netw_qOctetoGateway = str(self.calc_netw + 6)
self.calc_netw_broadcast = str(self.calc_netw + 7)
self.calc_netw_mask = '255.255.255.248'
elif self.calc_netw_cidr == '28':
self.calc_netw_first = str(self.calc_netw + 1)
self.calc_netw_last = str(self.calc_netw + 13)
self.calc_netw_qOctetoGateway = str(self.calc_netw + 14)
self.calc_netw_broadcast = str(self.calc_netw + 15)
self.calc_netw_mask = '255.255.255.240'
elif self.calc_netw_cidr == '27':
self.calc_netw_first = str(self.calc_netw + 1)
self.calc_netw_last = str(self.calc_netw + 29)
self.calc_netw_qOctetoGateway = str(self.calc_netw + 30)
self.calc_netw_broadcast = str(self.calc_netw + 31)
self.calc_netw_mask = '255.255.255.224'
elif self.calc_netw_cidr == '26':
self.calc_netw_first = str(self.calc_netw + 1)
self.calc_netw_last = str(self.calc_netw + 61)
self.calc_netw_qOctetoGateway = str(self.calc_netw + 62)
self.calc_netw_broadcast = str(self.calc_netw + 63)
self.calc_netw_mask = '255.255.255.192'
elif self.calc_netw_cidr == '25':
self.calc_netw_first = str(self.calc_netw + 1)
self.calc_netw_last = str(self.calc_netw + 125)
self.calc_netw_qOctetoGateway = str(self.calc_netw + 126)
self.calc_netw_broadcast = str(self.calc_netw + 127)
self.calc_netw_mask = '255.255.255.128'
elif self.calc_netw_cidr == '24':
self.calc_netw_first = str(self.calc_netw + 1)
self.calc_netw_last = str(self.calc_netw + 253)
self.calc_netw_qOctetoGateway = str(self.calc_netw + 254)
self.calc_netw_broadcast = str(self.calc_netw + 255)
self.calc_netw_mask = '255.255.255.0'
else:
return None
else:
return None
self.calc_netw_fband = ''.join(
self.calc_netw_fOcteto + '.' + self.calc_netw_sOcteto + '.' + self.calc_netw_tOcteto + '.' +
self.calc_netw_first)
self.calc_netw_lband = ''.join(
self.calc_netw_fOcteto + '.' + self.calc_netw_sOcteto + '.' + self.calc_netw_tOcteto + '.' +
self.calc_netw_last)
self.calc_netw_ipGateway = ''.join(
self.calc_netw_fOcteto + '.' + self.calc_netw_sOcteto + '.' + self.calc_netw_tOcteto + '.' +
self.calc_netw_qOctetoGateway)
self.calc_netw_broadcast = ''.join(
self.calc_netw_fOcteto + '.' + self.calc_netw_sOcteto + '.' + self.calc_netw_tOcteto + '.' +
self.calc_netw_broadcast)
return self.calc_netw_fband, self.calc_netw_lband, self.calc_netw_ipGateway, \
self.calc_netw_broadcast, self.calc_netw_mask
def search_in_ticket(self, tag, data, pattern):
"""Searches for a specified string within a list and returns only the required information."""
self.sear_tick_tag = tag
self.sear_tick_data = data
self.sear_tick_pattern = pattern
for self.sear_tick_string in self.sear_tick_data:
re.search(self.sear_tick_tag, self.sear_tick_string)
if re.search(self.sear_tick_tag, self.sear_tick_string):
self.sear_tick_found = re.findall(self.sear_tick_pattern, self.sear_tick_string)
self.sear_tick_found = ''.join(self.sear_tick_found)
return self.sear_tick_found
else:
# print('\nNo match was found')
continue
pass
pass
return None
def search_in_template(self, tag, data):
"""Searches for a specified string within a list and returns only the required information."""
self.sear_temp_tag = tag
self.sear_temp_data = data
for self.sear_temp_string in self.sear_temp_data:
re.search(self.sear_temp_tag, self.sear_temp_string)
# print('Searching for "%s" in \n\n%s' % (self.sear_temp_tag, self.sear_temp_string ))
if re.search(self.sear_temp_tag, self.sear_temp_string):
# print('Match was foud.\n')
self.sear_temp_linenumber = self.sear_temp_data.index(self.sear_temp_string)
return self.sear_temp_linenumber
else:
# print('\nNo match was Foud\n')
continue
pass
pass
def validate_range_extension(self, extensions):
"""Receives an extension or a range of extensions to and performs a pattern check.
Ex. 1932000000 or 1932000000 ~ 1932000099"""
self.vali_rang_exten = extensions
if '~' in self.vali_rang_exten:
self.vali_rang_gama = self.vali_rang_exten.split('~')
self.vali_rang_begin, self.vali_rang_end = self.vali_rang_gama
if self.vali_rang_begin.isnumeric() and self.vali_rang_end.isnumeric:
self.vali_rang_size = int(len(self.vali_rang_begin) + len(self.vali_rang_end))
if self.vali_rang_size == 20:
return True
else:
return False
else:
return False
else:
if self.vali_rang_exten.isnumeric():
self.vali_rang_size = int(len(self.vali_rang_exten))
if self.vali_rang_size == 10:
return True
else:
return False
pass
else:
return False
def run_range_extension(self, tag, new_extension, extension, template):
"""Inserts numbers of extensions into the model according to the growing sequence received."""
self.run_ran_ext_tag = tag
self.run_ran_ext_new_extension = new_extension
self.run_ran_ext_extension = extension
self.run_ran_ext_template = template
if '~' in self.run_ran_ext_extension:
self.run_ran_ext_prefix, self.run_ran_ext_suffix = tools.compare_range(self.run_ran_ext_extension)
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number,
'gw manipulations src-number-map-tel2ip ' + str(
self.run_ran_ext_new_extension) + '\n')
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number,
'src-prefix "' + self.run_ran_ext_suffix + '"\n')
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number, 'num-of-digits-to-leave 0\n')
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number,
'prefix-to-add "' + self.run_ran_ext_prefix + '"\n')
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number, 'activate\n')
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number, 'exit\n')
self.run_ran_ext_new_extension += 1
else:
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number,
'gw manipulations src-number-map-tel2ip ' + str(
self.run_ran_ext_new_extension) + '\n')
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number, 'num-of-digits-to-leave 0\n')
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number,
'prefix-to-add "' + self.run_ran_ext_extension + '"\n')
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number, 'activate\n')
self.run_ran_ext_line_number = (tools.search_in_template(self.run_ran_ext_tag, self.run_ran_ext_template))
self.run_ran_ext_template.insert(self.run_ran_ext_line_number, 'exit\n')
self.run_ran_ext_new_extension += 1
return self.run_ran_ext_template
def run_key_extension(self, tag, extension, template):
"""Inserts a unique extension number.."""
self.run_key_ext_tag = tag
self.run_key_ext_extension = extension
self.run_key_ext_template = template
self.run_key_ext_line_number = (tools.search_in_template(self.run_key_ext_tag, self.run_key_ext_template))
self.run_key_ext_template.insert(self.run_key_ext_line_number, 'gw manipulations src-number-map-tel2ip 0\n')
self.run_key_ext_line_number = (tools.search_in_template(self.run_key_ext_tag, self.run_key_ext_template))
self.run_key_ext_template.insert(self.run_key_ext_line_number, 'num-of-digits-to-leave 0\n')
self.run_key_ext_line_number = (tools.search_in_template(self.run_key_ext_tag, self.run_key_ext_template))
self.run_key_ext_template.insert(self.run_key_ext_line_number,
'prefix-to-add "' + self.run_key_ext_extension + '"\n')
self.run_key_ext_line_number = (tools.search_in_template(self.run_key_ext_tag, self.run_key_ext_template))
self.run_key_ext_template.insert(self.run_key_ext_line_number, 'activate\n')
self.run_key_ext_line_number = (tools.search_in_template(self.run_key_ext_tag, self.run_key_ext_template))
self.run_key_ext_template.insert(self.run_key_ext_line_number, 'exit\n')
return self.run_key_ext_template
def compare_range(self, extensions):
"""Compares two telephone numbers and identifies the variations, changes the variation by 'X' which equals
0 ~ 9 on the router"""
self.comp_rang_exten = extensions
self.comp_rang_gama = self.comp_rang_exten.split('~')
self.comp_rang_begin, self.comp_rang_end = self.comp_rang_gama
if self.comp_rang_begin[-1] != self.comp_rang_end[-1]:
self.comp_rang_check = [x for x in self.comp_rang_end]
self.comp_rang_check[-1] = 'X'
if self.comp_rang_begin[-2] != self.comp_rang_end[-2]:
self.comp_rang_check[-2] = 'X'
self.comp_rang_prefix = [x for x in self.comp_rang_check[:6]]
self.comp_rang_suffix = [x for x in self.comp_rang_check[6:10]]
self.comp_rang_prefix = ''.join(self.comp_rang_prefix)
self.comp_rang_suffix = ''.join(self.comp_rang_suffix)
return self.comp_rang_prefix, self.comp_rang_suffix
class OS:
"""This class is responsible for the attributes of the service order that is reported by the user."""
def __init__(self):
self.id_os = ''
self.size_id = 0
self.product = ''
self.hostname = ''
self.size_host = 0
self.circuit = ''
self.size_circ = 0
self.vlan = ''
self.wan = ''
self.lan = ''
self.speed = ''
self.signaling = ''
self.channel = 0
self.os_host_tag = 'SW: '
self.os_host_pattern = '[^SW: \n]'
self.os_host_tag2 = '(HOSTNAME)'
self.os_inter_circ_tag = 'ID DO SERVIÇO = '
self.os_inter_circ_pattern = '[^A-Za-z:=çÇ \t\n]+'
self.os_inter_circ_tag2 = '(CIRCUITO DADOS)'
self.os_inter_vlan_tag = 'VLAN: '
self.os_inter_vlan_pattern = '[^A-Za-z: \t\n]+'
self.os_inter_vlan_tag2 = '(VLAN DADOS)'
self.os_inter_wan_tag = 'Endereco IP WAN : '
self.os_inter_wan_pattern = '[^A-Za-z: \t\n]+'
self.os_inter_wan_tag2 = '(WAN DE DADOS MASCARA)'
self.os_inter_wan_tag3 = '(WAN DADOS CALC)'
self.os_inter_wan_tag4 = '(WAN DE DADOS PE)'
self.os_inter_lan_tag = 'Endereco IP LAN : '
self.os_inter_lan_pattern = '[^A-Za-z: \t\n]+'
self.os_inter_lan_tag2 = '(LAN DE DADOS MASCARA)'
self.os_inter_lan_tag3 = '(LAN DE DADOS BROAD)'
self.os_inter_lan_tag4 = '(LAN DE DADOS CALC)'
self.os_inter_speed_tag = 'Velocidade = '
self.os_inter_speed_pattern = '[^A-Za-z:= \t\n]+'
self.os_inter_speed_tag2 = '(VELOCIDADE)'
self.os_voip_circ_tag = 'ID DO SERVIÇO = '
self.os_voip_circ_pattern = '[^A-Za-z:=çÇ \t\n]+'
self.os_voip_circ_tag2 = '(CIRCUITO VOIP)'
self.os_voip_vlan_tag = 'VLAN: '
self.os_voip_vlan_pattern = '[^A-Za-z: \t\n]+'
self.os_voip_vlan_tag2 = '(VLAN VOIP)'
self.os_voip_wan_tag = 'Endereco IP WAN : '
self.os_voip_wan_pattern = '[^A-Za-z: \t\n]+'
self.os_voip_wan_tag2 = '(WAN DE VOIP MASCARA)'
self.os_voip_lan_tag = 'Endereco IP LAN : '
self.os_voip_lan_pattern = '[^A-Za-z: \t\n]+'
self.os_voip_lan_tag2 = '(LAN DE VOIP MASCARA)'
self.os_voip_sbc_tag = 'IP SBC: '
self.os_voip_sbc_pattern = '[^A-Za-z: \t\n]+'
self.os_voip_sbc_tag2 = '(SBC)'
self.os_voip_channel_tag = 'CANAIS: '
self.os_voip_channel_pattern = '[^A-Za-z: \t\n]+'
self.os_voip_channel_tag2 = 'last-b-channel '
self.os_voip_man_add_ran_tag = '#FIM DOS RAMAIS'
self.os_voip_auto_add_ran_tag = 'GAMA '
self.os_voip_auto_add_ran_pattert = '[^A-Za-z: \t\n]+'
self.os_voip_auto_add_ran_tag2 = '#FIM DOS RAMAIS'
self.os_voip_man_add_key_tag = '#FIM DOS RAMAIS'
self.os_voip_auto_add_key_tag = 'NUMERO CHAVE ='
self.os_voip_auto_add_key_pattert = '[^A-Za-z: =\t\n]+'
self.os_voip_auto_add_key_tag2 = '#FIM DOS RAMAIS'
self.os_voip_billing_tag = 'Tarifação: '
self.os_voip_billing_pattern = '[^Tarifação: \t\n]'
self.os_voip_billing_tag2 = 'GAMA '
self.os_voip_extension_tag = 'GAMA: '
self.os_voip_extension_pattern = '[^A-Za-z: \t\n]+'
def validate_id(self, id_os):
"""Validates the size of the Service Order number entered by the user."""
self.id_os = id_os
if self.id_os.isnumeric():
self.size_id = len(self.id_os)
if self.size_id <= 6:
return self.id_os
else:
print(tools.centralize_message('\n\nOrdem de Serviço tem Apenas 6 Números!'))
time.sleep(2)
else:
print(tools.centralize_message('\n\nDigite Apenas Números!'))
time.sleep(2)
return False #
def validate_product(self, product):
"""Validates whether it is a valid product to be configured."""
self.product = product
if self.product == 'Internet Link':
return 'Internet Link'
elif self.product == 'Voz Total':
return 'Voz Total'
elif self.product == 'Ponto de Acesso':
return 'Ponto de Acesso'
else:
return None
def validate_hostname(self, hostname):
"""Validate the hostname accepted by the router."""
self.hostname = hostname
self.size_host = len(self.hostname)
if 15 <= self.size_host <= 30:
self.hostname = self.hostname.replace('clm-sw-', 'cl-rt-')
return self.hostname
else:
return None
def validate_circuit(self, circuit):
"""Validate the circuit pattern to be configured."""
self.circuit = circuit
if self.circuit.isnumeric():
self.size_circ = len(self.circuit)
if self.size_circ <= 10:
return self.circuit
else:
print(tools.centralize_message('\n\nDigite no máximo até 10 números!'))
time.sleep(2)
else:
print(tools.centralize_message('\n\nDigite Apenas Números!'))
time.sleep(2)
return None
def validate_vlan(self, vlan):
"""Validate the range of valid vlans."""
self.vlan = vlan
if self.vlan.isnumeric():
self.vlan = int(self.vlan)
if 0 < self.vlan <= 4000:
return str(self.vlan)
else:
print(tools.centralize_message('\n\nDigite Vlan entre 1 e 4000!'))
time.sleep(2)
return None
else:
print(tools.centralize_message('\n\nDigite Apenas Números!'))
time.sleep(2)
return None
def validate_wan(self, wan):
"""Validates the range and calculates valid WAN IPs."""
self.wan = wan
return tools.calculate_network_mask(self.wan)
def validate_lan(self, lan):
"""Validates the range and calculates valid LAN IPs."""
self.lan = lan
return tools.calculate_network_mask(self.lan)
def validate_speed(self, speed):
"""Calculates and converts the reported speed in Mbps to bps."""
self.speed = speed
if self.speed.isnumeric():
self.speed = int(self.speed)
if self.speed > 0:
self.speed *= 1024
return str(self.speed)
else:
return None
else:
print(tools.centralize_message('\n\nDigite Apenas Números!'))
time.sleep(2)
return None
def validate_signaling(self, signaling):
"""Validates the voice signal to be configured."""
self.signaling = signaling
if self.signaling == 'R2':
return 'R2'
elif self.signaling == 'ISDN':
return 'ISDN'
def validate_sbc(self, sbc):
"""Validates the SBC IP octets."""
self.sbc = sbc
return tools.validate_octets(self.sbc)
def validate_channel(self, channel):
"""Validates the valid channel interval for configuration."""
self.channel = channel
if self.channel.isnumeric():
self.channel = int(self.channel)
if 0 < self.channel <= 30:
return str(self.channel)
else:
print(tools.centralize_message('\n\nDigite Canais entre 1 e 30!'))
time.sleep(2)
return None
else:
print(tools.centralize_message('\n\nDigite Apenas Números'))
time.sleep(2)
return None
class Product:
"""This class is responsible for identifying the type of product that will be configured in the equipment"""
def __init__(self, equipment, product, tickets):
self.prod_equipment = equipment
self.prod_product = product
self.prod_tickets = tickets
self.audio_ivr2_hostname = None
self.audio_ivr2_inter_circuit = None
self.audio_ivr2_inter_vlan = None
self.audio_ivr2_inter_wan = None
self.audio_ivr2_inter_lan = None
self.audio_ivr2_inter_speed = None
self.audio_ivr2_voip_circuit = None
self.audio_ivr2_voip_vlan = None
self.audio_ivr2_voip_wan = None
self.audio_ivr2_voip_lan = None
self.audio_ivr2_voip_sbc = None
self.audio_ivr2_voip_channel = None
self.audio_ivr2_voip_billing = None
self.audio_ivr2_archive = ''
self.audio_ivr2_template = []
self.facilities = OS()
self.audio_ivr2_internet_link = []
self.audio_ivr2_voz_total = []
self.audio_ivr2_ponto_de_acesso = []
self.host_hostname = ''
self.host_template = []
self.host_linenumber = 0
self.circ_circuit_inter = ''
self.circ_template_inter = []
self.circ_linenumber_inter = 0
self.vl_vlan_inter = ''
self.vl_template_inter = []
self.vl_linenumber_inter = 0
self.vl_occurrence_inter = 0
self.vl_string_inter = ''
self.vl_int_inter = 0
self.wan_inter_wan = ''
self.wan_inter_template = []
self.wan_inter_string = ''
self.wan_inter_occurrences = 0
self.wan_inter_occurrences1 = 0
self.wan_inter_occurrences2 = 0
self.wan_inter_fband = ''
self.wan_inter_lband = ''
self.wan_inter_ipGateway = ''
self.wan_inter_broadcast = ''
self.wan_inter_mask = ''
self.wan_inter_search = ''
self.wan_inter_line_number = 0
self.lan_inter_wan = ''
self.lan_inter_template = []
self.lan_inter_string = ''
self.lan_inter_occurrences = 0
self.lan_inter_occurrences1 = 0
self.lan_inter_occurrences2 = 0
self.lan_inter_fband = ''
self.lan_inter_lband = ''
self.lan_inter_ipGateway = ''
self.lan_inter_broadcast = ''
self.lan_inter_mask = ''
self.lan_inter_search = ''
self.lan_inter_line_number = 0
self.speed_speed_inter = ''
self.speed_template_inter = []
self.speed_linenumber_inter = 0
self.speed_occurrence_inter = 0
self.speed_string_inter = ''
self.circ_circuit_voip = ''
self.circ_template_voip = []
self.circ_linenumber_voip = 0
self.vl_vlan_voip = ''
self.vl_template_voip = []
self.vl_linenumber_voip = 0
self.vl_occurrence_voip = 0
self.vl_string_voip = ''
self.wan_voip_wan = ''
self.wan_voip_template = []
self.wan_voip_string = ''
self.wan_voip_occurrences = 0
self.wan_voip_occurrences1 = 0
self.wan_voip_occurrences2 = 0
self.wan_voip_fband = ''
self.wan_voip_lband = ''
self.wan_voip_ipGateway = ''
self.wan_voip_broadcast = ''
self.wan_voip_mask = ''
self.wan_voip_search = ''
self.wan_voip_line_number = 0
self.lan_voip_wan = ''
self.lan_voip_template = []
self.lan_voip_string = ''
self.lan_voip_occurrences = 0
self.lan_voip_occurrences1 = 0
self.lan_voip_occurrences2 = 0
self.lan_voip_fband = ''
self.lan_voip_lband = ''
self.lan_voip_ipGateway = ''
self.lan_voip_broadcast = ''
self.lan_voip_mask = ''
self.lan_voip_search = ''
self.lan_voip_line_number = 0
self.sbc_voip_sbc = ''
self.sbc_voip_template = []
self.sbc_linenumber_voip = 0
self.sbc_occurrence_voip = 0
self.sbc_string_voip = ''
self.ch_channel_voip = ''
self.ch_template_voip = []
self.ch_linenumber_voip = 0
self.ch_occurrence_voip = 0
self.ch_string_voip = ''
self.man_add_ran_exten = ''
self.man_add_ran_template = []
self.man_add_ran_new_exten = 0
self.man_add_ran_check = False
self.man_add_ran_line_number = 0
self.man_add_ran_add = ''
self.auto_add_ran_exten = ''
self.auto_add_ran_template = []
self.auto_add_ran_ticket_voztotal = []
self.auto_add_ran_new_exten = 0
self.auto_add_ran_check = False
self.man_add_key_exten = ''
self.man_add_key_template = ''
self.man_add_key_check = False
self.auto_add_key_exten = ''
self.auto_add_key_template = []
self.auto_add_key_ticket_voztotal = []
self.auto_add_key_new_exten = 0
self.auto_add_key_check = False
self.bi_billing_voip = ''
self.bi_template_voip = []
self.bi_ticket_voztotal = []
self.bi_occurrence_voip = 0
self.bi_new_extension = 0
self.bi_billing_extension = ''
self.gener_template = []
def hostname(self, hostname, template):
"""Enter the "hostname" of the router in the default configuration template."""
self.host_hostname = hostname
self.host_template = template
self.host_linenumber = tools.search_in_template(self.facilities.os_host_tag2, self.host_template)
while True:
if self.host_hostname is None:
os.system('cls')
self.host_hostname = input(tools.centralize_message(
main.banner + '\n\n\nDIGITE HOSTNAME:\tEx. cl-sw-cas-00001-empresa-01') + '\n\n\n Hostname > ')
self.host_hostname = OS.validate_hostname(self, self.host_hostname)
if self.host_hostname is None:
print(tools.centralize_message('\nHostname deve ter entre 15 e 30 caracteres!'))
time.sleep(2)
continue
else:
self.host_template[self.host_linenumber] = self.host_template[self.host_linenumber].replace \
(self.facilities.os_host_tag2, self.host_hostname)
return self.host_template
else:
self.host_hostname = OS.validate_hostname(self, self.host_hostname)
self.host_template[self.host_linenumber] = self.host_template[self.host_linenumber].replace \
(self.facilities.os_host_tag2, self.host_hostname)
return self.host_template
def circuit_inter(self, circuit, template):
"""Enter the circuit number in the default configuration template."""
self.circ_circuit_inter = circuit
self.circ_template_inter = template
self.circ_linenumber_inter = tools.search_in_template(self.facilities.os_inter_circ_tag2,
self.circ_template_inter)
while True:
if self.circ_circuit_inter is None:
os.system('cls')
self.circ_circuit_inter = input(
tools.centralize_message(main.banner + '\n\n\nDigite ID do Circuito Internet Link:'
'\tEx. 0000000001') +
'\n\n\n Circuito de Internet Link > ')
self.circ_circuit_inter = self.facilities.validate_circuit(self.circ_circuit_inter)
if self.circ_circuit_inter is None:
continue
else:
self.circ_template_inter[self.circ_linenumber_inter] = self.circ_template_inter[
self.circ_linenumber_inter].replace(self.facilities.os_inter_circ_tag2, self.circ_circuit_inter)
return self.circ_template_inter
else:
self.circ_circuit_inter = self.facilities.validate_circuit(self.circ_circuit_inter)
self.circ_template_inter[self.circ_linenumber_inter] = self.circ_template_inter[
self.circ_linenumber_inter].replace(self.facilities.os_inter_circ_tag2, self.circ_circuit_inter)
return self.circ_template_inter
def vlan_inter(self, vlan, template):
"""Inserts the Internet VLAN into the default configuration template.."""
self.vl_vlan_inter = vlan
self.vl_template_inter = template
for self.vl_string_inter in self.vl_template_inter:
if self.facilities.os_inter_vlan_tag2 in self.vl_string_inter:
self.vl_occurrence_inter += 1
while True:
if self.vl_vlan_inter is None:
os.system('cls')
self.vl_vlan_inter = input(tools.centralize_message(
main.banner + '\n\n\nDigite Vlan de Internet Link:\tEx. 10') + '\n\n\n Vlan de Internet Link > ')
self.vl_vlan_inter = self.facilities.validate_vlan(self.vl_vlan_inter)
if self.vl_vlan_inter is None:
continue
else:
for self.vl_string_inter in range(self.vl_occurrence_inter):
self.vl_linenumber_inter = tools.search_in_template(self.facilities.os_inter_vlan_tag2,
self.vl_template_inter)
self.vl_template_inter[self.vl_linenumber_inter] = self.vl_template_inter[
self.vl_linenumber_inter].replace(self.facilities.os_inter_vlan_tag2, self.vl_vlan_inter)
return self.vl_template_inter
else:
self.vl_vlan_inter = self.facilities.validate_vlan(self.vl_vlan_inter)
for self.vl_int_inter in range(self.vl_occurrence_inter):
self.vl_linenumber_inter = tools.search_in_template(self.facilities.os_inter_vlan_tag2,
self.vl_template_inter)
self.vl_template_inter[self.vl_linenumber_inter] = self.vl_template_inter[
self.vl_linenumber_inter].replace(self.facilities.os_inter_vlan_tag2, self.vl_vlan_inter)
return self.vl_template_inter
def wan_inter(self, wan, template):
"""Inserts the WAN IPs calculated in the default configuration template according to each field."""
self.wan_inter_wan = wan
self.wan_inter_template = template
for self.wan_inter_string in self.wan_inter_template:
if self.facilities.os_inter_wan_tag2 in self.wan_inter_string:
self.wan_inter_occurrences += 1
for self.wan_inter_string in self.wan_inter_template:
if self.facilities.os_inter_wan_tag3 in self.wan_inter_string:
self.wan_inter_occurrences1 += 1
for self.wan_inter_string in self.wan_inter_template:
if self.facilities.os_inter_wan_tag4 in self.wan_inter_string:
self.wan_inter_occurrences2 += 1
while True:
if self.wan_inter_wan is None:
os.system('cls')
self.wan_inter_wan = input(tools.centralize_message(
main.banner + '\n\n\nDigite a faixa Wan de Internet Link:\tEx. 200.125.78.28/30') +
'\n\n\n Wan de Internet Link > ')
try:
self.wan_inter_fband, self.wan_inter_lband, self.wan_inter_ipGateway, self.wan_inter_broadcast, \
self.wan_inter_mask = (self.facilities.validate_wan(self.wan_inter_wan))
except ValueError:
print(tools.centralize_message('\n Entrada Invalida!'))
time.sleep(2)
self.wan_inter_wan = None
continue
except TypeError:
print(tools.centralize_message('\n Faixa de Wan Invalida!'))
time.sleep(2)
self.wan_inter_wan = None
continue
for self.wan_inter_search in range(self.wan_inter_occurrences):
self.wan_inter_line_number = (
tools.search_in_template(self.facilities.os_inter_wan_tag2, self.wan_inter_template))
self.wan_inter_template[self.wan_inter_line_number] = self.wan_inter_template[
self.wan_inter_line_number].replace(self.facilities.os_inter_wan_tag2,
self.wan_inter_fband + ' ' + self.wan_inter_mask)
for self.wan_inter_search in range(self.wan_inter_occurrences1):
self.wan_inter_line_number = (
tools.search_in_template(self.facilities.os_inter_wan_tag3, self.wan_inter_template))
self.wan_inter_template[self.wan_inter_line_number] = self.wan_inter_template[
self.wan_inter_line_number].replace(self.facilities.os_inter_wan_tag3, self.wan_inter_fband)
for self.wan_inter_search in range(self.wan_inter_occurrences2):
self.wan_inter_line_number = (
tools.search_in_template(self.facilities.os_inter_wan_tag4, self.wan_inter_template))
self.wan_inter_template[self.wan_inter_line_number] = self.wan_inter_template[
self.wan_inter_line_number].replace(self.facilities.os_inter_wan_tag4, self.wan_inter_lband)
return self.wan_inter_template
else:
try:
self.wan_inter_fband, self.wan_inter_lband, self.wan_inter_ipGateway, self.wan_inter_broadcast, \
self.wan_inter_mask = (self.facilities.validate_wan(self.wan_inter_wan))
except ValueError:
self.wan_inter_wan = None
continue
except TypeError:
self.wan_inter_wan = None
continue
for self.wan_inter_search in range(self.wan_inter_occurrences):
self.wan_inter_line_number = (
tools.search_in_template(self.facilities.os_inter_wan_tag2, self.wan_inter_template))
self.wan_inter_template[self.wan_inter_line_number] = self.wan_inter_template[
self.wan_inter_line_number].replace(self.facilities.os_inter_wan_tag2,
self.wan_inter_fband + ' ' + self.wan_inter_mask)
for self.wan_inter_search in range(self.wan_inter_occurrences1):
self.wan_inter_line_number = (
tools.search_in_template(self.facilities.os_inter_wan_tag3, self.wan_inter_template))
self.wan_inter_template[self.wan_inter_line_number] = self.wan_inter_template[
self.wan_inter_line_number].replace(self.facilities.os_inter_wan_tag3, self.wan_inter_fband)
for self.wan_inter_search in range(self.wan_inter_occurrences2):
self.wan_inter_line_number = (
tools.search_in_template(self.facilities.os_inter_wan_tag4, self.wan_inter_template))
self.wan_inter_template[self.wan_inter_line_number] = self.wan_inter_template[
self.wan_inter_line_number].replace(self.facilities.os_inter_wan_tag4, self.wan_inter_lband)
return self.wan_inter_template
def lan_inter(self, lan, template):
"""Inserts the LAN IPs calculated in the default configuration template according to each field."""
self.lan_inter_lan = lan
self.lan_inter_template = template
for self.lan_inter_string in self.lan_inter_template:
if self.facilities.os_inter_lan_tag2 in self.lan_inter_string:
self.lan_inter_occurrences += 1
for self.lan_inter_string in self.lan_inter_template:
if self.facilities.os_inter_lan_tag3 in self.lan_inter_string:
self.lan_inter_occurrences1 += 1
for self.lan_inter_string in self.lan_inter_template:
if self.facilities.os_inter_lan_tag4 in self.lan_inter_string:
self.lan_inter_occurrences2 += 1
while True:
if self.lan_inter_lan is None:
os.system('cls')
self.lan_inter_lan = input(
tools.centralize_message(
main.banner + '\n\n\nDigite a faixa Lan de Internet Link:\tEx. 200.125.78.24/29') +