#!/usr/bin/perl


#  PROJECT HONEY POT ADDRESS DISTRIBUTION SCRIPT
#  For more information visit: http://www.projecthoneypot.org/
#  Copyright (C) 2004-2010, Unspam Technologies, Inc.
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
#  02111-1307  USA
#  
#  If you choose to modify or redistribute the software, you must
#  completely disconnect it from the Project Honey Pot Service, as
#  specified under the Terms of Service Use. These terms are available
#  here:
#  
#  http://www.projecthoneypot.org/terms_of_service_use.php
#  
#  The required modification to disconnect the software from the
#  Project Honey Pot Service is explained in the comments below. To find the
#  instructions, search for:  *** DISCONNECT INSTRUCTIONS ***
#  
#  Generated On: Thu, 23 Dec 2010 07:33:02 -0800
#  For Domain: www.castlevaniadungeon.net
#  
#  
use strict;
use Digest::MD5 qw(md5_hex);



#  *** DISCONNECT INSTRUCTIONS ***
#  
#  You are free to modify or redistribute this software. However, if
#  you do so you must disconnect it from the Project Honey Pot Service.
#  To do this, you must delete the lines of code below located between the
#  *** START CUT HERE *** and *** FINISH CUT HERE *** comments. Under the
#  Terms of Service Use that you agreed to before downloading this software,
#  you may not recreate the deleted lines or modify this software to access
#  or otherwise connect to any Project Honey Pot server.
#  
#  *** START CUT HERE ***
#  
my $__REQUEST_HOST    = 'hpr3.projecthoneypot.org';
my $__REQUEST_PORT    = '80';
my $__REQUEST_SCRIPT  = '/cgi/serve.php';
#  
#  *** FINISH CUT HERE ***
#  

my $__HPOT_TAG1       = 'e11953f6c42987bed7574f4485c38c68';
my $__HPOT_TAG2       = '5658e835391bb9666f23482ac3f3bc2d';
my $__HPOT_TAG3       = '60eff423c208d7fdab40a0dd2d377e0b';

my $__CLASS_STYLE_1   = 'writrepepr';
my $__CLASS_STYLE_2   = 'docheruce';

my $__DIV1            = 'k994n4z4sp5';

my $__VANITY_L1       = 'MEMBER OF PROJECT HONEY POT';
my $__VANITY_L2       = 'Spam Harvester Protection Network';
my $__VANITY_L3       = 'provided by Unspam';

my $__DOC_TYPE1       = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n';
my $__HEAD1           = '<html>\n<head>\n';
my $__HEAD2           = '<title>barrelchested www.castlevaniadungeon.net mousy heap</title>\n</head>\n';
my $__ROBOT1          = '<meta name="robots" content="noarchive,follow">\n<meta name="robots" content="noindex">\n';
my $__NOCOLLECT1      = '<meta name="no-email-collection" content="/">\n';
my $__TOP1            = '<body>\n<div align="center">\n';
my $__EMAIL1A         = '<a href="mailto:';
my $__EMAIL1B         = '" style="display: none;">';
my $__EMAIL1C         = '</a>';
my $__EMAIL2A         = '<a href="mailto:';
my $__EMAIL2B         = '" style="display:none;">';
my $__EMAIL2C         = '</a>';
my $__EMAIL3A         = '<a style="display: none;" href="mailto:';
my $__EMAIL3B         = '">';
my $__EMAIL3C         = '</a>';
my $__EMAIL4A         = '<a style="display:none;" href="mailto:';
my $__EMAIL4B         = '">';
my $__EMAIL4C         = '</a>';
my $__EMAIL5A         = '<a href="mailto:';
my $__EMAIL5B         = '"></a>';
my $__EMAIL5C         = '..';
my $__EMAIL6A         = '<span style="display: none;"><a href="mailto:';
my $__EMAIL6B         = '">';
my $__EMAIL6C         = '</a></span>';
my $__EMAIL7A         = '<span style="display:none;"><a href="mailto:';
my $__EMAIL7B         = '">';
my $__EMAIL7C         = '</a></span>';
my $__EMAIL8A         = '<!-- <a href="mailto:';
my $__EMAIL8B         = '">';
my $__EMAIL8C         = '</a> -->';
my $__EMAIL9A         = '<div id="'.$__DIV1.'"><a href="mailto:';
my $__EMAIL9B         = '">';
my $__EMAIL9C         = '</a></div><br><script language="JavaScript" type="text/javascript">document.getElementById(\''.$__DIV1.'\').innerHTML=\'\';</script>';
my $__EMAIL10A        = '<a href="mailto:';
my $__EMAIL10B        = '"><!-- ';
my $__EMAIL10C        = ' --></a>';
my $__LEGAL1          = '';
my $__LEGAL2          = '\n';
my $__STYLE1          = '\n<style>a.'.$__CLASS_STYLE_1.'{color:#FFF;font:bold 10px arial,sans-serif;text-decoration:none;}</style>';
my $__VANITY1         = '<table cellspacing="0"cellpadding="0"border="0"style="background:#999;width:230px;"><tr><td valign="top"style="padding: 1px 2px 5px 4px;border-right:solid 1px #CCC;"><span style="font:bold 30px arial,sans-serif;color:#666;top:0px;position:relative;">@</span></td><td valign="top" align="left" style="padding:3px 0 0 4px;"><a href="http://www.projecthoneypot.org/" class="'.$__CLASS_STYLE_1.'">'.$__VANITY_L1.'</a><br><a href="http://www.unspam.com"class="'.$__CLASS_STYLE_1.'">'.$__VANITY_L2.'<br>'.$__VANITY_L3.'</a></td></tr></table>\n';
my $__BOTTOM1         = '</div>\n</body>\n</html>\n';


sub getLegalContent() { return '<table cellspacing="0" border="0" cellpadding="0"><tr>\n<td style="font-family: courier, monospace;">&nbsp;&nbsp; <b><font color=white>d</font></b>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <b><font color=white>d</font></b>&nbsp; &nbsp; &nbsp; <br>&nbsp;<br>Th&#101;<font color=white>i</font>website fro&#109; whi<br>to you subj&#101;ct t&#111; th<br>othe&#114; t&#101;rms governin<br>Web&#115;ite &#121;ou accept t<br>re&#97;&#100; the&#109; c&#97;refully.<br>agen&#116;s of the indivi<br>them. &#84;he access<font color=white>i</font>&#114;ig<br>no&#110;-transfe&#114;ab&#108;e wit<br>Web&#115;ite.<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <b><font color=white>d</font></b>&nbsp; &nbsp; <b><font color=white>g</font>S&#80;ECI</b><br>&nbsp;<br>Specia&#108; r&#101;strictions<br>N&#111;&#110;-Human Visit&#111;rs. <br>spi&#100;ers, bots&#44; &#105;ndex<br>p&#114;ograms &#100;esigned to<br>automat&#105;&#99;&#97;l&#108;y.<br><br>&#69;m&#97;il a&#100;&#100;resses on t<br>It is r&#101;&#99;&#111;g<span style="display: none">phantom itchy</span>niz&#101;d<font color=white>i</font>tha<br>alo&#110;e. &#89;ou acknowled<br>has a valu&#101; not le&#115;s<br>storage,<font color=white>h</font>and/or dis&#116;<br>value &#111;f these add&#114;e<br>stori&#110;g<font color=white>o</font>this Webs<span style="display: none">alternative blossom portrait</span>ite<br>agreeme<span style="display: none">ingrown pretentious</span>nt and &#101;&#120;pres<br><br>&nbsp; &nbsp; &nbsp; <b><font color=white>d</font><font color=white>e</font></b>&nbsp; <b><font color=white>k</font><font color=white>g</font><font color=white>g</font></b>&nbsp; &nbsp; &nbsp; <b><font color=white>c</font></b><br>&nbsp;<br>Each party agrees th<br>agains<span style="display: none">miss</span>t the othe<span style="display: none">outline resolvent live orientation misfit</span>&#114; in<br>&#40;"Judicial A&#99;ti&#111;n") <br>the<font color=white>s</font>registered Ad&#109;in<br>suc&#104; laws are &#97;&#112;plie<br>and<font color=white>h</font>&#112;&#101;rform&#101;d entire<br>o&#102; federal and s&#116;a&#116;&#101;<br>any action<font color=white>k</font>br&#111;ught a<br>&#83;ervice. You consent<br>the<font color=white>a</font>abov&#101; agreement.<br><br>&nbsp;&nbsp; <b><font color=white>g</font></b>&nbsp; &nbsp;&nbsp; <b><font color=white>p</font></b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp;<br>&#89;ou<font color=white>a</font>&#99;onse&#110;t to havi&#110;<br>may a<span style="display: none">hypothetical guy team contradictory</span>p&#112;ear some&#119;here<br>&#97;b&#117;s&#101;. T&#104;e Identifie<br>Visitors agree &#110;ot t<br><br>VISI&#84;O&#82;S<font color=white>f</font>AGREE<font color=white>c</font>THAT <br>P&#65;RTY<font color=white>e</font>O<span style="display: none">border approval testament</span>R<font color=white>k</font>SEN&#68;ING A<span style="display: none">unwilling housebroken successful congruent</span>N&#89;<br>S&#85;BSEQUENT BR&#69;ACH &#79;F<br></td>\n<td style="font-family: courier, monospace;">&nbsp; &nbsp; &nbsp;&nbsp; <b>TER&#77;S</b>&nbsp;<b>A&#78;&#68;</b>&nbsp;<b>C&#79;N</b><br><br>ch<font color=white>c</font>you &#97;&#99;cessed thi&#115;<br>e f&#111;llowi<span style="display: none">organ band</span>ng conditio<br>g access to the W&#101;bs<br>h&#101;se terms an&#100; c&#111;n<span style="display: none">permeable museum</span>&#100;i<br>&nbsp;A<span style="display: none">event reputation abnormal aid calf</span>n<span style="display: none">coherent illness</span>y &#78;on&#45;Hum&#97;n Visit<br>dual(&#115;) &#119;ho co<span style="display: none">geographical sacred portrait decollete bucolic</span>n&#116;&#114;ols<br>hts<font color=white>e</font>gra<span style="display: none">gastropod alcoholic parsimonious</span>nted to you &#117;<br>hou&#116; &#116;he<font color=white>h</font>expres&#115; &#119;ri<br><br><br><b>&#65;L</b>&nbsp;<b>LICENSE</b>&nbsp;<b>RESTRIC&#84;I</b><br><br><font color=white>a</font>on a visito&#114;\'s &#108;ice<br>Non&#45;Human Vi&#115;itors &#105;<br>e&#114;s, &#114;&#111;&#98;ots, crawler<br>&nbsp;access,<font color=white>s</font>rea&#100;, compi<br><br><br>his site are consid&#101;<br>&#116; thes&#101;<font color=white>s</font>email add&#114;&#101;&#115;<br>ge and agr&#101;&#101; th&#97;t ea<br>&nbsp;than US $5&#48;. &#89;ou fu<br>r&#105;but&#105;on of thes&#101; ad<br>sses. Inte&#110;t<span style="display: none">kangaroos charter plain arco stemwinding</span>i&#111;nal co<br>\'s e&#109;ail a&#100;dr<span style="display: none">coffee county naval sanity</span>ess&#101;s i<br>&#115;ly pro&#104;ib&#105;ted.<br><br>&nbsp; &nbsp; <b><font color=white>o</font>A&#80;P&#76;ICABLE</b>&nbsp;<b>LAW</b>&nbsp;<br><br>a<span style="display: none">array</span>t any<font color=white>t</font>sui<span style="display: none">jail comedy breakaway almighty bombing</span>t, action <br>&nbsp;conne&#99;tio&#110; with or<font color=white>t</font><br>shall b<span style="display: none">headline angry ingrown</span>e governed by<br>istrativ&#101; Contact<span style="display: none">centre rare</span>&nbsp;(t<br>d to &#97;g&#114;eement&#115; &#98;e&#116;w<br>ly wit&#104;in th<span style="display: none">champaign childish</span>e Ad&#109;in <br>&nbsp;&#99;ourts within<font color=white>a</font>t&#104;e &#65;<br>gainst him i&#110; conne&#99;<br>&nbsp;&#116;o ele&#99;tr&#111;ni&#99; &#115;&#101;r&#118;&#105;<br><br><br>&nbsp; &nbsp; <b>RECORD<span style="display: none">trucks dance intent cab battle</span>S</b>&nbsp;<b>OF</b>&nbsp;<b>VI&#83;I&#84;</b><br><br>g your Int&#101;rnet<font color=white>f</font>&#80;rot<br>&nbsp;on t<span style="display: none">exclusive nasty result hotheaded</span>his page (the "<br>r is uniquely ma&#116;che<br>o use &#116;his &#97;&#100;dress f<br><br>HARVESTING, GATH&#69;&#82;IN<br>&nbsp;MESSAGE(S)<span style="display: none">hounds</span>&nbsp;TO THE I<br>&nbsp;THESE TERMS OF SERV<br></td>\n<td style="font-family: courier, monospace;"><b>DITIONS</b>&nbsp;<b>OF</b>&nbsp;<b>USE</b>&nbsp;<br><br><font color=white>e</font>agreem<span style="display: none">bonfire xanadu</span>&#101;nt<font color=white>f</font>("the Web<br>&#110;s. The&#115;e terms are <br>ite. By &#118;isiting (in<br>tions (t&#104;e<font color=white>h</font>"Terms &#111;&#102;<br>or&#115; to the Website s<br>, au&#116;hors o&#114; othe&#114;wi<br>nder the T&#101;rms of Se<br>t&#116;en permi&#115;sion o<span style="display: none">shot courtiers</span>f t<br><br><br><b>O&#78;S</b>&nbsp;<b>FOR</b>&nbsp;<b>NO&#78;-HUMAN</b>&nbsp;<b>VI</b><br><br>n&#115;e to access the We<br>nclud&#101;, but<font color=white>e</font>&#97;re not <br>s, h<span style="display: none">duty</span>arve&#115;ters&#44; or an<br>le or &#103;a<span style="display: none">departure apathetic</span>the&#114; content<br><br><br>red proprietary inte<br>ses are &#112;&#114;ov&#105;d&#101;d for<br>c&#104;<font color=white>t</font>email address the<br>rther agree that &#116;he<br>&#100;r&#101;sses subst&#97;ntiall<br>ll&#101;ction, harvesting<br>&#115; &#114;ecognized a<span style="display: none">singular repulsive insect irrational</span>s a &#118;i<br><br><br><b>A&#78;D</b>&nbsp;<b>JURISDICT&#73;ON</b>&nbsp;<br><br>or proceedin&#103; brough<br>a&#114;i&#115;&#105;ng from th&#101; Te&#114;<br>&nbsp;t&#104;&#101; law of t&#104;e st&#97;t<br>&#104;e "Adm&#105;n &#83;&#116;ate") fo<br>een Admi&#110; Stat&#101; resi<br>Stat&#101;. You consent &#116;<br>dmin State. Y&#111;u c&#111;ns<br>tion wit&#104; brea&#99;h<span style="display: none">wakeful progressive husky nouns</span>e&#115; o<br>&#99;e of proces&#115; regard<br><br><br><b>OR</b>&nbsp;<b>US&#69;</b>&nbsp;<b>AND</b>&nbsp;<b>ABUSE</b>&nbsp;<br><br>ocol address recor&#100;e<span style="display: none">diagnostic</span><br>Identifie&#114;"&#41; if we s<br>d &#116;o your Int&#101;rn&#101;t P<br>or any reason.<br><br>G, STORING&#44; TRANSFER<br>&#68;ENTIF&#73;ER CONST&#73;&#84;UTE<br>ICE.<br></td>\n<td style="font-family: courier, monospace;"><br><br>&#115;ite"&#41; is p<span style="display: none">jam encouragement subaltern supervision intensive</span>r&#111;vided<br>&#105;n &#97;ddition to<font color=white>s</font>any<br>&nbsp;any man&#110;er) the<br>&nbsp;Service")&#46; Plea&#115;&#101;<br>hall be c&#111;nsi&#100;ered<br>s<span style="display: none">hysterical harmonious anxious commercial</span>e m&#97;kes us&#101;<font color=white>g</font>of<br>rvi&#99;e a<span style="display: none">abolition forgetful velocity nomadic wellbalanced</span>re<br>he &#111;wne&#114; of the<br><br><br><b>SITORS</b>&nbsp;<br><br>bsite apply &#116;o<br>limited<font color=white>t</font>to, &#119;e&#98;<br>y ot&#104;er comp&#117;t&#101;r<br>&nbsp;f&#114;om the Websi&#116;e<br><br><br>llect&#117;&#97;l pr&#111;perty.<br>&nbsp;&#104;uman vi&#115;i&#116;ors<br>&nbsp;W&#101;bsite contains<br>&nbsp;compilation,<br>y &#100;&#105;mini&#115;he&#115; the<br>&#44; gathering, &#97;nd/or<br>olat&#105;o&#110; of this<br><br><br><br><br>t<font color=white>o</font>by<font color=white>p</font>such<font color=white>i</font>p&#97;rty<br>ms of Service<br>e &#111;f &#114;esidence<font color=white>e</font>&#111;f<br>r &#116;h&#101; W&#101;bsite as<br>de&#110;&#116;s ente&#114;ed into<br>o the<font color=white>d</font>j&#117;r&#105;&#115;dictio&#110;<br>ent<font color=white>i</font>to<font color=white>c</font>the<font color=white>t</font>venue i&#110;<br>f<font color=white>g</font>the&#115;e Terms of<br>&#105;ng actions u&#110;der<br><br><br><br><br>&#100;. An emai&#108; addr&#101;ss<br>us<span style="display: none">emergency worthless cloud relevant animal</span>&#112;e&#99;t &#112;&#111;te&#110;tial<br>rotocol address&#46;<br><br><br>R&#73;NG TO A THIRD<br>S AN A<span style="display: none">worker multistage</span>&#67;CEPTAN&#67;E A&#78;D<br><br></td>\n</tr>\n</table>\n<br>'; }


#!/usr/bin/perl                


sub formatHTML        {
    my $s = $_[0];
    $s =~ s/\\n/\n/g;
    return $s;
}
sub getDocType          { return formatHTML($__DOC_TYPE1); }
sub getHeadHTML         { return formatHTML($__HEAD1); }
sub getRobotHTML        { return formatHTML($__ROBOT1); }
sub getNoCollectHTML    { return formatHTML($__NOCOLLECT1); }
sub getHeadHTML2        { return formatHTML($__HEAD2); }
sub getTopHTML          { return formatHTML($__TOP1); }
sub getEmailHTML        {
    my $method=$_[0];
    my $m=$_[1];
    if ($method eq "0" || !$method) {
        return "";
    } elsif ($method eq "1") {
        return formatHTML($__EMAIL1A.$m.$__EMAIL1B.$m.$__EMAIL1C);
    } elsif ($method eq "2") {
        return formatHTML($__EMAIL2A.$m.$__EMAIL2B.$m.$__EMAIL2C);
    } elsif ($method eq "3") {
        return formatHTML($__EMAIL3A.$m.$__EMAIL3B.$m.$__EMAIL3C);
    } elsif ($method eq "4") {
        return formatHTML($__EMAIL4A.$m.$__EMAIL4B.$m.$__EMAIL4C);
    } elsif ($method eq "5") {
        return formatHTML($__EMAIL5A.$m.$__EMAIL5B);
    } elsif ($method eq "6") {
        return formatHTML($__EMAIL6A.$m.$__EMAIL6B.$m.$__EMAIL6C);
    } elsif ($method eq "7") {
        return formatHTML($__EMAIL7A.$m.$__EMAIL7B.$m.$__EMAIL7C);
    } elsif ($method eq "8") {
        return formatHTML($__EMAIL8A.$m.$__EMAIL8B.$m.$__EMAIL8C);
    } elsif ($method eq "9") {
        return formatHTML($__EMAIL9A.$m.$__EMAIL9B.$m.$__EMAIL9C); 
    }
    return formatHTML($__EMAIL9A.$m.$__EMAIL9B.$m.$__EMAIL9C);
}
sub getLegalHTML    {
    my $legal_text = &getLegalContent;
    return formatHTML($__LEGAL1.($legal_text).$__LEGAL2);
}
sub getStyleHTML    { return formatHTML($__STYLE1); }
sub getVanityHTML    { return formatHTML($__VANITY1); }
sub getBottomHTML    { return formatHTML($__BOTTOM1); }

sub performRequest {
    
    my $request = $_[0];
    my $response = "";
    my $head = "";
    
        $head .= "POST ".$__REQUEST_SCRIPT." HTTP/1.1\r\n";
        $head .= "Host: ".$__REQUEST_HOST."\r\n";
        $head .= "User-Agent: PHPot ".$__HPOT_TAG2."\r\n";
        $head .= "Content-Type: application/x-www-form-urlencoded\r\n";
        $head .= "Content-Length: ".length($request)."\r\n";
        $head .= "Connection: close\r\n\r\n";

    use Socket;

    socket(SH, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die $!;
    my $sin = sockaddr_in($__REQUEST_PORT,inet_aton($__REQUEST_HOST));
    connect(SH,$sin) || die "\n<br>Unable to contact the server...<br>\n";
    syswrite(SH, $head, length($head));    
    syswrite(SH, $request, length($request));    
    my $line;
    while ($line = <SH>) {
        $response .= $line;
    }
    
    close(SH);
    return $response;
}

sub prepareRequest {
    my %postvars        = ();
    my $buffer;
    my @pairs;
    my $pair;
    my $name;
    my $value;

    $postvars{"tag1"}    = $__HPOT_TAG1;
    $postvars{"tag2"}    = $__HPOT_TAG2;
    $postvars{"tag3"}    = $__HPOT_TAG3;
    if ($ENV{"SCRIPT_FILENAME"}) {
        $postvars{"tag4"}  = md5_hex(&file_get_contents(&basename($ENV{"SCRIPT_FILENAME"}))); 
    } elsif($ENV{"PATH_TRANSLATED"}) {
        $postvars{"tag4"}   = md5_hex(&file_get_contents(&basename($ENV{"PATH_TRANSLATED"}))); 
    } else {
        $postvars{"tag4"}   = md5_hex(&file_get_contents(&basename($ENV{"X_TOMCAT_SCRIPT_PATH"}))); 
    }

    $postvars{"ip"}     = $ENV{"REMOTE_ADDR"};

    $postvars{"svrn"}   = $ENV{"SERVER_NAME"};
    
    $postvars{"svp"}    = $ENV{"SERVER_PORT"};

    $postvars{"svip"}   = $ENV{"SERVER_ADDR"};

    $postvars{"rquri"}  = $ENV{"REQUEST_URI"};
    
    $postvars{"sn"}     = $ENV{"SCRIPT_NAME"};
    $postvars{"sn"}     =~ s/ /%20/g;
    
    $postvars{"ref"}    = $ENV{"HTTP_REFERER"};
    
    $postvars{"uagnt"}  = $ENV{"HTTP_USER_AGENT"};

    $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
    if ($ENV{'REQUEST_METHOD'} eq "POST" && $ENV{'CONTENT_LENGTH'} > 0 && defined($ENV{'CONTENT_TYPE'})) {
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
        if ($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=\"?([^\";,]+)\"?/) {
            my $boundary  = "--".$1;
            my @multipart = split(/(${boundary}(--)?[\r\n]+)/,$buffer);
            trim(@multipart);
            foreach my $part (@multipart) {
               if ($part =~ /Content-Disposition: form-data; name="([^"]+)"?\r?\n\r?\n(.+)/s) {
                  $name  = $1;
                  $value = trim($2);
                  $postvars{"post|$name"} = $value;
                  if (defined($postvars{"has_post"})) {
                     $postvars{"has_post"}++;
                  } else {
                     $postvars{"has_post"} = 1;
                  }
               }
            }
        } elsif ($ENV{'CONTENT_TYPE'} =~ /x-www-form-urlencoded/) {
           @pairs = split(/&/, $buffer);
           $postvars{"has_post"} = @pairs;
           foreach $pair (@pairs) {
              ($name, $value) = split(/=/, $pair);
              $value =~ tr/+/ /;
              $value =~ s/%(..)/pack("C", hex($1))/eg;
              $postvars{"post|$name"} = $value;
           }
        }
    }
    
    $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
    if ($ENV{'REQUEST_METHOD'} eq "GET" && $ENV{'QUERY_STRING'}) {
        $buffer = $ENV{'QUERY_STRING'};
        @pairs = split(/&/, $buffer);
        $postvars{"has_get"} = @pairs;
        foreach $pair (@pairs) {
           ($name, $value) = split(/=/, $pair);
           $value =~ tr/+/ /;
           $value =~ s/%(..)/pack("C", hex($1))/eg;
           $postvars{"get|$name"} = $value;
        }
    }

    my $header_count = 0;
    foreach my $key (keys %ENV) {
        if (($key =~ /^HTTP/) && ($key !~ /^HTTP_COOKIE/)) {
            $postvars{"header|$key"} = $ENV{$key};
            $header_count++;
        }
    }
    $postvars{"has_header"} = $header_count;

    return %postvars;
}

sub transcribeResponse {
    my $response    = $_[0];
    my %settings    = ();
    my @directives    = ();
    my @arr            = split("\n",$response);
    my $isParam        = 0;

   
    my $i = 0;
    
    foreach my $v (@arr) {
       if ($v eq "<END>") { $isParam    = 0; }

       if ($isParam) {          
           my @pieces                     = split("=",$v,2);
           $settings{$pieces[0]}        = &urldecode($pieces[1]);
       }
       if ($v eq "<BEGIN>") { $isParam    = 1; }
    }
    

    if ($settings{"directives"}) {
        @directives        = split(",",$settings{"directives"});
    }

    return \(@directives,%settings);
}

print "Content-Type: text/html\n";
print "Cache-Control: no-cache\n\n";

my $response      = "";
my $request        = "";
my %post          = prepareRequest();

foreach my $k (keys %post) {
    $request .= "&$k=".&urlencode(&stripslashes($post{$k}));
}

$request    = substr($request,1);
$response   = performRequest($request);

if ($response == "-1") {
    exit();
}

my ($directives_ref,$settings_ref)   = transcribeResponse($response);

my @directives = @$directives_ref;
my %settings = %$settings_ref;

my $email        = $settings{"email"};
my $emailmethod  = $settings{"emailmethod"};


if ($directives[0] eq "1") { print getDocType(); }
if ($settings{"injDocType"}) { print $settings{"injDocTypeMsg"}; }
if ($directives[1] eq "1") { print getHeadHTML(); }
if ($settings{"injHead1HTML"}) { print $settings{"injHead1HTMLMsg"}; }
if ($directives[8] eq "1") { print getRobotHTML(); }
if ($settings{"injRobotHTML"}) { print $settings{"injRobotHTMLMsg"}; }
if ($directives[9] eq "1") { print getNoCollectHTML(); }
if ($settings{"injNoCollectHTML"}) { print $settings{"injNoCollectHTMLMsg"}; }
if ($directives[1] eq "1") { print $settings{"injHead2HTMLMsg"}; }
if ($settings{"injHead2HTML"}) { print $settings{"injHead2HTMLMsg"}; }
if ($directives[2] eq "1") { print getTopHTML(); }
if ($settings{"injTopHTML"}) { print $settings{"injTopHTMLMsg"}; }
if ($settings{"actMsgOn"}) { print $settings{"actMsg"}; }
if ($settings{"errMsgOn"}) { print $settings{"errMsg"}; }
if ($settings{"customMsgOn"}) { print $settings{"customMsg"}; }
if ($directives[3] eq "1") { print getLegalHTML(); }
if ($settings{"injLegalHTML"}) { print $settings{"injLegalHTMLMsg"}; }
if ($settings{"altLegalOn"}) { print $settings{"altLegalMsg"}; }

if ($directives[4] eq "1") { print getEmailHTML($emailmethod,$email); }
if ($settings{"injEmailHTML"}) { print $settings{"injEmailHTMLMsg"}; }
if ($directives[5] eq "1") { print getStyleHTML(); }
if ($settings{"injStyleHTML"}) { print $settings{"injStyleHTMLMsg"}; }
if ($directives[6] eq "1") { print getVanityHTML(); }
if ($settings{"injVanityHTML"}) { print $settings{"injVanityHTMLMsg"}; }

if ($settings{"altVanityOn"}) { print $settings{"altVanityMsg"}; }

if ($directives[7] eq "1") { print getBottomHTML(); }
if ($settings{"injBottomHTML"}) { print $settings{"injBottomHTMLMsg"}; }


#################### PERL <-> PHP functions ################

sub file_get_contents {
    open(FILE, "< $_[0]") or die "can't open $_[0]: $!";
    undef $/;
    my $whole_file = <FILE>;               # 'slurp' mode
    $whole_file =~ s/^#![a-zA-Z0-9\/\\\:\.\-\_\~ ]*[\n\r;]//;
    close(FILE);
    return $whole_file;
}

sub basename {

    return $_[0];
}

sub urldecode {
    my $theURL = $_[0];
    $theURL =~ tr/+/ /;
    $theURL =~ s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg;
    $theURL =~ s/<!--(.|\n)*-->//g;
    return $theURL;
}

sub urlencode {
    my $theURL = $_[0];
    $theURL =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
    return $theURL;
}

sub stripslashes {
    return $_[0];
}

sub trim {
    my $string = shift;
    for ($string) {
        s/^\s+//;
        s/\s+$//;
    }
    return $string;
}
