From 820ab96c6927c4e3ecbbe2df1342b635cc598ce7 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 26 Feb 2019 10:16:21 +0000 Subject: [PATCH 1/3] DHCP: Escape slashes in filename Fixes: #12006 Signed-off-by: Michael Tremer --- html/cgi-bin/dhcp.cgi | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/html/cgi-bin/dhcp.cgi b/html/cgi-bin/dhcp.cgi index 3eb5349a9..82c6b2066 100644 --- a/html/cgi-bin/dhcp.cgi +++ b/html/cgi-bin/dhcp.cgi @@ -1272,7 +1272,7 @@ sub buildconf { print FILE ", " . $dhcpsettings{"WINS2_${itf}"} if ($dhcpsettings{"WINS2_${itf}"}); print FILE ";\n" if ($dhcpsettings{"WINS1_${itf}"}); print FILE "\tnext-server " . $dhcpsettings{"NEXT_${itf}"} . ";\n" if ($dhcpsettings{"NEXT_${itf}"}); - print FILE "\tfilename \"" . $dhcpsettings{"FILE_${itf}"} . "\";\n" if ($dhcpsettings{"FILE_${itf}"}); + print FILE "\tfilename \"" . &EscapeFilename($dhcpsettings{"FILE_${itf}"}) . "\";\n" if ($dhcpsettings{"FILE_${itf}"}); print FILE "\tdefault-lease-time " . ($dhcpsettings{"DEFAULT_LEASE_TIME_${itf}"} * 60). ";\n"; print FILE "\tmax-lease-time " . ($dhcpsettings{"MAX_LEASE_TIME_${itf}"} * 60) . ";\n"; print FILE "\tallow bootp;\n" if ($dhcpsettings{"ENABLEBOOTP_${itf}"} eq 'on'); @@ -1325,7 +1325,7 @@ sub buildconf { print FILE "\thardware ethernet $temp[0];\n"; print FILE "\tfixed-address $temp[1];\n"; print FILE "\tnext-server $temp[3];\n" if ($temp[3]); - print FILE "\tfilename \"$temp[4]\";\n" if ($temp[4]); + print FILE "\tfilename \"" . &EscapeFilename($temp[4]) . "\";\n" if ($temp[4]); print FILE "\toption root-path \"$temp[5]\";\n" if ($temp[5]); print FILE "}\n"; $key++; @@ -1392,3 +1392,12 @@ sub IsUsedNewOptionDefinition { } return 0; } + +sub EscapeFilename($) { + my $filename = shift; + + # Replace all single / by \/ + $filename =~ s/\//\\\//g; + + return $filename; +} From 4eb23a91987a39c504e10d96d89bd1de46f9c0fe Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 26 Feb 2019 10:18:33 +0000 Subject: [PATCH 2/3] DHCP: Restart server in background This allows for the CGI to return quicker. Signed-off-by: Michael Tremer --- html/cgi-bin/dhcp.cgi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/cgi-bin/dhcp.cgi b/html/cgi-bin/dhcp.cgi index 82c6b2066..900ea3a9c 100644 --- a/html/cgi-bin/dhcp.cgi +++ b/html/cgi-bin/dhcp.cgi @@ -1335,7 +1335,7 @@ sub buildconf { close FILE; if ( $dhcpsettings{"ENABLE_GREEN"} eq 'on' || $dhcpsettings{"ENABLE_BLUE"} eq 'on' ) {system '/usr/local/bin/dhcpctrl enable >/dev/null 2>&1';} else {system '/usr/local/bin/dhcpctrl disable >/dev/null 2>&1';} - system '/usr/local/bin/dhcpctrl restart >/dev/null 2>&1'; + system '/usr/local/bin/dhcpctrl restart >/dev/null 2>&1 &'; } # From 31672dc8bdb223ebf425ff96be64318f2d68e0d7 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 26 Feb 2019 11:02:56 +0000 Subject: [PATCH 3/3] DHCP: Fix error when editing a newly added fixed lease They key was remembered but then the array was sorted which resulted the key showing a wrong line. Signed-off-by: Michael Tremer --- html/cgi-bin/dhcp.cgi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/html/cgi-bin/dhcp.cgi b/html/cgi-bin/dhcp.cgi index 900ea3a9c..675d80012 100644 --- a/html/cgi-bin/dhcp.cgi +++ b/html/cgi-bin/dhcp.cgi @@ -446,15 +446,17 @@ if ($dhcpsettings{'ACTION'} eq $Lang::tr{'add'}.'2') { &General::log($Lang::tr{'fixed ip lease added'}); # Enter edit mode - $dhcpsettings{'KEY2'} = $key; + $dhcpsettings{'KEY2'} = 0; } else { @current2[$dhcpsettings{'KEY2'}] = "$dhcpsettings{'FIX_MAC'},$dhcpsettings{'FIX_ADDR'},$dhcpsettings{'FIX_ENABLED'},$dhcpsettings{'FIX_NEXTADDR'},$dhcpsettings{'FIX_FILENAME'},$dhcpsettings{'FIX_ROOTPATH'},$dhcpsettings{'FIX_REMARK'}\n"; $dhcpsettings{'KEY2'} = ''; # End edit mode &General::log($Lang::tr{'fixed ip lease modified'}); + + # sort newly added/modified entry + &sortcurrent2; } #Write changes to dhcpd.conf. - &sortcurrent2; # sort newly added/modified entry &buildconf; # before calling buildconf which use fixed lease file ! } }