Annotation of loncom/publisher/loncfile.pm, revision 1.87
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to rename files, etc, in construction space
3: #
1.9 foxr 4: # This file responds to the various buttons and events
5: # in the top frame of the construction space directory.
6: # Each event is processed in two phases. The first phase
7: # presents a page that describes the proposed action to the user
8: # and requests confirmation. The second phase commits the action
9: # and displays a page showing the results of the action.
10: #
1.24 albertel 11: #
1.87 ! albertel 12: # $Id: loncfile.pm,v 1.86 2007/07/25 19:56:57 albertel Exp $
1.7 albertel 13: #
14: # Copyright Michigan State University Board of Trustees
15: #
16: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
17: #
18: # LON-CAPA is free software; you can redistribute it and/or modify
19: # it under the terms of the GNU General Public License as published by
20: # the Free Software Foundation; either version 2 of the License, or
21: # (at your option) any later version.
22: #
23: # LON-CAPA is distributed in the hope that it will be useful,
24: # but WITHOUT ANY WARRANTY; without even the implied warranty of
25: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26: # GNU General Public License for more details.
27: #
28: # You should have received a copy of the GNU General Public License
29: # along with LON-CAPA; if not, write to the Free Software
30: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31: #
32: # /home/httpd/html/adm/gpl.txt
33: #
34: # http://www.lon-capa.org/
35: #
1.12 foxr 36: =pod
37:
38: =head1 NAME
39:
40: Apache::loncfile - Construction space file management.
41:
42: =head1 SYNOPSIS
43:
44: Content handler for buttons on the top frame of the construction space
45: directory.
46:
47: =head1 INTRODUCTION
48:
49: loncfile is invoked when buttons in the top frame of the construction
1.17 harris41 50: space directory listing are clicked. All operations proceed in two phases.
1.12 foxr 51: The first phase describes to the user exactly what will be done. If the user
52: confirms the operation, the second phase commits the operation and indicates
53: completion. When the user dismisses the output of phase2, they are returned to
54: an "appropriate" directory listing in general.
55:
56: This is part of the LearningOnline Network with CAPA project
57: described at http://www.lon-capa.org.
58:
59: =head2 Subroutines
60:
61: =cut
1.1 www 62:
63: package Apache::loncfile;
64:
65: use strict;
66: use Apache::File;
1.15 foxr 67: use File::Basename;
1.1 www 68: use File::Copy;
1.18 foxr 69: use HTML::Entities();
1.1 www 70: use Apache::Constants qw(:common :http :methods);
71: use Apache::loncacc;
1.15 foxr 72: use Apache::lonnet;
1.33 www 73: use Apache::loncommon();
1.47 sakharuk 74: use Apache::lonlocal;
1.80 albertel 75: use LONCAPA qw(:DEFAULT :match);
76:
1.9 foxr 77:
1.45 taceyjo1 78: my $DEBUG=0;
1.10 foxr 79: my $r; # Needs to be global for some stuff RF.
1.12 foxr 80:
81: =pod
82:
83: =item Debug($request, $message)
84:
1.17 harris41 85: If debugging is enabled puts out a debugging message determined by the
1.12 foxr 86: caller. The debug message goes to the Apache error log file. Debugging
1.17 harris41 87: is enabled by setting the module global DEBUG variable to nonzero (TRUE).
1.12 foxr 88:
89: Parameters:
90:
91: =over 4
92:
1.17 harris41 93: =item $request - The current request operation.
1.12 foxr 94:
1.17 harris41 95: =item $message - The message to put in the log file.
1.12 foxr 96:
97: =back
98:
99: Returns:
100: nothing.
101:
102: =cut
103:
1.9 foxr 104: sub Debug {
1.55 albertel 105: # Put out the indicated message butonly if DEBUG is true.
106: if ($DEBUG) {
1.73 albertel 107: my ($r,$message) = @_;
1.55 albertel 108: $r->log_reason($message);
109: }
1.12 foxr 110: }
111:
112: =pod
113:
114: =item URLToPath($url)
115:
116: Convert a URL to a file system path.
117:
118: In order to manipulate the construction space objects, it is necessary
119: to access url identified objects a filespace objects. This function
120: translates a construction space URL to a file system path.
121: Parameters:
122:
123: =over 4
124:
125: =item Url - string [in] The url to convert.
126:
127: =back
128:
129: Returns:
130:
131: =over 4
132:
1.16 harris41 133: =item The corresponding file system path.
1.12 foxr 134:
135: =back
136:
137: Global References
138:
139: =over 4
140:
141: =item $r - Request object [in] Referenced in the &Debug calls.
142:
143: =back
144:
145: =cut
146:
147: sub URLToPath {
1.55 albertel 148: my $Url = shift;
149: &Debug($r, "UrlToPath got: $Url");
150: $Url=~ s/\/+/\//g;
151: $Url=~ s/^http\:\/\/[^\/]+//;
152: $Url=~ s/^\///;
1.80 albertel 153: $Url=~ s/(\~|priv\/)($match_username)\//\/home\/$2\/public_html\//;
1.55 albertel 154: &Debug($r, "Returning $Url \n");
155: return $Url;
1.12 foxr 156: }
157:
1.36 www 158: sub url {
159: my $fn=shift;
1.80 albertel 160: $fn=~s/^\/home\/($match_username)\/public\_html/\/priv\/$1/;
1.56 albertel 161: $fn=&HTML::Entities::encode($fn,'<>"&');
1.36 www 162: return $fn;
163: }
164:
165: sub display {
166: my $fn=shift;
1.80 albertel 167: $fn=~s-^/home/($match_username)/public_html-/priv/$1-;
1.87 ! albertel 168: return '<span class="LC_filename">'.$fn.'</span>';
1.36 www 169: }
170:
1.50 www 171:
172: # see if the file is
173: # a) published (return 0 if not)
174: # b) if, so obsolete (return 0 if not)
175:
176: sub obsolete_unpub {
177: my ($user,$domain,$construct)=@_;
178: my $published=$construct;
179: $published=~
180: s/^\/home\/$user\/public\_html\//\/home\/httpd\/html\/res\/$domain\/$user\//;
181: if (-e $published) {
182: if (&Apache::lonnet::metadata($published,'obsolete')) {
183: return 1;
184: }
185: return 0;
186: } else {
187: return 1;
188: }
189: }
190:
1.70 raeburn 191: # see if directory is empty
1.74 www 192: # ignores any .meta, .save, .bak, and .log files created for a previously
1.70 raeburn 193: # published file, which has since been marked obsolete and deleted.
194: sub empty_directory {
195: my ($dirname,$phase) = @_;
196: if (opendir DIR, $dirname) {
197: my @files = grep(!/^\.\.?$/, readdir(DIR)); # ignore . and ..
198: if (@files) {
1.74 www 199: my @orphans = grep(/\.(meta|save|log|bak)$/,@files);
1.70 raeburn 200: if (scalar(@files) - scalar(@orphans) > 0) {
201: return 0;
202: } else {
203: if (($phase eq 'Delete2') && (@orphans > 0)) {
204: foreach my $file (@orphans) {
1.74 www 205: if ($file =~ /\.(meta|save|log|bak)$/) {
1.70 raeburn 206: unlink($dirname.$file);
207: }
208: }
209: }
210: }
211: }
212: closedir(DIR);
213: return 1;
214: }
215: return 0;
216: }
1.50 www 217:
1.12 foxr 218: =pod
219:
1.39 www 220: =item exists($user, $domain, $file)
1.12 foxr 221:
1.17 harris41 222: Determine if a resource file name has been published or exists
1.12 foxr 223: in the construction space.
224:
225: Parameters:
226:
227: =over 4
228:
1.85 albertel 229: =item $user - string [in] - Name of the user for which to check.
1.12 foxr 230:
1.85 albertel 231: =item $domain - string [in] - Name of the domain in which the resource
1.12 foxr 232: might have been published.
233:
1.85 albertel 234: =item $file - string [in] - Name of the file.
235:
236: =item $creating - string [in] - optional, type of object being created,
237: either 'directory' or 'file'. Defaults to
238: 'file' if unspecified.
1.12 foxr 239:
240: =back
241:
242: Returns:
243:
244: =over 4
245:
1.83 albertel 246: =item string - Either undef, 'warning' or 'error' depending on the
247: type of problem
248:
1.12 foxr 249: =item string - Either where the resource exists as an html string that can
250: be embedded in a dialog or an empty string if the resource
251: does not exist.
252:
253: =back
254:
255: =cut
256:
1.8 albertel 257: sub exists {
1.85 albertel 258: my ($user, $domain, $construct, $creating) = @_;
259: $creating ||= 'file';
260:
1.55 albertel 261: my $published=$construct;
262: $published=~
1.83 albertel 263: s{^/home/$user/public_html/}{/home/httpd/html/res/$domain/$user/};
264: my ($type,$result);
1.55 albertel 265: if ( -d $construct ) {
1.83 albertel 266: return ('error','<p><span class="LC_error">'.&mt('Error: destination for operation is an existing directory.').'</span></p>');
267:
1.55 albertel 268: }
1.83 albertel 269:
1.55 albertel 270: if ( -e $published) {
1.83 albertel 271: if ( -e $construct ) {
272: $type = 'warning';
273: $result.='<p><span class="LC_warning">'.&mt('Warning: target file exists, and has been published!').'</span></p>';
274: } else {
1.85 albertel 275: my $published_type = (-d $published) ? 'directory' : 'file';
276:
277: if ($published_type eq $creating) {
278: $type = 'warning';
279: $result.='<p><span class="LC_warning">'.&mt("Warning: a published $published_type of this name exists.").'</span></p>';
280: } else {
281: $type = 'error';
282: $result.='<p><span class="LC_error">'.&mt("Error: a published $published_type of this name exists.").'</span></p>';
283: }
1.83 albertel 284: }
1.55 albertel 285: } elsif ( -e $construct) {
1.83 albertel 286: $type = 'warning';
287: $result.='<p><span class="LC_warning">'.&mt('Warning: target file exists!').'</span></p>';
1.55 albertel 288: }
1.83 albertel 289:
290: return ($type,$result);
1.8 albertel 291: }
292:
1.12 foxr 293: =pod
294:
295: =item checksuffix($old, $new)
296:
297: Determine if a resource filename suffix (the stuff after the .) would change
298: as a result of this operation.
299:
300: Parameters:
301:
302: =over 4
303:
304: =item $old = string [in] Previous filename.
305:
306: =item $new = string [in] Resultant filename.
307:
308: =back
309:
310: Returns:
311:
312: =over 4
313:
1.17 harris41 314: =item Empty string if everything worked.
1.12 foxr 315:
316: =item String containing an error message if there was a problem.
317:
318: =back
319:
320: =cut
321:
1.8 albertel 322: sub checksuffix {
323: my ($old,$new) = @_;
324: my $result;
325: my $oldsuffix;
326: my $newsuffix;
327: if ($new=~m:(.*/*)([^/]+)\.(\w+)$:) { $newsuffix=$3; }
328: if ($old=~m:(.*)/+([^/]+)\.(\w+)$:) { $oldsuffix=$3; }
1.82 albertel 329: if (lc($oldsuffix) ne lc($newsuffix)) {
1.12 foxr 330: $result.=
1.82 albertel 331: '<p><span class="LC_warning">'.&mt('Warning: change of MIME type!').'</span></p>';
1.8 albertel 332: }
333: return $result;
334: }
1.32 albertel 335:
336: sub cleanDest {
1.64 albertel 337: my ($request,$dest,$subdir,$fn,$uname)=@_;
1.32 albertel 338: #remove bad characters
1.58 albertel 339: my $foundbad=0;
340: if ($subdir && $dest =~/\./) {
341: $foundbad=1;
342: $dest=~s/\.//g;
343: }
1.87 ! albertel 344: $dest =~ s/(\s+$|^\s+)//g;
1.72 albertel 345: if ($dest=~/[\#\?&%\":]/) {
1.58 albertel 346: $foundbad=1;
1.72 albertel 347: $dest=~s/[\#\?&%\":]//g;
1.58 albertel 348: }
1.63 albertel 349: if ($dest=~m|/|) {
350: my ($newpath)=($dest=~m|(.*)/|);
1.64 albertel 351: $newpath=&relativeDest($fn,$newpath,$uname);
352: if (! -d "$newpath") {
1.87 ! albertel 353: $request->print("<p><span class=\"LC_error\">".&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).'"')."</span></p>");
1.63 albertel 354: $dest=~s|.*/||;
355: }
356: }
1.84 albertel 357: if ($dest =~ /\.(\d+)\.(\w+)$/){
358: $request->print('<span class="LC_error">'
1.87 ! albertel 359: .&mt('Bad filename [_1].<br /> <tt>(name).(number).(extension)</tt> not allowed. <br /> Removing the <tt>.number.</tt> from requested filename.',&display($dest))
1.84 albertel 360: .'</span>');
361: $dest =~ s/\.(\d+)(\.\w+)$/$2/;
362: }
1.58 albertel 363: if ($foundbad) {
1.83 albertel 364: $request->print("<p><span class=\"LC_error\">".&mt('Invalid characters in requested name have been removed.')."</span></p>");
1.32 albertel 365: }
366: return $dest;
367: }
368:
1.36 www 369: sub relativeDest {
370: my ($fn,$newfilename,$uname)=@_;
371: if ($newfilename=~/^\//) {
372: # absolute, simply add path
373: $newfilename='/home/'.$uname.'/public_html/';
374: } else {
375: my $dir=$fn;
376: $dir=~s/\/[^\/]+$//;
377: $newfilename=$dir.'/'.$newfilename;
378: }
379: $newfilename=~s://+:/:g; # remove duplicate /
380: while ($newfilename=~m:/\.\./:) {
381: $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
382: }
383: return $newfilename;
384: }
385:
1.12 foxr 386: =pod
387:
388: =item CloseForm1($request, $user, $file)
389:
390: Close of a form on the successful completion of phase 1 processing
391:
392: Parameters:
393:
394: =over 4
395:
396: =item $request - Apache Request Object [in] - Apache server request object.
397:
1.13 foxr 398: =item $cancelurl - the url to go to on cancel.
1.12 foxr 399:
400: =back
401:
402: =cut
403:
404: sub CloseForm1 {
1.55 albertel 405: my ($request, $fn) = @_;
406: $request->print('<p><input type="submit" value="'.&mt('Continue').'" /></p></form>');
407: $request->print('<form action="'.&url($fn).
408: '" method="POST"><p><input type="submit" value="'.&mt('Cancel').'" /></p></form>');
1.12 foxr 409: }
410:
411:
412: =pod
413:
414: =item CloseForm2($request, $user, $directory)
415:
416: Successfully close off the phase 2 form.
417:
418: Parameters:
419:
420: =over 4
421:
422: =item $request - Apache Request object [in] - The request that is being
423: executed.
424:
425: =item $user - string [in] - Name of the user that is initiating the
426: request.
427:
428: =item $directory - string [in] - Directory in which the operation is
429: being done relative to the top level construction space
430: directory.
431:
432: =back
433:
434: =cut
435:
436: sub CloseForm2 {
1.55 albertel 437: my ($request, $user, $fn) = @_;
438: $request->print('<h3><a href="'.&url($fn).'/">'.&mt('Done').'</a></h3>');
1.12 foxr 439: }
440:
441: =pod
442:
443: =item Rename1($request, $filename, $user, $domain, $dir)
444:
445: Perform phase 1 processing of the file rename operation.
446:
447: Parameters:
448:
449: =over 4
450:
451: =item $request - Apache Request Object [in] The request object for the
452: current request.
453:
454: =item $filename - The filename relative to construction space.
455:
456: =item $user - Name of the user making the request.
457:
458: =item $domain - User login domain.
459:
460: =item $dir - Directory specification of the path to the file.
461:
462: =back
463:
464: Side effects:
465:
466: =over 4
467:
468: =item A new form is displayed prompting for confirmation. The newfilename
469: hidden field of this form is loaded with
470: new filename relative to the current directory ($dir).
471:
472: =back
473:
474: =cut
475:
476: sub Rename1 {
1.52 albertel 477: my ($request, $user, $domain, $fn, $newfilename, $style) = @_;
1.36 www 478:
479: if(-e $fn) {
480: if($newfilename) {
1.42 albertel 481: # is dest a dir
1.52 albertel 482: if ($style eq 'move') {
483: if (-d $newfilename) {
484: if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; }
485: }
1.42 albertel 486: }
1.29 albertel 487: if ($newfilename =~ m|/[^\.]+$|) {
1.36 www 488: #no extension add on original extension
489: if ($fn =~ m|/[^\.]*\.([^\.]+)$|) {
1.24 albertel 490: $newfilename.='.'.$1;
491: }
492: }
1.36 www 493: $request->print(&checksuffix($fn, $newfilename));
1.27 albertel 494: #renaming a dir, delete the trailing /
1.39 www 495: #remove second to last element for current dir
496: if (-d $fn) {
1.53 www 497: $newfilename=~/\.(\w+)$/;
498: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
1.82 albertel 499: $request->print('<br /><span classr="LC_warning">'.
1.55 albertel 500: &mt('Cannot change MIME type of a directory').
1.82 albertel 501: '</span>'.
1.55 albertel 502: '<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
1.53 www 503: return;
504: }
1.39 www 505: $newfilename=~s/\/[^\/]+\/([^\/]+)$/\/$1/;
1.27 albertel 506: }
1.42 albertel 507: $newfilename=~s://+:/:g; # remove duplicate /
508: while ($newfilename=~m:/\.\./:) {
509: $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
510: }
1.83 albertel 511: my ($type, $return)=&exists($user, $domain, $newfilename);
1.21 albertel 512: $request->print($return);
1.83 albertel 513: if ($type eq 'error') {
1.47 sakharuk 514: $request->print('<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
1.21 albertel 515: return;
516: }
1.50 www 517: unless (&obsolete_unpub($user,$domain,$fn)) {
518: $request->print('<h3>'.&mt('Cannot rename or move non-obsolete published file').'</h3>'.
519: '<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
520: return;
521: }
1.52 albertel 522: my $action;
523: if ($style eq 'rename') {
524: $action=&mt('Rename');
525: } else {
526: $action=&mt('Move');
527: }
1.23 albertel 528: $request->print('<input type="hidden" name="newfilename" value="'.
1.12 foxr 529: $newfilename.
1.52 albertel 530: '" /><p>'.$action.' '.&display($fn).
1.87 ! albertel 531: '</p><br />to '.&display($newfilename).'?</p>');
1.36 www 532: &CloseForm1($request, $fn);
1.12 foxr 533: } else {
1.47 sakharuk 534: $request->print('<p>'.&mt('No new filename specified.').'</p></form>');
1.12 foxr 535: return;
536: }
537: } else {
1.47 sakharuk 538: $request->print('<p> '.&mt('No such file').': '.&display($fn).'</p></form>');
1.12 foxr 539: return;
540: }
541:
542: }
1.55 albertel 543:
1.12 foxr 544: =pod
545:
546: =item Delete1
547:
548: Performs phase 1 processing of the delete operation. In phase one
549: we just check to be sure the file exists.
550:
551: Parameters:
552:
553: =over 4
554:
1.36 www 555: =item $request - Apache Request Object [in] request object for the current
1.12 foxr 556: request.
557:
1.36 www 558: =item $user - string [in] Name of the user initiating the request.
1.12 foxr 559:
1.36 www 560: =item $domain - string [in] Domain the initiating user is logged in as
1.13 foxr 561:
1.36 www 562: =item $filename - string [in] Source filename.
1.12 foxr 563:
564: =back
565:
566: =cut
567:
568: sub Delete1 {
1.55 albertel 569: my ($request, $user, $domain, $fn) = @_;
1.12 foxr 570:
1.55 albertel 571: if( -e $fn) {
572: $request->print('<input type="hidden" name="newfilename" value="'.
573: $fn.'"/>');
1.70 raeburn 574: if (-d $fn) {
575: unless (&empty_directory($fn,'Delete1')) {
576: $request->print('<h3>'.&mt('Only empty directories may be deleted.').'</h3>'.
577: 'You must delete the contents of the directory first.<br />'.
578: '<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
579: return;
580: }
581: } else {
582: unless (&obsolete_unpub($user,$domain,$fn)) {
583: $request->print('<h3>'.&mt('Cannot delete non-obsolete published file').'</h3>'.
1.55 albertel 584: '<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
1.70 raeburn 585: return;
586: }
587: }
1.55 albertel 588: $request->print('<p>'.&mt('Delete').' '.&display($fn).'?</p>');
589: &CloseForm1($request, $fn);
590: } else {
591: $request->print('<p>'.&mt('No such file').': '.&display($fn).'</p></form>');
1.50 www 592: }
1.12 foxr 593: }
594:
595: =pod
596:
597: =item Copy1($request, $user, $domain, $filename, $newfilename)
598:
599: Performs phase 1 processing of the construction space copy command.
1.17 harris41 600: Ensure that the source file exists. Ensure that a destination exists,
601: also warn if the destination already exists.
1.12 foxr 602:
603: Parameters:
604:
605: =over 4
606:
607: =item $request - Apache Request Object [in] request object for the current
608: request.
609:
610: =item $user - string [in] Name of the user initiating the request.
611:
612: =item $domain - string [in] Domain the initiating user is logged in as
613:
1.36 www 614: =item $fn - string [in] Source filename.
1.12 foxr 615:
616: =item $newfilename-string [in] Destination filename.
617:
618: =back
619:
620: =cut
621:
622: sub Copy1 {
1.42 albertel 623: my ($request, $user, $domain, $fn, $newfilename) = @_;
1.12 foxr 624:
1.42 albertel 625: if(-e $fn) {
626: # is dest a dir
627: if (-d $newfilename) {
628: if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; }
629: }
630: if ($newfilename =~ m|/[^\.]+$|) {
631: #no extension add on original extension
632: if ($fn =~ m|/[^\.]*\.([^\.]+)$|) { $newfilename.='.'.$1; }
633: }
634: $newfilename=~s://+:/:g; # remove duplicate /
635: while ($newfilename=~m:/\.\./:) {
636: $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
637: }
638: $request->print(&checksuffix($fn,$newfilename));
1.83 albertel 639: my ($type,$return)=&exists($user, $domain, $newfilename);
1.42 albertel 640: $request->print($return);
1.83 albertel 641: if ($type eq 'error') {
1.47 sakharuk 642: $request->print('<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
1.42 albertel 643: return;
644: }
645: $request->print('<input type="hidden" name="newfilename" value="'.
646: $newfilename.
1.47 sakharuk 647: '" /><p>'.&mt('Copy').' '.&display($fn).'<br />to '.
1.42 albertel 648: &display($newfilename).'?</p>');
649: &CloseForm1($request, $fn);
650: } else {
1.47 sakharuk 651: $request->print('<p>'.&mt('No such file').': '.&display($fn).'</p></form>');
1.21 albertel 652: }
1.19 albertel 653: }
654:
655: =pod
656:
1.12 foxr 657: =item NewDir1
658:
659: Does all phase 1 processing of directory creation:
660: Ensures that the user provides a new directory name,
661: and that the directory does not already exist.
662:
663: Parameters:
664:
665: =over 4
666:
667: =item $request - Apache Request Object [in] - Server request object for the
1.17 harris41 668: current url.
1.12 foxr 669:
670: =item $username - Name of the user that is requesting the directory creation.
671:
1.36 www 672: =item $domain - Domain user is in
673:
674: =item $fn - source file.
1.12 foxr 675:
676: =item $newdir - Name of the directory to be created; path relative to the
677: top level of construction space.
678: =back
679:
680: Side Effects:
681:
682: =over 4
683:
684: =item A new form is displayed. Clicking on the confirmation button
685: causes the newdir operation to transition into phase 2. The hidden field
686: "newfilename" is set with the construction space path to the new directory.
687:
688:
689: =back
690:
691: =cut
692:
693:
1.55 albertel 694: sub NewDir1 {
695: my ($request, $username, $domain, $fn, $newfilename, $mode) = @_;
696:
1.85 albertel 697: my ($type, $result)=&exists($username,$domain,$newfilename,'directory');
1.83 albertel 698: $request->print($result);
1.85 albertel 699: if ($type eq 'error') {
1.83 albertel 700: $request->print('</form>');
1.55 albertel 701: } else {
702: if ($mode eq 'testbank') {
703: $request->print('<input type="hidden" name="callingmode" value="testbank">');
704: } elsif ($mode eq 'imsimport') {
705: $request->print('<input type="hidden" name="callingmode" value="imsimport">');
706: }
707: $request->print('<input type="hidden" name="newfilename" value="'.
708: $newfilename.'" /><p>'.&mt('Make new directory').' '.
709: &display($newfilename).'?</p>');
710: &CloseForm1($request, $fn);
711: }
1.12 foxr 712: }
713:
1.44 taceyjo1 714:
715: sub Decompress1 {
1.55 albertel 716: my ($request, $user, $domain, $fn) = @_;
717: if( -e $fn) {
1.44 taceyjo1 718: $request->print('<input type="hidden" name="newfilename" value="'.$fn.'"/>');
1.47 sakharuk 719: $request->print('<p>'.&mt('Decompress').' '.&display($fn).'?</p>');
1.44 taceyjo1 720: &CloseForm1($request, $fn);
1.55 albertel 721: } else {
722: $request->print('<p>'.&mt('No such file').': '.&display($fn).'</p></form>');
723: }
1.44 taceyjo1 724: }
1.55 albertel 725:
1.12 foxr 726: =pod
727:
1.22 albertel 728: =item NewFile1
729:
730: Does all phase 1 processing of file creation:
731: Ensures that the user provides a new filename, adds proper extension
732: if needed and that the file does not already exist, if it is a html,
733: problem, page, or sequence, it then creates a form link to hand the
734: actual creation off to the proper handler.
735:
736: Parameters:
737:
738: =over 4
739:
740: =item $request - Apache Request Object [in] - Server request object for the
741: current url.
742:
743: =item $username - Name of the user that is requesting the directory creation.
744:
745: =item $domain - Name of the domain of the user
746:
1.36 www 747: =item $fn - Source file name
1.22 albertel 748:
749: =item $newfilename
750: - Name of the file to be created; no path information
751: =back
752:
753: Side Effects:
754:
755: =over 4
756:
757: =item 2 new forms are displayed. Clicking on the confirmation button
758: causes the browser to attempt to load the specfied URL, allowing the
1.36 www 759: proper handler to take care of file creation. There is also a Cancel
1.22 albertel 760: button which returns you to the driectory listing you came from
761:
762: =back
763:
764: =cut
765:
766: sub NewFile1 {
1.36 www 767: my ($request, $user, $domain, $fn, $newfilename) = @_;
1.22 albertel 768:
1.67 albertel 769: if ($env{'form.action'} =~ /new(.+)file/) {
1.22 albertel 770: my $extension=$1;
1.40 www 771:
772: ##Informs User (name).(number).(extension) not allowed
773: if($newfilename =~ /\.(\d+)\.(\w+)$/){
1.83 albertel 774: $r->print('<span class="LC_error">'.$newfilename.
1.69 www 775: ' - '.&mt('Bad Filename').'<br />('.&mt('name').').('.&mt('number').').('.&mt('extension').') '.
1.83 albertel 776: ' '.&mt('Not Allowed').'</span>');
1.69 www 777: return;
778: }
779: if($newfilename =~ /(\:\:\:|\&\&\&|\_\_\_)/){
1.83 albertel 780: $r->print('<span class="LC_error">'.$newfilename.
1.69 www 781: ' - '.&mt('Bad Filename').'<br />('.&mt('Must not include').' '.$1.') '.
1.83 albertel 782: ' '.&mt('Not Allowed').'</span>');
1.40 www 783: return;
784: }
1.22 albertel 785: if ($newfilename !~ /\Q.$extension\E$/) {
1.81 albertel 786: if ($newfilename =~ m|/[^/.]*\.(?:[^/.]+)$|) {
1.26 albertel 787: #already has an extension strip it and add in expected one
1.81 albertel 788: $newfilename =~ s|(/[^./])\.(?:[^.]+)$|$1|;
1.26 albertel 789: }
1.22 albertel 790: $newfilename.=".$extension";
791: }
1.31 albertel 792: }
1.83 albertel 793: my ($type, $result)=&exists($user,$domain,$newfilename);
794: $request->print($result);
795: if ($type eq 'error') {
796: $request->print('</form>');
1.39 www 797: } else {
1.83 albertel 798:
1.47 sakharuk 799: $request->print('<p>'.&mt('Make new file').' '.&display($newfilename).'?</p>');
1.22 albertel 800: $request->print('</form>');
1.36 www 801: $request->print('<form action="'.&url($newfilename).
1.47 sakharuk 802: '" method="POST"><p><input type="submit" value="'.&mt('Continue').'" /></p></form>');
1.36 www 803: $request->print('<form action="'.&url($fn).
1.47 sakharuk 804: '" method="POST"><p><input type="submit" value="'.&mt('Cancel').'" /></p></form>');
1.22 albertel 805: }
806: }
807:
808: =pod
809:
1.12 foxr 810: =item phaseone($r, $fn, $uname, $udom)
811:
812: Peforms phase one processing of the request. In phase one, error messages
813: are returned if the request cannot be performed (e.g. attempts to manipulate
814: files that are nonexistent). If the operation can be performed, what is
815: about to be done will be presented to the user for confirmation. If the
816: user confirms the request, then phase two is executed, the action
817: performed and reported to the user.
818:
819: Parameters:
820:
821: =over 4
822:
823: =item $r - request object [in] - The Apache request being executed.
824:
825: =item $fn = string [in] - The filename being manipulated by the
826: request.
827:
828: =item $uname - string [in] Name of user logged in and doing this action.
829:
1.17 harris41 830: =item $udom - string [in] Domain name under which the user logged in.
1.12 foxr 831:
832: =back
833:
834: =cut
1.8 albertel 835:
1.1 www 836: sub phaseone {
1.55 albertel 837: my ($r,$fn,$uname,$udom)=@_;
1.12 foxr 838:
1.58 albertel 839: my $doingdir=0;
1.67 albertel 840: if ($env{'form.action'} eq 'newdir') { $doingdir=1; }
841: my $newfilename=&cleanDest($r,$env{'form.newfilename'},$doingdir,$fn,$uname);
1.55 albertel 842: $newfilename=&relativeDest($fn,$newfilename,$uname);
843: $r->print('<form action="/adm/cfile" method="post">'.
844: '<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'.
845: '<input type="hidden" name="phase" value="two" />'.
1.67 albertel 846: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
1.12 foxr 847:
1.67 albertel 848: if ($env{'form.action'} eq 'rename') {
1.55 albertel 849: &Rename1($r, $uname, $udom, $fn, $newfilename, 'rename');
1.67 albertel 850: } elsif ($env{'form.action'} eq 'move') {
1.55 albertel 851: &Rename1($r, $uname, $udom, $fn, $newfilename, 'move');
1.67 albertel 852: } elsif ($env{'form.action'} eq 'delete') {
1.55 albertel 853: &Delete1($r, $uname, $udom, $fn);
1.67 albertel 854: } elsif ($env{'form.action'} eq 'decompress') {
1.55 albertel 855: &Decompress1($r, $uname, $udom, $fn);
1.67 albertel 856: } elsif ($env{'form.action'} eq 'copy') {
1.55 albertel 857: if($newfilename) {
858: &Copy1($r, $uname, $udom, $fn, $newfilename);
859: } else {
860: $r->print('<p>'.&mt('No new filename specified.').'</p></form>');
861: }
1.67 albertel 862: } elsif ($env{'form.action'} eq 'newdir') {
1.55 albertel 863: my $mode = '';
1.67 albertel 864: if (exists($env{'form.callingmode'}) ) {
865: $mode = $env{'form.callingmode'};
1.55 albertel 866: }
867: &NewDir1($r, $uname, $udom, $fn, $newfilename, $mode);
1.67 albertel 868: } elsif ($env{'form.action'} eq 'newfile' ||
869: $env{'form.action'} eq 'newhtmlfile' ||
870: $env{'form.action'} eq 'newproblemfile' ||
871: $env{'form.action'} eq 'newpagefile' ||
872: $env{'form.action'} eq 'newsequencefile' ||
873: $env{'form.action'} eq 'newrightsfile' ||
874: $env{'form.action'} eq 'newstyfile' ||
1.86 albertel 875: $env{'form.action'} eq 'newtaskfile' ||
1.67 albertel 876: $env{'form.action'} eq 'newlibraryfile' ||
877: $env{'form.action'} eq 'Select Action') {
1.65 www 878: my $empty=&mt('Type Name Here');
879: if (($newfilename!~/\/$/) && ($newfilename!~/$empty$/)) {
1.55 albertel 880: &NewFile1($r, $uname, $udom, $fn, $newfilename);
881: } else {
882: $r->print('<p>'.&mt('No new filename specified.').'</p></form>');
883: }
884: }
1.12 foxr 885: }
886:
887: =pod
888:
889: =item Rename2($request, $user, $directory, $oldfile, $newfile)
890:
1.17 harris41 891: Performs phase 2 processing of a rename reequest. This is where the
1.12 foxr 892: actual rename is performed.
893:
894: Parameters
895:
896: =over 4
897:
898: =item $request - Apache request object [in] The request being processed.
899:
900: =item $user - string [in] The name of the user initiating the request.
901:
902: =item $directory - string [in] The name of the directory relative to the
903: construction space top level of the renamed file.
904:
905: =item $oldfile - Name of the file.
906:
907: =item $newfile - Name of the new file.
908:
909: =back
910:
911: Returns:
912:
913: =over 4
914:
915: =item 1 Success.
916:
917: =item 0 Failure.
918:
919: =cut
920:
921: sub Rename2 {
922:
1.55 albertel 923: my ($request, $user, $directory, $oldfile, $newfile) = @_;
1.12 foxr 924:
1.55 albertel 925: &Debug($request, "Rename2 directory: ".$directory." old file: ".$oldfile.
926: " new file ".$newfile."\n");
927: &Debug($request, "Target is: ".$directory.'/'.
928: $newfile);
929: if (-e $oldfile) {
930:
931: my $oRN=$oldfile;
932: my $nRN=$newfile;
933: unless (rename($oldfile,$newfile)) {
1.83 albertel 934: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1.55 albertel 935: return 0;
936: }
937: ## If old name.(extension) exits, move under new name.
938: ## If it doesn't exist and a new.(extension) exists
939: ## delete it (only concern when renaming over files)
940: my $tmp1=$oRN.'.meta';
941: my $tmp2=$nRN.'.meta';
942: if(-e $tmp1){
943: unless(rename($tmp1,$tmp2)){ }
944: } elsif(-e $tmp2){
945: unlink $tmp2;
946: }
947: $tmp1=$oRN.'.save';
948: $tmp2=$nRN.'.save';
949: if(-e $tmp1){
950: unless(rename($tmp1,$tmp2)){ }
951: } elsif(-e $tmp2){
952: unlink $tmp2;
953: }
954: $tmp1=$oRN.'.log';
955: $tmp2=$nRN.'.log';
956: if(-e $tmp1){
957: unless(rename($tmp1,$tmp2)){ }
958: } elsif(-e $tmp2){
959: unlink $tmp2;
960: }
961: $tmp1=$oRN.'.bak';
962: $tmp2=$nRN.'.bak';
963: if(-e $tmp1){
964: unless(rename($tmp1,$tmp2)){ }
965: } elsif(-e $tmp2){
966: unlink $tmp2;
967: }
968: } else {
969: $request->print("<p> ".&mt('No such file').": ".&display($oldfile).'</p></form>');
970: return 0;
971: }
972: return 1;
1.12 foxr 973: }
1.55 albertel 974:
1.12 foxr 975: =pod
976:
977: =item Delete2($request, $user, $filename)
978:
979: Performs phase two of a delete. The user has confirmed that they want
980: to delete the selected file. The file is deleted and the results of the
981: delete attempt are indicated.
982:
983: Parameters:
984:
985: =over 4
986:
987: =item $request - Apache Request object [in] the request object for the current
988: delete operation.
989:
990: =item $user - string [in] The name of the user initiating the delete
991: request.
992:
1.17 harris41 993: =item $filename - string [in] The name of the file, relative to construction
994: space, to delete.
1.12 foxr 995:
996: =back
997:
998: Returns:
999: 1 - success.
1000: 0 - Failure.
1001:
1002: =cut
1003:
1004: sub Delete2 {
1.55 albertel 1005: my ($request, $user, $filename) = @_;
1.70 raeburn 1006: if (-d $filename) {
1007: unless (&empty_directory($filename,'Delete2')) {
1.83 albertel 1008: $request->print('<span class="LC_error">'.&mt('Error: Directory Non Empty').'</span>');
1.55 albertel 1009: return 0;
1010: } else {
1011: if(-e $filename) {
1012: unless(rmdir($filename)) {
1.83 albertel 1013: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1.55 albertel 1014: return 0;
1015: }
1016: } else {
1017: $request->print('<p> '.&mt('No such file').'. </p></form>');
1018: return 0;
1019: }
1020: }
1.48 taceyjo1 1021: } else {
1.55 albertel 1022: if(-e $filename) {
1023: unless(unlink($filename)) {
1.83 albertel 1024: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1.55 albertel 1025: return 0;
1026: }
1027: } else {
1028: $request->print('<p> '.&mt('No such file').'. </p></form>');
1029: return 0;
1.46 taceyjo1 1030: }
1.55 albertel 1031: }
1032: return 1;
1.12 foxr 1033: }
1034:
1035: =pod
1036:
1037: =item Copy2($request, $username, $dir, $oldfile, $newfile)
1038:
1039: Performs phase 2 of a copy. The file is copied and the status
1040: of that copy is reported back to the user.
1041:
1042: =over 4
1043:
1044: =item $request - Apache request object [in]; the apache request currently
1045: being executed.
1046:
1047: =item $username - string [in] Name of the user who is requesting the copy.
1048:
1049: =item $dir - string [in] Directory path relative to the construction space
1050: of the destination file.
1051:
1052: =item $oldfile - string [in] Name of the source file.
1053:
1054: =item $newfile - string [in] Name of the destination file.
1055:
1056:
1057: =back
1058:
1.71 raeburn 1059: Returns 0 failure, and 1 successs.
1.12 foxr 1060:
1061: =cut
1.1 www 1062:
1.12 foxr 1063: sub Copy2 {
1064: my ($request, $username, $dir, $oldfile, $newfile) = @_;
1065: &Debug($request ,"Will try to copy $oldfile to $newfile");
1066: if(-e $oldfile) {
1.71 raeburn 1067: if ($oldfile eq $newfile) {
1.83 albertel 1068: $request->print('<span class="LC_error">'.&mt('Warning').': '.&mt('Name of new file is the same as name of old file').' - '.&mt('no action taken').'.</span>');
1.71 raeburn 1069: return 1;
1070: }
1.12 foxr 1071: unless (copy($oldfile, $newfile)) {
1.83 albertel 1072: $request->print('<span class="LC_error">'.&mt('copy Error').': '.$!.'</span>');
1.12 foxr 1073: return 0;
1.61 albertel 1074: } elsif (!chmod(0660, $newfile)) {
1.83 albertel 1075: $request->print('<span class="LC_error">'.&mt('chmod error').': '.$!.'</span>');
1.61 albertel 1076: return 0;
1077: } elsif (-e $oldfile.'.meta' &&
1078: !copy($oldfile.'.meta', $newfile.'.meta') &&
1079: !chmod(0660, $newfile.'.meta')) {
1.83 albertel 1080: $request->print('<span class="LC_error">'.&mt('copy metadata error').
1081: ': '.$!.'</span>');
1.61 albertel 1082: return 0;
1.12 foxr 1083: } else {
1084: return 1;
1085: }
1.11 albertel 1086: } else {
1.47 sakharuk 1087: $request->print('<p> '.&mt('No such file').' </p>');
1.12 foxr 1088: return 0;
1.11 albertel 1089: }
1.12 foxr 1090: return 1;
1091: }
1.55 albertel 1092:
1.12 foxr 1093: =pod
1094:
1095: =item NewDir2($request, $user, $newdirectory)
1.1 www 1096:
1.12 foxr 1097: Performs phase 2 processing of directory creation. This involves creating the directory and
1098: reporting the results of that creation to the user.
1099:
1100: Parameters:
1101: =over 4
1102:
1103: =item $request - Apache request object [in]. Object representing the current HTTP request.
1104:
1105: =item $user - string [in] The name of the user that is initiating the request.
1106:
1107: =item $newdirectory - string [in] The full path of the directory being created.
1108:
1109: =back
1110:
1111: Returns 0 - failure 1 - success.
1112:
1113: =cut
1.8 albertel 1114:
1.12 foxr 1115: sub NewDir2 {
1.55 albertel 1116: my ($request, $user, $newdirectory) = @_;
1.12 foxr 1117:
1.55 albertel 1118: unless(mkdir($newdirectory, 02770)) {
1.83 albertel 1119: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1.55 albertel 1120: return 0;
1121: }
1122: unless(chmod(02770, ($newdirectory))) {
1.83 albertel 1123: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1.55 albertel 1124: return 0;
1125: }
1126: return 1;
1.1 www 1127: }
1.55 albertel 1128:
1.44 taceyjo1 1129: sub decompress2 {
1.55 albertel 1130: my ($r, $user, $dir, $file) = @_;
1131: &Apache::lonnet::appenv('cgi.file' => $file);
1132: &Apache::lonnet::appenv('cgi.dir' => $dir);
1133: my $result=&Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
1134: $r->print($result);
1135: &Apache::lonnet::delenv('cgi.file');
1136: &Apache::lonnet::delenv('cgi.dir');
1137: return 1;
1.44 taceyjo1 1138: }
1.55 albertel 1139:
1.12 foxr 1140: =pod
1141:
1142: =item phasetwo($r, $fn, $uname, $udom)
1143:
1144: Controls the phase 2 processing of file management
1145: requests for construction space. In phase one, the user
1146: was asked to confirm the operation. In phase 2, the operation
1147: is performed and the result is shown.
1148:
1149: The strategy is to break out the processing into specific action processors
1150: named action2 where action is the requested action and the 2 denotes
1151: phase 2 processing.
1152:
1153: Parameters:
1154:
1155: =over 4
1156:
1157: =item $r - Apache Request object [in] The request object for this httpd
1158: transaction.
1159:
1160: =item $fn - string [in] A filename indicating the object that is being
1161: manipulated.
1162:
1163: =item $uname - string [in] The name of the user initiating the file management
1164: request.
1165:
1166: =item $udom - string [in] The login domain of the user initiating the
1167: file management request.
1168: =back
1169:
1170: =cut
1171:
1.1 www 1172: sub phasetwo {
1173: my ($r,$fn,$uname,$udom)=@_;
1.12 foxr 1174:
1.9 foxr 1175: &Debug($r, "loncfile - Entering phase 2 for $fn");
1.12 foxr 1176:
1.78 banghart 1177: # Break down the file into its component pieces.
1.12 foxr 1178:
1.27 albertel 1179: my $dir; # Directory path
1180: my $main; # Filename.
1181: my $suffix; # Extension.
1.46 taceyjo1 1182: if ($fn=~m:(.*)/([^/]+):) {
1.27 albertel 1183: $dir=$1; # Directory path
1184: $main=$2; # Filename.
1.54 albertel 1185: }
1186: if($main=~m:\.(\w+)$:){ # Fixes problems with filenames with no extensions
1.68 albertel 1187: $suffix=$1; #This is the actually filename extension if it exists
1.66 albertel 1188: $main=~s/\.\w+$//; #strip the extension
1.54 albertel 1189: }
1.79 banghart 1190: my $dest; #
1191: my $dest_dir; # On success this is where we'll go.
1192: my $disp_newname; #
1193: my $dest_newname; #
1.55 albertel 1194: &Debug($r,"loncfile::phase2 dir = $dir main = $main suffix = $suffix");
1.67 albertel 1195: &Debug($r," newfilename = ".$env{'form.newfilename'});
1.9 foxr 1196:
1197: my $conspace=$fn;
1.12 foxr 1198:
1.55 albertel 1199: &Debug($r,"loncfile::phase2 Full construction space name: $conspace");
1.12 foxr 1200:
1.67 albertel 1201: &Debug($r,"loncfie::phase2 action is $env{'form.action'}");
1.12 foxr 1202:
1203: # Select the appropriate processing sub.
1.67 albertel 1204: if ($env{'form.action'} eq 'decompress') {
1.66 albertel 1205: $main .= '.'.$suffix;
1.55 albertel 1206: if(!&decompress2($r, $uname, $dir, $main)) {
1207: return ;
1208: }
1209: $dest = $dir."/.";
1.67 albertel 1210: } elsif ($env{'form.action'} eq 'rename' ||
1211: $env{'form.action'} eq 'move') {
1212: if($env{'form.newfilename'}) {
1.27 albertel 1213: if (!defined($dir)) {
1214: $fn=~m:^(.*)/:;
1.55 albertel 1215: $dir=$1;
1.27 albertel 1216: }
1.67 albertel 1217: if(!&Rename2($r, $uname, $dir, $fn, $env{'form.newfilename'})) {
1.12 foxr 1218: return;
1219: }
1.78 banghart 1220: $dest = $dir."/";
1.79 banghart 1221: $dest_newname = $env{'form.newfilename'};
1222: $env{'form.newfilename'} =~ /.+(\/.+$)/;
1223: $disp_newname = $1;
1224: $disp_newname =~ s/\///;
1.12 foxr 1225: }
1.67 albertel 1226: } elsif ($env{'form.action'} eq 'delete') {
1227: if(!&Delete2($r, $uname, $env{'form.newfilename'})) {
1.12 foxr 1228: return ;
1229: }
1230: # Once a resource is deleted, we just list the directory that
1231: # previously held it.
1232: #
1.20 albertel 1233: $dest = $dir."/."; # Parent dir.
1.67 albertel 1234: } elsif ($env{'form.action'} eq 'copy') {
1235: if($env{'form.newfilename'}) {
1236: if(!&Copy2($r, $uname, $dir, $fn, $env{'form.newfilename'})) {
1.44 taceyjo1 1237: return ;
1.55 albertel 1238: }
1.67 albertel 1239: $dest = $env{'form.newfilename'};
1.55 albertel 1240: } else {
1.47 sakharuk 1241: $r->print('<p>'.&mt('No New filename specified').'</p></form>');
1.12 foxr 1242: return;
1243: }
1244:
1.67 albertel 1245: } elsif ($env{'form.action'} eq 'newdir') {
1246: my $newdir= $env{'form.newfilename'};
1.12 foxr 1247: if(!&NewDir2($r, $uname, $newdir)) {
1248: return;
1249: }
1.55 albertel 1250: $dest = $newdir."/";
1.12 foxr 1251: }
1.67 albertel 1252: if ( ($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') && ( ($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport') ) ) {
1.55 albertel 1253: $r->print('<h3><a href="javascript:self.close()">'.&mt('Done').'</a></h3>');
1.51 raeburn 1254: } else {
1.79 banghart 1255: if ($env{'form.action'} eq 'rename') {
1256: $r->print('<h3><a href="'.&url($dest).'">'.&mt('Return to Directory').'</a></h3>');
1257: $r->print('<h3><a href="'.&url($dest_newname).'">'.$disp_newname.'</a></h3>');
1258: } else {
1259: $r->print('<h3><a href="'.&url($dest).'">'.&mt('Done').'</a></h3>');
1260: }
1.51 raeburn 1261: }
1.1 www 1262: }
1263:
1264: sub handler {
1265:
1.55 albertel 1266: $r=shift;
1.1 www 1267:
1.60 www 1268: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress','action','filename','newfilename']);
1.9 foxr 1269:
1.55 albertel 1270: &Debug($r, "loncfile.pm - handler entered");
1.67 albertel 1271: &Debug($r, " filename: ".$env{'form.filename'});
1272: &Debug($r, " newfilename: ".$env{'form.newfilename'});
1.36 www 1273: #
1274: # Determine the root filename
1275: # This could come in as "filename", which actually is a URL, or
1276: # as "qualifiedfilename", which is indeed a real filename in filesystem
1277: #
1.55 albertel 1278: my $fn;
1.1 www 1279:
1.67 albertel 1280: if ($env{'form.filename'}) {
1281: &Debug($r, "test: $env{'form.filename'}");
1.77 www 1282: $fn=&unescape($env{'form.filename'});
1.55 albertel 1283: $fn=&URLToPath($fn);
1.67 albertel 1284: } elsif($ENV{'QUERY_STRING'} && $env{'form.phase'} ne 'two') {
1.55 albertel 1285: #Just hijack the script only the first time around to inject the
1286: #correct information for further processing
1.77 www 1287: $fn=&unescape($env{'form.decompress'});
1.44 taceyjo1 1288: $fn=&URLToPath($fn);
1.67 albertel 1289: $env{'form.action'}="decompress";
1290: } elsif ($env{'form.qualifiedfilename'}) {
1291: $fn=$env{'form.qualifiedfilename'};
1.55 albertel 1292: } else {
1293: &Debug($r, "loncfile::handler - no form.filename");
1.67 albertel 1294: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1.55 albertel 1295: ' unspecified filename for cfile', $r->filename);
1296: return HTTP_NOT_FOUND;
1297: }
1.44 taceyjo1 1298:
1.55 albertel 1299: unless ($fn) {
1300: &Debug($r, "loncfile::handler - doctored url is empty");
1.67 albertel 1301: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1.55 albertel 1302: ' trying to cfile non-existing file', $r->filename);
1303: return HTTP_NOT_FOUND;
1304: }
1.1 www 1305:
1306: # ----------------------------------------------------------- Start page output
1.55 albertel 1307: my $uname;
1308: my $udom;
1309:
1310: ($uname,$udom)=
1311: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
1312: &Debug($r,
1313: "loncfile::handler constructaccess uname = $uname domain = $udom");
1314: unless (($uname) && ($udom)) {
1315: $r->log_reason($uname.' at '.$udom.
1.67 albertel 1316: ' trying to manipulate file '.$env{'form.filename'}.
1.55 albertel 1317: ' ('.$fn.') - not authorized',
1318: $r->filename);
1319: return HTTP_NOT_ACCEPTABLE;
1320: }
1321:
1.1 www 1322:
1.55 albertel 1323: &Apache::loncommon::content_type($r,'text/html');
1324: $r->send_http_header;
1325:
1.75 albertel 1326: my (%loaditem,$js);
1327:
1.67 albertel 1328: if ( ($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') && ( ($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport') ) ) {
1329: my $newdirname = $env{'form.newfilename'};
1.75 albertel 1330: $js = qq|
1331: <script type="text/javascript">
1.51 raeburn 1332: function writeDone() {
1333: var winName = window.opener
1334: window.focus();
1335: winName.document.dataForm.newdir.value = "$newdirname"
1336: setTimeout("self.close()",10000)
1337: }
1338: </script>
1.75 albertel 1339: |;
1.76 albertel 1340: $loaditem{'onload'} = "writeDone()";
1.55 albertel 1341: }
1.75 albertel 1342:
1343: $r->print(&Apache::loncommon::start_page('Construction Space File Operation',
1344: $js,
1345: {'add_entries' => \%loaditem,}));
1.1 www 1346:
1.55 albertel 1347: $r->print('<h3>'.&mt('Location').': '.&display($fn).'</h3>');
1.1 www 1348:
1.67 albertel 1349: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.83 albertel 1350: $r->print('<h3><span class="LC_error">'.&mt('Co-Author').': '.$uname.' at '.$udom.
1351: '</span></h3>');
1.55 albertel 1352: }
1353:
1354:
1.67 albertel 1355: &Debug($r, "loncfile::handler Form action is $env{'form.action'} ");
1356: if ($env{'form.action'} eq 'delete') {
1.55 albertel 1357: $r->print('<h3>'.&mt('Delete').'</h3>');
1.67 albertel 1358: } elsif ($env{'form.action'} eq 'rename') {
1.55 albertel 1359: $r->print('<h3>'.&mt('Rename').'</h3>');
1.67 albertel 1360: } elsif ($env{'form.action'} eq 'move') {
1.55 albertel 1361: $r->print('<h3>'.&mt('Move').'</h3>');
1.67 albertel 1362: } elsif ($env{'form.action'} eq 'newdir') {
1.55 albertel 1363: $r->print('<h3>'.&mt('New Directory').'</h3>');
1.67 albertel 1364: } elsif ($env{'form.action'} eq 'decompress') {
1.55 albertel 1365: $r->print('<h3>'.&mt('Decompress').'</h3>');
1.67 albertel 1366: } elsif ($env{'form.action'} eq 'copy') {
1.55 albertel 1367: $r->print('<h3>'.&mt('Copy').'</h3>');
1.67 albertel 1368: } elsif ($env{'form.action'} eq 'newfile' ||
1369: $env{'form.action'} eq 'newhtmlfile' ||
1370: $env{'form.action'} eq 'newproblemfile' ||
1371: $env{'form.action'} eq 'newpagefile' ||
1372: $env{'form.action'} eq 'newsequencefile' ||
1373: $env{'form.action'} eq 'newrightsfile' ||
1374: $env{'form.action'} eq 'newstyfile' ||
1.86 albertel 1375: $env{'form.action'} eq 'newtaskfile' ||
1.67 albertel 1376: $env{'form.action'} eq 'newlibraryfile' ||
1377: $env{'form.action'} eq 'Select Action' ) {
1.55 albertel 1378: $r->print('<h3>'.&mt('New Resource').'</h3>');
1379: } else {
1.75 albertel 1380: $r->print('<p>'.&mt('Unknown Action').' '.$env{'form.action'}.' </p>'.
1381: &Apache::loncommon::end_page());
1.55 albertel 1382: return OK;
1383: }
1.67 albertel 1384: if ($env{'form.phase'} eq 'two') {
1.55 albertel 1385: &Debug($r, "loncfile::handler entering phase2");
1386: &phasetwo($r,$fn,$uname,$udom);
1387: } else {
1388: &Debug($r, "loncfile::handler entering phase1");
1389: &phaseone($r,$fn,$uname,$udom);
1390: }
1.1 www 1391:
1.75 albertel 1392: $r->print(&Apache::loncommon::end_page());
1.55 albertel 1393: return OK;
1.1 www 1394: }
1395:
1396: 1;
1397: __END__
1.9 foxr 1398:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>