From 24267b8afd48d6fc9069bd2732e5ea27b1d4c749 Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Sat, 23 May 2020 15:54:53 +0300 Subject: [PATCH] Redirec to exact URL .. ..otherwise, every second click on the link from the same page, will result in 'too many redirects' error, as referer will equal initial restart target on the second go, ending-up broken --- bind8/bind8-lib.pl | 10 +++++++--- bind8/restart.cgi | 8 +++++++- bind8/restart_zone.cgi | 8 ++++---- bind8/start.cgi | 9 ++++++++- bind8/stop.cgi | 9 ++++++++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/bind8/bind8-lib.pl b/bind8/bind8-lib.pl index 71b3bf783..8b1efb477 100755 --- a/bind8/bind8-lib.pl +++ b/bind8/bind8-lib.pl @@ -3161,6 +3161,10 @@ my ($zone) = @_; my @rv; if (!$access{'ro'} && $access{'apply'}) { my $r = $ENV{'REQUEST_METHOD'} eq 'POST' ? 0 : 1; + my $zone_name; + if ($zone) { + $zone_name = "&" . "zone=$zone->{'name'}&type=$zone->{'type'}"; + } if (&is_bind_running()) { if ($zone && ($access{'apply'} == 1 || $access{'apply'} == 2)) { # Apply this zone @@ -3171,16 +3175,16 @@ if (!$access{'ro'} && $access{'apply'}) { } # Apply whole config if ($access{'apply'} == 1 || $access{'apply'} == 3) { - push(@rv, &ui_link("restart.cgi?return=$r", $text{'links_restart'}) ); + push(@rv, &ui_link("restart.cgi?return=$r$zone_name", $text{'links_restart'}) ); } if ($access{'apply'} == 1) { # Stop BIND - push(@rv, &ui_link("stop.cgi?return=$r", $text{'links_stop'}) ); + push(@rv, &ui_link("stop.cgi?return=$r$zone_name", $text{'links_stop'}) ); } } elsif ($access{'apply'} == 1) { # Start BIND - push(@rv, &ui_link("start.cgi?return=$r", $text{'links_start'})); + push(@rv, &ui_link("start.cgi?return=$r$zone_name", $text{'links_start'})); } } return join('
', @rv); diff --git a/bind8/restart.cgi b/bind8/restart.cgi index 7fb68a97c..92f852a75 100755 --- a/bind8/restart.cgi +++ b/bind8/restart.cgi @@ -26,5 +26,11 @@ if ($access{'remote'}) { } &webmin_log("apply"); -&redirect($in{'return'} ? $ENV{'HTTP_REFERER'} : ""); +my $redir_targ = ($in{'type'} eq "master" ? "edit_master.cgi" : + $in{'type'} eq "forward" ? "edit_forward.cgi" : "edit_slave.cgi"); +my $zone; +if ($in{'zone'}) { + $zone = "?zone=$in{'zone'}"; +} +&redirect($zone && $in{'return'} ? "$redir_targ$zone" : ""); diff --git a/bind8/restart_zone.cgi b/bind8/restart_zone.cgi index f3861aaee..0928b58f0 100755 --- a/bind8/restart_zone.cgi +++ b/bind8/restart_zone.cgi @@ -16,12 +16,12 @@ my $err = &restart_zone($zone->{'name'}, $zone->{'view'}); &webmin_log("apply", $zone->{'name'}); my $tv = $zone->{'type'}; +my $redir_targ = ($tv eq "master" ? "edit_master.cgi" : + $tv eq "forward" ? "edit_forward.cgi" : "edit_slave.cgi"); if ($in{'return'}) { - &redirect($ENV{'HTTP_REFERER'}); + &redirect($redir_targ . "?zone=$in{'zone'}"); } else { - &redirect(($tv eq "master" ? "edit_master.cgi" : - $tv eq "forward" ? "edit_forward.cgi" : "edit_slave.cgi"). - "?zone=$in{'zone'}&view=$in{'view'}"); + &redirect($redir_targ . "?zone=$in{'zone'}&view=$in{'view'}"); } diff --git a/bind8/start.cgi b/bind8/start.cgi index cf584be92..d5d199225 100755 --- a/bind8/start.cgi +++ b/bind8/start.cgi @@ -6,10 +6,17 @@ use warnings; our (%access, %text, %in); require './bind8-lib.pl'; +&ReadParse(); $access{'ro'} && &error($text{'start_ecannot'}); $access{'apply'} || &error($text{'start_ecannot'}); my $err = &start_bind(); &error($err) if ($err); &webmin_log("start"); -&redirect($in{'return'} ? $ENV{'HTTP_REFERER'} : ""); +my $redir_targ = ($in{'type'} eq "master" ? "edit_master.cgi" : + $in{'type'} eq "forward" ? "edit_forward.cgi" : "edit_slave.cgi"); +my $zone; +if ($in{'zone'}) { + $zone = "?zone=$in{'zone'}"; +} +&redirect($zone && $in{'return'} ? "$redir_targ$zone" : ""); diff --git a/bind8/stop.cgi b/bind8/stop.cgi index 1ee2010f3..9c8c2baca 100755 --- a/bind8/stop.cgi +++ b/bind8/stop.cgi @@ -2,10 +2,17 @@ # Stop bind 8 require './bind8-lib.pl'; +&ReadParse(); $access{'ro'} && &error($text{'stop_ecannot'}); $access{'apply'} || &error($text{'stop_ecannot'}); $err = &stop_bind(); &error($err) if ($err); &webmin_log("stop"); -&redirect($in{'return'} ? $ENV{'HTTP_REFERER'} : ""); +my $redir_targ = ($in{'type'} eq "master" ? "edit_master.cgi" : + $in{'type'} eq "forward" ? "edit_forward.cgi" : "edit_slave.cgi"); +my $zone; +if ($in{'zone'}) { + $zone = "?zone=$in{'zone'}"; +} +&redirect($zone && $in{'return'} ? "$redir_targ$zone" : "");