From a2b4488ae53c92b6ffefa2abb2ee4601e4907014 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Thu, 1 Apr 2021 11:46:11 +0200 Subject: [PATCH] ids.cgi: Finish code to handle toggeling a provider enabled/disabled. Signed-off-by: Stefan Schantl --- html/cgi-bin/ids.cgi | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/html/cgi-bin/ids.cgi b/html/cgi-bin/ids.cgi index 908ad9c287..e927fb617b 100644 --- a/html/cgi-bin/ids.cgi +++ b/html/cgi-bin/ids.cgi @@ -871,14 +871,28 @@ if ($cgiparams{'RULESET'} eq $Lang::tr{'save'}) { # Write the changed hash to the providers settings file. &General::writehasharray($IDS::providers_settings_file, \%used_providers); - # XXX - The ruleset needs to be regenerated - # XXX - Suricata requires a reload or if the last provider - # has been disabled suricata needs to be stopped. + # Get all enabled providers. + my @enabled_providers = &IDS::get_enabled_providers(); + + # Write the main providers include file. + &IDS::write_main_used_rulefiles_file(@enabled_providers); + # Check if the IDS is running. - #if(&IDS::ids_is_running()) { - # # Call suricatactrl to perform a reload. - # &IDS::call_suricatactrl("reload"); - #} + if(&IDS::ids_is_running()) { + # Gather the amount of enabled providers (elements in the array). + my $amount = @enabled_providers; + + # Check if there are still enabled ruleset providers. + if ($amount >= 1) { + # Call suricatactrl to perform a restart. + &IDS::call_suricatactrl("restart"); + + # No active ruleset provider, suricata has to be stopped. + } else { + # Stop suricata. + &IDS::call_suricatactrl("stop"); + } + } # Undefine providers flag. undef($cgiparams{'PROVIDERS'}); -- 2.39.2