From: Stefan Schantl Date: Sat, 9 Aug 2025 14:46:37 +0000 (+0200) Subject: ids-functions.pl: Add generate_report_generator_config() function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=30dd4d3e6bbbeb25a3083b60ab21a3afc6742a06;p=ipfire-2.x.git ids-functions.pl: Add generate_report_generator_config() function This function is used to genereate the config file for the newly introduced suricata-report-generator. Signed-off-by: Stefan Schantl Signed-off-by: Michael Tremer --- diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index 1a72e4c3e..3d45b5d01 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -113,9 +113,15 @@ our $whitelist_file = "$rulespath/whitelist.rules"; # (Sourcefire, Emergingthreads, etc..) our $rulesetsourcesfile = "$settingsdir/ruleset-sources"; +# File which contains the configuration for the suricata-report-generator. +our $report_generator_config_file = "$settingsdir/reporter.conf"; + # The pidfile of the IDS. our $idspidfile = "/var/run/suricata.pid"; +# The pidfile of the report-generator. +our $report_generator_pid = "/var/run/suricata/reporter.pid"; + # Location of suricatactrl. my $suricatactrl = "/usr/local/bin/suricatactrl"; @@ -1743,4 +1749,42 @@ sub unlock_ids_page() { unlink($ids_page_lock_file); } +# +## Function to generate to configuration for the suricata-report-generator. +# +sub generate_report_generator_config() { + my %idssettings = (); + + # Read-in IDS settings. + &General::readhash("$ids_settings_file", \%idssettings); + + # Get amount of available CPU cores. + my $cpu_count = &General::number_cpu_cores(); + + # Open config file for writing. + open(FILE, ">", "$report_generator_config_file") or die "Could not write to $report_generator_config_file. $!\n"; + + # Print notice about autogenerated file. + print FILE "#Autogenerated file. Any custom changes will be overwritten!\n\n"; + + # Sylog settings. + print FILE "[syslog]\n"; + print FILE "enabled = true\n\n"; + + # Mail settings. + print FILE "[email]\n"; + + # Check if mail alerts are enabled. + if ($idssettings{'ENABLE_EMAIL'} eq "on") { + print FILE "enabled = true\n"; + } else { + print FILE "enabled = false\n"; + } + + print FILE "sender = $idssettings{'EMAIL_SENDER'}\n"; + print FILE "recipients = $idssettings{'EMAIL_RECIPIENTS'}\n"; + + close(FILE); +} + 1;