From 434001d0a0eb05946fccded7090e1e1fa6e2c64d Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Sat, 28 Jul 2018 16:34:50 +0200 Subject: [PATCH] IDS: Rework error and log handling in ids-functions.pl Signed-off-by: Stefan Schantl --- config/cfgroot/ids-functions.pl | 28 +++++++++++++++++----------- html/cgi-bin/ids.cgi | 11 ++++++----- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index 74713d77ad..647aa1f4c8 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -24,7 +24,6 @@ package IDS; require '/var/ipfire/general-functions.pl'; -require "${General::swroot}/lang.pl"; # Location where all config and settings files are stored. our $settingsdir = "${General::swroot}/snort"; @@ -59,11 +58,11 @@ sub checkdiskspace () { # Check if the available disk space is more than 300MB. if ($available < 300) { - # If there is not enough space, print out an error message. - my $errormessage = "$Lang::tr{'not enough disk space'} < 300MB, /var $available MB"; + # Log error to syslog. + &_log_to_syslog("Not enough free disk space on /var. Only $available MB from 300 MB available."); - # Exit function and return the error message. - return $errormessage; + # Exit function and return "1" - False. + return 1; } } } @@ -120,8 +119,11 @@ sub downloadruleset { # Add proxy server address and port. $proxy_url .= "$peer\:$peerport"; } else { - # Break and return error message. - return "$Lang::tr{'could not download latest updates'}"; + # Log error message and break. + &_log_to_syslog("Could not proper configure the proxy server access."); + + # Return "1" - false. + return 1; } # Setup proxy settings. @@ -136,8 +138,9 @@ sub downloadruleset { # Abort if no url could be determined for the vendor. unless ($url) { - # Abort and return errormessage. - return "$Lang::tr{'could not download latest updates'}"; + # Log error and abort. + &_log_to_syslog("Unable to gather a download URL for the selected ruleset."); + return 1; } # Pass the requested url to the downloader. @@ -148,8 +151,11 @@ sub downloadruleset { # Check if there was any error. unless ($response->is_success) { - # Return error message. - return "$response->status_line"; + # Log error message. + &_log_to_syslog("Unable to download the ruleset. $response->status_line"); + + # Return "1" - false. + return 1; } # If we got here, everything worked fine. Return nothing. diff --git a/html/cgi-bin/ids.cgi b/html/cgi-bin/ids.cgi index 71fc1ea608..2ada96f520 100644 --- a/html/cgi-bin/ids.cgi +++ b/html/cgi-bin/ids.cgi @@ -265,7 +265,9 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'update'}) { } # Check if enought free disk space is availabe. - $errormessage = &IDS::checkdiskspace(); + if(&IDS::checkdiskspace()) { + $errormessage = "$Lang::tr{'not enough disk space'}"; + } # Check if any errors happend. unless ($errormessage) { @@ -274,12 +276,11 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'update'}) { &working_notice("$Lang::tr{'snort working'}"); # Call subfunction to download the ruleset. - $errormessage = &IDS::downloadruleset(); + if(&IDS::downloadruleset()) { + $errormessage = $Lang::tr{'could not download latest updates'}; - # Check if the downloader returned an error. - if ($errormessage) { # Call function to store the errormessage. - &IDS::log_error($errormessage); + &IDS::_store_error_message($errormessage); # Preform a reload of the page. &reload(); -- 2.39.5