Here's the full code:
The area that I'm having a problem with is here:
First question, if this is the first time running this script or this script is run from the host directory, then $newDirectory will be null. How do I avoid crashing this script?
Second, if this script is run from a later position, it WILL have a value. Should this run in its current state?
- MT
Code:
#!/usr/bin/perl -wT
print "Content-type: text/html\n\n";
my $newDirectory = substr $ENV{"QUERY_STRING"};
if ($newDirectory) {
opendir (FTPDIR, "$newDirectory") || Error ('open', 'directory');
}
else {
opendir (FTPDIR, "/var/[URL unfurl="true"]www/html/effTeePee")[/URL] || Error ('open', 'directory');
}
my @folderContents = readdir (FTPDIR);
closedir (FTPDIR);
print <<"HTML code";
<html>
<head>
<title>Untitled Document</title>
<link href=../ftpStyle.css rel=stylesheet type=text/css>
<script src=../jsLib.js></script>
</head>
<body>
<table width=80% border=0 align=center cellpadding=0 cellspacing=0>
<tr align=center valign=top>
<td width=19 height=20><img src=../images/box_gray_corner_tl.gif width=19 height=20></td>
<td background=../images/box_gray_side_t.gif><img src=../images/box_gray_side_t.gif width=2 height=20></td>
<td width=19 height=20><img src=../images/box_gray_corner_tr.gif width=19 height=20></td>
</tr>
<tr align=center valign=top>
<td background=../images/box_gray_side_l.gif><img src=../images/box_gray_side_l.gif width=19 height=2></td>
<td bgcolor=#f2f2f2>
<table width=100% border=0 cellspacing=5 cellpadding=0>
<tr valign=top>
<td width=3% align=center> </td>
<td width=80% class=tableHeader>Name</td>
<td width=7% class=tableHeader>Date</td>
<td width=10% class=tableHeader>Size</td>
</tr>
<tr valign=top>
<td align=center><img src=../images/icon_folderOpen.gif width=27 height=22></td>
<td>/ Folder Name </td>
<td> </td>
<td> </td>
</tr>
HTML code
if (@folderContents) {
foreach my $indivFile (@folderContents) {
next if $indivFile=~m/^\.+$/;
my $fullUnit = $indivFile;
# escape the following "."
my ($name, $extension) = split (/\./ , $indivFile);
if ($extension) {
print "<tr valign=top>\n";
print "<td align=center><img src=../images/icon_" . $extension . ".gif width=18 height=22></td>\n";
print "<td><a href=fileDownload.cgi?fileName=" . $fullUnit . ">$fullUnit<a></td>\n";
print "<td>[DATE]</td>\n";
print "<td>[SIZE]</td>\n";
print "</tr>";
}
else {
print "<tr valign=top>\n";
print "<td align=center><img src=../images/icon_.gif width=20 height=22></td>\n";
print "<td><a href=listFiles.cgi?newDirectory=" . $fullUnit . ">$fullUnit<a></td>\n";
print "<td> </td>\n";
print "<td> </td>\n";
print "</tr>";
}
}
}
print <<"HTML code";
</table>
<br>
<br>
</td>
<td background=../images/box_gray_side_r.gif><img src=../images/box_gray_side_r.gif width=19 height=2></td>
</tr>
<tr align=center valign=top>
<td width=19 height=20><img src=../images/box_gray_corner_bl.gif width=19 height=20></td>
<td background=../images/box_gray_side_b.gif><img src=../images/box_gray_side_b.gif width=2 height=20></td>
<td width=19 height=20><img src=../images/box_gray_corner_br.gif width=19 height=20></td>
</tr>
</table>
</body>
</html>
HTML code
The area that I'm having a problem with is here:
Code:
my $newDirectory = substr $ENV{"QUERY_STRING"};
if ($newDirectory) {
opendir (FTPDIR, "$newDirectory") || Error ('open', 'directory');
}
else {
opendir (FTPDIR, "/var/[URL unfurl="true"]www/html/effTeePee")[/URL] || Error ('open', 'directory');
}
First question, if this is the first time running this script or this script is run from the host directory, then $newDirectory will be null. How do I avoid crashing this script?
Second, if this script is run from a later position, it WILL have a value. Should this run in its current state?
- MT