]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/ids.cgi
ids-functions.pl: Rework function write_modify_sids_file().
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / ids.cgi
index 54db48b7d0b7fb42d0b9df2e5019525f0a7ad5a8..74f5ca2238796ea302211d77bc259399c0fb79ad 100644 (file)
@@ -359,7 +359,7 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'save'}) {
                                $errormessage = "$Lang::tr{'could not download latest updates'} - $Lang::tr{'system is offline'}";
                        }
 
-                       # Check if enought free disk space is availabe.
+                       # Check if enough free disk space is availabe.
                        if(&IDS::checkdiskspace()) {
                                $errormessage = "$Lang::tr{'not enough disk space'}";
                        }
@@ -370,6 +370,9 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'save'}) {
                                # a new ruleset.
                                &working_notice("$Lang::tr{'ids working'}");
 
+                               # Write the modify sid's file and pass the taken ruleaction.
+                               &IDS::write_modify_sids_file();
+
                                # Call subfunction to download the ruleset.
                                if(&IDS::downloadruleset()) {
                                        $errormessage = $Lang::tr{'could not download latest updates'};
@@ -396,7 +399,7 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'save'}) {
        }
 
 # Save ruleset.
-} elsif ($cgiparams{'RULESET'} eq $Lang::tr{'update'}) {
+} elsif ($cgiparams{'RULESET'} eq $Lang::tr{'ids apply'}) {
        # Arrays to store which rulefiles have been enabled and will be used.
        my @enabled_rulefiles;
 
@@ -598,19 +601,8 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'save'}) {
        # Generate file to store the home net.
        &IDS::generate_home_net_file();
 
-       # Temporary variable to set the ruleaction.
-       # Default is "drop" to use suricata as IPS.
-       my $ruleaction="drop";
-
-       # Check if the traffic only should be monitored.
-       if($cgiparams{'MONITOR_TRAFFIC_ONLY'} eq 'on') {
-               # Switch the ruleaction to "alert".
-               # Suricata acts as an IDS only.
-               $ruleaction="alert";
-       }
-
        # Write the modify sid's file and pass the taken ruleaction.
-       &IDS::write_modify_sids_file($ruleaction);
+       &IDS::write_modify_sids_file();
 
        # Check if "MONITOR_TRAFFIC_ONLY" has been changed.
        if($cgiparams{'MONITOR_TRAFFIC_ONLY'} ne $oldidssettings{'MONITOR_TRAFFIC_ONLY'}) {
@@ -689,20 +681,26 @@ print"var show = \"$Lang::tr{'ids show'}\"\;\n";
 print"var hide = \"$Lang::tr{'ids hide'}\"\;\n";
 
 print <<END
-       // JQuery function to show/hide the text input field for
+       // Java Script function to show/hide the text input field for
        // Oinkcode/Subscription code.
-       \$(function() {
-               \$('#RULES').change(function(){
-                       if(\$('#RULES').val() == 'registered') {
-                               \$('#code').show();
-                       } else if(\$('#RULES').val() == 'subscripted') {
-                               \$('#code').show();
-                       } else if(\$('#RULES').val() == 'emerging_pro') {
-                               \$('#code').show();
-                       } else {
-                               \$('#code').hide();
-                       }
-               });
+       var update_code = function() {
+               if(\$('#RULES').val() == 'registered') {
+                       \$('#code').show();
+               } else if(\$('#RULES').val() == 'subscripted') {
+                       \$('#code').show();
+               } else if(\$('#RULES').val() == 'emerging_pro') {
+                       \$('#code').show();
+               } else {
+                       \$('#code').hide();
+               }
+       };
+
+       // JQuery function to call corresponding function when
+       // the ruleset is changed or the page is loaded for showing/hiding
+       // the code area.
+       \$(document).ready(function() {
+               \$('#RULES').change(update_code);
+               update_code();
        });
 
        // Tiny java script function to show/hide the rules
@@ -783,17 +781,6 @@ END
 END
 }
 
-my $rulesdate;
-
-# Check if a ruleset allready has been downloaded.
-if ( -f "$IDS::rulestarball"){
-        # Call stat on the filename to obtain detailed information.
-        my @Info = stat("$IDS::rulestarball");
-
-        # Grab details about the creation time.
-        $rulesdate = localtime($Info[9]);
-}
-
 # Only show this area, if a ruleset is present.
 if (%idsrules) {
 
@@ -938,7 +925,7 @@ END
 #
 # Whitelist / Ignorelist
 #
-&Header::openbox('100%', 'center', $Lang::tr{'guardian ignored hosts'});
+&Header::openbox('100%', 'center', $Lang::tr{'ids ignored hosts'});
 
 print <<END;
        <table width='100%'>
@@ -1069,7 +1056,20 @@ END
 
 # Only show the section for configuring the ruleset if one is present.
 if (%idsrules) {
-       &Header::openbox('100%', 'LEFT', $Lang::tr{'intrusion detection system rules'});
+       # Load neccessary perl modules for file stat and to format the timestamp.
+       use File::stat;
+       use POSIX qw( strftime );
+
+       # Call stat on the rulestarball.
+       my $stat = stat("$IDS::rulestarball");
+
+       # Get timestamp the file creation.
+       my $mtime = $stat->mtime;
+
+       # Convert into human read-able format.
+       my $rulesdate = strftime('%Y-%m-%d %H:%M:%S', localtime($mtime));
+
+       &Header::openbox('100%', 'LEFT', "$Lang::tr{'intrusion detection system rules'} ($rulesdate)" );
 
                print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
 
@@ -1164,9 +1164,7 @@ if (%idsrules) {
 print <<END
 <table width='100%'>
 <tr>
-       <td width='100%' align='right'><input type='submit' name='RULESET' value='$Lang::tr{'update'}'>
-               &nbsp; <!-- space for future online help link -->
-       </td>
+       <td width='100%' align='right'><input type='submit' name='RULESET' value='$Lang::tr{'ids apply'}'></td>
 </tr>
 </table>
 </form>