in reply to File Included
Here is an example that prints the contents of the current directory and generates links to each of the files. It only scans one level deep, for more check out File::Find. Each link displays the contents of that file as text - care is taken to make sure that the user cannot view files outside of the directory. Be careful with this - it is a loaded gun! And always, always, use the -T (taint option) on CGI scripts. Also, mod_proxy might just be a better solution (thanks for the link grinder).
#!/usr/bin/perl -Tw use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); my $file; if ($file = param('file')) { # only allow files in this dir if ($file =~ /[\/~]/ or $file =~ /^\./) { print header; die "access to $file not allowed" } unless (open(FH,$file)) { print header; die "$file does not exist"; } print header(-type=>'text/plain'); print while <FH>; } else { print header,start_html('Contents of current dir'); print ul(li([ map { a({-href=>qq|@{[script_name]}?file=$_|},$_) } <*> ])); }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|