--- loncom/publisher/loncfile.pm 2007/03/30 20:37:31 1.81
+++ loncom/publisher/loncfile.pm 2009/05/11 16:51:32 1.97
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.81 2007/03/30 20:37:31 albertel Exp $
+# $Id: loncfile.pm,v 1.97 2009/05/11 16:51:32 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -109,6 +109,17 @@ sub Debug {
}
}
+sub done {
+ my ($url)=@_;
+ my $done=&mt("Done");
+ return(<$done
+
+ENDDONE
+}
+
=pod
=item URLToPath($url)
@@ -148,7 +159,7 @@ sub URLToPath {
my $Url = shift;
&Debug($r, "UrlToPath got: $Url");
$Url=~ s/\/+/\//g;
- $Url=~ s/^http\:\/\/[^\/]+//;
+ $Url=~ s/^https?\:\/\/[^\/]+//;
$Url=~ s/^\///;
$Url=~ s/(\~|priv\/)($match_username)\//\/home\/$2\/public_html\//;
&Debug($r, "Returning $Url \n");
@@ -165,7 +176,7 @@ sub url {
sub display {
my $fn=shift;
$fn=~s-^/home/($match_username)/public_html-/priv/$1-;
- return ''.$fn.'';
+ return ''.$fn.'';
}
@@ -226,12 +237,16 @@ sub empty_directory {
=over 4
-=item $user - string [in] - Name of the user for which to check.
+=item $user - string [in] - Name of the user for which to check.
-=item $domain - string [in] - Name of the domain in which the resource
+=item $domain - string [in] - Name of the domain in which the resource
might have been published.
-=item $file - string [in] - Name of the file.
+=item $file - string [in] - Name of the file.
+
+=item $creating - string [in] - optional, type of object being created,
+ either 'directory' or 'file'. Defaults to
+ 'file' if unspecified.
=back
@@ -239,6 +254,9 @@ Returns:
=over 4
+=item string - Either undef, 'warning' or 'error' depending on the
+ type of problem
+
=item string - Either where the resource exists as an html string that can
be embedded in a dialog or an empty string if the resource
does not exist.
@@ -248,20 +266,39 @@ Returns:
=cut
sub exists {
- my ($user, $domain, $construct) = @_;
+ my ($user, $domain, $construct, $creating) = @_;
+ $creating ||= 'file';
+
my $published=$construct;
$published=~
- s/^\/home\/$user\/public\_html\//\/home\/httpd\/html\/res\/$domain\/$user\//;
- my $result='';
+ s{^/home/$user/public_html/}{/home/httpd/html/res/$domain/$user/};
+ my ($type,$result);
if ( -d $construct ) {
- return &mt('Error: destination for operation is an existing directory.');
+ return ('error','
'.&mt('Error: destination for operation is an existing directory.').'
');
+
}
+
if ( -e $published) {
- $result.='
'.&mt('Warning: target file exists, and has been published!').'
';
}
- return $result;
+
+ return ($type,$result);
}
=pod
@@ -300,9 +337,9 @@ sub checksuffix {
my $newsuffix;
if ($new=~m:(.*/*)([^/]+)\.(\w+)$:) { $newsuffix=$3; }
if ($old=~m:(.*)/+([^/]+)\.(\w+)$:) { $oldsuffix=$3; }
- if ($oldsuffix ne $newsuffix) {
+ if (lc($oldsuffix) ne lc($newsuffix)) {
$result.=
- '
'.&mt('Warning: change of MIME type!').'
';
+ '
'.&mt('Warning: change of MIME type!').'
';
}
return $result;
}
@@ -315,6 +352,7 @@ sub cleanDest {
$foundbad=1;
$dest=~s/\.//g;
}
+ $dest =~ s/(\s+$|^\s+)//g;
if ($dest=~/[\#\?&%\":]/) {
$foundbad=1;
$dest=~s/[\#\?&%\":]//g;
@@ -323,12 +361,25 @@ sub cleanDest {
my ($newpath)=($dest=~m|(.*)/|);
$newpath=&relativeDest($fn,$newpath,$uname);
if (! -d "$newpath") {
- $request->print("
".&mt('You have requested to create file in directory [_1] which doesn\'t exist. The requested directory path has been removed from the requested file name.','"'.$newpath.'"')."
");
+ $request->print('
'
+ .&mt("You have requested to create file in directory [_1] which doesn't exist. The requested directory path has been removed from the requested file name."
+ ,'"'.&display($newpath).'"')
+ .'
');
$dest=~s|.*/||;
}
}
+ if ($dest =~ /\.(\d+)\.(\w+)$/){
+ $request->print(''
+ .&mt('Bad filename [_1]',''.&display($dest).'')
+ .' '
+ .&mt('[_1](name).(number).(extension)[_2] not allowed.','','')
+ .' '
+ .&mt('Removing the [_1].number.[_2] from requested filename.','','')
+ .'');
+ $dest =~ s/\.(\d+)(\.\w+)$/$2/;
+ }
if ($foundbad) {
- $request->print("
".&mt('Invalid characters in requested name have been removed.')."
");
+ $request->print("
".&mt('Invalid characters in requested name have been removed.')."
");
}
return $dest;
}
@@ -372,7 +423,7 @@ sub CloseForm1 {
my ($request, $fn) = @_;
$request->print('');
$request->print('');
+ '" method="post">');
}
@@ -402,7 +453,7 @@ Parameters:
sub CloseForm2 {
my ($request, $user, $fn) = @_;
- $request->print('
'.
+ &mt('The name of the new file needs to end with an appropriate file extension to indicate the type of file to create.').' '.
+ &mt('The following are valid extensions: [_1].',$validexts).
+ '
'.
+ '
'.
+ '');
+ return;
+ }
+
$request->print('
'.&mt('Make new file').' '.&display($newfilename).'?
');
$request->print('');
+
$request->print('');
+ '" method="post">');
$request->print('');
+ '" method="post">');
+ }
+ return;
+}
+
+sub filename_check {
+ my ($newfilename) = @_;
+ ##Informs User (name).(number).(extension) not allowed
+ if($newfilename =~ /\.(\d+)\.(\w+)$/){
+ $r->print(''.$newfilename.
+ ' - '.&mt('Bad Filename').' ('.&mt('name').').('.&mt('number').').('.&mt('extension').') '.
+ ' '.&mt('Not Allowed').'');
+ return;
+ }
+ if($newfilename =~ /(\:\:\:|\&\&\&|\_\_\_)/){
+ $r->print(''.$newfilename.
+ ' - '.&mt('Bad Filename').' ('.&mt('Must not include').' '.$1.') '.
+ ' '.&mt('Not Allowed').'');
+ return;
}
+ return 'ok';
}
=pod
@@ -836,6 +920,7 @@ sub phaseone {
$env{'form.action'} eq 'newsequencefile' ||
$env{'form.action'} eq 'newrightsfile' ||
$env{'form.action'} eq 'newstyfile' ||
+ $env{'form.action'} eq 'newtaskfile' ||
$env{'form.action'} eq 'newlibraryfile' ||
$env{'form.action'} eq 'Select Action') {
my $empty=&mt('Type Name Here');
@@ -894,7 +979,7 @@ sub Rename2 {
my $oRN=$oldfile;
my $nRN=$newfile;
unless (rename($oldfile,$newfile)) {
- $request->print(''.&mt('Error').': '.$!.'');
+ $request->print(''.&mt('Error').': '.$!.'');
return 0;
}
## If old name.(extension) exits, move under new name.
@@ -968,12 +1053,12 @@ sub Delete2 {
my ($request, $user, $filename) = @_;
if (-d $filename) {
unless (&empty_directory($filename,'Delete2')) {
- $request->print(' '.&mt('Error: Directory Non Empty').'');
+ $request->print(''.&mt('Error: Directory Non Empty').'');
return 0;
} else {
if(-e $filename) {
unless(rmdir($filename)) {
- $request->print(''.&mt('Error').': '.$!.'');
+ $request->print(''.&mt('Error').': '.$!.'');
return 0;
}
} else {
@@ -984,7 +1069,7 @@ sub Delete2 {
} else {
if(-e $filename) {
unless(unlink($filename)) {
- $request->print(''.&mt('Error').': '.$!.'');
+ $request->print(''.&mt('Error').': '.$!.'');
return 0;
}
} else {
@@ -1028,20 +1113,20 @@ sub Copy2 {
&Debug($request ,"Will try to copy $oldfile to $newfile");
if(-e $oldfile) {
if ($oldfile eq $newfile) {
- $request->print(' '.&mt('Warning').': '.&mt('Name of new file is the same as name of old file').' - '.&mt('no action taken').'.');
+ $request->print(''.&mt('Warning').': '.&mt('Name of new file is the same as name of old file').' - '.&mt('no action taken').'.');
return 1;
}
unless (copy($oldfile, $newfile)) {
- $request->print(' '.&mt('copy Error').': '.$!.'');
+ $request->print(''.&mt('copy Error').': '.$!.'');
return 0;
} elsif (!chmod(0660, $newfile)) {
- $request->print(' '.&mt('chmod error').': '.$!.'');
+ $request->print(''.&mt('chmod error').': '.$!.'');
return 0;
} elsif (-e $oldfile.'.meta' &&
!copy($oldfile.'.meta', $newfile.'.meta') &&
!chmod(0660, $newfile.'.meta')) {
- $request->print(' '.&mt('copy metadata error').
- ': '.$!.'');
+ $request->print(''.&mt('copy metadata error').
+ ': '.$!.'');
return 0;
} else {
return 1;
@@ -1079,11 +1164,11 @@ sub NewDir2 {
my ($request, $user, $newdirectory) = @_;
unless(mkdir($newdirectory, 02770)) {
- $request->print(''.&mt('Error').': '.$!.'');
+ $request->print(''.&mt('Error').': '.$!.'');
return 0;
}
unless(chmod(02770, ($newdirectory))) {
- $request->print(' '.&mt('Error').': '.$!.'');
+ $request->print(''.&mt('Error').': '.$!.'');
return 0;
}
return 1;
@@ -1091,8 +1176,8 @@ sub NewDir2 {
sub decompress2 {
my ($r, $user, $dir, $file) = @_;
- &Apache::lonnet::appenv('cgi.file' => $file);
- &Apache::lonnet::appenv('cgi.dir' => $dir);
+ &Apache::lonnet::appenv({'cgi.file' => $file});
+ &Apache::lonnet::appenv({'cgi.dir' => $dir});
my $result=&Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
$r->print($result);
&Apache::lonnet::delenv('cgi.file');
@@ -1219,7 +1304,7 @@ sub phasetwo {
$r->print('