]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/routing.cgi
BUG11466: fix routing.cgi the function call in routing.cgi was fixed to call the...
[ipfire-2.x.git] / html / cgi-bin / routing.cgi
index 2a5176026a327e42faa8ffcdd55a1e40c89ababa..f2014e2e12f917ecc31c56c7490534a52a420874 100644 (file)
@@ -118,12 +118,15 @@ if ($settings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
 }
 
 if ($settings{'ACTION'} eq $Lang::tr{'add'}) {
-       # Convert subnet masks to CIDR notation.
-       $settings{'IP'} = &General::iporsubtocidr($settings{'IP'});
-
-# Validate inputs
-       if (( !&General::validip($settings{'IP'})) and ( !&General::validipandmask($settings{'IP'}))){
-       $errormessage = $Lang::tr{'invalid ip'}." / ".$Lang::tr{'invalid netmask'};
+       # Validate inputs
+       if (!&General::validipandmask($settings{'IP'})){
+               $errormessage = $Lang::tr{'invalid ip'}." / ".$Lang::tr{'invalid netmask'};
+       }else{
+               #set networkip if not already correctly defined
+               my($ip,$cidr) = split(/\//,$settings{'IP'});
+               $cidr = &General::iporsubtocidr($cidr);
+               my $netip=&General::getnetworkip($ip,$cidr);
+               $settings{'IP'} = "$netip/$cidr";
        }
 
        if ($settings{'IP'} =~ /^0\.0\.0\.0/){
@@ -134,6 +137,27 @@ if ($settings{'ACTION'} eq $Lang::tr{'add'}) {
        $errormessage = $Lang::tr{'invalid ip'}. " - ".$Lang::tr{'gateway ip'};
        }
 
+       #set networkip if not already correctly defined
+       my($ip,$cidr) = split(/\//,$settings{'IP'});
+       my $netip=&General::getnetworkip($ip,$cidr);
+       $settings{'IP'} = "$netip/$cidr";
+
+       #Check for already existing routing entry
+       foreach my $line (@current) {
+               chomp($line);                           # remove newline
+               my @temp=split(/\,/,$line);
+               $temp[2] ='' unless defined $temp[2]; # not always populated
+               $temp[3] ='' unless defined $temp[2]; # not always populated
+               #Same ip already used?
+               if($temp[1] eq $settings{'IP'} && $settings{'KEY1'} eq ''){
+                       $errormessage = $Lang::tr{'ccd err irouteexist'};
+                       last;
+               }
+               #Is the network part of an internal network?
+               $errormessage .= &General::check_net_internal_exact($settings{'IP'});
+               last;
+       }
+
     unless ($errormessage) {
        if ($settings{'KEY1'} eq '') { #add or edit ?
            unshift (@current, "$settings{'EN'},$settings{'IP'},$settings{'GATEWAY'},$settings{'REMARK'}\n");
@@ -244,10 +268,10 @@ print <<END
     <td><input type='text' name='REMARK' value='$settings{'REMARK'}' size='25'/></td>
 </tr>
 </table>
-<hr />
+<br>
 <table width='100%'>
 <tr>
-    <td width='50%' align='center'><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /><input type='submit' name='SUBMIT' value='$buttontext' /></td>
+    <td width='50%' align='right'><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /><input type='submit' name='SUBMIT' value='$buttontext' /></td>
 </tr>
 </table>
 </form>