]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/ids.cgi
ids.cgi: Display oinkcode section after page load when neccessary.
[ipfire-2.x.git] / html / cgi-bin / ids.cgi
index 60e40d7de59733d6b2d5d81e7a8e80b030501d29..00db6a0c3afd197627547d09ee3f635610f8971a 100644 (file)
@@ -210,6 +210,22 @@ if (($cgiparams{'WHITELIST'} eq $Lang::tr{'add'}) || ($cgiparams{'WHITELIST'} eq
        }
 }
 
+# Check if the page is locked, in this case, the ids_page_lock_file exists.
+if (-e $IDS::ids_page_lock_file) {
+       # Lock the webpage and print notice about autoupgrade of the ruleset
+       # is in progess.
+       &working_notice("$Lang::tr{'ids ruleset autoupdate in progress'}");
+
+       # Loop and check if the file still exists.
+       while(-e $IDS::ids_page_lock_file) {
+               # Sleep for a second and re-check.
+               sleep 1;
+       }
+
+       # Page has been unlocked, perform a reload.
+       &reload();
+}
+
 # Check if any error has been stored.
 if (-e $IDS::storederrorfile) {
         # Open file to read in the stored error message.
@@ -225,9 +241,9 @@ if (-e $IDS::storederrorfile) {
         unlink($IDS::storederrorfile);
 }
 
-## Grab all available snort rules and store them in the idsrules hash.
+## Grab all available rules and store them in the idsrules hash.
 #
-# Open snort rules directory and do a directory listing.
+# Open rules directory and do a directory listing.
 opendir(DIR, $IDS::rulespath) or die $!;
        # Loop through the direcory.
        while (my $file = readdir(DIR)) {
@@ -352,7 +368,7 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'save'}) {
                        unless ($errormessage) {
                                # Lock the webpage and print notice about downloading
                                # a new ruleset.
-                               &working_notice("$Lang::tr{'snort working'}");
+                               &working_notice("$Lang::tr{'ids working'}");
 
                                # Call subfunction to download the ruleset.
                                if(&IDS::downloadruleset()) {
@@ -380,7 +396,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;
 
@@ -481,7 +497,7 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'save'}) {
        &IDS::write_used_rulefiles_file(@enabled_rulefiles);
 
        # Lock the webpage and print message.
-       &working_notice("$Lang::tr{'snort working'}");
+       &working_notice("$Lang::tr{'ids apply ruleset changes'}");
 
        # Call oinkmaster to alter the ruleset.
        &IDS::oinkmaster();
@@ -511,7 +527,7 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'save'}) {
        unless ($errormessage) {
                # Lock the webpage and print notice about downloading
                # a new ruleset.
-               &working_notice("$Lang::tr{'snort working'}");
+               &working_notice("$Lang::tr{'ids download new ruleset'}");
 
                # Call subfunction to download the ruleset.
                if(&IDS::downloadruleset()) {
@@ -536,7 +552,7 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'save'}) {
                        &reload();
                }
        }
-# Save snort settings.
+# Save IDS settings.
 } elsif ($cgiparams{'IDS'} eq $Lang::tr{'save'}) {
        my %oldidssettings;
        my $reload_page;
@@ -601,7 +617,7 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'save'}) {
                # Check if a ruleset exists.
                if (%idsrules) {
                        # Lock the webpage and print message.
-                       &working_notice("$Lang::tr{'snort working'}");
+                       &working_notice("$Lang::tr{'ids working'}");
 
                        # Call oinkmaster to alter the ruleset.
                        &IDS::oinkmaster();
@@ -673,20 +689,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
@@ -767,17 +789,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) {
 
@@ -902,8 +913,8 @@ print <<END
                        <td align='right'>
 END
 ;
-                       # Check if a ruleset has been downloaded yet.
-                       if (%idsrules) {
+                       # Show the "Update Ruleset"-Button only if a ruleset has been downloaded yet and automatic updates are disabled.
+                       if ((%idsrules) && ($rulessettings{'AUTOUPDATE_INTERVAL'} eq "off")) {
                                # Display button to update the ruleset.
                                print"<input type='submit' name='RULESET' value='$Lang::tr{'update ruleset'}'>\n";
                }
@@ -922,7 +933,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%'>
@@ -1053,7 +1064,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";
 
@@ -1148,9 +1172,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>