]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/forwardfw/convert-dmz
3 ########################################################################
6 # Author: Alexander Marx (amarx@ipfire.org)
7 ########################################################################
9 # This script converts old dmz holes rules from old Firewall
10 # to the new one. This is a 2-step process.
11 # STEP1: read old config and normalize settings
12 # STEP2: check valid ip and save valid rules to new firewall
14 ########################################################################
20 require '/var/ipfire/general-functions.pl';
21 my $dmzconfig = "${General::swroot}/dmzholes/config";
22 my $fwdfwconfig = "${General::swroot}/forward/config";
23 my $ifacesettings = "${General::swroot}/ethernet/settings";
24 my $field0 = 'ACCEPT';
25 my $field1 = 'FORWARDFW';
26 my $field2 = ''; #ON or emtpy
27 my $field3 = ''; #std_net_src or src_addr
28 my $field4 = ''; #ALL or IP-Address with /32
29 my $field5 = ''; #std_net_tgt or tgt_addr
30 my $field6 = ''; #IP or network name
31 my $field11 = 'ON'; #use target port
32 my $field12 = ''; #TCP or UDP
33 my $field13 = 'All ICMP-Types';
34 my $field14 = 'TGT_PORT';
35 my $field15 = ''; #Port Number
36 my $field16 = ''; #remark
37 my $field26 = '00:00';
38 my $field27 = '00:00';
39 open(FILE
, $dmzconfig) or die 'Unable to open config file.';
43 open (LOG
, ">/var/log/converters/dmz-convert.log") or die $!;
44 &General
::readhash
($ifacesettings, \
%ifaces);
45 &General
::readhasharray
($fwdfwconfig,\
%configfwdfw);
48 foreach my $line (@current){
50 #get values from old configfile
51 my ($a,$b,$c,$d,$e,$f,$g,$h) = split (",",$line);
53 print LOG
"$now Processing A: $a B: $b C: $c D: $d E: $e F: $f G: $g H: $h\n";
54 #Now convert values and check ip addresses
57 $field2=$e if($e eq 'ON');
60 if (&General
::validipandmask
($b)){
61 #When ip valid, check if we have a network
62 my ($ip,$subnet) = split ("/",$b);
63 if ($f eq 'orange' && $ip eq $ifaces{'ORANGE_NETADDRESS'}){
64 $field3='std_net_src';
66 }elsif($f eq 'blue' && $ip eq $ifaces{'BLUE_NETADDRESS'}){
67 $field3='std_net_src';
69 }elsif($f eq 'orange' && &General
::IpInSubnet
($ip,$ifaces{'ORANGE_NETADDRESS'},$ifaces{'ORANGE_NETMASK'})){
72 }elsif($f eq 'blue' && &General
::IpInSubnet
($ip,$ifaces{'BLUE_NETADDRESS'},$ifaces{'BLUE_NETMASK'})){
76 print LOG
"$now ->NOT Converted, source ip $b not part of source network $f \n\n";
80 print LOG
"$now -> SOURCE IP INVALID. \n\n";
85 if (&General
::validipandmask
($c)){
87 #When ip valid, check if we have a network
88 my ($ip,$subnet) = split ("/",$c);
89 if ($g eq 'green' && $ip eq $ifaces{'GREEN_NETADDRESS'}){
90 $field5='std_net_tgt';
92 }elsif($g eq 'blue' && $ip eq $ifaces{'BLUE_NETADDRESS'}){
93 $field5='std_net_tgt';
95 }elsif($g eq 'green' && &General
::IpInSubnet
($ip,$ifaces{'GREEN_NETADDRESS'},$ifaces{'GREEN_NETMASK'})){
98 }elsif($g eq 'blue' && &General
::IpInSubnet
($ip,$ifaces{'BLUE_NETADDRESS'},$ifaces{'BLUE_NETMASK'})){
102 print LOG
"$now ->NOT Converted, target ip $c not part of target network $g \n\n";
106 print LOG
"$now -> TARGET IP INVALID. \n\n";
114 my $key = &General
::findhasharraykey
(\
%configfwdfw);
115 foreach my $i (0 .. 27) { $configfwdfw{$key}[$i] = "";}
116 $configfwdfw{$key}[0] = $field0;
117 $configfwdfw{$key}[1] = $field1;
118 $configfwdfw{$key}[2] = $field2;
119 $configfwdfw{$key}[3] = $field3;
120 $configfwdfw{$key}[4] = $field4;
121 $configfwdfw{$key}[5] = $field5;
122 $configfwdfw{$key}[6] = $field6;
123 $configfwdfw{$key}[7] = '';
124 $configfwdfw{$key}[8] = '';
125 $configfwdfw{$key}[9] = '';
126 $configfwdfw{$key}[10] = '';
127 $configfwdfw{$key}[11] = $field11;
128 $configfwdfw{$key}[12] = $field12;
129 $configfwdfw{$key}[13] = $field13;
130 $configfwdfw{$key}[14] = $field14;
131 $configfwdfw{$key}[15] = $field15;
132 $configfwdfw{$key}[16] = $field16;
133 $configfwdfw{$key}[17] = '';
134 $configfwdfw{$key}[18] = '';
135 $configfwdfw{$key}[19] = '';
136 $configfwdfw{$key}[20] = '';
137 $configfwdfw{$key}[21] = '';
138 $configfwdfw{$key}[22] = '';
139 $configfwdfw{$key}[23] = '';
140 $configfwdfw{$key}[24] = '';
141 $configfwdfw{$key}[25] = '';
142 $configfwdfw{$key}[26] = $field26;
143 $configfwdfw{$key}[27] = $field27;
144 print LOG
"$Now -> Converted to $field0,$field1,$field2,$field3,$field4,$field5,$field6,,,,,$field11,$field12,$field13,$field14,$field15,$field16,,,,,,,,,,$field26,$field27\n";
146 &General
::writehasharray
($fwdfwconfig,\
%configfwdfw);
154 #ip with subnet in decimal
155 if($adr =~ m/^(\d\d?\d?).(\d\d?\d?).(\d\d?\d?).(\d\d?\d?)\/(\d
{1,2})$/){
156 $adr=int($1).".".int($2).".".int($3).".".int($4);
157 my $b = &General
::iporsubtodec
($5);
159 }elsif($adr =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
160 $adr=int($1).".".int($2).".".int($3).".".int($4);
161 if(&General
::validip
($adr)){
165 if(&General
::validipandmask
($adr)){
166 $a=&General
::iporsubtodec
($adr);