Skip to content

Commit

Permalink
Issue RotherOSS#17: refrain from using $ENV{SCRIPT_NAME}
Browse files Browse the repository at this point in the history
Use $ParamObject->ScriptName() instead.
  • Loading branch information
bschmalhofer committed Jun 6, 2020
1 parent 8361d1c commit ab1953b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Kernel/Modules/Installer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ sub Run {
}
}

my $OTOBOHandle = $ENV{SCRIPT_NAME};
my $OTOBOHandle = $ParamObject->ScriptName();
$OTOBOHandle =~ s/\/(.*)\/installer\.pl/$1/;
my $Output =
$LayoutObject->Header(
Expand Down
5 changes: 2 additions & 3 deletions Kernel/Modules/MigrateFromOTRS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -583,18 +583,17 @@ sub _Finish {
}
}

# prepare link
# prepare link to the agent interface
my $Host = $ENV{HTTP_HOST} || $Param{ConfigObject}->Get('FQDN');
$Host =~ s/\/$//;
my $OTOBOHandle = $ENV{SCRIPT_NAME};
my $OTOBOHandle = $Kernel::OM->Get('Kernel::System::Web::Request')->ScriptName();
$OTOBOHandle =~ s/migration\.pl/index.pl/;

return {
Webserver => $Webserver,
OTOBOHandle => $OTOBOHandle,
Host => $Host,
};

}

sub _CheckConfig {
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Output/HTML/Layout.pm
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ sub new {
$Self->{Charset} = $Self->{UserCharset}; # just for compat.
$Self->{SessionID} = $Param{SessionID} || '';
$Self->{SessionName} = $Param{SessionName} || 'SessionID';
$Self->{CGIHandle} = $ENV{SCRIPT_NAME} || 'No-$ENV{"SCRIPT_NAME"}';
$Self->{CGIHandle} = $Kernel::OM->Get('Kernel::System::Web::Request')->ScriptName() || 'No-$ENV{"SCRIPT_NAME"}';

# baselink
$Self->{Baselink} = $Self->{CGIHandle} . '?';
Expand Down
32 changes: 31 additions & 1 deletion Kernel/System/Web/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ sub GetCookie {
get the remote address of the HTTP client.
This is a wrapper around CGI::remote_addr().
my $RemoteAddre = $ParamObject->RemoteAddr();
my $RemoteAddr = $ParamObject->RemoteAddr();
=cut

Expand All @@ -368,6 +368,36 @@ sub RemoteAddr {
return $Self->{Query}->remote_addr( @Params );
}

=head2 ScriptName
return the script name as a partial URL, for self-referring scripts.
This is a wrapper around CGI::script_name().
my $ScriptName = $ParamObject->ScriptName();
=cut

sub ScriptName {
my ( $Self, @Params ) = @_;

return $Self->{Query}->script_name( @Params );
}

=head2 PathInfo
Returns additional path information from the script URL.
This is a wrapper around CGI::path_info().
my $PathInfo = $ParamObject->PathInfo();
=cut

sub PathInfo {
my ( $Self, @Params ) = @_;

return $Self->{Query}->path_info( @Params );
}

=head2 HTTP
get the HTTP environment variable. Called with a single argument get the specific environment variable.
Expand Down
9 changes: 5 additions & 4 deletions bin/psgi-bin/otobo.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ eval {
# this might improve performance
CGI->compile(':cgi');

warn "PLEASE NOTE THAT PLACK SUPPORT IS AS OF MAY 25th 2020 EXPERIMENTAL AND NOT SUPPORTED!\n";
warn "PLEASE NOTE THAT PLACK SUPPORT IS AS OF JUNE 6TH 2020 EXPERIMENTAL AND NOT SUPPORTED!\n";

# conditionally enable profiling
my $NYTProfMiddleWare = sub {
Expand Down Expand Up @@ -473,8 +473,9 @@ my $App = builder {
# 0=off;1=on;
my $Debug = 0;

# %ENV has to be used here as the PSGI is not passed as an arg to this anonymous sub.
# $ENV{SCRIPT_NAME} contains the matching mountpoint. Can be e.g. '/otobo' or '/otobo/index.pl'
# $ENV{PATH_INFO} contains the path after the $ENV{SCRIPT_NAME}. Can be e.g. '/rpc.pl' or ''
# $ENV{PATH_INFO} contains the path after the $ENV{SCRIPT_NAME}. Can be e.g. '/index.pl' or ''
# The extracted ScriptFileName should be something like index.pl, customer.pl, or rpc.pl
my ($ScriptFileName) = ( ( $ENV{SCRIPT_NAME} // '' ) . ( $ENV{PATH_INFO} // '' ) ) =~ m{/([A-Za-z\-_]+\.pl)};

Expand Down Expand Up @@ -574,8 +575,8 @@ builder {
# OTOBO DBViewer, must be below /otobo because of the session cookie
mount '/otobo/dbviewer' => $DBViewerApp;

# Wrap the CGI-scripts in bin/cgi-bin.
# The pathes are such that $ENV{SCRIPT_NAME} is set the same way as under mod_perl
# Provide routes that are the equivalents of the scripts in bin/cgi-bin.
# The pathes are such that $ENV{SCRIPT_NAME} and $ENV{PATH_INFO} are set up just like they are set up under mod_perl,
mount '/otobo/index.pl' => $App;
mount '/otobo/customer.pl' => $App;
mount '/otobo/public.pl' => $App;
Expand Down
1 change: 1 addition & 0 deletions scripts/test/Layout/RichTextDocumentServe.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use utf8;

use vars (qw($Self));

# This setting will be picked up whenever an instance of Kernel::System::Web::Request is created.
local $ENV{SCRIPT_NAME} = 'index.pl';

my $Helper = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
Expand Down

0 comments on commit ab1953b

Please sign in to comment.