I decided to spend a little time in sprucing this up a small bit, just for fun. I took out the nasty javascript, changed the copyright (not that this snippet is copyrighten or anything), threw in a templating system, and some very simple error checking. Enjoy.
#!c:/perl/bin/perl -w $|++; use strict; use CGI::Simple; use HTML::Template; my $q = CGI::Simple->new; my $t = HTML::Template->new( filehandle => *DATA ); my @ext = qw( pl css htm html shtm shtml ); my $file = $q->param('file'); my $fh; if ( ($file =~ /[^a-zA-Z0-9_\-\.]/) or ($file =~ /\.\./) or ($file eq '.') or !(grep { $file =~ /\.$_\z/i } @ext) !(-e $file) or !(open $fh, '<', $file) or ) { $t->param( title => 'My File Viewer', file => 'Script Error', code => 'An error occured while preparing the file for display.' ); } else { $t->param( title => 'My File Viewer', file => $file, code => do { local $/; <$fh> } ); } print $q->header, $t->output; exit; __DATA__ <html> <head> <title>Pekkhum's Script Veiwer</title> </head> <body> <p style="text-align: center; font-weight: bold"> <!-- TMPL_VAR NAME="title" ESCAPE="HTML" --> </p> <p><hr /></p> <p style="text-decoration: underline; font-weight: bold"> <!-- TMPL_VAR NAME="file" ESCAPE="HTML" --> </p> <form> <textarea name="code" rows="30" cols="90" readonly> <!-- TMPL_VAR NAME="code" ESCAPE="HTML" --> </textarea> </form> <p> <small>© Copyright 2003 Nathan Bessette</small> </p> </body> </html>
If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.
In reply to Re: Not my first program, but the first I'll share...
by Coruscate
in thread Not my first program, but the first I'll share...
by pekkhum
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |