#!/usr/bin/perl -wT
#
# image.pl
#
# Russell Milliner
# February 12, 2000
# Prevents other website from just pointing to images and using
# my bandwidth
#

use CGI qw(:all);
use strict;

if (param('image')) {
    my $path       = "/www/tmdrfan.com/tmdr_images/";
    my $referer    = referer() || die "no referer specified";
    my $image_name = param('image');
    my $image_ext  = (split(/\./,param('image')))[1];

    ($referer =~ /^http:\/\/www.tmdrfan.com\//) || 
    die "invalid referer: $referer";

    ($image_ext eq 'jpg') && (print "Content-Type: image/jpeg\n\n");
    ($image_ext eq 'gif') && (print "Content-Type: image/gif\n\n");

    open (IMAGE,$path.$image_name) || die "Could not open image file";
    print <IMAGE>;
    close IMAGE;
}

exit;
