From 89d00b85ff3b06339f7e8dc0dcf2be0c1472902a Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Sat, 23 Sep 2023 21:00:44 +0300 Subject: [PATCH] Add working redirect from `/awstats` https://forum.virtualmin.com/t/awstats-report-basic-authentication-not-working/119491/45?u=ilia --- virtual_feature.pl | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/virtual_feature.pl b/virtual_feature.pl index bb76eab..997069a 100755 --- a/virtual_feature.pl +++ b/virtual_feature.pl @@ -197,17 +197,29 @@ sub feature_setup $d->{'dom'}, $port); if ($virt) { my $conf = &apache::get_config(); + my $done; my @sa = &apache::find_directive( "ScriptAlias", $vconf); my ($aw) = grep { $_ =~ /^\/awstats/ } @sa; if (!$aw) { # Need to add - push(@sa, "/awstats/ $cgidir/"); + push(@sa, "/awstats $cgidir/awstats.pl"); &apache::save_directive("ScriptAlias", \@sa, $vconf, $conf); + $done++; + } + my @rm = &apache::find_directive( + "RedirectMatch", $vconf); + my ($rm) = grep { $_ =~ /^\^\/awstats\$\s+\/awstats/ } @rm; + if (!$rm) { + &apache::save_directive("RedirectMatch", + ['^/awstats$ /awstats/'], $vconf, $conf); + $done++; + } + if ($done) { &flush_file_lines($virt->{'file'}); &virtual_server::register_post_action( - \&virtual_server::restart_apache); + \&virtual_server::restart_apache); } } } @@ -463,6 +475,7 @@ sub feature_delete $d->{'dom'}, $port); if ($virt) { my $conf = &apache::get_config(); + my $done; my @sa = &apache::find_directive( "ScriptAlias", $vconf); my ($aw) = grep { $_ =~ /^\/awstats/ } @sa; @@ -471,9 +484,22 @@ sub feature_delete @sa = grep { $_ ne $aw } @sa; &apache::save_directive("ScriptAlias", \@sa, $vconf, $conf); + $done++; + } + my @rm = &apache::find_directive( + "RedirectMatch", $vconf); + my ($rm) = grep { $_ =~ /^\^\/awstats\$\s+\/awstats\// } @rm; + if ($rm) { + @rm = grep { $_ ne $rm } @rm; + &apache::save_directive( + "RedirectMatch", \@rm, + $vconf, $conf); + $done++; + } + if ($done) { &flush_file_lines($virt->{'file'}); &virtual_server::register_post_action( - \&virtual_server::restart_apache); + \&virtual_server::restart_apache); } } }