2017-02-16 08:37:40 +01:00
|
|
|
# Main auto-protected PSGI adapter for LLNG handler
|
|
|
|
#
|
2019-02-04 20:58:04 +01:00
|
|
|
# See https://lemonldap-ng.org/documentation/latest/handlerarch
|
2017-02-11 08:47:22 +01:00
|
|
|
package Lemonldap::NG::Handler::PSGI::Main;
|
2015-05-14 08:44:38 +02:00
|
|
|
|
2016-01-25 19:03:48 +01:00
|
|
|
use strict;
|
2016-03-17 23:19:44 +01:00
|
|
|
use base 'Lemonldap::NG::Handler::Main';
|
2019-08-16 15:22:06 +02:00
|
|
|
our $VERSION = '2.0.6';
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
# Specific modules and constants for Test or CGI
|
2016-01-28 07:43:46 +01:00
|
|
|
use constant FORBIDDEN => 403;
|
|
|
|
use constant HTTP_UNAUTHORIZED => 401;
|
|
|
|
use constant REDIRECT => 302;
|
|
|
|
use constant OK => 0;
|
|
|
|
use constant DECLINED => 0;
|
|
|
|
use constant DONE => 0;
|
|
|
|
use constant SERVER_ERROR => 500;
|
|
|
|
use constant AUTH_REQUIRED => 401;
|
|
|
|
use constant MAINTENANCE => 503;
|
2017-02-15 07:41:50 +01:00
|
|
|
use constant defaultLogger => 'Lemonldap::NG::Common::Logger::Std';
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
## @method void thread_share(string $variable)
|
|
|
|
# share or not the variable (if authorized by specific module)
|
|
|
|
# @param $variable the name of the variable to share
|
|
|
|
sub thread_share {
|
|
|
|
|
|
|
|
# nothing to do in PSGI
|
|
|
|
}
|
|
|
|
|
2017-03-28 23:07:49 +02:00
|
|
|
## @method void setServerSignature(string sign)
|
|
|
|
# modifies web server signature
|
|
|
|
# @param $sign String to add to server signature
|
|
|
|
sub setServerSignature {
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
## @method void set_user(string user)
|
2016-01-31 23:53:23 +01:00
|
|
|
# sets remote_user in response headers
|
2015-05-14 08:44:38 +02:00
|
|
|
# @param user string username
|
|
|
|
sub set_user {
|
2017-03-28 23:07:49 +02:00
|
|
|
my ( $class, $req, $user ) = @_;
|
|
|
|
push @{ $req->{respHeaders} }, 'Lm-Remote-User' => $user;
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2019-08-16 15:22:06 +02:00
|
|
|
## @method void set_custom(string custom)
|
|
|
|
# sets remote_custom in response headers
|
|
|
|
# @param custom string custom_value
|
|
|
|
sub set_custom {
|
|
|
|
my ( $class, $req, $custom ) = @_;
|
2019-08-21 10:47:53 +02:00
|
|
|
push @{ $req->{respHeaders} }, 'Lm-Remote-Custom' => $custom
|
|
|
|
if defined $custom;
|
2019-08-16 15:22:06 +02:00
|
|
|
}
|
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
## @method void set_header_in(hash headers)
|
|
|
|
# sets or modifies request headers
|
|
|
|
# @param headers hash containing header names => header value
|
|
|
|
sub set_header_in {
|
2017-03-28 23:07:49 +02:00
|
|
|
my ( $class, $req, %headers ) = @_;
|
2015-05-14 08:44:38 +02:00
|
|
|
while ( my ( $h, $v ) = each %headers ) {
|
2019-04-09 21:01:55 +02:00
|
|
|
$req->{env}->{ cgiName($h) } = $v if ( defined $v );
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
## @method void unset_header_in(array headers)
|
|
|
|
# removes request headers
|
|
|
|
# @param headers array with header names to remove
|
|
|
|
sub unset_header_in {
|
2017-03-28 23:07:49 +02:00
|
|
|
my ( $class, $req, @headers ) = @_;
|
2015-05-14 08:44:38 +02:00
|
|
|
foreach my $h (@headers) {
|
2017-03-28 23:07:49 +02:00
|
|
|
delete $req->{env}->{ cgiName($h) };
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
## @method void set_header_out(hash headers)
|
|
|
|
# sets response headers
|
|
|
|
# @param headers hash containing header names => header value
|
|
|
|
sub set_header_out {
|
2017-03-28 23:07:49 +02:00
|
|
|
my ( $class, $req, %headers ) = @_;
|
2015-05-14 08:44:38 +02:00
|
|
|
while ( my ( $h, $v ) = each %headers ) {
|
2017-03-28 23:07:49 +02:00
|
|
|
push @{ $req->{respHeaders} }, $h => $v;
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
## @method boolean is_initial_req
|
|
|
|
# always returns true
|
|
|
|
# @return is_initial_req boolean
|
|
|
|
sub is_initial_req {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
## @method void print(string data)
|
|
|
|
# write data in HTTP response body
|
|
|
|
# @param data Text to add in response body
|
|
|
|
sub print {
|
2017-03-28 23:07:49 +02:00
|
|
|
my ( $class, $req, $data ) = @_;
|
|
|
|
$req->{respBody} .= $data;
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2016-02-27 07:52:05 +01:00
|
|
|
sub addToHtmlHead {
|
|
|
|
my $self = shift;
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error(
|
2018-09-02 17:31:58 +02:00
|
|
|
'Features like form replay or logout_app can only be used with Apache');
|
2016-02-27 07:52:05 +01:00
|
|
|
}
|
|
|
|
|
2017-03-28 23:07:49 +02:00
|
|
|
sub cgiName {
|
|
|
|
my $h = uc(shift);
|
|
|
|
$h =~ s/-/_/g;
|
|
|
|
return "HTTP_$h";
|
|
|
|
}
|
|
|
|
|
2016-02-27 07:52:05 +01:00
|
|
|
*setPostParams = *addToHtmlHead;
|
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
1;
|