]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
ids.cgi: Add some more sanity checks when adding a new provider.
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 14 Apr 2021 18:32:14 +0000 (20:32 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 19 Dec 2021 12:23:45 +0000 (13:23 +0100)
* Check if the system is online.
* Check if enough free disk space is available.
* Abort whith an error message if the ruleset could not be
  downloaded.

In error case the provider now will be removed again from the file which
keeps the configured providers. Sadly it needs to be added first because
otherwise the downloader could not read the required values from it.....

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
html/cgi-bin/ids.cgi
langs/de/cgi-bin/de.pl
langs/en/cgi-bin/en.pl

index e72820204087e6ca5a60dd1b04a3ecea3c43cea4..27f72ba4d70b60b7c38f159f703fbff82df088a9 100644 (file)
@@ -815,34 +815,56 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'ids apply'}) {
 
                # Check if a new provider will be added.
                if ($cgiparams{'PROVIDERS'} eq $Lang::tr{'add'}) {
-                       # Lock the webpage and print notice about downloading
-                       # a new ruleset.
-                       &working_notice("$Lang::tr{'ids working'}");
+                       # Check if the red device is active.
+                       unless (-e "${General::swroot}/red/active") {
+                               $errormessage = "$Lang::tr{'ids could not add provider'} - $Lang::tr{'system is offline'}";
+                       }
+
+                       # Check if enough free disk space is availabe.
+                       if(&IDS::checkdiskspace()) {
+                               $errormessage = "$Lang::tr{'ids could not add provider'} - $Lang::tr{'not enough disk space'}";
+                       }
 
-                       # Download the ruleset.
-                       &IDS::downloadruleset($provider);
+                       # Check if any errors happend.
+                       unless ($errormessage) {
+                               # Lock the webpage and print notice about downloading
+                               # a new ruleset.
+                               &working_notice("$Lang::tr{'ids working'}");
 
-                       # Extract the ruleset
-                       &IDS::extractruleset($provider);
+                               # Download the ruleset.
+                               if(&IDS::downloadruleset($provider)) {
+                                       $errormessage = "$Lang::tr{'ids could not add provider'} - $Lang::tr{'ids unable to download the ruleset'}";
 
-                       # Move the ruleset.
-                       &IDS::move_tmp_ruleset();
+                                       # Call function to store the errormessage.
+                                       &IDS::_store_error_message($errormessage);
 
-                       # Cleanup temporary directory.
-                       &IDS::cleanup_tmp_directory();
+                                       # Remove the configured provider again.
+                                       &remove_provider($id);
+                               } else {
+                                       # Extract the ruleset
+                                       &IDS::extractruleset($provider);
 
-                       # Create new empty file for used rulefiles
-                       # for this provider.
-                       &IDS::write_used_provider_rulefiles_file($provider);
+                                       # Move the ruleset.
+                                       &IDS::move_tmp_ruleset();
 
-                       # Perform a reload of the page.
-                       &reload();
+                                       # Cleanup temporary directory.
+                                       &IDS::cleanup_tmp_directory();
+
+                                       # Create new empty file for used rulefiles
+                                       # for this provider.
+                                       &IDS::write_used_provider_rulefiles_file($provider);
+                               }
+
+                               # Perform a reload of the page.
+                               &reload();
+                       }
                }
 
-               # Undefine providers flag.
-               undef($cgiparams{'PROVIDERS'});
        }
 
+       # Undefine providers flag.
+       undef($cgiparams{'PROVIDERS'});
+
 ## Toggle Enabled/Disabled for an existing provider.
 #
 } elsif ($cgiparams{'PROVIDERS'} eq $Lang::tr{'toggle enable disable'}) {
index a4a81fc38980600e6564d179aa054102ccbf4801..bb2e8f8e2a1a3806c61b002d2a04ee34fc417e48 100644 (file)
 'ids apply ruleset changes' => 'Regeländerungen werden übernommen. Bitte warten Sie, bis dieser Vorgang erfolgreich beendet wurde...',
 'ids autoupdates' => 'Automatische Updates',
 'ids automatic rules update' => 'Automatische Regelaktualisierung',
+'ids could not add provider' => 'Provider konnte nicht hinzugefügt werden',
 'ids customize ruleset' => 'Regelset anpassen',
 'ids download new ruleset' => 'Das neue Regelset wird heruntergeladen und entpackt. Bitte warten Sie, bis dieser Vorgang erfolgreich beendet wurde...',
 'ids enable' => 'Einbruchsverhinderungssystem aktivieren',
 'ids ruleset settings' => 'Regelsatzeinstellungen',
 'ids show' => 'Anzeigen',
 'ids the choosen provider is already in use' => 'Der gewhählte Provider wird bereits verwendet.',
+'ids unable to download the ruleset' => 'Das Regelset konnte nicht heruntergeladen werden.',
 'ids visit provider website' => 'Anbieter-Webseite besuchen',
 'ids working' => 'Änderungen werden übernommen. Bitte warten Sie, bis dieser Vorgang erfolgreich beendet wurde.',
 'iface' => 'Iface',
index 59496b195e05b85b9d12d03ec5a638a1f649d886..2c7ae2d7c345342bcf3ce22031d36fce48693d33 100644 (file)
 'ids apply ruleset changes' => 'The ruleset changes are being applied. Please wait until all operations have completed successfully...',
 'ids autoupdates' => 'Automatic updates',
 'ids automatic rules update' => 'Automatic Rule Update',
+'ids could not add provider' => 'Could not add provider',
 'ids customize ruleset' => 'Customize ruleset',
 'ids download new ruleset' => 'Downloading and unpacking new ruleset. Please wait until all operations have completed successfully...',
 'ids enable' => 'Enable Intrusion Prevention System',
 'ids ruleset settings' => 'Ruleset Settings',
 'ids show' => 'Show',
 'ids the choosen provider is already in use' => 'The choosen provider is already in use.',
+'ids unable to download the ruleset' => 'Unable to download the ruleset',
 'ids visit provider website' => 'Visit provider website',
 'ids working' => 'Changes are being applied. Please wait until all operations have completed successfully...',
 'iface' => 'Iface',