head	1.1;
access;
symbols;
locks; strict;
comment	@# @;


1.1
date	2003.09.16.10.24.11;	author rse;	state Exp;
branches;
next	;


desc
@@


1.1
log
@flush pending First April Fool stuff
@
text
@#!/e/openpkg/sw/bin/perl

use IO;
use CGI;

#   switch to unbuffered I/O
$|++;

#  read HTML page
my $io = new IO::File "<buy.html" || die;
my $html; { local $/ = undef; $html = <$io>; }
$io->close;

my $cgi = new CGI;

my $url = $cgi->param("url") || "/";
$url = "/" if ($url !~ m|^/.*|);

sub escape {
    my ($v) = @@_;
    $v =~ s|&|&amp;|sg;
    $v =~ s|<|&lt;|sg;
    $v =~ s|>|&gt;|sg;
    $v =~ s|[\t\n]| |sg;
    return $v;
}

my $count = ($cgi->cookie('com') || 0) + 1;

my $log = '';
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
my $date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
my $addr = $ENV{REMOTE_ADDR} || "NN";
$log .= "<log date=\"$date\" addr=\"$addr\" count=\"$count\">";
$log .= "<url>".&escape($url)."</url>";
foreach my $p ($cgi->param) {
    next if ($p eq 'url');
    $log .= "<$p>".&escape($cgi->param($p))."</$p>";
}
$log .= "</log>\n";

$io = new IO::File ">>buy.log";
$io->print($log);
$io->close;

my %texts = (
    'Order' => q{
        <h2>Thank you for ordering OpenPKG!</h2>
        <p>
        Fortunately, OpenPKG is available completely free of charge.
        We were just kidding with the commercial order form you filled out.
        Your credit card will not be charged, of course.
        Additionally, please remember that entering your credit card
        information into an order form over plain HTTP is a big security
        problem. Next time make sure your working over secure HTTPS.
        <p>
        Now feel free to proceed on <b>openpkg.ORG</b>...
    },
    'Order!' => q{
        <h2>Thank you for having humor!</h2>
        <p>
        Obviously, OpenPKG is available completely free of charge.
        We were just kidding with the commercial order form you were presented.
        <p>
        Now feel free to proceed on <b>openpkg.ORG</b>...
    },
    'Complain?' => q{
        <h2>Thank you for complaining!</h2>
        <p>
        Clever as you are, you have recognized that a commercial
        OpenPKG offering can be just a fake.
        Obviously, OpenPKG is available completely free of charge.
        We were just kidding with the commercial order form you were presented.
        <p>
        Now feel free to proceed on <b>openpkg.ORG</b>...
    },
    'Complain' => q{
        <h2>Thank you for complaining!</h2>
        <p>
        Clever as you are, you have recognized that a commercial OpenPKG
        offering can be just a fake. Your feedback comment is much
        appreciated and has been filed. Obviously, OpenPKG is available
        completely free of charge. We were just kidding with the
        commercial order form you were presented.
        <p>
        Now feel free to proceed on <b>openpkg.ORG</b>...
    },
);
my $submit = $cgi->param('submit') || "Complain?";
if (    $submit eq 'Order!' 
    and $cgi->param('cn1') ne ''
    and $cgi->param('cn2') ne ''
    and $cgi->param('cn3') ne ''
    and $cgi->param('cn4') ne ''
    and $cgi->param('cin') ne '') {
    $submit = "Order";
}
if (    $submit eq 'Complain?' 
    and $cgi->param('oc') ne '') {
    $submit = "Complain";
}
my $text = $texts{$submit} || "Complain?";

if ((($mon+1) == 3 and ($mday == 31)) or
    (($mon+1) == 4 and ($mday == 1)) or
    (($mon+1) == 4 and ($mday == 2))) {
    $text = "<font color=\"#cc3333\" size=+2><b>You were caught by the OpenPKG 1st April Fool website!</b></font>" . $text;
}

$html =~ s|%URL%|$url|sg;
$html =~ s|%TEXT%|$text|sg;

my $cookies = [];
push(@@{$cookies}, $cgi->cookie(
    -name => "com",
    -value => $count,
    -expires => '+30d',
    -domain => ".openpkg.com",
    -secure => 0
));

print STDOUT $cgi->header(-cookie => $cookies) . $html;

exit(0);

@
