From 99754ea44420940fc77b5170f83a4f752d0d1df9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 16 Mar 2021 10:38:14 +0100 Subject: [PATCH] Bug 27555: Use psgi_env from errors sripts --- C4/Auth.pm | 13 +++++++------ errors/400.pl | 2 +- errors/401.pl | 2 +- errors/402.pl | 2 +- errors/403.pl | 2 +- errors/404.pl | 2 +- errors/500.pl | 2 +- opac/errors/400.pl | 2 +- opac/errors/401.pl | 2 +- opac/errors/402.pl | 2 +- opac/errors/403.pl | 2 +- opac/errors/404.pl | 2 +- opac/errors/500.pl | 2 +- 13 files changed, 19 insertions(+), 18 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 8368dd82ff..37a6082a07 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -52,13 +52,14 @@ use C4::Log qw/logaction/; # use utf8; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout); -BEGIN { - sub psgi_env { any { /^psgi\./ } keys %ENV } +sub psgi_env { any { /(^psgi\.|^plack\.)/i } keys %ENV } - sub safe_exit { - if (psgi_env) { die 'psgi:exit' } - else { exit } - } +sub safe_exit { + if (psgi_env) { die 'psgi:exit' } + else { exit } +} + +BEGIN { C4::Context->set_remote_address; diff --git a/errors/400.pl b/errors/400.pl index 2e9324d6ea..1e1ddbf49c 100755 --- a/errors/400.pl +++ b/errors/400.pl @@ -39,7 +39,7 @@ $template->param ( errno => 400, ); my $status = '400 Bad Request'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/errors/401.pl b/errors/401.pl index 8b67c98174..c08d2388e2 100755 --- a/errors/401.pl +++ b/errors/401.pl @@ -38,7 +38,7 @@ $template->param ( errno => 401, ); my $status = '401 Unauthorized'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/errors/402.pl b/errors/402.pl index 0e5719d677..a8f0112ff3 100755 --- a/errors/402.pl +++ b/errors/402.pl @@ -39,7 +39,7 @@ $template->param ( errno => 402, ); my $status = '402 Payment Required'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/errors/403.pl b/errors/403.pl index dbb6ee6722..c97ea72c87 100755 --- a/errors/403.pl +++ b/errors/403.pl @@ -39,7 +39,7 @@ $template->param ( errno => 403, ); my $status = '403 Forbidden'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/errors/404.pl b/errors/404.pl index 95215a7a8d..6590abb456 100755 --- a/errors/404.pl +++ b/errors/404.pl @@ -39,7 +39,7 @@ $template->param ( errno => 404, ); my $status = '404 Not Found'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/errors/500.pl b/errors/500.pl index 7f92673ce1..f580b45b20 100755 --- a/errors/500.pl +++ b/errors/500.pl @@ -39,7 +39,7 @@ $template->param ( errno => 500, ); my $status = '500 Internal Server Error'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/opac/errors/400.pl b/opac/errors/400.pl index e295c0bf29..321e018996 100755 --- a/opac/errors/400.pl +++ b/opac/errors/400.pl @@ -39,7 +39,7 @@ $template->param ( errno => 400, ); my $status = '400 Bad Request'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/opac/errors/401.pl b/opac/errors/401.pl index 011698d5a6..1b316639fc 100755 --- a/opac/errors/401.pl +++ b/opac/errors/401.pl @@ -39,7 +39,7 @@ $template->param ( errno => 401, ); my $status = '401 Unauthorized'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/opac/errors/402.pl b/opac/errors/402.pl index b3f94e6992..e1393c80d4 100755 --- a/opac/errors/402.pl +++ b/opac/errors/402.pl @@ -39,7 +39,7 @@ $template->param ( errno => 402, ); my $status = '402 Payment Required'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/opac/errors/403.pl b/opac/errors/403.pl index 2768a14945..e2ee73b146 100755 --- a/opac/errors/403.pl +++ b/opac/errors/403.pl @@ -39,7 +39,7 @@ $template->param ( errno => 403, ); my $status = '403 Forbidden'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/opac/errors/404.pl b/opac/errors/404.pl index 6fe04c218b..ab00054f87 100755 --- a/opac/errors/404.pl +++ b/opac/errors/404.pl @@ -39,7 +39,7 @@ $template->param ( errno => 404, ); my $status = '404 Not Found'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; diff --git a/opac/errors/500.pl b/opac/errors/500.pl index be1e374fbe..04c9061757 100755 --- a/opac/errors/500.pl +++ b/opac/errors/500.pl @@ -39,7 +39,7 @@ $template->param ( errno => 500, ); my $status = '500 Internal Server Error'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Auth::psgi_env() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; -- 2.20.1