#!/usr/bin/perl -w
# --- Grundinitialisierung / Variablendekleration -----------------
use strict;
#use CGI::Carp qw(fatalsToBrowser);

# --- Variablen deklarieren ---------------------------------------
my $buffer;
my $name;
my $value;
my $pair;
my @pairs;
my %FORM;
my $line;
my $suche;
my $start;
# ----- Einlesen der Übergabeparameter ----------------
# local ($buffer, @pairs, $pair, $name, $value, %FORM);
    # Read in text
    $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
    if ($ENV{'REQUEST_METHOD'} eq "POST")
    {
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    }else {
        $buffer = $ENV{'QUERY_STRING'};
    }

# ---------- Variablen festlegen -----------------------------------------------------
    # Split information into name/value pairs
    $buffer = lc($buffer);
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs)
    {
        ($name, $value) = split(/=/, $pair);
        $value =~ tr/+/ /;
        $value =~ s/%(..)/pack("C", hex($1))/eg;
         for ($value) {
        s/^\s+//;  #f&uuml;hrende Leerzeichen
        s/\s+$//;  #endende Leerzeichen
         }
        $FORM{$name} = $value;

    }

# --- Variablen deklarieren ---------------------------------------

my $ip_string = $ENV{'REMOTE_ADDR'};
my $ipport_string = $ENV{'REMOTE_IDENT'};
my $remote_port = $ENV{'REMOTE_PORT'};
my $host_string = $ENV{'REMOTE_HOST'};
my $user_string = $ENV{'REMOTE_USER'};
my $user_password = $ENV{'PWD'};
my $auth_type = $ENV{'AUTH_TYPE'};
my $browser_string = $ENV{'HTTP_USER_AGENT'};
my $browser_language = $ENV{'HTTP_ACCEPT_LANGUAGE'};
my $time = localtime(time);
# my $limiter = index $browser_language, ",";
# if ($limiter == 0) {$limiter = 3};

my $lang = substr $browser_language, 0, 2;
my $syslang = lc($lang);

if ($FORM{"lang"} ne "") {
$lang = $FORM{"lang"};
}

if ($FORM{"language"} ne "") {
$lang = $FORM{"language"};
}

$lang = lc($lang);

if ($lang eq "de"){
german();
}else{
if ($lang eq "ro"){
roman();
}else{
english();
}}

exit(0);


sub english{
print <<"(END HTML)";
Content-type: text/html

<!DOCTYPE html>

<html lang="en-US">

<head>

  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
  <meta name="keywords" lang="en" content="" />

  <meta name="author" content="Hans-Joachim Schippritt" />
  <meta name="date" content="2018-01-23T15:00:00+02:00" />
  <meta name="robots" content="index,follow" />


  <title>browser info</title>

  <link rel="icon" href="./images/favicon.png" type="image/png" />

</head>
<body style="background-color:transparent; color: #2E3436; font-family:'arial','helvetica','sans serif','utopia'; font-size:12px">
<h3>That's what your browser sends:</h3>
<br style="font-size:4px" />
<ul>
(END HTML)
#
if ($ip_string ne "") {print "<li><b>your ip-address:</b> $ip_string</li>"};
if ($remote_port ne "") {print "<li><b>your source-port:</b> $remote_port</li>"};
if ($user_string ne "") {print "<li><b>your user-name:</b> $user_string</li>"};
if ($user_password ne "") {print "<li><b>your password:</b> $user_password</li>"};
if ($auth_type ne "") {print "<li><b>your password is coded:</b> $auth_type</li>"};
if ($browser_string ne "") {print "<li><b>your browser:</b> $browser_string</li>"};
if ($browser_language ne "") {print "<li><b>your browser-language:</b> $browser_language</li>"};
#
print <<"(END HTML)";
</ul><br style="font-size:4px"></body></html>
(END HTML)
#
}

sub german{
print <<"(END HTML)";
Content-type: text/html

<!DOCTYPE html>

<html lang="de">

<head>

  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
  <meta name="keywords" lang="en" content="" />

  <meta name="author" content="Hans-Joachim Schippritt" />
  <meta name="date" content="2018-01-23T15:00:00+02:00" />
  <meta name="robots" content="index,follow" />


  <title>browser info</title>

  <link rel="icon" href="./images/favicon.png" type="image/png" />

</head>
<body style="background-color:transparent; color: #2E3436; font-family:'arial','helvetica','sans serif','utopia'; font-size:12px">
<h3>Dies &uuml;bertr&auml;gt Ihr Browser:</h3>
<br style="font-size:4px" />
<ul>
(END HTML)
#
if ($ip_string ne "") {print "<li><b>Ihre IP-Adresse:</b> $ip_string</li>"};
if ($remote_port ne "") {print "<li><b>Ihr Sendeport:</b> $remote_port</li>"};
if ($user_string ne "") {print "<li><b>Ihr Benutzername:</b> $user_string</li>"};
if ($user_password ne "") {print "<li><b>Ihr  Passwort:</b> $user_password</li>"};
if ($auth_type ne "") {print "<li><b>Ihre Passwort-Verschl&uuml;sselung:</b> $auth_type</li>"};
if ($browser_string ne "") {print "<li><b>Ihr Browser:</b> $browser_string</li>"};
if ($browser_language ne "") {print "<li><b>Ihre Spracheinstellungen:</b> $browser_language</li>"};
#
print <<"(END HTML)";
</ul><br style="font-size:4px"></body></html>
(END HTML)
#
}

sub roman{
print <<"(END HTML)";
Content-type: text/html

<!DOCTYPE html>

<html lang="ro">

<head>

  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
  <meta name="keywords" lang="en" content="" />

  <meta name="author" content="Hans-Joachim Schippritt" />
  <meta name="date" content="2018-01-23T15:00:00+02:00" />
  <meta name="robots" content="index,follow" />


  <title>browser info</title>

  <link rel="icon" href="./images/favicon.png" type="image/png" />

</head>
<body style="background-color:transparent; color: #2E3436; font-family:'arial','helvetica','sans serif','utopia'; font-size:12px">
<h3>Acestea transfera browser-ul dvs.:</h3>
<br style="font-size:4px" />
<ul>
(END HTML)
#
if ($ip_string ne "") {print "<li><b>adresa dvs. IP:</b> $ip_string</li>"};
if ($remote_port ne "") {print "<li><b>port-ul dvs. transmis:</b> $remote_port</li>"};
if ($user_string ne "") {print "<li><b>Nume de utilizator dvs.:</b> $user_string</li>"};
if ($user_password ne "") {print "<li><b>parol&#259; dvs.:</b> $user_password</li>"};
if ($auth_type ne "") {print "<li><b>metoda de criptare:</b> $auth_type</li>"};
if ($browser_string ne "") {print "<li><b>browser-ul dvs.:</b> $browser_string</li>"};
if ($browser_language ne "") {print "<li><b>configur&#259;rile de limb&#259;:</b> $browser_language</li>"};
#
print <<"(END HTML)";
</ul><br style="font-size:4px"></body></html>
(END HTML)
#
}