From 2bbf176619985f552e2418e167100425163aa5e7 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Mon, 17 May 2021 22:25:44 +0200 Subject: [PATCH] dhcp.cgi: Use perl built-in grep Signed-off-by: Stefan Schantl --- html/cgi-bin/dhcp.cgi | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/html/cgi-bin/dhcp.cgi b/html/cgi-bin/dhcp.cgi index 58891f9c51..4c9fff8353 100644 --- a/html/cgi-bin/dhcp.cgi +++ b/html/cgi-bin/dhcp.cgi @@ -130,6 +130,15 @@ open(FILE, "$filename2") or die 'Unable to open fixed leases file.'; our @current2 = ; close(FILE); +# Open and read-in file which contains the list of allowed advanced options. +open(FILE, $filename3) or die "Could not open $filename3. $!\n" + +# Grab file content. +my @advoptions_list = ; + +# Close file handle. +close(FILE); + # Check Settings1 first because they are needed by &buildconf if ($dhcpsettings{'ACTION'} eq $Lang::tr{'save'}) { foreach my $itf (@ITFs) { @@ -338,7 +347,7 @@ if ($dhcpsettings{'ACTION'} eq $Lang::tr{'add'}.'1' && map ($dhcpsettings{"ADVOPT_SCOPE_$_"} = 'off', @ITFs); # force global } elsif (ValidNewOption ($dhcpsettings{'ADVOPT_NAME'} . ' ' . $dhcpsettings{'ADVOPT_DATA'})) { #was a new option - } elsif (! `grep "\$option $dhcpsettings{'ADVOPT_NAME'} " $filename3`) { + } elsif (! grep(/option $dhcpsettings{'ADVOPT_NAME'}/, @advoptions_list)) { $errormessage=$Lang::tr{'dhcp advopt unknown'}.': '.$dhcpsettings{'ADVOPT_NAME'}; } @@ -714,7 +723,11 @@ if ($dhcpsettings{'KEY1'} ne '') { } #search if the 'option' is in the list and print the syntax model -my $opt = `grep "\$option $dhcpsettings{'ADVOPT_NAME'} " $filename3`; +my @opt = grep(/option $dhcpsettings{'ADVOPT_NAME'}/, @advoptions_list); + +# Assign array element to variable and remove newlines. +my $opt = chomp(@opt[0]); + if ($opt ne '') { $opt =~ s/option $dhcpsettings{'ADVOPT_NAME'}/Syntax:/; # "option xyz abc" => "syntax: abc" $opt =~ s/;//; -- 2.39.2