# Location and name of the tarball which contains the ruleset.
my $rulestarball = "/var/tmp/snortrules.tar.gz";
+# File to store any errors, which also will be read and displayed by the wui.
+my $storederrorfile = "/tmp/ids_storederror";
+
#
## Function for checking if at least 300MB of free disk space are available
## on the "/var" partition.
system("/usr/local/bin/oinkmaster.pl -v -s -u file://$rulestarball -C /var/ipfire/snort/oinkmaster.conf -o /etc/snort/rules 2>&1 |logger -t oinkmaster");
}
+#
+## Function to do all the logging stuff if the downloading or updating of the ruleset fails.
+#
+sub log_error ($) {
+ my ($error) = @_;
+
+ # Remove any newline.
+ chomp($error);
+
+ # Call private function to write/store the error message in the storederrorfile.
+ &_store_error_message($error);
+}
+
+#
+## Private function to write a given error message to the storederror file.
+#
+sub _store_error_message ($) {
+ my ($message) = @_;
+
+ # Remove any newline.
+ chomp($message);
+
+ # Open file for writing.
+ open (ERRORFILE, ">$storederrorfile") or die "Could not write to $storederrorfile. $!\n";
+
+ # Write error to file.
+ print ERRORFILE "$message\n";
+
+ # Close file.
+ close (ERRORFILE);
+}
+
1;
&working("$Lang::tr{'snort working'}");
}
+# Check if any error has been stored.
+if (-e $IDS::storederrorfile) {
+ # Open file to read in the stored error message.
+ open(FILE, "<$IDS::storederrorfile") or die "Could not open $IDS::storederrorfile. $!\n";
+
+ # Read the stored error message.
+ $errormessage = <FILE>;
+
+ # Close file.
+ close (FILE);
+
+ # Delete the file, which is now not longer required.
+ unlink($IDS::storederrorfile);
+}
+
+
## Grab all available snort rules and store them in the snortrules hash.
#
# Open snort rules directory and do a directory listing.
$errormessage = $Lang::tr{'could not download latest updates'};
}
- # Check if there is enought free disk space available.
+ # Check if enought free disk space is availabe.
$errormessage = &IDS::checkdiskspace();
# Check if any errors happend.
unless ($errormessage) {
+ &Header::openpage($Lang::tr{'intrusion detection system'}, 1, '');
+ &Header::openbigbox('100%', 'left', '', $errormessage);
+ &Header::openbox( 'Waiting', 1,);
+ print <<END;
+ <table>
+ <tr>
+ <td><img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' /></td>
+ <td>$Lang::tr{'snort working'}</td>
+ </tr>
+ </table>
+END
+ &Header::closebox();
+ &Header::closebigbox();
+ &Header::closepage();
+
# Call subfunction to download the ruleset.
$errormessage = &IDS::downloadruleset();
- }
- # Sleep for 1 second
- sleep(1);
+ # Check if the downloader returned an error.
+ if ($errormessage) {
+ # Call function to store the errormessage.
+ &IDS::log_error($errormessage);
- # Check if the downloader returend any error message.
- unless ($errormessage) {
- # Call subfunction to launch oinkmaster.
- &oinkmaster();
+ # Preform a reload of the page.
+ &reload();
+ } else {
+ # Call subfunction to launch oinkmaster.
+ &IDS::oinkmaster();
- # Sleep for 1 seconds.
- sleep(1);
+ # Perform a reload of the page.
+ &reload();
+ }
}
# Save snort settings.
} elsif ($cgiparams{'SNORT'} eq $Lang::tr{'save'}) {
&Header::closebigbox();
&Header::closepage();
-sub working ($) {
- my $message = $_[0];
-
- &Header::openpage($Lang::tr{'intrusion detection system'}, 1, '');
- &Header::openbigbox('100%', 'left', '', $errormessage);
- &Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='1'>" );
- print <<END;
- <table>
- <tr>
- <td><img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' /></td>
- <td>$message</td>
- </tr>
- <tr>
- <td colspan='2' align='center'>
- <form method='post' action='$ENV{'SCRIPT_NAME'}'>
- <input type='image' alt='$Lang::tr{'reload'}' title='$Lang::tr{'reload'}' src='/images/view-refresh.png' />
- </form>
- </tr>
- </table>
-END
- &Header::closebox();
- &Header::closebigbox();
- &Header::closepage();
- exit;
+#
+## A tiny function to perform a reload of the webpage after one second.
+#
+sub reload () {
+ print "<meta http-equiv='refresh' content='1'>\n";
+
+ # Stop the script.
+ exit;
}
#