#!/dcs/bin/perl ###################################################### # upload a file with netscape 2.0+ or IE 4.0+ # Muhammad A Muquit # When: Long time ago # Changelog: # James Bee" reported that from Windows filename # such as c:\foo\fille.x saves as c:\foo\file.x, Fixed, Jul-22-1999 ###################################################### use strict; use CGI; $|=1; my $version="V1.1"; ## vvvvvvvvvvvvvvvvvvv MODIFY vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv # the text database of the user. The text database contains the colon # separated items, namely login:encrypted password:upload path # example: muquit:fhy687kq1hger:/usr/local/web/upload/muquit # if no path is specified, the file must be located in the cgi-bin directory. my $g_upload_db="upload.db"; # overwrite the existing file or not. Default is to overwrite # chanage the value to 0 if you do not want to overwrite an existing file. my $g_overwrite=1; ## ^^^^^^^^^^^^^^^^^^^ MODIFY ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #-------------- globals---------- STARTS ------------------ my $query=new CGI; my $g_debug=0; my $progName="."; my $g_title="File upload"; my $g_upload_path='/ece/ece35/class/ece145ta/www/upload'; my $debugPrefix = ""; my $rosterDB = "roster.db"; # name and student ID my $uploadDB = "upload.db"; # 8-digit ID and file name my @students=(); my %sInfo = (); # multiply indexed by $id, 'name' or 'email' my @submittedStu = (); my %fInfo = (); # multiply indexed by $id, 'filename' my $deadline = "Mar 17 17:30:00 2001"; #-------------- globals---------- ENDS ------------------ print $query->header; # Java Script for form validation # my $JSCRIPT=<path_info eq "/author") { &printForm; &printAuthorInfo; return; } if ($query->param) { &doWork(); } else { &printForm(); } &printHTMLTrailer(); # end of mail file sub printHTMLTrailer { my $e3 = "http://e3.uci.edu"; print << "EOF";
Back to ECE 145 homepage
[ EEE Home | UCI Home | Site Search | Help ]
Links on these pages to commercial sites do not represent endorsement by the University of California or its affiliates. See UCI Administrative Policies & Procedures Section 800-16 for the World Wide Web Publishing Policy
EOF ; } ##----- # printForm() - print the HTML form ##----- sub printForm { print "
\n"; print "\n"; print $query->start_multipart_form,"\n"; #------------- userid print "\n"; print "\n"; print "\n"; print "\n"; #------------- password print "\n"; print "\n"; print "\n"; print "\n"; #------------- upload print "\n"; print "\n"; print "\n"; print "\n"; #------------- submit print "\n"; print "\n"; print "\n"; print $query->endform,"\n"; print "
\n"; print "UCINetID:\n"; print "\n"; print $query->textfield(-name=>'userid', -size=>20); print "
\n"; print "8-digit student ID:\n"; print "\n"; print $query->password_field(-name=>'password', -size=>20); print "
\n"; print "Upload file:\n"; print "\n"; print $query->filefield(-name=>'upload_file', -size=>30, -maxlength=>280); print "
\n"; print "
\n"; print $query->submit(-label=>'Upload', -value=>'Upload', -onClick=>"return ValidateAllFields(this.form)"),"\n"; print "
\n"; print "
\n"; } # read from the roster file. it has student ID, name, and email sub readRoster { unless (open(RBF, "$debugPrefix$rosterDB")) { &printError("Warning: Could not open roster file"); return; } while () { if (!/\S+/) { next; } chomp; my ($sid, $name, $email) = split(/\t/); my ($userid, $domain) = split (/@/, $email); # $sid ~= /\s//g; $name ~= /\s*$//g; $email ~= /\s//g; push(@students, $sid); $sInfo{$userid,'name'} = $name; $sInfo{$userid,'sid'} = $sid; $sInfo{$userid,'email'} = $email; } } sub printHTMLHeader { print $query->start_html( -title=>"$g_title", -script=>$JSCRIPT, -bgcolor=>"#ffffff" #-link=>"#ffff00", -vlink=>"#00ffff", -alink=>"#ffff00", -text=>"#000000" ); print << "EOF";

ENGRECE 145

Senior Design Project

Course Number: ENGRECE 145, Quarter: w01, Course Code: 15278

Instructor P. Chou (PHCHOU\@uci.edu)

Final Project Report Submission (due by 5pm Sat 3/17)

1. Final report in PDF format
2. An archive file (.tar, .zip, .tar.gz, or .sit ) which contains ALL your related web pages, images, source files, any library and executables. (Re-submissions are allowed. Only the latest version is accepted.)
(click here to learn how to generate postscript files and use this page to convert a postscript file to a PDF file.)
EOF ; } ##------- # doWork() - upload file ##------- sub doWork { ################## my $em=''; ################## # import the paramets into a series of variables in 'q' namespace $query->import_names('q'); # check if the necessary fields are empty or not $em .= "
You must specify your Userid!
" if !$q::userid; $em .= "You must specify your Password!
" if !$q::password; $em .= "You must select a file to upload!
" if !$q::upload_file; my $rc=0; my ($u,$p); my $userid=$query->param('userid'); $userid =~ tr/a-z/A-Z/; my $plain_pass=$query->param('password'); my $filename=''; &printForm(); if ($em) { &printError($em); return; } &readRoster(); if ($sInfo{$userid,'sid'} ne $plain_pass) { &printError("Will not upload! Could not validate Userid: $q::userid"); return; } my $filepath=$query->param('upload_file'); if ($filepath =~ /([^\/\\]+)$/) { $filename="$1"; } else { $filename="$filepath"; } $filename =~ s/\s+//g; # if ($filename =~ /pdf$/) {;} else # { # &printError("Will not upload! File should be in .pdf format."); # return; # } # now upload file &uploadFile(); &updateDB($plain_pass,$sInfo{$userid,'name'}, $filename); # if (isLate()) { printError("Late submission"); } } ##-------- # islate() ##-------- # check if the submission misses the deadline sub isLate { my $islate ; require 'ctime.pl'; my $getctime = &ctime(time); $getctime =~ s/(\s)+/$1/g ; my ($date, $mon, $day, $time, $timeZone, $year ) = split (/\s/, $getctime); my ($mymon, $myday, $mytime, $myyear) = split(/\s/, $deadline); if ( $myyear <= $year and $mymon le $mon and $myday <= $day) { if ( $mytime le $time) { $islate = 0;} } else { $islate = 1; } printText($mymon."|".$myday."|".$mytime."|".$myyear."\n"); return $islate; } ##-------- # uploadFile() ##-------- sub uploadFile { my $bytes_read=0; my $size=''; my $buff=''; my $start_time; my $time_took; my $filename=''; my $filepath=''; my $write_file=''; $filepath=$query->param('upload_file'); my $plain_pass=$query->param('password'); if ($filepath =~ /([^\/\\]+)$/) { $filename="$1"; } else { $filename="$filepath"; } $filename =~ s/\s+//g; $write_file="$g_upload_path" . "/" . "$plain_pass" . "_"."$filename"; print "Filename=$filename
\n" if $g_debug; print "Writefile= $write_file
\n" if $g_debug; if ($g_overwrite == 0) { if (-e $write_file) { &printError("File $filename exists, will not overwrite!"); return; } } if (!open(WFD,">$write_file")) { &printError("Error opening file for writing"); return; } $start_time=time(); while ($bytes_read=read($filepath,$buff,2096)) { $size += $bytes_read; binmode WFD; print WFD $buff; } print "size= $size
\n" if $g_debug; close(WFD); if ((stat $write_file)[7] <= 0) { unlink($write_file); &printError("Could not upload file: $filename"); return; } else { $time_took=time()-$start_time; print<
File $filename of size $size bytes is uploaded successfully!
EOF ; } } sub updateDB { my ($id,$name, $fn) = @_ ; unless (open(RBF, ">>"."$debugPrefix$uploadDB")) { touch("$debugPrefix$uploadDB"); } print RBF "$id:$name:$fn\n"; close(RBF); } ##------ # printError() - print error message ##------ sub printError { my $em=shift; print<
Error - $em
EOF ; } sub printAuthorInfo { my $url="http://www.fccc.edu/users/muquit/"; my $upl_url="$url" . "upload/upload.html"; print<
upload.pl $version by Muhammad A Muquit
EOF ; } sub printText { my ($t)=@_; print << "EOF"

$t

EOF ; } sub printAA { my %array = @_ ; my $key; my $pointer = "->"; my $output = () ; foreach $key (sort keys (%array)) { $output = $key.$pointer.$array{$key}; &printText($output); } } # if ($g_debug == 1) # { # my @all=$query->param; # my $name; # foreach $name (@all) # { # print "$name ->", $query->param($name),"
\n"; # } # }