]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
ids-functions.pl: Add generate_report_generator_config() function
authorStefan Schantl <stefan.schantl@ipfire.org>
Sat, 9 Aug 2025 14:46:37 +0000 (16:46 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Sep 2025 17:42:01 +0000 (18:42 +0100)
This function is used to genereate the config file for the newly
introduced suricata-report-generator.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/ids-functions.pl

index 1a72e4c3e2bdd635ea437424d36eb8c0e98e9918..3d45b5d0108cc147f808dd44f618e64e1157960a 100644 (file)
@@ -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;