]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - config/suricata/convert-snort
convert-snort: Try to download ruleset if none is present.
[ipfire-2.x.git] / config / suricata / convert-snort
index 68d6d337949170dbf1ca666187b0d199cadd53d2..ca650b149a212d9f0074297d78626fec96d8fd11 100644 (file)
@@ -33,18 +33,6 @@ my $snort_config_file = "/etc/snort/snort.conf";
 # Snort rules tarball.
 my $snort_rules_tarball = "/var/tmp/snortrules.tar.gz";
 
-# Check if a snort settings file exists.
-unless( -f "$snort_settings_file") {
-        print "$snort_settings_file not found - Nothing to do. Exiting!\n";
-        exit(0);
-}
-
-# Check if the snort settings file is empty.
-if (-z "$snort_settings_file") {
-       print "$snort_settings_file is empty - Nothing to do. Exiting!\n";
-       exit(0);
-}
-
 #
 ## Step 1: Setup directory and file layout, if not present and set correct
 ##         ownership. The converter runs as a privileged user, but the files
@@ -70,6 +58,18 @@ unless (-d $IDS::rulespath) {
 &IDS::set_ownership("$IDS::settingsdir");
 &IDS::set_ownership("$IDS::rulespath");
 
+# Check if a snort settings file exists.
+unless( -f "$snort_settings_file") {
+       print "$snort_settings_file not found - Nothing to do. Exiting!\n";
+       exit(0);
+}
+
+# Check if the snort settings file is empty.
+if (-z "$snort_settings_file") {
+       print "$snort_settings_file is empty - Nothing to do. Exiting!\n";
+       exit(0);
+}
+
 #
 ## Step 2: Import snort settings and convert to the required format for the new IDS
 ##         (suricata).
@@ -209,6 +209,9 @@ if ($idssettings{"MONITOR_TRAFFIC_ONLY"} eq "off") {
 # Call subfunction and pass the desired IDS action.
 &IDS::write_modify_sids_file($IDS_action);
 
+# Set correct ownership.
+&IDS::set_ownership("$IDS::modify_sids_file");
+
 #
 ## Step 6: Move rulestarball to its new location.
 #
@@ -222,7 +225,15 @@ if (-f $snort_rules_tarball) {
        move($snort_rules_tarball, $IDS::rulestarball);
 
        # Set correct ownership.
-       chown($uid, $gid, $IDS::rulestarball);
+       &IDS::set_ownership("$IDS::rulestarball");
+
+# In case no tarball is present, try to download the ruleset.
+} else {
+       # Check if enought disk space is available.
+       if(&IDS::checkdiskspace()) {
+               # Call the download function and grab the new ruleset.
+               &IDS::downloadruleset();
+       }
 }
 
 #
@@ -233,6 +244,9 @@ if (-f $snort_rules_tarball) {
 if (-f $IDS::rulestarball) {
        # Launch oinkmaster by calling the subfunction.
        &IDS::oinkmaster();
+
+       # Set correct ownership for the rulesdir and files.
+       &IDS::set_ownership("$IDS::rulespath");
 }
 
 #