package ShlomifServe; use strict; use warnings; use CGI; use IO::All; use MIME::Types; sub serve { my (%args) = (@_); my $dir_to_serve = $args{'dir_to_serve'}; my $cgi = CGI->new(); my $mimetypes = MIME::Types->new(); my $path = $cgi->path_info(); if (grep { ($_ eq ".") || ($_ eq "..") } (split /\//, $path)) { print $cgi->header(); print "
You suck! Don't use .. or . as path components"; exit(0); } if ($path =~ m{/$}) { if (-f $dir_to_serve.$path."index.html") { $path .= "index.html"; } else { opendir D, $dir_to_serve.$path; my @files = (grep { $_ ne "." } readdir(D)); closedir(D); print $cgi->header(); my $title = "Listing for " . CGI::escapeHTML($path); my $files_string = join("", map { my $fn = CGI::escapeHTML($_) . ((-d $dir_to_serve.$path."/".$_)?"/":""); qq{