forked from cgustave/fgtconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfg_translate.pm
More file actions
1968 lines (1540 loc) · 64.9 KB
/
cfg_translate.pm
File metadata and controls
1968 lines (1540 loc) · 64.9 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
# ****************************************************
# * *
# * T R A N S L A T E *
# * *
# * Fortigate KVM converter for lab tests *
# * *
# * Framework : fgtconfig *
# * Author : Cedric Gustave cgustave@fortinet.com *
# * *
# ****************************************************
package cfg_translate ;
my $obj = "cfg_translate" ;
use Moose ;
extends('cfg_fgtconfig') ;
use strict ;
use warnings ;
use XML::LibXML ;
use lib "." ;
use constant NESTED => 1 ;
use constant NOTNESTED => 0 ;
# the XML transform file with all transforms actions to process
has 'transform' => (
isa => 'Str',
is => 'rw',
required => '1',
) ;
# ---
sub BUILD {
my $subn = "BUILD" ;
my $self = shift ;
warn "\n* Entering $obj:$subn debug_level=" . $self->debug_level() if $self->debug_level() ;
# object debug masks
# 1 : translate
# 2 : fgtconfig
# 4 : cfg_dissector
# 8 : cfg_interfaces
# 16 : cfg_global
# 32 : cfg_vdom
# 64 : cfg_display
# 128 : cfg_statistics
# Set debug for ourself if & 2
$self->debug(1) if ($self->debug_level & 1) ;
}
# ---
sub start {
my $subn = "start" ;
my $self = shift ;
print "\nStarting translation of " . $self->configfile . " based on transform " . $self->transform . "\n" ;
print " o load configuration\n" ;
# Read-only
$self->parse() ;
print " o summary :\n\n" ;
$self->summary() ;
$self->load_transform() ;
# Header transform
$self->header_transform() ;
# Configuration modification
$self->global_transforms() ;
# Interfaces translations
$self->interfaces_processing() ;
$self->interfaces_post_processing() ;
# All vdoms
$self->all_vdoms_processing() ;
# Specific vdoms processing
$self->vdoms_processing() ;
# Save configuration
$self->save() ;
}
# ---
sub load_transform {
my $subn = "load_transform" ;
my $self = shift ;
warn "\n* Entering $obj:$subn" if $self->debug ;
print " o load transform file : " . $self->transform . "\n" ;
$self->XMLTrsf(new XML::LibXML->load_xml(location => $self->transform)) or die "Cannot open transform XML file " . $self->transform ;
# TODO : Optional validation of the file could be done here
# Provide transform to fgtconfig
$self->XMLTrsf($self->XMLTrsf) ;
}
# ---
sub header_transform {
my $subn = "header_transform" ;
my $self = shift ;
warn "\n* Entering $obj:$subn" if $self->debug ;
my $hdr = $self->cfg->get_line(index => 1) ;
if (
(my $platform) =
$hdr =~ /
(?:\#config-version=)
(\S{6})
(?:-)
/x
)
{
warn "$obj:$subn platform=$platform" if $self->debug ;
# Replace platform with FGVMK6
$hdr =~ s/$platform/FGVMK6/ ;
# Replacing whichever admin user with admin
$hdr =~ s/:user=(\S+)/:user=admin/g ;
warn "$obj:$subn transformed header=$hdr" if $self->debug ;
# save header
chomp($hdr) ;
$self->cfg->replace(index => 1, content => $hdr . "\n") ;
}
else {
die "unrecognised header format" ;
}
}
# ---
sub global_transforms {
my $subn = "global_transforms" ;
# All config transform appluying globally
# defined in XML <global> section
my $self = shift ;
warn "\n* Entering $obj:$subn" if $self->debug ;
# <system_global admintimeout="475" alias="HUB2" gui-theme="neutrino" admin-port="80" admin-sport="443" admin-ssh-port="22" timezone="28"/>
my $admintimeout = $self->XMLTrsf->findvalue('/transform/global/system_global/@admintimeout') ;
my $alias = $self->XMLTrsf->findvalue('/transform/global/system_global/@alias') ;
my $guitheme = $self->XMLTrsf->findvalue('/transform/global/system_global/@gui-theme') ;
my $adminport = $self->XMLTrsf->findvalue('/transform/global/system_global/@admin-port') ;
my $adminsport = $self->XMLTrsf->findvalue('/transform/global/system_global/@admin-sport') ;
my $adminsshport = $self->XMLTrsf->findvalue('/transform/global/system_global/@admin-ssh-port') ;
my $timezone = $self->XMLTrsf->findvalue('/transform/global/system_global/@timezone') ;
if (($admintimeout ne "") or ($alias ne "") or ($guitheme ne "")) {
$self->global_system_global(admintimeout=>$admintimeout, alias=>$alias, guitheme=>$guitheme, timezone=>$timezone,
adminport=>$adminport, adminsport=>$adminsport, adminsshport=>$adminsshport) ;
}
# <system_admin password="unset" />
my $password = $self->XMLTrsf->findvalue('/transform/global/system_admin/@password') ;
my $trustedhost = $self->XMLTrsf->findvalue('/transform/global/system_admin/@trustedhost');
$self->global_system_admin($password, $trustedhost) if (($password ne "") or ($trustedhost ne "")) ;
# <system_dns primary="8.8.8.8" source-ip="unset" />
my $primary = $self->XMLTrsf->findvalue('/transform/global/system_dns/@primary') ;
my $secondary = $self->XMLTrsf->findvalue('/transform/global/system_dns/@secondary') ;
my $source_ip = $self->XMLTrsf->findvalue('/transform/global/system_dns/@source-ip') ;
my $dns_over_tls = $self->XMLTrsf->findvalue('/transform/global/system_dns/@dns-over-tls');
$self->global_system_dns($primary, $secondary, $source_ip, $dns_over_tls)
if (($primary ne "") or ($secondary ne "") or ($source_ip ne "") or ($dns_over_tls ne "")) ;
# remove hardware-switch
my $hswitch_action = $self->XMLTrsf->findvalue('/transform/global/system_physical-switch/@action') ;
$self->global_system_physical_switch_remove() if ($hswitch_action eq "remove") ;
# remove virtual-switch
my $vswitch_action = $self->XMLTrsf->findvalue('/transform/global/system_virtual-switch/@action') ;
$self->global_system_virtual_switch_remove() if ($vswitch_action eq "remove") ;
# <system_ha password="unset" group-id="7" />
my $ha_password = $self->XMLTrsf->findvalue('/transform/global/system_ha/@password') ;
my $ha_group_id = $self->XMLTrsf->findvalue('/transform/global/system_ha/@group-id') ;
my $ha_monitor = $self->XMLTrsf->findvalue('/transform/global/system_ha/@monitor') ;
$self->global_system_ha($ha_password, $ha_group_id, $ha_monitor)
if (($ha_group_id ne "") or ($ha_password ne "") or ($ha_monitor ne "")) ;
# central management fmg-source-ip
my $cm_fmg_source_ip = $self->XMLTrsf->findvalue('/transform/global/system_central-management/@fmg-source-ip') ;
my $cm_type = $self->XMLTrsf->findvalue('/transform/global/system_central-management/@type') ;
$self->global_system_central_management($cm_type, $cm_fmg_source_ip)
if (($cm_fmg_source_ip ne "") or ($cm_type ne "")) ;
# fortianalyzer setting
my $faz_status = $self->XMLTrsf->findvalue('/transform/global/log_fortianalyzer_setting/@status') ;
my $faz_server = $self->XMLTrsf->findvalue('/transform/global/log_fortianalyzer_setting/@server') ;
my $faz_source_ip = $self->XMLTrsf->findvalue('/transform/global/log_fortianalyzer_setting/@source-ip') ;
$self->global_log_fortianalyzer_setting($faz_status, $faz_server, $faz_source_ip)
if (($faz_status ne "") or ($faz_server ne "") or ($faz_source_ip ne "")) ;
# system ntp
my $ntp_ntpsync = $self->XMLTrsf->findvalue('/transform/global/system_ntp/@ntpsync') ;
my $ntp_server = $self->XMLTrsf->findvalue('/transform/global/system_ntp/@server') ;
my $ntp_source_ip = $self->XMLTrsf->findvalue('/transform/global/system_ntp/@source-ip') ;
$self->global_system_ntp($ntp_ntpsync, $ntp_server, $ntp_source_ip)
if (($ntp_ntpsync ne "") or ($ntp_server ne "") or ($ntp_source_ip ne "")) ;
# Netflow
my $netflow_collector_ip = $self->XMLTrsf->findvalue('/transform/global/system_netflow/@collector-ip') ;
my $netflow_source_ip = $self->XMLTrsf->findvalue('/transform/global/system_netflow/@source-ip') ;
$self->global_system_netflow($netflow_collector_ip, $netflow_source_ip)
if (($netflow_collector_ip ne "") or ($netflow_source_ip ne "")) ;
}
# ---
sub global_system_global {
my $subn = "global_system_global" ;
my $self = shift ;
my %options = @_ ;
my $admintimeout = $options{'admintimeout'} ;
my $alias = $options{'alias'} ;
my $guitheme = $options{'guitheme'} ;
my $adminsshport = $options{'adminsshport'} ;
my $adminsport = $options{'adminsport'} ;
my $adminport = $options{'adminport'} ;
my $timezone = $options{'timezone'} ;
warn "\n*Enter $obj:$subn with admintimeout=$admintimeout and alias=$alias guitheme=$guitheme adminsshport=$adminsshport adminsport=$adminsport adminport=$adminport timezone=$timezone" if $self->debug ;
my @scope = () ;
$self->cfg->scope_config(\@scope, 'config system global') ;
if ($self->cfg->feedback('found')) {
if ($admintimeout ne "") {
print " o set admintimeout $admintimeout\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'admintimeout',
value => $admintimeout,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 1
) ;
}
if ($alias ne "") {
print " o set alias $alias\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'alias',
value => $alias,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 1
) ;
}
if ($guitheme ne "") {
die "gui-theme can only be 'green*|neutrino|blue|melongene|mariner' but not $guitheme"
if $guitheme !~ /green|neutrino|blue|melongene|mariner/;
print " o set gui-them $guitheme\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'gui-theme',
value => $guitheme,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 1
) ;
}
if ($adminport ne "") {
die "$adminport must be an integer" if ($adminport !~ /\d+/);
print " o set admin-port $adminport\n";
$self->cfg->set_key(
aref_scope => \@scope,
key => 'admin-port',
value => $adminport,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 1
) ;
}
if ($adminsport ne "") {
die "$adminsport must be an integer" if ($adminsport !~ /\d+/);
print " o set admin-sport $adminsport\n";
$self->cfg->set_key(
aref_scope => \@scope,
key => 'admin-sport',
value => $adminsport,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 1
) ;
}
if ($adminsshport ne "") {
die "$adminsshport must be an integer" if ($adminsshport !~ /\d+/);
print " o set admin-sshport $adminsshport\n";
$self->cfg->set_key(
aref_scope => \@scope,
key => 'admin-ssh-port',
value => $adminsshport,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 1
) ;
}
if ($timezone ne "") {
die "$timezone must be an integer" if ($timezone !~ /\d+/);
print " o set timezone $timezone\n";
$self->cfg->set_key(
aref_scope => \@scope,
key => 'timezone',
value => $timezone,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 1
) ;
}
}
}
# ---
sub global_system_physical_switch_remove {
my $subn = "global_system_physical_switch_remove" ;
my $self = shift ;
warn "\n* Entering $obj:$subn" if $self->debug ;
my @scope = () ;
$self->cfg->scope_config(\@scope, 'config system physical-switch') ;
if ($self->cfg->feedback('found')) {
$self->cfg->delete_block(startindex => $scope[0], endindex=>$scope[1]) ;
print " o Deleting physical-switch\n";
}
else {
print " ! Could not found physical-switch configuration\n";
}
}
# ---
sub global_system_virtual_switch_remove {
my $subn = "global_system_virtual_switch_remove" ;
my $self = shift ;
warn "\n* Entering $obj:$subn" if $self->debug ;
my @scope = () ;
$self->cfg->scope_config(\@scope, 'config system virtual-switch') ;
if ($self->cfg->feedback('found')) {
$self->cfg->delete_block(startindex => $scope[0], endindex=>$scope[1]) ;
print " o Deleting virtual-switch\n";
}
else {
print " ! Could not found virtual-switch configuration\n";
}
}
# ---
sub global_system_admin {
my $subn = "global_system_admin" ;
my $self = shift ;
my $password = shift ;
my $trustedhost = shift ;
warn "\n* Entering $obj:$subn with password=$password trustedhost=$trustedhost" if $self->debug ;
my @scope = () ;
$self->cfg->scope_config(\@scope, 'config system admin') ;
$self->cfg->scope_edit(\@scope, 'edit "admin"') ;
if ($self->cfg->feedback('found')) {
if ($password eq 'unset') {
print " o unset admin password\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'password') ;
}
elsif ($password ne "") {
print " o set admin password $password\n" ;
# if insertion is request, password will be inserted just after edit "admin"
$self->cfg->set_key(
aref_scope => \@scope,
key => 'password',
value => $password,
nb_spaces => 8,
netsted => 'NOTNESTED',
increment_index => 3
) ;
}
# remove all trustedhosts (unset only)
if ($trustedhost eq 'unset') {
print " o unset all trustedhosts (1 to 10)\n" ;
my $i ;
for ($i=1, $i<11, $i++) {
$self->cfg->unset_key(aref_scope => \@scope, key => 'trustedhost'.$i) ;
}
}
}
else {
print " WARNING : no admin user found on the config\n" ;
}
}
# ---
sub global_system_dns {
my $subn = "global_system_dns" ;
my $self = shift ;
my $primary = shift ;
my $secondary = shift ;
my $source_ip = shift ;
my $dns_over_tls = shift ;
warn "\n* Entering $obj:$subn with primary=$primary secondary=$secondary source_ip=$source_ip dns_over_tls=$dns_over_tls" if $self->debug ;
my @scope = () ;
$self->cfg->scope_config(\@scope, 'config system dns') ;
if ($self->cfg->feedback('found')) {
if ($primary ne "") {
print " o set primary dns $primary\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'primary',
value => $primary,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 1
) ;
}
if ($secondary ne "") {
print " o set secondary dns $secondary\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'secondary',
value => $secondary,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 2
) ;
}
if ($source_ip ne "") {
if ($source_ip eq "unset") {
print " o unset dns source-ip\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'source-ip') ;
}
else {
print " o set dns source-ip $source_ip\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'source-ip',
value => $source_ip,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 3
) ;
}
}
if ($dns_over_tls ne "") {
if ($dns_over_tls eq "unset") {
print " o unset dns-over-tls\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'dns-over-tls') ;
}
else {
print " o set dns-over-tls $dns_over_tls\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'dns-over-tls',
value => $dns_over_tls,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 3
) ;
}
}
}
else {
print " WARNING : can't find config system dns\n" ;
}
}
# ---
sub global_system_ha {
my $subn = "global_system_ha" ;
my $self = shift ;
my $password = shift ;
my $group_id = shift ;
my $monitor = shift ;
warn "\n* Entering $obj:$subn with password=$password group_id=$group_id monitor=$monitor" if $self->debug ;
my @scope = () ;
$self->cfg->scope_config(\@scope, 'config system ha') ;
if ($self->cfg->feedback('found')) {
if ($password eq "unset") {
print " o unser ha password\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'password') ;
}
else {
print " o set ha password $password\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'password',
value => $password,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 3
) ;
}
if ($group_id ne "") {
print " o set ha group-id $group_id\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'group-id',
value => $group_id,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 4
) ;
}
if ($monitor eq "unset") {
print " o unset ha monitor\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'monitor') ;
}
else {
print " o set ha monitor $monitor\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'monitor',
value => $monitor,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 5
) ;
}
}
else {
print " WARNING : can't find config system ha\n" ;
}
}
# ---
sub global_system_central_management {
my $subn = "global_system_central_management" ;
my $self = shift ;
my $type = shift ;
my $fmg_source_ip = shift ;
warn "\n* Entering $obj:$subn with type=$type and fmg_source_ip=$fmg_source_ip" if $self->debug ;
my @scope = () ;
$self->cfg->scope_config(\@scope, 'config system central-management') ;
if ($self->cfg->feedback('found')) {
# type
if ($type eq "unset") {
print " o unset central-management type\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'type') ;
}
elsif ($type ne "") {
die "type can only be none|fortiguard|fortimanager"
if ($type !~ /none|fortiguard|fortimanager|unset/) ;
print " o set central-management type $type\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'type',
value => $type,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 2
) ;
}
# source-ip
if ($fmg_source_ip eq "unset") {
print " o unset central-management fmg-source-ip\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'fmg-source-ip') ;
}
elsif ($fmg_source_ip ne "") {
$self->cfg->set_key(
aref_scope => \@scope,
key => 'fmg-source-ip',
value => $fmg_source_ip,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 3
) ;
}
}
else {
print " WARNING : can't find config system central-management\n" ;
}
}
# ---
sub global_log_fortianalyzer_setting {
my $subn = "global_log_fortianalyzer_setting" ;
my $self = shift ;
my $status = shift ;
my $server = shift ;
my $source_ip = shift ;
warn "\n* Entering $obj:$subn with status=$status server=$server source_ip=$source_ip" if $self->debug ;
my @scope = () ;
$self->cfg->scope_config(\@scope, 'config log fortianalyzer setting') ;
if ($self->cfg->feedback('found')) {
# status
if ($status eq "unset") {
print " o unset fortianalyzer setting status\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'status') ;
}
elsif ($status ne "") {
die "status can only be enable|disable|unset" if ($status !~ /enable|disable|unset/) ;
print " o set fortianalyzer setting status\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'status',
value => $status,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 2
) ;
}
# server
if ($server eq "unset") {
print " o unset fortianalyzer setting server\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'server') ;
}
elsif ($server ne "") {
print " o set fortianalyzer setting server\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'server',
value => $server,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 2
) ;
}
# source-ip
if ($source_ip eq "unset") {
print " o unset fortianalyzer source-ip\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'source-ip') ;
}
elsif ($source_ip ne "") {
$self->cfg->set_key(
aref_scope => \@scope,
key => 'source-ip',
value => $source_ip,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 2
) ;
}
}
}
# ---
sub global_system_ntp {
my $subn = "global_system_ntp" ;
my $self = shift ;
my $ntpsync = shift ;
my $server = shift ;
my $source_ip = shift ;
warn "\n* Entering $obj:$subn with ntpsync=$ntpsync server=$server source_ip=$source_ip" if $self->debug ;
my @scope = () ;
$self->cfg->scope_config(\@scope, 'config system ntp') ;
if ($self->cfg->feedback('found')) {
# ntpsync
if ($ntpsync eq "unset") {
print " o unset system ntp ntpsync\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'ntpsync') ;
}
elsif ($ntpsync ne "") {
die "ntpsync can only be unset|enable|disable" if ($ntpsync !~ /unset|enable|disable"/) ;
print " o set system ntp ntpsync $ntpsync\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'ntpsync',
value => $ntpsync,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 2
) ;
}
# server
if ($server ne "") {
print " o set system ntp server $server\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'server',
value => $server,
nb_spaces => 12,
netsted => 'NESTED',
increment_index => 2
) ;
}
# source-ip
if ($source_ip eq "unset") {
print " o unset system ntp source-ip\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'source-ip') ;
}
}
else {
print " WARNING : could not find system ntp ntpsync\n" ;
}
}
# ---
sub global_system_netflow {
my $subn = "global_system_netflow" ;
my $self = shift ;
my $collector_ip = shift ;
my $source_ip = shift ;
warn "\n* Entering $obj:$subn with collector_ip=$collector_ip source_ip=$source_ip" if $self->debug ;
my @scope = () ;
$self->cfg->scope_config(\@scope, 'config system netflow') ;
if ($self->cfg->feedback('found')) {
# collector-ip
if ($collector_ip ne "") {
print " o set netflow collector-ip $collector_ip\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'collector-ip',
value => $collector_ip,
nb_spaces => 4,
netsted => 'NOTNESTED',
increment_index => 2
) ;
}
# source-ip
if ($source_ip eq "unset") {
print " o unset netflow source-ip\n" ;
$self->cfg->unset_key(aref_scope => \@scope, key => 'source-ip') ;
}
elsif ($source_ip ne "") {
print " o set netflow source-ip $source_ip\n" ;
$self->cfg->set_key(
aref_scope => \@scope,
key => 'source-ip',
value => $source_ip,
nb_spaces => 8,
netsted => 'NOTNESTED',
increment_index => 2
) ;
}
}
else {
print " WARNING : cannot find config system netflow\n" ;
}
}
# ---
sub interfaces_processing {
my $subn = "interfaces_processing" ;
my $self = shift ;
warn "\n* Entering $obj:$subn" if $self->debug ;
die "undefined XMLTrsf" if (not(defined($self->XMLTrsf))) ;
# Get node pointer on system_interfaces
my $nodes = $self->XMLTrsf->findnodes('/transform/global/system_interfaces')->get_node(1) ;
# Proceed first with all translation
$self->_interfaces_translations(\$nodes) ;
# all tunnel interfaces brough down by default if asked
my $tunnel_status = $self->XMLTrsf->findvalue('/transform/global/system_interfaces/@tunnel_status') ;
$self->_interfaces_tunnel_default_disable() if ($tunnel_status eq "disable") ;
# When done, proceed with configuration
$self->_interfaces_configurations(\$nodes) ;
}
# ---
sub interfaces_post_processing {
my $subn = "interfaces_post_processing" ;
# To be used after interface processing for some adjustments like :
# - ha hbdev can only have physical ports and does not allow loopacks
my $self = shift ;
warn "\n* Entering $obj:$subn" if $self->debug ;
print " o interface post processing : " ;
# ha hbdev can only have physical ports and does not allow loopacks
my @scope = () ;
# Create table of physical ports
my %hash_physical = () ;
foreach my $int (@{$self->intfs->{_INTERFACE_LIST}}) {
next if ($self->intfs->get(name => $int, key => 'type') ne 'physical') ;
$hash_physical{$int} = 1 ;
}
print "remove non-physical HA hbdev" ;
if ($self->cfg->scope_config(\@scope, 'config system ha', 0) and $self->cfg->feedback('found')) {
$self->cfg->get_key(\@scope, 'hbdev', NOTNESTED, "") ;
if ($self->cfg->feedback('found')) {
my $index = $self->cfg->feedback('index') ;
my $line = $self->cfg->get_line(index => $index) ;
warn "$obj:$subn nbdev found at index=$index line=$line" if $self->debug ;
$line =~ s/(\s+)set hbdev// ;
my $new_line = " set hbdev" ;
my $hbdev ;
my $priority ;
while ($line =~ /(?:\s*")(\S+)(?:"\s*)(\d+)(?:\s)/g) {
warn "$obj:$subn hbdev=$1 priority=$2" if $self->debug ;
if (defined($hash_physical{$1})) {
warn "$obj:$subn hbdev $1 is accepted because it is a physical device" if $self->debug ;
$new_line .= " \"$1\" $2" ;
}
else {
warn "$obj:$subn hbdev $1 is refused because it is not a physical device" if $self->debug ;
}
}
warn "$obj:$subn result line : $new_line" if $self->debug ;
$self->cfg->set_line(index => $index, content => $new_line . "\n") ;
}
}
print "\n" ;
}
# ---
sub all_vdoms_processing {
my $subn = "all_vdoms_processing" ;
my $self = shift ;
warn "\n* Entering $obj:$subn" if $self->debug ;
die "undefined XMLTrsf" if (not(defined($self->XMLTrsf))) ;
# Get node pointer on system_interfaces
my $nodes = $self->XMLTrsf->findnodes('/transform/all_vdoms')->get_node(1) ;
if (defined($nodes)) {
# Proceed first with all translation
$self->_all_vdoms_firewall_policies(\$nodes) ;
# IPsec vpn phase1-interface
$self->_all_vdoms_vpn_ipsec_phase1_interface(\$nodes) ;
# Limit address groups length
$self->_address_groups(\$nodes) ;
}
}
# ---
sub vdoms_processing {
my $subn = "vdoms_processing" ;
my $self = shift ;
warn "\n* Entering $obj:$subn" if $self->debug ;
die "undefined XMLTrsf" if (not(defined($self->XMLTrsf))) ;
# Get pointer on vdoms
my $nodes = $self->XMLTrsf->findnodes('/transform/vdoms')->get_node(1) ;
if (defined($nodes)) {
foreach my $node ($nodes->findnodes('./vdom')) {
my $vdom = $node->findvalue('./@name') ;
print " o processing vdom $vdom\n" ;
warn "$obj:$subn : vdom=$vdom" if $self->debug;
# Config may have been touched, need to register vdoms again
my @scope_vdom = () ;
$self->cfg->register_vdoms() ;
@scope_vdom = $self->cfg->scope_vdom($vdom) ;
# Process virtual-wan-link
$self->virtual_wan_link_processing($vdom, \@scope_vdom, \$node) ;
}
}
}
# ---
sub virtual_wan_link_processing {
my $subn = "virtual_wan_link_processing" ;
my $self = shift ;
my $vdom = shift ;
my $ref_scope = shift ;
my $ref_nodes = shift ;
warn "\n* Entering $obj:$subn with vdom=$vdom" if $self->debug() ;
my $vwl_node = $$ref_nodes->findnodes('./system_virtual-wan-link')->get_node(1) ;
if (defined($vwl_node)) {
print " o processing system virtual-wan-link\n" ;
if ($self->cfg->scope_config($ref_scope, 'config system virtual-wan-link') and $self->cfg->feedback('found')) {
$self->virtual_wan_link_health_check($vdom, $ref_scope, \$vwl_node) ;
}
else {
print "Warning : skip - could not find 'config system virtual-wan-link\n" ;
}
}
}
# ---
sub virtual_wan_link_health_check {