[LON-CAPA-cvs] cvs: loncom /publisher loncfile.pm lonconstruct.pm lonupload.pm
foxr
lon-capa-cvs@mail.lon-capa.org
Sat, 24 Aug 2002 03:56:58 -0000
foxr Fri Aug 23 23:56:58 2002 EDT
Modified files:
/loncom/publisher loncfile.pm lonconstruct.pm lonupload.pm
Log:
Bug 442: Two issues with special chars. solved here:
1. spaces in names - escape works fine on this issue.
2. apostrophe's in uploaded file names:
Apostrophe solution not so easy as spaces: The problem was in the
Frame src tag for the lower frame of construction space.. it's of the form:
<frame> src='$lowerframe' ...Thanks to matt for finding this.
The embedded ' closes the src from the point of view of the html. Amazingly the
extra characters don't cause browsers to complain. The problem: demonstrably,
escaping via lonnet::escape does nothing worth while. Using my handy dandy
html pocket guide, I determined that lonnet::escape is too simple minded
and may in fact be not quite right. did a:
1. made the quotations " rather than '
2. Substituted for " in $lowerframe by:
$lowerframe=~s/\"/"\;/g;
Turning " -> " as per the entity chart on pg 82 of HTML Pocket ref.
This works fine.
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.14 loncom/publisher/loncfile.pm:1.15
--- loncom/publisher/loncfile.pm:1.14 Sun Aug 4 22:09:05 2002
+++ loncom/publisher/loncfile.pm Fri Aug 23 23:56:58 2002
@@ -7,10 +7,10 @@
# presents a page that describes the proposed action to the user
# and requests confirmation. The second phase commits the action
# and displays a page showing the results of the action.
-#
+#
#
-# $Id: loncfile.pm,v 1.14 2002/08/05 02:09:05 foxr Exp $
+# $Id: loncfile.pm,v 1.15 2002/08/24 03:56:58 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -86,10 +86,12 @@
use strict;
use Apache::File;
+use File::Basename;
use File::Copy;
use Apache::Constants qw(:common :http :methods);
use Apache::loncacc;
use Apache::Log ();
+use Apache::lonnet;
my $DEBUG=0;
my $r; # Needs to be global for some stuff RF.
@@ -1016,6 +1018,12 @@
&Debug($r, "Final url is: $dest");
$dest =~ s/\/home\//\/priv\//;
$dest =~ s/\/public_html//;
+
+ my $base = &Apache::lonnet::escape(&File::Basename::basename($dest));
+ my $dpath= &File::Basename::dirname($dest);
+ $dest = $dpath.'/'.$base;
+
+
&Debug($r, "Final url after rewrite: $dest");
$r->print('<h3><a href="'.$dest.'">Done</a></h3>');
Index: loncom/publisher/lonconstruct.pm
diff -u loncom/publisher/lonconstruct.pm:1.6 loncom/publisher/lonconstruct.pm:1.7
--- loncom/publisher/lonconstruct.pm:1.6 Tue Dec 4 10:34:57 2001
+++ loncom/publisher/lonconstruct.pm Fri Aug 23 23:56:58 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Construction Space Page Wrapper for Construction
#
-# $Id: lonconstruct.pm,v 1.6 2001/12/04 15:34:57 albertel Exp $
+# $Id: lonconstruct.pm,v 1.7 2002/08/24 03:56:58 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,11 +36,56 @@
#
# 11/22,11/23,11/28,
# 03/30/01 Gerd Kortemeyer
-
package Apache::lonconstruct;
+
use strict;
-use Apache::Constants qw(:common :http);
+use Apache::Constants qw(:common :http :methods);
+use Apache::lonnet;
+use Apache::Log ();
+
+
+my $DEBUG = 0;
+=pod
+
+=item Debug($request, $message)
+
+ If debugging is enabled puts out a debuggin message determined by the
+ caller. The debug message goes to the Apache error log file. Debugging
+ is enabled by ssetting the module global DEBUG variable to nonzero (TRUE).
+
+ Parameters:
+
+=over 4
+
+=item $request - The curretn request operation.
+
+=item $message - The message to put inthe log file.
+
+=back
+
+ Returns:
+ nothing.
+
+=cut
+
+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);
+ }
+}
+
+
+
# ================================================================ Main Handler
@@ -54,14 +99,19 @@
return OK if $r->header_only;
my $lowerframe=$r->path_info;
+
+ &Debug($r, "Initial URL for lower frame: ".$lowerframe);
$lowerframe=~s/^\//\/\~/;
+ &Debug($r, "Lower frame URL afer ~ subst: ".$lowerframe);
+ $lowerframe=~s/\"/"\;/g;
+ &Debug($r, "LOwer frame URL after quote subst: ".$lowerframe);
$r->print(<<ENDPAGE);
<html>
<head><title>LON-CAPA Construction Space</title></head>
<frameset rows="110,*">
<frame src='/adm/publisher.html'>
-<frame src='$lowerframe' name="LONCAPAToBePublished">
+<frame src="$lowerframe" name="LONCAPAToBePublished">
</frameset>
</html>
ENDPAGE
Index: loncom/publisher/lonupload.pm
diff -u loncom/publisher/lonupload.pm:1.12 loncom/publisher/lonupload.pm:1.13
--- loncom/publisher/lonupload.pm:1.12 Wed Aug 7 22:30:39 2002
+++ loncom/publisher/lonupload.pm Fri Aug 23 23:56:58 2002
@@ -2,7 +2,7 @@
# The LearningOnline Network with CAPA
# Handler to upload files into construction space
#
-# $Id: lonupload.pm,v 1.12 2002/08/08 02:30:39 foxr Exp $
+# $Id: lonupload.pm,v 1.13 2002/08/24 03:56:58 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -53,10 +53,12 @@
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;
my $DEBUG=0;
@@ -104,7 +106,10 @@
$fn.=$ENV{'form.upfile.filename'};
$fn=~s/^\///;
$fn=~s/(\/)+/\//g;
- $fn=~s/%20/ /g;
+
+# Fn is the full path to the destination filename.
+#
+
&Debug($r, "Filename for upload: $fn");
if (($fn) && ($fn!~/\/$/)) {
$r->print(
@@ -143,10 +148,20 @@
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 = Apache::lonnet::escape($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')) {
@@ -154,7 +169,7 @@
'<form action=/adm/upload method=post>'.
'File <tt>'.$fn.'</tt> exists. Overwrite? '.
'<input type=hidden name=phase value=two>'.
- '<input type=hidden name=filename value="'.$fn.'">'.
+ '<input type=hidden name=filename value="'."$url".'">'.
'<input type=hidden name=datatoken value="'.$datatoken.'">'.
'<input type=submit name=override value="Yes"></form>');
} else {
@@ -178,7 +193,7 @@
} elsif (copy($source,$target)) {
chmod(0660, $target); # Set permissions to rw-rw---.
$r->print('File copied.');
- $r->print('<p><font size=+2><a href="'.$fn.
+ $r->print('<p><font size=+2><a href="'.$url.
'">View file</a></font>');
} else {
$r->print('Failed to copy: '.$!);