in reply to Not my first program, but the first I'll share...
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Not my first program, but the first I'll share...
by pekkhum (Sexton) on Oct 28, 2003 at 00:23 UTC | |
by bradcathey (Prior) on Oct 28, 2003 at 02:08 UTC | |
by pekkhum (Sexton) on Oct 28, 2003 at 02:48 UTC | |
by Art_XIV (Hermit) on Oct 28, 2003 at 18:11 UTC | |
by Coruscate (Sexton) on Oct 28, 2003 at 23:54 UTC |