Slightly tested. Fun to mess around with anyway. Be *careful* about what you let the user request or this is a major security hole.
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw(:standard);
use Path::Class;
use MIME::Types;
my $unc = param("unc") || "";
if ( $unc and -r $unc and -f _ )
{
# NORMALIZE/SANITIZE/VERIFY SAFETY OF REQUESTED PATH!!!!
my $file = Path::Class::File->new($unc);
my ( $ext ) = $file =~ /\.(\w+)\z/;
my $type = MIME::Types->new->mimeTypeOf( $ext );
print header($type || "text/plain");
my $fh = $file->openr();
print while <$fh>;
close $fh;
}
elsif ( $unc )
{
print
header("text/plain"),
"$unc is unreadable or doesn't exist";
}
else
{
print
header("text/plain"),
"You gots t'aks for da unc files, man...\n",
"Oh, a-right! This is a recent picture o'me.\n",
" ...Well, what'd'ya think? Hot or not?\n\n";
my $self = Path::Class::File->new($0);
my $fh = $self->openr();
print while <$fh>;
close $fh;
}
|