mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-25 18:32:57 +02:00
ids.cgi: Rework CGI logic to download a new ruleset
* Drop function to show a notice about snort is working. * Introduce the log_error function which is responsible for log any error messages. Currently it writes it to a tempory file, which will be read by the WUI, the message will be displayed and the temporary file will be released again. * Introduce a tiny function to easily perform a reload of the generated webpage. Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
This commit is contained in:
@@ -29,6 +29,9 @@ require "${General::swroot}/lang.pl";
|
||||
# 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.
|
||||
@@ -155,4 +158,36 @@ sub oinkmaster () {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user