#!/usr/bin/perl

# Gregory Fleischer (gfleischer@gmail.com)

use strict;

my $test_cookie = 1;

my $referer = $ENV{'HTTP_REFERER'};
my $cookie = $ENV{'HTTP_COOKIE'};

my $status = "500 Internal Server Error";
my $response = "unknown error";

if ($referer=~m!http://bank.com/.*$!) {
    if (!$test_cookie or (defined($cookie) and $cookie=~/auth=true/)) {
	$status = "200 Okay";
	$response = "secret revealed!";
    } else {
	$status = "402 Payment Required";
	$response = "no cookie for you";
    }
} else {
    $status = "406 Unacceptable";
    $response = "go away cracker...";
}

print "Status: $status\r\n",
    "Content-Type: text/plain\r\n",
    "Max-age: 0\r\n",
    "Cache-control: no-store, no-cache\r\n",
    "\r\n",
    $response;

# eof
