]> git.ipfire.org Git - people/meitelwein/ipfire-2.x.git/commitdiff
BUG10940: remove leading zeros in ip address
authorAlexander Marx <alexander.marx@ipfire.org>
Mon, 9 Nov 2015 11:42:47 +0000 (12:42 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 Nov 2015 17:32:59 +0000 (17:32 +0000)
in firewallgroups (hosts) an error was created when using ip adresses
like 192.168.000.008. Now all leading zeros are deleted in
firewallgroups and in the firewall itself when using single ip addresses
as source or target.

Signed-off-by: Alexander Marx <alexander.marx@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/network-functions.pl
html/cgi-bin/firewall.cgi
html/cgi-bin/fwhosts.cgi

index cb4ca3dd88306f61290fab895308c0725c1ecdac..70fa5ed356c9024573ab3005f7d8a9fb2efe5ac0 100644 (file)
@@ -122,6 +122,19 @@ sub network2bin($) {
        return ($network_start, $netmask_bin);
 }
 
+# Deletes leading zeros in ip address
+sub ip_remove_zero{
+       my $address = shift;
+       my @ip = split (/\./, $address);
+
+       foreach my $octet (@ip) {
+               $octet = int($octet);
+       }
+
+       $address = join (".", @ip);
+
+       return $address;
+}
 # Returns True for all valid IP addresses
 sub check_ip_address($) {
        my $address = shift;
index 682c2855c6101694952eb495b0abb487a8b9928a..8007182e9d0f079d490d1f88e6f32a5aed00a80e 100644 (file)
@@ -31,6 +31,7 @@ no warnings 'uninitialized';
 #use CGI::Carp 'fatalsToBrowser';
 
 require '/var/ipfire/general-functions.pl';
+require '/var/ipfire/network-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 require "${General::swroot}/geoip-functions.pl";
@@ -465,6 +466,9 @@ sub checksource
                        }
                }
                if ($fwdfwsettings{'isip'} eq 'on'){
+                       #remove leading zero
+                       $ip = &Network::ip_remove_zero($ip);
+
                        ##check if ip is valid
                        if (! &General::validip($ip)){
                                $errormessage.=$Lang::tr{'fwdfw err src_addr'}."<br>";
@@ -569,11 +573,15 @@ sub checktarget
                        ($ip,$subnet)=split (/\//,$fwdfwsettings{'tgt_addr'});
                        $subnet = &General::iporsubtocidr($subnet);
                }
+
                #check if only ip
                if($fwdfwsettings{'tgt_addr'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
                        $ip=$fwdfwsettings{'tgt_addr'};
                        $subnet='32';
                }
+               #remove leading zero
+               $ip = &Network::ip_remove_zero($ip);
+
                #check if ip is valid
                if (! &General::validip($ip)){
                        $errormessage.=$Lang::tr{'fwdfw err tgt_addr'}."<br>";
index 994a50a1048c581a7259c20de4e578d59af0b62e..35afad3e446616f48c7856a15b03ec3ecb4f2d4d 100644 (file)
@@ -27,6 +27,7 @@ use Sort::Naturally;
 use CGI::Carp 'fatalsToBrowser';
 no warnings 'uninitialized';
 require '/var/ipfire/general-functions.pl';
+require '/var/ipfire/network-functions.pl';
 require "/var/ipfire/geoip-functions.pl";
 require "/usr/lib/firewall/firewall-lib.pl";
 require "${General::swroot}/lang.pl";
@@ -277,6 +278,9 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                &addnet;
                &viewtablenet;
        }else{
+               #convert ip if leading '0' exists
+               $fwhostsettings{'IP'} = &Network::ip_remove_zero($fwhostsettings{'IP'});
+
                #check valid ip 
                if (!&General::validipandmask($fwhostsettings{'IP'}."/".$fwhostsettings{'SUBNET'}))
                {
@@ -372,9 +376,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                        foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
                        $fwhostsettings{'SUBNET'}       = &General::iporsubtocidr($fwhostsettings{'SUBNET'});
                        $customnetwork{$key}[0]         = $fwhostsettings{'HOSTNAME'};
-                       #convert ip when leading '0' in byte
-                       $fwhostsettings{'IP'}           =&General::ip2dec($fwhostsettings{'IP'});
-                       $fwhostsettings{'IP'}           =&General::dec2ip($fwhostsettings{'IP'});
                        $customnetwork{$key}[1]         = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ;
                        $customnetwork{$key}[2]         = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ;
                        $customnetwork{$key}[3]         = $fwhostsettings{'NETREMARK'};
@@ -423,6 +424,9 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                }
                #CHECK IP-PART
                if ($fwhostsettings{'type'} eq 'ip'){
+                       #convert ip if leading '0' exists
+                       $fwhostsettings{'IP'} = &Network::ip_remove_zero($fwhostsettings{'IP'});
+
                        #check for subnet
                        if (rindex($fwhostsettings{'IP'},'/') eq '-1' ){
                                if($fwhostsettings{'type'} eq 'ip' && !&General::validipandmask($fwhostsettings{'IP'}."/32"))
@@ -503,9 +507,6 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
                        $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ;
                        $customhost{$key}[1] = $fwhostsettings{'type'} ;
                        if ($fwhostsettings{'type'} eq 'ip'){
-                               #convert ip when leading '0' in byte
-                               $fwhostsettings{'IP'}=&General::ip2dec($fwhostsettings{'IP'});
-                               $fwhostsettings{'IP'}=&General::dec2ip($fwhostsettings{'IP'});
                                $customhost{$key}[2] = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
                        }else{
                                $customhost{$key}[2] = $fwhostsettings{'IP'};