Okay, here is my first program to post. I need help making it more efficient and such. Please ignore my not using CGI.PMs HTML shortcuts, I'm still reading up on those.
Anyway, this script uses the query string to select a file and then displays it's contents on a webpage. Only files in the same directory and with certain allowed extensions can be viewed.
#!perl -w
use strict;
print "Content-type: text/html\n\n";
#Extensions that can be viewed. (Seperated with vertical lines.)
my $ext='pl|css|html|htm|shtm|shtml';
my $request=$ENV{'QUERY_STRING'};
$request=~/([-\w_]+\.($ext))/g;
my $file=$1;
open(SCRIPT,"<$file");
flock(SCRIPT,1);
my @code=<SCRIPT>;
close(SCRIPT);
foreach(@code){
$_=~s/</</g;
$_=~s/>/>/g;
}
print<<FIRSTPART;
<HTML>
<LINK REL=stylesheet TYPE="text/css" HREF="style.css">
<HEAD>
<TITLE>Pekkhum's Script Veiwer</TITLE>
<meta name="robots" content="index,follow">
</HEAD>
<BODY ONMOUSEOVER="window.status='Pekkhum's Script Veiwer'; return tru
+e">
<CENTER>
<H1>Pekkhum's Script Veiwer</H3>
<HR><BR><BR><BR>
<H3><U>$file</U></H3><BR>
<TEXTAREA NAME="code" ROWS=30 COLS=90 READONLY>
FIRSTPART
foreach(@code){
print $_;
}
print<<LASTPART;
</TEXTAREA>
<BR><BR>
<SMALL>©\;Copyright 2003 David Cheatham</SMALL>
</CENTER></BODY></HTML>
LASTPART
P.S. - This program was made just to help me practice Perl scripting.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.