From 77c3130174cd492f0bae12205cfd3000b9b7798c Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Wed, 30 Jan 2019 11:57:49 +0100 Subject: [PATCH] ids-functions.pl: Add get_aliases() This subfunction is used to get all configured and enabled aliases for the RED network zone. They will be returned as an array. Signed-off-by: Stefan Schantl --- config/cfgroot/ids-functions.pl | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index efe89b512f..114d5763db 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -841,4 +841,50 @@ sub set_ownership($) { chown($uid, $gid, "$target"); } } + +# +## Function to read-in the aliases file and returns all configured and enabled aliases. +# +sub get_aliases() { + # Location of the aliases file. + my $aliases_file = "${General::swroot}/ethernet/aliases"; + + # Array to store the aliases. + my @aliases; + + # Check if the file is empty. + if (-z $aliases_file) { + # Abort nothing to do. + return; + } + + # Open the aliases file. + open(ALIASES, $aliases_file) or die "Could not open $aliases_file. $!\n"; + + # Loop through the file content. + while (my $line = ) { + # Remove newlines. + chomp($line); + + # Splitt line content into single chunks. + my ($address, $state, $remark) = split(/\,/, $line); + + # Check if the state of the current processed alias is "on". + if ($state eq "on") { + # Check if the address is valid. + if(&Network::check_ip_address($address)) { + # Add the alias to the array of aliases. + push(@aliases, $address); + } + } + } + + # Close file handle. + close(ALIASES); + + # Return the array. + return @aliases; +} + + 1; -- 2.39.2