Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1054 bin cgi bin #1111

Merged
merged 14 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Kernel/Config/GenericAgent.pm
Kernel/Config.pm
Kernel/Language/*.old
bin/cgi-bin/.htaccess
scripts/apache2-perl-startup2.pl
var/virtualfs
var/run
var/log/*.log
Expand Down
2 changes: 1 addition & 1 deletion Kernel/GenericInterface/Transport/HTTP/SOAP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use PerlIO;

# CPAN modules
use HTTP::Status;
use SOAP::Lite;
use Plack::Response;
use SOAP::Lite; # for enabling debugging import +trace => 'all'

# OTOBO modules
use Kernel::System::VariableCheck qw(:all);
Expand Down
2 changes: 1 addition & 1 deletion bin/cgi-bin/customer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#local $ENV{PLACK_URLMAP_DEBUG} = 1; # enable when the URL mapping does not work

# otobo.psgi looks primarily in $ENV{PATH_INFO}
local $ENV{PATH_INFO} = join '/', grep { defined $_ || $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{PATH_INFO} = join '/', grep { defined $_ && $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{SCRIPT_NAME} = '';

my $CgiBinDir = dirname(__FILE__);
Expand Down
2 changes: 1 addition & 1 deletion bin/cgi-bin/index.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#local $ENV{PLACK_URLMAP_DEBUG} = 1; # enable when the URL mapping does not work

# otobo.psgi looks primarily in $ENV{PATH_INFO}
local $ENV{PATH_INFO} = join '/', grep { defined $_ || $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{PATH_INFO} = join '/', grep { defined $_ && $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{SCRIPT_NAME} = '';

my $CgiBinDir = dirname(__FILE__);
Expand Down
2 changes: 1 addition & 1 deletion bin/cgi-bin/installer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#local $ENV{PLACK_URLMAP_DEBUG} = 1; # enable when the URL mapping does not work

# otobo.psgi looks primarily in $ENV{PATH_INFO}
local $ENV{PATH_INFO} = join '/', grep { defined $_ || $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{PATH_INFO} = join '/', grep { defined $_ && $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{SCRIPT_NAME} = '';

my $CgiBinDir = dirname(__FILE__);
Expand Down
2 changes: 1 addition & 1 deletion bin/cgi-bin/migration.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#local $ENV{PLACK_URLMAP_DEBUG} = 1; # enable when the URL mapping does not work

# otobo.psgi looks primarily in $ENV{PATH_INFO}
local $ENV{PATH_INFO} = join '/', grep { defined $_ || $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{PATH_INFO} = join '/', grep { defined $_ && $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{SCRIPT_NAME} = '';

my $CgiBinDir = dirname(__FILE__);
Expand Down
109 changes: 105 additions & 4 deletions bin/cgi-bin/nph-genericinterface.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,118 @@
use File::Basename qw(dirname);

# CPAN modules
use Plack::Util qw();
use Plack::Builder;
use Plack::Handler::CGI qw();
use Plack::Util qw();

# OTOBO modules

#local $ENV{PLACK_URLMAP_DEBUG} = 1; # enable when the URL mapping does not work

# otobo.psgi looks primarily in $ENV{PATH_INFO}
local $ENV{PATH_INFO} = join '/', grep { defined $_ || $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{PATH_INFO} = join '/', grep { defined $_ && $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{SCRIPT_NAME} = '';

my $CgiBinDir = dirname(__FILE__);
state $App = Plack::Util::load_psgi("$CgiBinDir/../psgi-bin/otobo.psgi");
Plack::Handler::CGI->new()->run($App);

state $App = builder {

# enable 'Plack::Middleware::DebugLogging',
# debug => 1,
# response => 1,
# request => 1;

Plack::Util::load_psgi("$CgiBinDir/../psgi-bin/otobo.psgi");
};

#$Plack::Middleware::DebugLogging::module_map->{'text/xml; charset=utf-8'} = 'XML::Simple';
#$Plack::Middleware::DebugLogging::module_map->{'text/xml; charset=UTF-8'} = 'XML::Simple';

# set up a PSGI environment from %ENV
my $PSGIEnv = Plack::Handler::CGI->new()->setup_env();

# run the PSGI-application
my $Res = $App->($PSGIEnv);

# sanity check
die "Bad response from the PSGI app" unless ref $Res eq 'ARRAY';
die "Bad response from the PSGI app" unless ref $Res->[2] eq 'ARRAY';

# turn the PSGI response into non parsed header HTTP response

# copied from HTTP::Status
my %Code2Message = (
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing', # RFC 2518 (WebDAV)
103 => 'Early Hints',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status', # RFC 2518 (WebDAV)
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Large',
415 => 'Unsupported Media Type',
416 => 'Request Range Not Satisfiable',
417 => 'Expectation Failed',
422 => 'Unprocessable Entity', # RFC 2518 (WebDAV)
423 => 'Locked', # RFC 2518 (WebDAV)
424 => 'Failed Dependency', # RFC 2518 (WebDAV)
425 => 'No code', # WebDAV Advanced Collections
426 => 'Upgrade Required', # RFC 2817
449 => 'Retry with', # unofficial Microsoft
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates', # RFC 2295
507 => 'Insufficient Storage', # RFC 2518 (WebDAV)
509 => 'Bandwidth Limit Exceeded', # unofficial
510 => 'Not Extended', # RFC 2774
);

*STDOUT->autoflush(1);
binmode STDOUT;

# first the status line
my $StatusMessage = $Code2Message{ $Res->[0] } // 'UNKNOWN';
my $Headers = "HTTP/1.1 $Res->[0] $StatusMessage\015\012";

# add the headers
while ( my ( $Key, $Val ) = splice $Res->[1]->@*, 0, 2 ) {
$Headers .= "$Key: $Val\015\012";
}
$Headers .= "\015\012";

print STDOUT $Headers;

for my $Line ( $Res->[2]->@* ) {
utf8::encode($Line);
print STDOUT $Line;
}
2 changes: 1 addition & 1 deletion bin/cgi-bin/public.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#local $ENV{PLACK_URLMAP_DEBUG} = 1; # enable when the URL mapping does not work

# otobo.psgi looks primarily in $ENV{PATH_INFO}
local $ENV{PATH_INFO} = join '/', grep { defined $_ || $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{PATH_INFO} = join '/', grep { defined $_ && $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{SCRIPT_NAME} = '';

my $CgiBinDir = dirname(__FILE__);
Expand Down
2 changes: 1 addition & 1 deletion bin/cgi-bin/rpc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#local $ENV{PLACK_URLMAP_DEBUG} = 1; # enable when the URL mapping does not work

# otobo.psgi looks primarily in $ENV{PATH_INFO}
local $ENV{PATH_INFO} = join '/', grep { defined $_ || $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{PATH_INFO} = join '/', grep { defined $_ && $_ ne '' } @ENV{qw(SCRIPT_NAME PATH_INFO)};
local $ENV{SCRIPT_NAME} = '';

my $CgiBinDir = dirname(__FILE__);
Expand Down
16 changes: 12 additions & 4 deletions bin/psgi-bin/otobo.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,17 @@ my $HelloApp = sub {
my $DumpEnvApp = sub {
my $Env = shift;

# collect some useful info
local $Data::Dumper::Sortkeys = 1;
my $Message = Data::Dumper->Dump(
[ "DumpEnvApp:", scalar localtime, $Env, \%ENV, \@INC, \%INC ],
[qw(Title Time Env ENV INC_array INC_hash)],
[ "DumpEnvApp:", scalar localtime, $Env, \%ENV, \@INC, \%INC, '🦦' ],
[qw(Title Time Env ENV INC_array INC_hash otter)],
);

# add some unicode
$Message .= "unicode: 🦦 ⛄ 🥨\n";

# emit the content as UTF-8
utf8::encode($Message);

return [
Expand Down Expand Up @@ -612,6 +618,8 @@ my $OTOBOApp = builder {
$ResponseObject->Code(200); # TODO: is it always 200 ?
$ResponseObject->Content($Content);

# for debugging: warn Dumper( { Response => $ResponseObject, is_utf8 => utf8::is_utf8( $ResponseObject->{Response}->{body} ) } );

# return the funnny unblessed array reference
return $ResponseObject->Finalize();
}
Expand Down Expand Up @@ -659,7 +667,7 @@ builder {
# Server the static files in var/httpd/httpd.
mount '/otobo-web' => $StaticApp;

# uncomment for trouble shouting
# uncomment for trouble shooting
#mount '/hello' => $HelloApp;
#mount '/dump_env' => $DumpEnvApp;
#mount '/otobo/hello' => $HelloApp;
Expand All @@ -683,5 +691,5 @@ builder {
mount "/index.html" => Plack::App::File->new( file => "$FindBin::Bin/../../var/httpd/htdocs/index.html" )->to_app();
};

# for debugging: dump the PSGI environment for any request
# enable for debugging: dump debugging info, including the PSGI environment, for any request
#$DumpEnvApp;
104 changes: 92 additions & 12 deletions scripts/apache2-httpd-cgi.include.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
# added for OTOBO (http://otobo.de/)
# --

# For running OTOBO as a PSGI app under Apache2 link to this file from
# /etc/apache2/sites-enables/zzz_otobo.conf.
# (cd /etc/apache2/sites-enabled && sudo ln -sf /opt/otobo/scripts/apache2-httpd-psgi.include.conf zzz_otobo.conf)
# This configuration is an example for running OTOBO via scripts in bin/cgi-bin.
# The scripts themselves are using the PSGI app otobo.psgi internally.
# Note that this is not the recommended way of running OTOBO under Apache.
# The recommended way is to use the config provided in scripts/apache2-httpd.include.conf.

# And then restart the webserver.
# sudo systemctl restart apache2.service
ScriptAlias /otobo/ "/opt/otobo/bin/cgi-bin/"
Alias /otobo-web/ "/opt/otobo/var/httpd/htdocs/"

# mod_perl is required
<IfModule mod_perl.c>

# Setup environment and preload modules
# each site should have it's own Perl interpreter
PerlOptions +Parent
Perlrequire /opt/otobo/scripts/apache2-perl-startup.pl

# Reload Perl modules when changed on disk
PerlModule Apache2::Reload
PerlInitHandler Apache2::Reload
# @INC is also set on otobo.psgi, but this has not been reliable
PerlSwitches -I /opt/otobo -I /opt/otobo/Kernel/cpan-lib -I /opt/otobo/Custom

# general mod_perl2 options
<Location /otobo>
#ErrorDocument 403 /otobo/customer.pl
# ErrorDocument 403 /otobo/customer.pl
ErrorDocument 403 /otobo/index.pl
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
Expand All @@ -43,3 +41,85 @@
</Location>

</IfModule>

<Directory "/opt/otobo/bin/cgi-bin/">
AllowOverride None
Options +ExecCGI -Includes

# Require supported starting with Apache 2.4
# No authentication and all requests are allowed.
Require all granted

<IfModule mod_filter.c>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/javascript application/javascript text/css text/xml application/json text/json
</IfModule>
</IfModule>

</Directory>

<Directory "/opt/otobo/var/httpd/htdocs/">
AllowOverride None

# Require supported starting with Apache 2.4
# No authentication and all requests are allowed.
Require all granted

<IfModule mod_filter.c>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/javascript application/javascript text/css text/xml application/json text/json
</IfModule>
</IfModule>

# Make sure CSS and JS files are read as UTF8 by the browsers.
AddCharset UTF-8 .css
AddCharset UTF-8 .js

# Set explicit mime type for woff fonts since it is relatively new and apache may not know about it.
AddType application/font-woff .woff

</Directory>

# Allow access to public interface for unauthenticated requests on systems with set-up authentication.
# Will work only for RegistrationUpdate, since page resources are still not be loaded.
# <Location /otobo/public.pl>
#
# # Require supported starting with Apache 2.4
# # No authentication and all requests are allowed.
# Require all granted
#
# </Location>

<IfModule mod_headers.c>
# Cache css-cache for 30 days
<Directory "/opt/otobo/var/httpd/htdocs/skins/*/*/css-cache">
<FilesMatch "\.(css|CSS)$">
Header set Cache-Control "max-age=2592000 must-revalidate"
</FilesMatch>
</Directory>

# Cache css thirdparty for 4 hours, including icon fonts
<Directory "/opt/otobo/var/httpd/htdocs/skins/*/*/css/thirdparty">
<FilesMatch "\.(css|CSS|woff|svg)$">
Header set Cache-Control "max-age=14400 must-revalidate"
</FilesMatch>
</Directory>

# Cache js-cache for 30 days
<Directory "/opt/otobo/var/httpd/htdocs/js/js-cache">
<FilesMatch "\.(js|JS)$">
Header set Cache-Control "max-age=2592000 must-revalidate"
</FilesMatch>
</Directory>

# Cache js thirdparty for 4 hours
<Directory "/opt/otobo/var/httpd/htdocs/js/thirdparty/">
<FilesMatch "\.(js|JS)$">
Header set Cache-Control "max-age=14400 must-revalidate"
</FilesMatch>
</Directory>
</IfModule>

# Limit the number of requests per child to avoid excessive memory usage.
# 1000 is the same value as the default value used by Gazelle.
MaxRequestsPerChild 1000
Loading