2008-12-22 18:49:36 +01:00
#!/usr/bin/perl
#================================================
# LemonLDAP::NG default test page
# Display headers and environment
#================================================
# Init CGI
use CGI ;
my $ cgi = CGI - > new ;
# GET parameters
my $ name = $ cgi - > param ( "name" ) || "LemonLDAP::NG sample protected application" ;
my $ color = $ cgi - > param ( "color" ) || "#ddd" ;
# Local parameters
2018-05-04 16:27:41 +02:00
my $ host = $ ENV { HTTP_HOST } ;
2018-05-10 13:10:46 +02:00
my ( $ domain , $ port ) = ( $ host =~ /\w+\.([^:]+)(:\d+)?/ ) ;
2018-05-07 22:16:35 +02:00
my $ protocol = ( $ ENV { HTTPS } =~ /^on$/i ) ? "https" : "http" ;
2018-05-09 21:24:11 +02:00
my $ portal_url = "$protocol://auth.$domain$port" ;
my $ manager_url = "$protocol://manager.$domain$port" ;
2008-12-22 18:49:36 +01:00
# CSS
my $ css = << EOT ;
2014-12-04 17:08:38 +01:00
html , body {
height:100 % ;
background: $ color ;
2008-12-22 18:49:36 +01:00
}
#content{
2014-12-04 17:08:38 +01:00
padding:20px ;
2010-03-11 16:42:16 +01:00
}
2008-12-22 18:49:36 +01:00
EOT
# Read headers
my % headers ;
2014-12-04 17:08:38 +01:00
foreach ( sort keys % ENV ) {
if ( $ _ =~ /^HTTP_/ ) {
( $ a = $ _ ) =~ s/^HTTP_//i ;
$ a = join '-' , map { ucfirst ( lc ) } split '_' , $ a ;
2008-12-22 18:49:36 +01:00
$ headers - > { $ a } = $ _ ;
}
}
# Display page
2014-12-04 17:08:38 +01:00
print $ cgi - > header ( - charset = > 'utf-8' ) ;
2008-12-22 18:49:36 +01:00
2014-12-04 17:08:38 +01:00
print "<!DOCTYPE html>\n" ;
2016-02-19 10:41:12 +01:00
print qq{ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> \ n } ;
2014-12-04 17:08:38 +01:00
print "<head>\n" ;
2016-02-19 10:41:12 +01:00
print qq{ <meta charset="utf-8"> \ n } ;
2014-12-04 17:08:38 +01:00
print "<title>$name</title>\n" ;
print
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" ;
print
"<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\" />\n" ;
print "<meta http-equiv=\"cache-control\" content=\"no-cache\" />\n" ;
print
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" ;
print
2017-07-17 19:40:46 +02:00
"<link href=\"$portal_url/static/bwr/bootstrap/dist/css/bootstrap.css\" rel=\"stylesheet\">\n" ;
2014-12-04 17:08:38 +01:00
print
2017-07-17 19:46:10 +02:00
"<link href=\"$portal_url/static/bwr/bootstrap/dist/css/bootstrap-theme.css\" rel=\"stylesheet\">\n" ;
2014-12-04 17:08:38 +01:00
print "<style>\n" ;
print "$css\n" ;
print "</style>\n" ;
print
2017-07-17 19:40:46 +02:00
"<script type=\"text/javascript\" src=\"$portal_url/static/bwr/jquery/dist/jquery.js\"></script>\n" ;
2014-12-04 17:08:38 +01:00
print
2017-07-17 19:40:46 +02:00
"<script type=\"text/javascript\" src=\"$portal_url/static/bwr/jquery-ui/jquery-ui.js\"></script>\n" ;
2018-05-07 22:16:35 +02:00
print
"<script src=\"$portal_url/static/bwr/bootstrap/dist/js/bootstrap.js\"></script>\n" ;
2014-12-04 17:08:38 +01:00
print "</head>\n" ;
print "<body>\n" ;
2008-12-22 18:49:36 +01:00
2014-12-04 17:08:38 +01:00
print "<div id=\"content\" class=\"container\">\n" ;
print "<div class=\"panel panel-info panel-body\">\n" ;
print "<div class=\"page-header\">\n" ;
print "<h1 class=\"text-center\">$name</h1>\n" ;
print "</div>\n" ;
2008-12-22 18:49:36 +01:00
2014-12-04 17:08:38 +01:00
print "<div class=\"panel panel-info\">\n" ;
print "<div class=\"panel-heading\">\n" ;
2016-12-19 21:47:44 +01:00
print "<h2 class=\"panel-title text-center\">Main information</h2>\n" ;
2014-12-04 17:08:38 +01:00
print "</div>\n" ;
print "<div class=\"panel-body\">\n" ;
print "<ul class=\"list-unstyled\">\n" ;
print
"<li><strong>Authentication status:</strong> <span class=\"label label-success\">Success</span></li>\n" ;
2008-12-22 18:49:36 +01:00
print "<li>Connected user: <ul>\n" ;
print "<li><tt>\$ENV{HTTP_AUTH_USER}</tt>: $ENV{HTTP_AUTH_USER}</li>\n" ;
print "<li><tt>\$ENV{REMOTE_USER}</tt>: $ENV{REMOTE_USER}</li>\n" ;
print "</ul></li>\n" ;
print "</ul>\n" ;
2014-12-04 17:08:38 +01:00
print
2016-02-11 11:58:56 +01:00
"<div class=\"alert alert-warning\">Be carefull, the <tt>\$ENV{REMOTE_USER}</tt> is set only if your script is in the same server than LemonLDAP::NG Handler (<tt>\$whatToTrace</tt> parameter). If you use it behind a reverse-proxy or in another server than Apache, <tt>REMOTE_USER</tt> is not set. See <a href=\"$manager_url/doc/pages/documentation/current/header_remote_user_conversion.html\">this documentation page</a> to know how to convert an HTTP header into an environment variable.</div>\n" ;
2014-12-04 17:08:38 +01:00
print "</div>\n" ;
print "</div>\n" ;
print "<div class=\"panel panel-info\">\n" ;
print "<div class=\"panel-heading\">\n" ;
print "<h2 class=\"panel-title text-center\">HTTP headers</h2>\n" ;
print "</div>\n" ;
print "<div class=\"panel-body\">\n" ;
print
"<p>To know who is connected in your applications, you can read HTTP headers:</p>\n" ;
print "<div class=\"table-responsive\">\n" ;
print "<table class=\"table table-striped table-hover\">\n" ;
print
2016-02-11 11:58:56 +01:00
"<thead><tr><th>Header</th><th>CGI environment variable</th><th>PHP script</th><th>Value</th></tr></thead><tbody>\n" ;
2014-12-04 17:08:38 +01:00
foreach ( sort keys %$ headers ) {
2010-03-11 11:44:48 +01:00
next if $ _ =~ /(Accept|Cache|User-Agent|Connection|Keep-Alive)/i ;
2016-02-03 07:43:11 +01:00
print qq{ <tr>
< td id = "h-$_" > $ _ </td>
2016-02-11 11:58:56 +01:00
<td> <tt> $ headers - > { $ _ } </tt> </td>
2014-12-04 17:08:38 +01:00
<td> <tt> \ $ _SERVER { $ headers - > { $ _ } } </tt> </td>
2016-02-03 07:43:11 +01:00
< td id = "v-$_" > } ;
2017-04-11 18:24:02 +02:00
print $ ENV { $ headers - > { $ _ } } // "☒" , ;
2016-02-03 07:43:11 +01:00
print "</td></tr>\n" ;
2008-12-22 18:49:36 +01:00
}
2014-12-04 17:08:38 +01:00
print "</tbody></table>\n" ;
2016-02-11 11:58:56 +01:00
print "</div><p></p>\n" ;
2014-12-04 17:08:38 +01:00
print
"<div class=\"alert alert-warning\">Note that LemonLDAP::NG cookie is hidden. So that application developpers can not spoof sessions.</div>\n" ;
print
"<div class=\"alert alert-info\">You can access to any information (IP address or LDAP attribute) by customizing exported headers with the <a href=\"$manager_url\">LemonLDAP::NG Management interface</a>.</div>\n" ;
print "</div>\n" ;
print "</div>\n" ;
2010-07-26 16:28:02 +02:00
2014-12-04 17:08:38 +01:00
print "<div class=\"panel panel-info\">\n" ;
print "<div class=\"panel-heading\">\n" ;
print "<h2 class=\"panel-title text-center\">Scripts parameters</h2>\n" ;
print "</div>\n" ;
print "<div class=\"panel-body\">\n" ;
2010-07-26 16:28:02 +02:00
print "<p>Find here all GET or POST parameters sent to this page:</p>\n" ;
2014-12-04 17:08:38 +01:00
print "<div class=\"table-responsive\">\n" ;
print "<table class=\"table table-striped table-hover\">\n" ;
print "<thead><tr><th>Parameter</th><th>Value</th></tr></thead><tbody>\n" ;
foreach ( sort $ cgi - > param ( ) ) {
2010-07-26 16:28:02 +02:00
my $ tmp = $ cgi - > param ( $ _ ) ;
2016-02-19 10:41:12 +01:00
print
qq{ <tr><td>$_</td><td><big>☞</big> <span id="field_$_">$tmp</span></td></tr> \ n } ;
2010-07-26 16:28:02 +02:00
}
2014-12-04 17:08:38 +01:00
print "</tbody></table>\n" ;
print "</div>\n" ;
print
2015-06-10 17:50:52 +02:00
"<div class=\"alert alert-info\">POST parameters can be forged by LemonLDAP::NG to <a href=\"$manager_url/doc/pages/documentation/current/formreplay.html\">autosubmit forms</a>.</div>\n" ;
2014-12-04 17:08:38 +01:00
print "</div>\n" ;
print "</div>\n" ;
print "<div class=\"panel panel-info\">\n" ;
print "<div class=\"panel-heading\">\n" ;
print "<h2 class=\"panel-title text-center\">Environment for Perl CGI</h2>\n" ;
print "</div>\n" ;
print "<div class=\"panel-body\">\n" ;
print "<div class=\"table-responsive\">\n" ;
print "<table class=\"table table-striped table-hover\">\n" ;
print
"<thead><tr><th>Environment variable</th><th>Value</th></tr></thead><tbody>\n" ;
2008-12-22 18:49:36 +01:00
2014-12-04 17:08:38 +01:00
foreach ( sort keys % ENV ) {
2008-12-22 18:49:36 +01:00
my $ tmp = $ ENV { $ _ } ;
$ tmp =~ s/&/&/g ;
$ tmp =~ s/>/>/g ;
$ tmp =~ s/</</g ;
2010-03-11 16:42:16 +01:00
print "<tr><td>$_</td><td><big>☞</big> $tmp</td></tr>\n" ;
2008-12-22 18:49:36 +01:00
}
2014-12-04 17:08:38 +01:00
print "</tbody></table>\n" ;
print "</div>\n" ;
print "</div>\n" ;
2008-12-22 18:49:36 +01:00
print "</div>\n" ;
2014-12-04 17:08:38 +01:00
print "</div>\n" ;
print "</div>\n" ;
2008-12-22 18:49:36 +01:00
print $ cgi - > end_html ;