Voici les sources des scripts utilisés plus haut :

text.bat

@echo off
echo Content-type: text/plain
type blank-line.txt
perl.exe text.pl

text.pl

parse_form_data (\%simple_form);

print "Votre nom est ", $simple_form{'nom1'}, ".", "\n";
print "Votre prénom est ", $simple_form{'nom2'}, ".", "\n";
print "Vos couleurs préférées sont ", $simple_form{'nom3'};

exit(0);

sub parse_form_data {
              local ($FORM_DATA) = @_;
              local( $request_method, $query_string, $key_value_pairs, $key_value, $key, $value);
              $request_method = $ENV{'REQUEST_METHOD'};

              if ($request_method eq "GET") {
                              $query_string = $ENV{'QUERY_STRING'};
              }elsif ($request_method eq "POST"){
                              read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
             }
            @key_value_pairs = split (/&/, $query_string);

           foreach $key_value (@key_value_pairs) {
                             ($key, $value) = split (/=/, $key_value);
                             $value =~ tr/+/ /;
                             $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
                             if (defined(%{$FORM_DATA}->{$key})) {
                                             %{$FORM_DATA}->{$key} = join ("\0", %{$FORM_DATA}->{$key}, $value);
                             }else{ %{$FORM_DATA}->{$key} = $value; }
            }
}

pass.bat

@echo off
echo Content-type: text/plain
type blank-line.txt
perl.exe pass.pl

pass.pl

parse_form_data (\%simple_form);
$pass=$simple_form{'pass'};

if ($pass eq "blabla"){
                  print "Le mot de passe est bien ", $pass, ".", "\n";
}else{
                  print "Pas de chance vous avez fait une faute de frappe. \n";
}

exit(0);

sub parse_form_data {
              local ($FORM_DATA) = @_;
              local( $request_method, $query_string, $key_value_pairs, $key_value, $key, $value);
              $request_method = $ENV{'REQUEST_METHOD'};

              if ($request_method eq "GET") {
                              $query_string = $ENV{'QUERY_STRING'};
              }elsif ($request_method eq "POST"){
                              read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
             }
            @key_value_pairs = split (/&/, $query_string);

           foreach $key_value (@key_value_pairs) {
                             ($key, $value) = split (/=/, $key_value);
                             $value =~ tr/+/ /;
                             $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
                             if (defined(%{$FORM_DATA}->{$key})) {
                                             %{$FORM_DATA}->{$key} = join ("\0", %{$FORM_DATA}->{$key}, $value);
                             }else{ %{$FORM_DATA}->{$key} = $value; }
            }
}

couleur.bat

@echo off
echo Content-type: text/html
type blank-line.txt
perl.exe couleur.pl

couleur.pl

&parse_form_data (\%simple_form);
$coul=$simple_form{'couleur'};
print "<html>";
print "<head>";
print "<title> Un exemple simple de script cgi en action </title>";
print "</head>";

if ($coul eq "ROUGE"){
                   print "<body bgcolor=#FF0000>";
}

if ($coul eq "VERT"){
                   print "<body bgcolor=#00FF00>";
}

if ($coul eq "BLEU"){
                   print "<body bgcolor=#0000FF>";
}

print "<font color=#FFFFFF> Salut les schtoumpf ! </font>";

print "</body>";
print "</html>";

exit(0);

sub parse_form_data {
              local ($FORM_DATA) = @_;
              local( $request_method, $query_string, $key_value_pairs, $key_value, $key, $value);
              $request_method = $ENV{'REQUEST_METHOD'};

              if ($request_method eq "GET") {
                              $query_string = $ENV{'QUERY_STRING'};
              }elsif ($request_method eq "POST"){
                              read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
             }
            @key_value_pairs = split (/&/, $query_string);

           foreach $key_value (@key_value_pairs) {
                             ($key, $value) = split (/=/, $key_value);
                             $value =~ tr/+/ /;
                             $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
                             if (defined(%{$FORM_DATA}->{$key})) {
                                             %{$FORM_DATA}->{$key} = join ("\0",%{$FORM_DATA}->{$key}, $value);
                             }else{ %{$FORM_DATA}->{$key} = $value; }
            }
}

box.bat

@echo off
echo Content-type: text/html
type blank-line.txt
perl.exe box.pl

box.pl

$request_method = $ENV{'REQUEST_METHOD'};

if ($request_method eq "GET") {
                          $query_string = $ENV{'QUERY_STRING'};
}elsif ($request_method eq "POST"){
                          read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
}

@couleur = (0..2);

if ($query_string =~ /couleur1/){
                 $couleur[0]="ff";
}else{
                 $couleur[0]="00";
}

if ( $query_string =~ /couleur2/){
                  $couleur[1]="ff";
}else{
                 $couleur[1]="00";
}

if ($query_string =~ /couleur3/){
                 $couleur[2]="ff";
}else{
                 $couleur[2]="00";
}

print "<html>\n";
print "<head>\n";
print "<title> Un exemple ultra simple de CGI </title> \n";
print "</head>\n";
print "<body bgcolor=\#$couleur[0]$couleur[1]$couleur[2]>\n";
print "<b> <font color = #ff9999> UN EXEMPLE PARMI D\'AUTRES </font> </b>\n";
print "</body>\n";
print "</html>\n";

exit(0);

area.bat

@echo off echo
Content-type: text/html
type blank-line.txt
perl.exe area.pl

area.pl

parse_form_data (\%simple_form);

$TEXTE=$simple_form{'TEXTE'};

$fichier = 'c:\WWWSRV\NS-HOME\DOCS\NewBrunette\files\cgi\filetest.html';

print "<html>\n";
print "<head>\n";
print "<title> L'op&eacute;ration a bien &eacute;t&eacute;e effectu&eacute;e. </title>\n";
print "</head>\n";
print "<body>\n";

if (open(IDENTFICH, ">>$fichier"))
{
            $taille = -s IDENTFICH;
            if ( $taille < 5000 ){
                  print "Le texte entr&eacute : $TEXTE . <p> Taille de fileTest : $taille <p>";
                  print IDENTFICH ($TEXTE);
            }else{
               print "Le fichier est fileTest.html est plein. Veuillez me contacter :
               <a href = \"mailto:bras\@helios.iihe.ac.be\"> bras\@helios.iihe.ac.be<\\a>.";
            }

            close(IDENTFICH);
            print "Ok !
            <a href = http://www.brunette.brucity.be/NewBrunette/files/cgi/cgi4.html>
            Retournons au point de d&eacute;part...</a>\n";
}else{
            print "L'op&eacute;ration ne c\'est pas bien effectu&eacute;e. Veuillez me contacter
            : <a href = \"mailto:bras\@helios.iihe.ac.be\"> bras\@helios.iihe.ac.be<\\a>.";
}
print "</body>\n";
print "</html>\n";
exit(0);

sub parse_form_data
{
        local ($FORM_DATA) = @_;
        local( $request_method, $query_string, $key_value_pairs, $key_value, $key, $value);
        $request_method = $ENV{'REQUEST_METHOD'};

        if ($request_method eq "GET")
       {
                  $query_string = $ENV{'QUERY_STRING'};
        }elsif ($request_method eq "POST"){
                  read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
       }

       @key_value_pairs = split (/&/, $query_string);

       foreach $key_value (@key_value_pairs) {
            ($key, $value) = split (/=/, $key_value);
            $value =~ tr/+/ /;
            $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
            if (defined(%{$FORM_DATA}->{$key})) {
                     %{$FORM_DATA}->{$key} = join ("\0", %{$FORM_DATA}->{$key}, $value);
            }else{
                    %{$FORM_DATA}->{$key} = $value;
            }
       }
}


suite-index