]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - config/forwardfw/convert-outgoingfw
Forward Firewall: some typos in dmz-converter
[people/teissler/ipfire-2.x.git] / config / forwardfw / convert-outgoingfw
index e118c08f97750b229c030b31446164c685d786ff..d065b5acdec4e759ade94de350a76bc6858a1241 100755 (executable)
@@ -1,5 +1,17 @@
 #!/usr/bin/perl
-
+######################################################################## 
+# Script:      convert-outgoingfw
+# Date:                21.03.2013
+# Author:      Alexander Marx (amarx@ipfire.org)
+########################################################################
+#
+# This script converts old groups and firewallrules 
+# to the new one. This is a 3-step process.
+# STEP1: convert groups ->LOG /var/log/converters
+# STEP2: convert rules  ->LOG /var/log/converters
+# STEP3: convert P2P rules 
+#
+########################################################################
 
 require '/var/ipfire/general-functions.pl';
 
@@ -35,10 +47,12 @@ my %fwconfig=();
 my %fwconfigout=();
 my %fwdsettings=();
 &General::readhash($outfwsettings,\%outsettings);
-
-&process_groups;
-&process_rules;
-&process_p2p;
+#ONLY RUN if /var/ipfire/outgoing exists
+if ( -d "/var/ipfire/outgoing"){
+       &process_groups;
+       &process_rules;
+       &process_p2p;
+}
 system("/usr/local/bin/forwardfwctrl");
 sub process_groups
 {
@@ -96,6 +110,7 @@ sub process_groups
                }
                &new_hostgrp($group,'mac');
                @hostarray=();
+               @zeilen=();
        }
        close (LOG);
 }
@@ -144,10 +159,21 @@ sub new_hostgrp
                                        $hosts{$key}[0] = $name2;
                                        $hosts{$key}[1] = $type;
                                        $hosts{$key}[2] = $ip;
-                                       $hosts{$key}[3] = 1;
+                                       $hosts{$key}[3] = '';
+                                       $hosts{$key}[4] = 1;
                                        print LOG "->Host (IP) $ip added to custom hosts\n"
                                }else{
-                                       print LOG "->Host (IP) $ip already exists\n";
+                                       print LOG "->Host (IP) $ip already exists in custom hosts\n";
+                                       $name="host ";
+                                       $name2=$name.$ippart;
+                                       foreach my $key (sort keys %hosts){
+                                               if($hosts{$key}[0] eq $name2){
+                                                       $hosts{$key}[4]++;
+                                               }
+                                       }
+                                       $name="host ";
+                                       $name2=$name.$ippart;
+                                       $name3="Custom Host";
                                }
                        }elsif($byte4 < '255'){
                                print LOG "Processing NETWORK $ippart/$subnet from Group $grp\n";
@@ -159,13 +185,24 @@ sub new_hostgrp
                                        $nets{$netkey}[0] = $name2;
                                        $nets{$netkey}[1] = $ippart;
                                        $nets{$netkey}[2] = $subnet;
-                                       $nets{$netkey}[3] = 1;
+                                       $nets{$netkey}[3] = '';
+                                       $nets{$netkey}[4] = 1;
                                        print LOG "->Network $ippart/$subnet added to custom networks\n";
                                }else{
-                                       print LOG "Network $ippart already exists\n";
+                                       print LOG "Network $ippart already exists in custom networks\n";
+                                       $name="net ";
+                                       $name2=$name.$ippart;
+                                       foreach my $key (sort keys %nets){
+                                               if($nets{$key}[0] eq $name2){
+                                                       $nets{$key}[4]++;
+                                               }
+                                       }
+                                       $name="net ";
+                                       $name2=$name.$ippart;
+                                       $name3="Custom Network";
                                }
                        }
-                       if($name2){
+                       if($name2 && !&check_grp($grp,$name2)){
                                my $grpkey      = &General::findhasharraykey(\%groups);
                                $groups{$grpkey}[0]     = $grp;
                                $groups{$grpkey}[1]     = '';
@@ -190,9 +227,19 @@ sub new_hostgrp
                                $hosts{$key}[4] = 1;
                                print LOG "->Host (MAC) $mac added to custom hosts\n";
                        }else{
-                               print LOG "->Host (MAC) $mac already exists\n";
+                               print LOG "->Host (MAC) $mac already exists in custom hosts \n";
+                               $name="host ";
+                               $name2=$name.$mac;
+                               foreach my $key (sort keys %hosts){
+                                       if($hosts{$key}[0] eq $name2){
+                                               $hosts{$key}[4]++;
+                                       }
+                               }
+                               $name="host ";
+                               $name2=$name.$mac;
+                               $name3="Custom Host";
                        }
-                       if($name2){
+                       if($name2 && !&check_grp($grp,$name2)){
                                my $grpkey      = &General::findhasharraykey(\%groups);
                                $groups{$grpkey}[0]     = $grp;
                                $groups{$grpkey}[1]     = '';