]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/fwhosts.cgi
captive-portal: Move CGI files to CGI directory
[ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
index 994a50a1048c581a7259c20de4e578d59af0b62e..a2ade8a202f30cafc9592e632f638df7b45b888d 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'}))
                {
@@ -297,7 +301,7 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                }
                if($fwhostsettings{'error'} ne 'on'){
                                my $fullip="$fwhostsettings{'IP'}/".&General::iporsubtocidr($fwhostsettings{'SUBNET'});
-                               $errormessage=$errormessage.&General::checksubnets($fwhostsettings{'HOSTNAME'},$fullip,"");
+                               $errormessage=$errormessage.&General::checksubnets($fwhostsettings{'HOSTNAME'},$fullip,"","exact");
                }
                #only check plausi when no error till now
                if (!$errormessage){
@@ -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'};
@@ -623,9 +624,9 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
                }
                #check if host/net exists in grp
                
-               my $test="$grp,$fwhostsettings{'oldremark'},@target";
+               my $test="$grp,$fwhostsettings{'oldremark'},@target,$type";
                foreach my $key (keys %customgrp) {
-                       my $test1="$customgrp{$key}[0],$customgrp{$key}[1],$customgrp{$key}[2]";
+                       my $test1="$customgrp{$key}[0],$customgrp{$key}[1],$customgrp{$key}[2],$customgrp{$key}[3]";
                        if ($test1 eq $test){
                                $errormessage=$Lang::tr{'fwhost err isingrp'};
                                $fwhostsettings{'update'} = 'on';
@@ -2554,18 +2555,6 @@ sub checkip
        }
        return 1;
 }
-sub checksubnet
-{
-       my %hash=%{(shift)};
-       &General::readhasharray("$confignet", \%hash);
-       foreach my $key (keys %hash) {
-               if(&General::IpInSubnet($fwhostsettings{'IP'},$hash{$key}[1],$hash{$key}[2]))
-               {
-                       return 1;
-               }
-       }
-       return 0;
-}
 sub checkservicegroup
 {
        &General::readhasharray("$configsrvgrp", \%customservicegrp);