file.pl // File Management
#!/usr/bin/perl -w
#file.pl -- Perl Uploadr by Brad Arsenault
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use Time::HiRes qw(gettimeofday tv_interval);
use Time::gmtime;
require "subs.pl";
$t0 = [gettimeofday];
$tp = "";
&connectDB();
if (length ($ENV{'QUERY_STRING'}) >= 1){
$buffer = $ENV{'QUERY_STRING'};
= split(/&/, $buffer);
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$in{$name} = $value;
}
}else{ # is 0
$tp .= &setMessage(5);
&printHeader("Empty Request");
print $tp;
&printFooter();
exit;
}
$sc = $in{'sc'};
if (!$sc){
$sc = $in{''};
}
# getting related information
$msq = "SELECT * FROM files WHERE sc LIKE ? ORDER BY revision DESC";
$qh_f = $dbh->prepare($msq) or die "Couldn't prepare statement: " . $dbh->errstr;
$qh_f ->execute($sc) or die "Couldn't execute: ".$dbh->errstr;
if($qh->rows == 0){
undef $qh_f;
$dbh->disconnect;
&printHeader("No Files Found from: ".$sc);
$tp .= &setMessage(3);
print $tp;
&printFooter();
exit;
}
if($qh_f->rows >= 1){
$i = 0;
$tp .= "
";
$qh_url = $dbh->prepare("SELECT * FROM urls WHERE sc=?");
$qh_u = $dbh->prepare("SELECT * FROM users WHERE id LIKE ?");
$qh_url1 = $dbh->prepare("UPDATE urls SET views='$_urlVC', dlu='$_nowTime' WHERE sc='$r_url{'sc'}");
while ($r = $qh_f->fectrow_hashref()) {
#$qh_u = $dbh->prepare("SELECT * FROM users WHERE id LIKE ?"); // moved before WHILE for speed
$qh_u->execute($r{'user'});
if($qh_u->rows != 1){
&printHeader("Uh Oh!");
$tp .= "
|
Filename |
Comment |
Username |
Time/Date |
Revison Number |
Revise? |
\n\n";
$tp .= "
There were
".$qh_u->rows." users with that ID found (the id being
".$r{'user'}.").... sarry!
";
$tp .= &setMessage(4);
print $tp;
&printFooter();
exit;
}else{
$_username = $qh->{name};
}
$tp .= "
";
$tp .= (
"
".($i + 1).".
\n".
"
".$r{'f_name'}."
\n".
"
".$r{'comment'}."
\n".
"
".$_username."
\n".
"
".&epochProc($r{'dt'})."
\n".
"
".$r{'revision'}."
\n".
"
".$files_revise_url.$r{'sc'}."
\n"
);
$tp .= "
\n";
# the url-view log // TEMPORARY UNTIL URL CAN UPDATE ITSELF
#$qh_url = $dbh->prepare("SELECT * FROM urls WHERE sc=?"); // moved before WHILE for speed
$qh_url->execute($r{'sc'});
$r_url = $qh_url->fetchrow_hashref();
$_urlVC = $r_url->{1}->{views};
$_urlVC++;
$_nowTime = time();
#$qh_url1 = $dbh->prepare("UPDATE urls SET views='?', dlu='$_nowTime' WHERE sc='?'"); // moved before WHILE to increase speed
$qh_url1->execute($_urlVC, $r{'sc'});
if($qh_url1->errstr){
$tp .= $qh_url1->errstr;
}
$i++;
undef $_urlVC, $_username, $r_url; #// for speed? see if it helps
}
}elsif($qh_f == 0){
$tp .= "
There were no files found with the shortcode you provided. WTF? I dunno.
";
&printHeader("File Not Found");
print $tp;
&printFooter();
exit;
}
&printHeader("Sucessful Listing | $qh_f->rows");
$tp .= "
Sucess!
";
print $tp;
&printFooter();