Download
Home
About

FAQs

General
Admin
Assist
Student

Docs

Admin
Assistant

CGI

Admin
Assistant
Download
Form
Student

Packages

AdminInterface
Assignments
AssistantInterface
Form
Interface
Record
Roster
StudentInterface
SystemVariables
Teams
VincentFile
VincentLog


  0 #!/bin/perl -w -I /l/vincent3/modules/
  1 #Copyright 2000 Matt Jadud
  2 #This program is free software; you can redistribute it and/or
  3 #modify it under the terms of the GNU General Public License
  4 #as published by the Free Software Foundation; either version 2
  5 #of the License, or (at your option) any later version.
  6 #
  7 #This program is distributed in the hope that it will be useful,
  8 #but WITHOUT ANY WARRANTY; without even the implied warranty of
  9 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 10 #GNU General Public License for more details.
 11 #
 12 #You should have received a copy of the GNU General Public License
 13 #along with this program; if not, write to the Free Software
 14 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 15 
 16 $| = 1;
 17 
 18 #Perl libraries that will come in handy. Get these out of the way...
 19 use CGI qw(:standard); # import shortcuts
 20 #use Fcntl qw(:flock);  # imports LOCK_EX, LOCK_SH, LOCK_NB
 21 
 22 
 23 use SystemVariables;
 24 use Record;
 25 use VincentFile;
 26 use VincentLog;
 27 
 28 my ( $username,
 29      $query,
 30      $filename,
 31      $downloadableFiles,
 32      $path,
 33      $allowed
 34      );
 35 
 36 #Grab the CGI Query
 37 $query = CGI->new(); 
 38 
 39 $username = $ENV{REMOTE_USER};
 40 
 41 #Grab the CGI Parameters
 42 $sysID = $query->param("SYSID");
 43 $filename = $query->param("FILENAME");
 44 $type = $query->param("TYPE");
 45 
 46 ##LOGGING
 47 VincentLog::clickLog("DOWNLOAD", "$filename downloaded");
 48 
 49 #If this is an admin-contributed file,
 50 # then the data will be slightly different than
 51 # if it is a file a student previously uploaded.
 52 # Hence, it will be handled sligntly differently here.
 53 if($type eq "admin") {
 54     
 55     $path = SystemVariables::getCourseConfigPath();
 56     $downloadableFiles = VincentFile::allDownloadableFiles($username);    
 57     
 58     $allowed = SystemVariables::existInList($sysID, $downloadableFiles);
 59     
 60     chomp $sysID;
 61     chomp $filename;
 62     chomp $path;
 63 
 64     $sysPath = $path . $sysID;
 65 
 66     print STDERR "$sysPath - $filenamen";
 67 
 68     if(1) {
 69 	print "Content-Type: application/unknown; name="" . $sysPath . ""n";
 70 	print "Content-Disposition: attachment; filename="" . $filename . ""n\n";
 71 	sendfile($sysPath, $filename);
 72     } else {
 73 	print header;
 74 	print "<HTML><BODY BGCOLOR='FFFFFF'>";
 75 	print "<CENTER><H1>You are not allowed to download";
 76 	print "<FONT COLOR='RED'>$filename</FONT> at this time.</H1>";
 77 	print "<P>You may <A HREF='student.cgi'>start over</A> and try again, though.</CENTER>";
 78 	print "</BODY></HTML>";
 79     }
 80        
 81     #Debugging Code
 82     #print STDERR "-------\n\n";
 83     
 84 } elsif ($type eq "student") {
 85 
 86     #BAD! What if I'm an AI trying to download a file? The path generated by
 87     # getStudentRecordPath needs to be to the student's file, not 
 88     # to my own directory.
 89 
 90     #This is probably worse; I grab the username of the target student
 91     # from the system name of the file. Talk about dangerous...
 92     ($stuusername) = (split(/./, $sysID))[0];
 93     
 94     #Replace the username in the path with the 
 95     $path = SystemVariables::getStudentRecordPath($stuusername);
 96 
 97     #Plunk the two together    
 98     chomp $sysID;
 99     chomp $filename;
 100     chomp $path;
 101 
 102     $sysPath = $path . $sysID;
 103 
 104     #If they are a god, an administrator, an assistant, OR
 105     # if the username that is authenticated matches that of the
 106     # username in the file, THEN they can download the file.
 107     if(Record::isGod($username) 
 108        || Record::isAdministrator($username) 
 109        || Record::isAssistant($username) 
 110        || ($stuusername eq $username)) {
 111 	print "Content-Type: application/unknown; name="" . $sysPath . ""n";
 112 	print "Content-Disposition: attachment; filename="" . $filename . ""n\n";
 113 
 114 	sendfile($sysPath, $filename);
 115     }
 116 
 117 } elsif ($type eq "ZIPFILE") {
 118    
 119     $sysPath = $query->param("ZIPPATH");
 120     $filename = $query->param("FILENAME");
 121 
 122     print "Content-Type: application/unknown; name="" . $sysPath . ""n";
 123     print "Content-Disposition: attachment; filename="" . $filename . ""n\n";
 124     sendfile($sysPath, $filename);
 125 
 126     $sysPath =~ /^(.*)/.*.zip$/;
 127     $rmdir = $1;
 128  
 129     #Delete the whole damn temp directory after files are downloaded.
 130     system("rm", "-rf", $rmdir);
 131     
 132 }
 133 
 134 
 135 sub sendfile  {
 136 
 137     my($sysPath, $filename);
 138     ($sysPath, $filename) = @_;
 139 
 140     open (FILE, $sysPath) || die("No file of name $filename found!");
 141     binmode(FILE);
 142     
 143     while (read FILE, $buffer, 1024) {
 144 	print $buffer;
 145     }
 146     close(FILE);
 147 }

Last update: 1/6/01; 9:32:31 AM