|
@@ -5,40 +5,41 @@ use Log::Log4perl qw(:easy);
|
|
use lib "/usr/local/lib";
|
|
use lib "/usr/local/lib";
|
|
use Shellex::Shellex qw(shellex findBin);
|
|
use Shellex::Shellex qw(shellex findBin);
|
|
use Exporter qw(import);
|
|
use Exporter qw(import);
|
|
-our @EXPORT_OK = qw();
|
|
|
|
|
|
+our @EXPORT_OK = qw(parse_gsg_config);
|
|
|
|
|
|
# https://perlmaven.com/trim
|
|
# https://perlmaven.com/trim
|
|
sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
|
|
sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
|
|
|
|
|
|
-sub parseGsgConfig($$) {
|
|
|
|
|
|
+sub parse_gsg_config($$) {
|
|
|
|
|
|
- my $configPath = shift;
|
|
|
|
|
|
+ my $config_path = shift;
|
|
my $logger = shift;
|
|
my $logger = shift;
|
|
- if ( ! -e $config ) {
|
|
|
|
- $logger->error("$config doesn't look like a regular file, exiting...");
|
|
|
|
|
|
+ if ( ! -e $config_path ) {
|
|
|
|
+ $logger->error("$config_path doesn't look like a regular file, exiting...");
|
|
exit 1;
|
|
exit 1;
|
|
}
|
|
}
|
|
- my $catCmd = findBin("cat",$logger);
|
|
|
|
- my @configLines = split("\n",shellex("$catCmd $config",$logger));
|
|
|
|
- my %configHash;
|
|
|
|
- foreach my $line ( @configLines ) {
|
|
|
|
|
|
+ # Should probably just open with perl, needless shellout TODO
|
|
|
|
+ my $cat_cmd = findBin("cat",$logger);
|
|
|
|
+ my @config_lines = split("\n",shellex("$cat_cmd $config_path",$logger));
|
|
|
|
+ my %config_hash;
|
|
|
|
+ foreach my $line ( @config_lines ) {
|
|
chomp $line;
|
|
chomp $line;
|
|
if ( $line =~ m/^(.*)\ =\ "(.*)"$/ ) {
|
|
if ( $line =~ m/^(.*)\ =\ "(.*)"$/ ) {
|
|
- $configHash{$1} = $2;
|
|
|
|
|
|
+ $config_hash{$1} = $2;
|
|
}
|
|
}
|
|
|
|
|
|
if ( $line =~ m/^(.*)\ =\ \[(.*)\]/ ) {
|
|
if ( $line =~ m/^(.*)\ =\ \[(.*)\]/ ) {
|
|
- my @trimmedPorts;
|
|
|
|
- my @ports = split(",",$2);
|
|
|
|
- foreach my $port (@ports) {
|
|
|
|
- $port =~ /(\d{1,5})/;
|
|
|
|
- push(@trimmedPorts,trim($1));
|
|
|
|
|
|
+ my @trimmed_vals;
|
|
|
|
+ my @vals = split(",",$2);
|
|
|
|
+ foreach my $val (@vals) {
|
|
|
|
+ $val =~ /"(.*)"/;
|
|
|
|
+ push(@trimmed_vals,trim($1));
|
|
}
|
|
}
|
|
- $configHash{$1} = \@trimmedPorts;
|
|
|
|
|
|
+ $config_hash{$1} = \@trimmed_vals;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return %configHash;
|
|
|
|
|
|
+ return %config_hash;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|