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