#!/usr/local/bin/perl

##############################################################################
# Bennie Webdesign File Browser v1.03                                        #
# Copyright 2000 Bennie Webdesign    webmaster@bennie-webdesign.com          #
# Scripts Archive at:                http://bennie-webdesign.com             #
##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright 2000 Bennie Webdesign            All Rights Reserved.            #
#                                                                            #
# The script may be used and modified free of charge by anyone for           #
# non-commercial use, so long as  this copyright notice and the comments     #
# above remain intact.  By using this code you agree to indemnify            #
# Bennie Webdesign from any liability that                                   #  
# might arise from it's use.                                                 #  
#                                                                            #
# You can register your copy for US$5 and get updates automaticaly in your   #  
# e-mail. This is required for commercial use of this script. Go to this     #
# link to register:                                                          #
# http://bennie-webdesign.com/cgi/buy/order.cgi?bwdfbv103                    #
#                                                                            #
# Selling the code for this program without prior written consent is         #
# expressly forbidden.                                                       #
#                                                                            #
# Obtain permission before redistributing this software over the Internet or #
# in any other medium.	In all cases copyright and header must remain intact.#
##############################################################################

$scriptname = (split(/\//,$0))[-1];

$query = $ENV{QUERY_STRING};
(@re) = split(/\//, $query);
(@er) = split (/\//, $ENV{DOCUMENT_ROOT});
$nmre = @re;
$nmer = @er;
(@sec) = split(/\/\.\./, $query);
$query = "$sec[0]";
$query = "$ENV{DOCUMENT_ROOT}" if ($nmre < $nmer);

&prstart;
&prdir;
&prend; 
exit;

###########
sub prstart {
###########
($tmp, @ARR) = split (/\//, $query);
$cont = @ARR;
$cnt = $cont-1;
$nim=2;
foreach $line (@ARR)
{
if ($nim > $nmer)
{
$pt = "$pt/$ARR[$nim-2]";
}
$nim++;
}
foreach $line (@ARR)
{
while ($num < $cnt)
{
$num++;
$path = "$path/$ARR[$num-1]";
}}
$|=1;
print "Content-type: text/html\n\n";
#system("/bin/cat /web/ae/public_html/.dhstop.php");
print "<html><head><title>Outdated archive</title></head><body>";
system("/bin/cat /web/ae/public_html/dhs/atarimods/cgi-bin/menu.php");
print <<"EOF";

<table border="0" bgcolor="#dddddd" width="100%" cellpadding="4" cellspacing="0">

<tr bgcolor="#aaaaaa">
<th width="20">&nbsp;</th>
<th align="left"><font size="-1" face="helvetica, arial">File Name</font></th>
<th colspan="2"><font size="-1" face="helvetica, arial">Size</font></th>
<th><font size="-1" face="helvetica, arial">Date</font></th>
<th><font size="-1" face="helvetica, arial">Status</font></th>
</tr>

<tr>
<td align="right">
<a href="/cgi-bin/$scriptname?$path"><img src="up.gif" width="16" height="16" border="0"></a>
</td>
<td colspan="5">
<a href="/cgi-bin/$scriptname?$path"><font size="-1" face="helvetica, arial">..</font></a>
</td>
</tr>
EOF

}

###########
sub prend {
###########

print <<"EOF";
</table>
EOF

#system("/bin/cat /web/ae/public_html/.dhsbot.php");
print "</body></html>";
}

############
sub prdir {
############
opendir (DR,"$query");
@files = readdir(DR);
closedir (DR);
foreach $line (sort @files)
{
if ($line ne ".")
{
if ($line ne "..")
{
$temp_file = "$query/$line";
($filesize, $filedate, $perm) = (stat($temp_file))[7, 9, 2];
$perm = sprintf "%lo", ($perm & 07777);
&getdate;
($a, $b) = split(/\./, $line);
if ($b eq "")
{
print <<"EOF";
<tr>
<td align="right">
<a href="/cgi-bin/$scriptname?$query/$line"><img src=folder.gif border="0" width="16" height="16" alt=" "></a>
</td>
<td><font size="-1" face="helvetica, arial"><a href="/cgi-bin/$scriptname?$query/$line">$line</a></font></td>
<td align="right"><font size="-1" face="helvetica, arial">$filesize</font></td>
<td><font size="-1" face="helvetica, arial">bytes</font></td>
<td align="center"><font size="-1" face="helvetica, arial">$filedate</font></td>
<td align="center"><font size="-1" face="helvetica, arial">$perm</font></td>
</tr>
EOF
}
}
}
}
foreach $line (sort @files)
{
$temp_file = "$query/$line";
($filesize, $filedate, $perm) = (stat($temp_file))[7, 9, 2];
$perm = sprintf "%lo", ($perm & 07777);
&getdate;
($a, $b) = split(/\./, $line);
if ($b ne "")
{
print <<"EOF";
<tr>

<td align="right">
<a href="http://$ENV{SERVER_NAME}$pt/$line"><img src="$b.gif" border="0" width="16" height="16" border="0" alt=" "></a>
</td>

<td><font size="-1" face="helvetica, arial"><a href="http://$ENV{SERVER_NAME}$pt/$line">$line</a></font></td>
<td align="right"><font size="-1" face="helvetica, arial">$filesize</font></td>
<td><font size="-1" face="helvetica, arial">bytes</font></td>
<td align="center"><font size="-1" face="helvetica, arial">$filedate</font></td>
<td align="center"><font size="-1" face="helvetica, arial">$perm</font></td>
</tr>
EOF
}}
}

###############
sub getdate {
###############
($min, $hr, $day, $mon, $yr) = (localtime($filedate))[1,2,3,4,5]; 


if ($min < 10) { $min = "0$min"; }
if ($hr < 10) { $hr = "0$hr"; }
if ($day < 10) { $day = "0$day"; }
if ($mon < 10) { $mon = "0$mon"; }
$yr = $yr+1900;
$filedate = "$day-$mon-$yr";
}
