[LON-CAPA-cvs] cvs: loncom /publisher loncfile.pm lonupload.pm
www
lon-capa-cvs@mail.lon-capa.org
Mon, 04 Aug 2003 17:45:06 -0000
www Mon Aug 4 13:45:06 2003 EDT
Modified files:
/loncom/publisher loncfile.pm lonupload.pm
Log:
Working on bug #2018: could not handle absolute vs. relative URLs
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.36 loncom/publisher/loncfile.pm:1.37
--- loncom/publisher/loncfile.pm:1.36 Sat Aug 2 20:40:00 2003
+++ loncom/publisher/loncfile.pm Mon Aug 4 13:45:06 2003
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.36 2003/08/03 00:40:00 www Exp $
+# $Id: loncfile.pm,v 1.37 2003/08/04 17:45:06 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -152,6 +152,7 @@
sub URLToPath {
my $Url = shift;
&Debug($r, "UrlToPath got: $Url");
+ $Url=~ s/\/+/\//g;
$Url=~ s/^http\:\/\/[^\/]+//;
$Url=~ s/^\///;
$Url=~ s/(\~|priv\/)(\w+)\//\/home\/$2\/public_html\//;
Index: loncom/publisher/lonupload.pm
diff -u loncom/publisher/lonupload.pm:1.17 loncom/publisher/lonupload.pm:1.18
--- loncom/publisher/lonupload.pm:1.17 Sat Jul 5 06:07:12 2003
+++ loncom/publisher/lonupload.pm Mon Aug 4 13:45:06 2003
@@ -2,7 +2,7 @@
# The LearningOnline Network with CAPA
# Handler to upload files into construction space
#
-# $Id: lonupload.pm,v 1.17 2003/07/05 10:07:12 www Exp $
+# $Id: lonupload.pm,v 1.18 2003/08/04 17:45:06 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,25 +26,6 @@
#
# http://www.lon-capa.org/
#
-# (Handler to retrieve an old version of a file
-#
-# (Publication Handler
-#
-# (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)
-#
-# 03/31,04/03 Gerd Kortemeyer)
-#
-# 04/05,04/09,05/25,06/23,06/24,08/22 Gerd Kortemeyer
-# 11/29 Matthew Hall
-#
###
package Apache::lonupload;
@@ -83,7 +64,7 @@
my $fname=$ENV{'form.upfile.filename'};
$fname=~s/\W//g;
- chop($ENV{'form.upfile'});
+ chomp($ENV{'form.upfile'});
my $datatoken=$ENV{'user.name'}.'_'.$ENV{'user.domain'}.
'_upload_'.$fname.'_'.time.'_'.$$;
@@ -116,9 +97,9 @@
'<form action=/adm/upload method=post>'.
'<input type=hidden name=phase value=two>'.
'<input type=hidden name=datatoken value="'.&upfile_store.'">'.
+ '<input type=hidden name=uploaduname value="'.$uname.'">'.
'Store uploaded file as '.
- '<input type=text size=50 name=filename value="/priv/'.
- $uname.'/'.$fn.'"><br>'.
+ '<input type=text size=50 name=filename value="'.$fn.'"><br>'.
'<input type=submit value="Store"></form>');
# Check for bad extension and warn user
if ($fn=~/\.(\w+)$/ &&
@@ -147,12 +128,11 @@
}
sub phasetwo {
- my ($r,$fn,$uname,$udom)=@_;
- &Debug($r, "Filename is ".$fn);
- if ($fn=~/^\/priv\/$uname\//) {
- &Debug($r, "Filename after priv substitution: ".$fn);
- my $tfn=$fn;
- $tfn=~s/^\/(\~|priv)\/(\w+)//;
+ my ($r,$tfn,$uname,$udom)=@_;
+ my $fn='/priv/'.$uname.'/'.$tfn;
+ $fn=~s/\/+/\//g;
+ &Debug($r, "Filename is ".$tfn);
+ if ($tfn) {
&Debug($r, "Filename for tfn = ".$tfn);
my $target='/home/'.$uname.'/public_html'.$tfn;
&Debug($r, "target -> ".$target);
@@ -220,6 +200,14 @@
my $uname;
my $udom;
+#
+# phase two: re-attach user
+#
+ if ($ENV{'form.uploaduname'}) {
+ $ENV{'form.filename'}='/priv/'.$ENV{'form.uploaduname'}.'/'.
+ $ENV{'form.filename'};
+ }
+#
($uname,$udom)=
&Apache::loncacc::constructaccess(
@@ -233,10 +221,12 @@
}
my $fn;
-
if ($ENV{'form.filename'}) {
$fn=$ENV{'form.filename'};
- $fn=~s/^http\:\/\/[^\/]+\/(\~|priv\/)(\w+)//;
+ $fn=~s/^http\:\/\/[^\/]+\///;
+ $fn=~s/^\///;
+ $fn=~s/(\~|priv\/)(\w+)//;
+ $fn=~s/\/+/\//g;
} else {
$r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
' unspecified filename for upload', $r->filename);