#!/usr/bin/perl # RedFox! Productions: DirList # All coding done by one Ranna Fox use rfp; use strict; my $r = new rfp; my $file = $ENV{'QUERY_STRING'} || "prefix/"; $r->print_start("RF!P::DL->($file);"); if ($file =~ /^\//) { print "Ahem...you may not list files with absolute paths. Especially not that absolute path\n"; $r->print_end; exit; } elsif ($file =~ /\.\./) { print "'Scuse me, I won't list directories with .. in their path. Better fix that.\n"; $r->print_end; exit; } elsif (not $file =~ /^prefix\//) { print "See, the way things work is that if you're gonna list a directory, you gotta put a 'prefix/' before it, which means it has to be in my directory.\n"; $r->print_end; exit; } my $filen; ($filen = $file) =~ s{^prefix/}{/home/admin/ranna/public_html/}; if (not -d $filen) { print "That...uh...doesn't appear to exist... o.O\n"; $r->print_end; exit; } &parse_dir($filen, $file); sub parse_dir { my $dir = $_[0]; my $req = $_[1]; opendir(PARSEDIR, "$dir") || die "Couldn't open directory $dir: $!\n"; my $currdir; ($currdir = $dir) =~ s{.*/([^/]*)$}{$1}; print "
  • $currdir/\n"; while (defined($file = readdir(PARSEDIR))) { next if $file == "." || ".." || ! -r $dir; if (-d $file) { my $to_read = $dir . "/" . $file; $req = $req . "/" . $file; &parse_dir($to_read, $req); } else { my @fparts = split (/./, $file); my $fext = $fparts[$#fparts]; (my($dirn) = $dir) =~ s{/home/admin/ranna/public_html}{}; print "
  • [Bare link]"; if (-T $file) { if ($fext =~ /php/i) { print "[Online]"; } elsif ($fext =~ /pl/i || /cgi/i || /pm/i || /conf/i) { print "[Online]"; } else { print "[Online]"; } } else { print "[Download]"; } print " - $file
  • \n"; } } closedir(PARSEDIR); } $r->print_end;