]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/fwhosts.cgi
vpn-statistic: change title of ovpn RW statistic page
[ipfire-2.x.git] / html / cgi-bin / fwhosts.cgi
index 042fdde0c5339b1f39c7e20450d442e393ef362f..f42947e8c7e99d056375fbd8165801ea9c68db44 100644 (file)
@@ -66,7 +66,6 @@ my $fwconfigfwd               = "${General::swroot}/firewall/config";
 my $fwconfiginp                = "${General::swroot}/firewall/input";
 my $fwconfigout                = "${General::swroot}/firewall/outgoing";
 my $configovpn         = "${General::swroot}/ovpn/settings";
-my $tdcolor='';
 my $configipsecrw      = "${General::swroot}/vpn/settings";
 
 unless (-e $confignet)    { system("touch $confignet"); }
@@ -292,42 +291,13 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                        $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'};
                }
                if($fwhostsettings{'error'} ne 'on'){
-                       #check if we use one of ipfire's networks (green,orange,blue)
-                       if (($ownnet{'GREEN_NETADDRESS'}        ne '' && $ownnet{'GREEN_NETADDRESS'}    ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'GREEN_NETADDRESS'},$ownnet{'GREEN_NETMASK'}))
-                       { 
-                               $errormessage=$errormessage.$Lang::tr{'ccd err green'}."<br>";
-                               $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
-                               if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
-                       }
-                       if (($ownnet{'ORANGE_NETADDRESS'}       ne '' && $ownnet{'ORANGE_NETADDRESS'}   ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'ORANGE_NETADDRESS'},$ownnet{'ORANGE_NETMASK'}))
-                       { 
-                               $errormessage=$errormessage.$Lang::tr{'ccd err orange'}."<br>";
-                               $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
-                               if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
-                       }
-                       if (($ownnet{'BLUE_NETADDRESS'}         ne '' && $ownnet{'BLUE_NETADDRESS'}     ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'BLUE_NETADDRESS'},$ownnet{'BLUE_NETMASK'}))
-                       { 
-                               $errormessage=$errormessage.$Lang::tr{'ccd err blue'}."<br>";
-                               $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
-                               if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
-                       }
-                       if (($ownnet{'RED_NETADDRESS'}  ne '' && $ownnet{'RED_NETADDRESS'}              ne '0.0.0.0') && &General::IpInSubnet($fwhostsettings{'IP'},$ownnet{'RED_NETADDRESS'},$ownnet{'RED_NETMASK'}))
-                       { 
-                               $errormessage=$errormessage.$Lang::tr{'ccd err red'}."<br>";
-                               $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
-                               if ($fwhostsettings{'update'} eq 'on'){$fwhostsettings{'ACTION'}='editnet';}
-                       }
+                               my $fullip="$fwhostsettings{'IP'}/".&General::iporsubtocidr($fwhostsettings{'SUBNET'});
+                               $errormessage=$errormessage.&General::checksubnets($fwhostsettings{'HOSTNAME'},$fullip,"");
                }
                #only check plausi when no error till now
                if (!$errormessage){
                        &plausicheck("editnet");
                }
-               #check if network ip is part of an already used one 
-               if(&checksubnet(\%customnetwork))
-               {
-                       $errormessage=$errormessage.$Lang::tr{'fwhost err partofnet'};
-                       $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
-               }                               
                if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage)
                {
                        $fwhostsettings{'actualize'} = '';
@@ -339,9 +309,8 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                        $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'};
                        &General::writehasharray("$confignet", \%customnetwork);
                        undef %customnetwork;
-               }                       
+               }
                if (!$errormessage){
-                       
                        &General::readhasharray("$confignet", \%customnetwork);
                        if ($fwhostsettings{'ACTION'} eq 'updatenet'){
                                if ($fwhostsettings{'update'} == '0'){
@@ -393,7 +362,7 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                                                &General::writehasharray("$fwconfiginp", \%fwinp);
                                        }
                                }
-                       }                                       
+                       }
                        my $key = &General::findhasharraykey (\%customnetwork);
                        foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";}
                        $fwhostsettings{'SUBNET'}       = &General::iporsubtocidr($fwhostsettings{'SUBNET'});
@@ -417,7 +386,8 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
                        }
                        &addnet;
                        &viewtablenet;
-               }else           {
+               }else{
+                       $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
                        &addnet;
                        &viewtablenet;
                }
@@ -758,10 +728,10 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
                        }
                }
        }
-       if ($tcpcounter > 15){
+       if ($tcpcounter > 14){
                $errormessage=$Lang::tr{'fwhost err maxservicetcp'};
        }
-       if ($udpcounter > 15){
+       if ($udpcounter > 14){
                $errormessage=$Lang::tr{'fwhost err maxserviceudp'};
        }
        $tcpcounter=0;
@@ -910,9 +880,6 @@ if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
        }
        &General::writehasharray("$configgrp", \%customgrp);
        &General::firewall_config_changed();
-       if ($fwhostsettings{'grpcnt'} > 0){
-               &General::firewall_config_changed();
-       }
        if ($fwhostsettings{'update'} eq 'on'){
                $fwhostsettings{'remark'}= $grpremark;
                $fwhostsettings{'grp_name'}=$grpname;
@@ -1624,6 +1591,7 @@ sub getcolor
                my $c=shift;
                my $sip;
                my $scidr;
+               my $tdcolor='';
                #Check if MAC
                if (&General::validmac($c)){ return $c;}
 
@@ -1635,7 +1603,7 @@ sub getcolor
                }
 
                #Now check if IP is part of ORANGE,BLUE or GREEN
-               if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
+               if ( &Header::orange_used() && &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){
                        $tdcolor="<font style='color: $Header::colourorange;'>$c</font>";
                        return $tdcolor;
                }
@@ -1643,11 +1611,14 @@ sub getcolor
                        $tdcolor="<font style='color: $Header::colourgreen;'>$c</font>";
                        return $tdcolor;
                }
-               if ( &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
+               if ( &Header::blue_used() && &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){
                        $tdcolor="<font style='color: $Header::colourblue;'>$c</font>";
                        return $tdcolor;
                }
-
+               if ("$sip/$scidr" eq "0.0.0.0/0"){
+                       $tdcolor="<font style='color: $Header::colourred;'>$c</font>";
+                       return $tdcolor;
+               }
                #Check if IP is part of OpenVPN N2N subnet
                foreach my $key (sort keys %ccdhost){
                        if ($ccdhost{$key}[3] eq 'net'){
@@ -1688,10 +1659,13 @@ sub getcolor
 
                #Check if IP is part of a IPsec N2N network
                foreach my $key (sort keys %ipsecconf){
-                       my ($a,$b) = split("/",$ipsecconf{$key}[11]);
-                       if (&General::IpInSubnet($sip,$a,$b)){
-                               $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
-                               return $tdcolor;
+                       if ($ipsecconf{$key}[11]){
+                               my ($a,$b) = split("/",$ipsecconf{$key}[11]);
+                               $b=&General::iporsubtodec($b);
+                               if (&General::IpInSubnet($sip,$a,$b)){
+                                       $tdcolor="<font style='color: $Header::colourvpn;'>$c</font>";
+                                       return $tdcolor;
+                               }
                        }
                }
                return "$c";
@@ -1840,11 +1814,11 @@ sub viewtablegrp
                                print "$customgrp{$key}[2]</td>";
                        }
                        if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){
-                               print "<td align='center' $col>$Lang::tr{'fwhost deleted'}</td><td align='center' $col>$customgrp{$key}[3]</td><td width='1%' $col><form method='post'>";
+                               print "<td align='center' $col>$Lang::tr{'fwhost deleted'}</td><td align='center' $col>$Lang::tr{'fwhost '.$customgrp{$key}[3]}</td><td width='1%' $col><form method='post'>";
                        }else{
                                my ($colip,$colsub) = split("/",$ip);
-                               $ip="$colip/".&General::subtocidr($colsub) if ($colsub);
-                               print"<td align='center' $col>".&getcolor($ip)."</td><td align='center' $col>$customgrp{$key}[3]</td><td width='1%' $col><form method='post'>";
+                               $ip="$colip/".&General::iporsubtocidr($colsub) if ($colsub);
+                               print"<td align='center' $col>".&getcolor($ip)."</td><td align='center' $col>$Lang::tr{'fwhost '.$customgrp{$key}[3]}</td><td width='1%' $col><form method='post'>";
                        }
                        if ($delflag > 0 && $ip ne ''){
                                print"<input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' />";
@@ -1855,8 +1829,7 @@ sub viewtablegrp
                                        }
                                }
                        }
-                       print"<input type='hidden' name='ACTION' value='deletegrphost'><input type='hidden' name='grpcnt' value='$customgrp{$key}[4]'><input type='hidden' name='update' value='$fwhostsettings{'update'}'><input type='hidden' name='delhost' value='$grpname,$remark,$customgrp{$key}[2],$customgrp{$key}[3]'></form></td></tr>";
-                       
+                       print"<input type='hidden' name='ACTION' value='deletegrphost'><input type='hidden' name='update' value='$fwhostsettings{'update'}'><input type='hidden' name='delhost' value='$grpname,$remark,$customgrp{$key}[2],$customgrp{$key}[3]'></form></td></tr>";
                        $helper=$customgrp{$key}[0];
                        $number++;
                }
@@ -2502,6 +2475,9 @@ sub getipforgroup
                        &General::readhash("${General::swroot}/vpn/settings",\%hash);
                        return $hash{'RW_NET'};
                }
+               if ($name eq 'RED'){
+                       return "0.0.0.0/0";
+               }
        }
 }
 sub decrease