]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/routing.cgi
suricata: Change midstream policy to "pass-flow"
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / routing.cgi
index 86e04293a406ada5098ee950a8e72818b02944fb..109fc3e3e54b8f3ea9bc351abd02157b4bc24082 100644 (file)
@@ -40,7 +40,7 @@ our $datafile = "${General::swroot}/main/routing";            #(our: used in subroutine)
 my %color = ();
 my %mainsettings = ();
 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
-&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
+&General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
 
 our %settings = ();
 
@@ -49,7 +49,7 @@ $settings{'IP'} = '';
 $settings{'GATEWAY'} = '';
 $settings{'REMARK'} = '';
 my @nosaved=('EN','IP','GATEWAY','REMARK');    # List here ALL setting2 fields. Mandatory
-    
+
 $settings{'ACTION'} = '';              # add/edit/remove
 $settings{'KEY1'} = '';                        # point record for ACTION
 
@@ -105,26 +105,31 @@ if ($settings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
     $temp[0] = $temp[0] ne '' ? '' : 'on';             # Toggle the field
     @current[$settings{'KEY1'}] = join (',',@temp)."\n";
     $settings{'KEY1'} = '';                            # End edit mode
-    
+
     &General::log($Lang::tr{'routing config changed'});
 
     #Save current
     open(FILE, ">$datafile") or die 'routing datafile error';
     print FILE @current;
     close(FILE);
-       
+
     # Rebuild configuration file
     &BuildConfiguration;
 }
 
 if ($settings{'ACTION'} eq $Lang::tr{'add'}) {
-
-# 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/){
+       if ($settings{'IP'} =~ /^0\.0\.0\.0/){
        $errormessage = $Lang::tr{'invalid ip'}." - 0.0.0.0";
        }
 
@@ -132,6 +137,30 @@ if ($settings{'ACTION'} eq $Lang::tr{'add'}) {
        $errormessage = $Lang::tr{'invalid ip'}. " - ".$Lang::tr{'gateway ip'};
        }
 
+       # Escape input in REMARK field
+       $settings{'REMARK'} = &Header::escape($settings{'REMARK'});
+
+       #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");
@@ -145,7 +174,7 @@ if ($settings{'ACTION'} eq $Lang::tr{'add'}) {
         # Write changes to config file.
         &SortDataFile;                         # sort newly added/modified entry
         &BuildConfiguration;                   # then re-build routing
-       
+
        #map ($settings{$_}='' ,@nosaved);      # Clear fields
     }
 }
@@ -163,7 +192,7 @@ if ($settings{'ACTION'} eq $Lang::tr{'edit'}) {
 }
 
 if ($settings{'ACTION'} eq $Lang::tr{'remove'}) {
-    splice (@current,$settings{'KEY1'},1);             # Delete line 
+    splice (@current,$settings{'KEY1'},1);             # Delete line
     open(FILE, ">$datafile") or die 'route datafile error';
     print FILE @current;
     close(FILE);
@@ -242,10 +271,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>
@@ -255,13 +284,13 @@ END
 
 &Header::openbox('100%', 'left', $Lang::tr{'routing table'});
 print <<END
-<hr />
-<table width='100%'>
+
+<table width='100%' class='tbl'>
 <tr>
-    <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IP'><b>$Lang::tr{'host ip'} / $Lang::tr{'network'}</b></a></td>
-    <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?GATEWAY'><b>$Lang::tr{'gateway'}</b></a></td>
-    <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?REMARK'><b>$Lang::tr{'remark'}</b></a></td>
-    <td width='10%' colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></td>
+    <th width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IP'><b>$Lang::tr{'host ip'} / $Lang::tr{'network'}</b></a></th>
+    <th width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?GATEWAY'><b>$Lang::tr{'gateway'}</b></a></th>
+    <th width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?REMARK'><b>$Lang::tr{'remark'}</b></a></th>
+    <th width='10%' colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></th>
 </tr>
 END
 ;
@@ -271,6 +300,7 @@ END
 #
 
 my $key = 0;
+my $col="";
 foreach my $line (@current) {
     chomp($line);                              # remove newline
     my @temp=split(/\,/,$line);
@@ -285,22 +315,24 @@ foreach my $line (@current) {
        $gdesc = $Lang::tr{'click to disable'};
     } else {
        $gif = 'off.gif';
-       $gdesc = $Lang::tr{'click to enable'}; 
+       $gdesc = $Lang::tr{'click to enable'};
     }
 
     #Colorize each line
     if ($settings{'KEY1'} eq $key) {
        print "<tr bgcolor='${Header::colouryellow}'>";
     } elsif ($key % 2) {
-       print "<tr bgcolor='$color{'color22'}'>";
+       print "<tr>";
+       $col="bgcolor='$color{'color20'}'";
     } else {
-       print "<tr bgcolor='$color{'color20'}'>"; 
+       print "<tr>";
+       $col="bgcolor='$color{'color22'}'";
     }
     print <<END
-<td align='center'>$temp[1]</td>
-<td align='center'>$temp[2]</td>
-<td align='center'>$temp[3]</td>
-<td align='center'>
+<td align='center' $col>$temp[1]</td>
+<td align='center' $col>$temp[2]</td>
+<td align='center' $col>$temp[3]</td>
+<td align='center' $col>
 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
@@ -308,7 +340,7 @@ foreach my $line (@current) {
 </form>
 </td>
 
-<td align='center'>
+<td align='center' $col>
 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
@@ -316,7 +348,7 @@ foreach my $line (@current) {
 </form>
 </td>
 
-<td align='center'>
+<td align='center' $col>
 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
@@ -373,7 +405,7 @@ if ( $output != "" ) {
 sub SortDataFile
 {
     our %entries = ();
-    
+
     # Sort pair of record received in $a $b special vars.
     # When IP is specified use numeric sort else alpha.
     # If sortname ends with 'Rev', do reverse sort.
@@ -417,13 +449,13 @@ sub SortDataFile
        # Build a pair 'Field Name',value for each of the data dataline.
        # Each SORTABLE field must have is pair.
        # Other data fields (non sortable) can be grouped in one
-       
+
        my @record = ('KEY',$key++,'EN',$temp[0],'IP',$temp[1],'GATEWAY',$temp[2],'REMARK',$temp[3]);
        my $record = {};                                # create a reference to empty hash
        %{$record} = @record;                           # populate that hash with @record
        $entries{$record->{KEY}} = $record;             # add this to a hash of hashes
     }
-    
+
     open(FILE, ">$datafile") or die 'routing datafile error';
 
     # Each field value is printed , with the newline ! Don't forget separator and order of them.
@@ -442,5 +474,5 @@ sub SortDataFile
 # Build the configuration file
 #
 sub BuildConfiguration {
-    system '/usr/local/bin/rebuildroutes';
-}
\ No newline at end of file
+    &General::system('/usr/local/bin/rebuildroutes');
+}