--- loncom/publisher/lonupload.pm 2001/12/04 18:13:06 1.9 +++ loncom/publisher/lonupload.pm 2003/06/23 21:56:31 1.16 @@ -1,7 +1,8 @@ + # The LearningOnline Network with CAPA # Handler to upload files into construction space # -# $Id: lonupload.pm,v 1.9 2001/12/04 18:13:06 matthew Exp $ +# $Id: lonupload.pm,v 1.16 2003/06/23 21:56:31 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,9 +32,11 @@ # # (TeX Content Handler # +# YEAR=2000 # 05/29/00,05/30,10/11 Gerd Kortemeyer) # # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer +# YEAR=2001 # 03/23 Guy Albertelli # 03/24,03/29 Gerd Kortemeyer) # @@ -41,15 +44,38 @@ # # 04/05,04/09,05/25,06/23,06/24,08/22 Gerd Kortemeyer # 11/29 Matthew Hall +# +### package Apache::lonupload; use strict; use Apache::File; use File::Copy; +use File::Basename; use Apache::Constants qw(:common :http :methods); use Apache::loncacc; +use Apache::loncommon(); +use Apache::Log(); use Apache::lonnet; +use HTML::Entities(); + +my $DEBUG=0; + +sub Debug { + + # Marshall the parameters. + + my $r = shift; + my $log = $r->log; + my $message = shift; + + # Put out the indicated message butonly if DEBUG is false. + + if ($DEBUG) { + $log->debug($message); + } +} sub upfile_store { my $r=shift; @@ -81,6 +107,10 @@ sub phaseone { $fn=~s/^\///; $fn=~s/(\/)+/\//g; +# Fn is the full path to the destination filename. +# + + &Debug($r, "Filename for upload: $fn"); if (($fn) && ($fn!~/\/$/)) { $r->print( '
'); # Check for bad extension and warn user if ($fn=~/\.(\w+)$/ && - (&Apache::lonnet::fileembstyle($1) eq 'hdn')) { + (&Apache::loncommon::fileembstyle($1) eq 'hdn')) { $r->print( ''. 'The extension on this file, "'.$1. @@ -100,7 +130,7 @@ sub phaseone { 'Please change the extension.'. ''); } elsif($fn=~/\.(\w+)$/ && - !defined(&Apache::lonnet::fileembstyle($1))) { + !defined(&Apache::loncommon::fileembstyle($1))) { $r->print( ''. 'The extension on this file, "'.$1. @@ -118,10 +148,20 @@ sub phaseone { sub phasetwo { my ($r,$fn,$uname,$udom)=@_; - if ($fn=~/^\/priv\/$uname\//) { + &Debug($r, "Filename is ".$fn); + if ($fn=~/^\/priv\/$uname\//) { + &Debug($r, "Filename after priv substitution: ".$fn); my $tfn=$fn; $tfn=~s/^\/(\~|priv)\/(\w+)//; + &Debug($r, "Filename for tfn = ".$tfn); my $target='/home/'.$uname.'/public_html'.$tfn; + &Debug($r, "target -> ".$target); +# target is the full filesystem path of the destination file. + my $base = &File::Basename::basename($fn); + my $path = &File::Basename::dirname($fn); + $base = &HTML::Entities::encode($base); + my $url = $path."/".$base; + &Debug($r, "URL is now ".$url); my $datatoken=$ENV{'form.datatoken'}; if (($fn) && ($datatoken)) { if ((-e $target) && ($ENV{'form.override'} ne 'Yes')) { @@ -129,7 +169,7 @@ sub phasetwo { ''); } else { @@ -137,23 +177,26 @@ sub phasetwo { '/tmp/'.$datatoken.'.tmp'; # Check for bad extension and disallow upload if ($fn=~/\.(\w+)$/ && - (&Apache::lonnet::fileembstyle($1) eq 'hdn')) { + (&Apache::loncommon::fileembstyle($1) eq 'hdn')) { $r->print( 'File '.$fn.' could not be copied.View file'); + $r->print('
Back to Directory');
} else {
$r->print('Failed to copy: '.$!);
}
@@ -170,6 +213,7 @@ sub phasetwo {
}
}
+# ---------------------------------------------------------------- Main Handler
sub handler {
my $r=shift;
@@ -231,3 +275,76 @@ sub handler {
1;
__END__
+
+=head1 NAME
+
+Apache::lonupload - upload files into construction space
+
+=head1 SYNOPSIS
+
+Invoked by /etc/httpd/conf/srm.conf:
+
+