mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-05-11 09:48:24 +02:00
ids-functions.pl: Rework &_cleanup_rulesdir() function
* Use a directory listing and delete the files. * Keep files with "config" as file extension. Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
This commit is contained in:
@@ -451,14 +451,20 @@ sub _check_rulesdir_permissions() {
|
|||||||
## the IDS rules, before extracting and modifing the new ruleset.
|
## the IDS rules, before extracting and modifing the new ruleset.
|
||||||
#
|
#
|
||||||
sub _cleanup_rulesdir() {
|
sub _cleanup_rulesdir() {
|
||||||
# Loop through the rules-directory.
|
# Open rules directory and do a directory listing.
|
||||||
while ($item = glob($rulespath/*)) {
|
opendir(DIR, $rulespath) or die $!;
|
||||||
# Skip element if it is a directory.
|
|
||||||
next if -d $item;
|
|
||||||
|
|
||||||
# Delete the current processed item, if not, exit this function
|
# Loop through the direcory.
|
||||||
|
while (my $file = readdir(DIR)) {
|
||||||
|
# We only want files.
|
||||||
|
next unless (-f "$rulespath/$file");
|
||||||
|
|
||||||
|
# Skip element if it has config as file extension.
|
||||||
|
next if ($file =~ m/\.config$/);
|
||||||
|
|
||||||
|
# Delete the current processed file, if not, exit this function
|
||||||
# and return an error message.
|
# and return an error message.
|
||||||
unlink($item) or return "Could not delete $item. $!\n";
|
unlink($rulespath/$file) or return "Could not delete $rulespath/$file. $!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return nothing;
|
# Return nothing;
|
||||||
|
|||||||
Reference in New Issue
Block a user