Annotation of loncom/publisher/lonpubdir.pm, revision 1.41
1.1 www 1: # The LearningOnline Network with CAPA
1.32 www 2: # Construction Space Directory Lister
1.16 albertel 3: #
1.41 ! www 4: # $Id: lonpubdir.pm,v 1.40 2003/09/25 22:30:06 www Exp $
1.16 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
1.1 www 27: #
28: #
29: # (TeX Content Handler
30: #
1.17 harris41 31: # YEAR=2000
1.1 www 32: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
33: #
34: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
1.17 harris41 35: # YEAR=2001
1.1 www 36: # 03/23 Guy Albertelli
37: # 03/24,03/29 Gerd Kortemeyer)
1.17 harris41 38: # 03/31,04/03,05/09,06/23,08/18,08/20 Gerd Kortemeyer
1.19 www 39: # 12/28 Gerd Kortemeyer
1.1 www 40: #
1.17 harris41 41: ###
1.1 www 42:
43: package Apache::lonpubdir;
44:
45: use strict;
46: use Apache::File;
47: use File::Copy;
48: use Apache::Constants qw(:common :http :methods);
1.6 www 49: use Apache::loncacc;
1.17 harris41 50: use Apache::loncommon();
1.39 www 51: use Apache::lonlocal;
1.1 www 52:
53: sub handler {
54:
55: my $r=shift;
56:
57: my $fn;
58:
1.23 foxr 59:
60:
61: $fn = getEffectiveUrl($r);
62:
63: # Validate access to the construction space and get username@domain.
1.6 www 64:
65: my $uname;
66: my $udom;
67:
1.9 www 68: ($uname,$udom)=
1.6 www 69: &Apache::loncacc::constructaccess(
1.9 www 70: $fn,$r->dir_config('lonDefDomain'));
71: unless (($uname) && ($udom)) {
1.6 www 72: $r->log_reason($uname.' at '.$udom.
1.32 www 73: ' trying to list directory '.$ENV{'form.filename'}.
1.6 www 74: ' ('.$fn.') - not authorized',
75: $r->filename);
76: return HTTP_NOT_ACCEPTABLE;
77: }
1.23 foxr 78:
1.32 www 79: # Remove trailing / from directory name.
1.23 foxr 80:
1.3 www 81: $fn=~s/\/$//;
1.1 www 82:
83: unless ($fn) {
84: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
1.2 www 85: ' trying to list empty directory', $r->filename);
1.1 www 86: return HTTP_NOT_FOUND;
87: }
88:
89: # ----------------------------------------------------------- Start page output
90:
1.23 foxr 91: my $thisdisfn=$fn;
92: $thisdisfn=~s/^\/home\/$uname\/public_html//; # subdirectory part of
93: # construction space.
94: my $docroot=$r->dir_config('lonDocRoot'); # Apache londocument root.
1.1 www 95:
1.23 foxr 96: my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn; # Resource directory
97: my $targetdir=$udom.'/'.$uname.$thisdisfn; # Publiction target directory.
1.25 www 98: my $linkdir='/priv/'.$uname.$thisdisfn; # Full URL name of constr space.
1.1 www 99:
100:
101:
1.26 www 102: &startpage($r, $uname, $udom, $thisdisfn); # Put out the start of page.
1.6 www 103:
1.23 foxr 104: # Start off the diretory table.
1.1 www 105:
1.2 www 106: $r->print('<table border=2>'.
1.39 www 107: '<tr><th>'.&mt('Actions').'</th><th>'.&mt('Name').'</th><th>'.
108: &mt('Title').'</th>'.
109: '<th>'.&mt('Status').'</th><th>'.&mt('Last Modified').
110: '</th></tr>');
1.1 www 111:
1.2 www 112: my $filename;
1.23 foxr 113: my $dirptr=16384; # Mask indicating a directory in stat.cmode.
1.1 www 114:
1.2 www 115: opendir(DIR,$fn);
1.10 albertel 116: my @files=sort(readdir(DIR));
1.11 albertel 117: foreach my $filename (@files) {
1.2 www 118: my ($cdev,$cino,$cmode,$cnlink,
119: $cuid,$cgid,$crdev,$csize,
120: $catime,$cmtime,$cctime,
121: $cblksize,$cblocks)=stat($fn.'/'.$filename);
1.12 www 122:
1.10 albertel 123: my $extension='';
124: if ($filename=~/\.(\w+)$/) { $extension=$1; }
1.15 matthew 125: if ($cmode&$dirptr) {
1.21 foxr 126: putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime);
1.17 harris41 127: } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') {
1.22 foxr 128: putresource($r, $uname, $filename, $thisdisfn, $resdir,
129: $targetdir, $linkdir, $cmtime);
1.14 albertel 130: } else {
1.15 matthew 131: # "hidden" extension and not a directory, so hide it away.
1.2 www 132: }
133: }
134: closedir(DIR);
135:
136: $r->print('</table></body></html>');
1.1 www 137: return OK;
138: }
1.21 foxr 139: #
1.23 foxr 140: # Gets the effective URL of the request and returns it:
141: # $effn = getEffectiveUrl($r);
142: # $r - The Apache Request object.
143: sub getEffectiveUrl {
144: my $r = shift;
145: my $fn;
146:
147: if ($ENV{'form.filename'}) { # If a form filename is defined.
148: $fn=$ENV{'form.filename'};
149: #
150: # Replace the ~username of the URL with /home/username/public_html
151: # so that we don't have to worry about ~ expansion internally.
152: #
1.32 www 153: $fn=~s/^http\:\/\/[^\/]+\///;
154: $fn=~s/^\///;
155: $fn=~s/\~(\w+)/\/home\/$1\/public_html/;
1.23 foxr 156:
157: # Remove trailing / strings (?)
158:
159: $fn=~s/\/[^\/]+$//;
1.24 albertel 160: } else {
161: # If no form is defined, use request filename.
162: $fn = $r->filename();
163: my $lonDocRoot=$r->dir_config('lonDocRoot');
164: if ( $fn =~ /$lonDocRoot/ ) {
165: #internal authentication, needs fixup.
166: $fn = $r->uri(); # non users do not get the full path request
167: # through SCRIPT_FILENAME
168: $fn=~s|^/~(\w+)|/home/$1/public_html|;
169: }
1.23 foxr 170: }
1.37 www 171: $fn=~s/\/+/\//g;
1.23 foxr 172: return $fn;
173: }
174: #
175: # Output the header of the page. This includes:
176: # - The HTML header
177: # - The H1/H3 stuff which includes the directory.
178: #
179: # startpage($r, $uame, $udom, $thisdisfn);
180: # $r - The apache request object.
181: # $uname - User name.
182: # $udom - Domain name the user is logged in under.
183: # $thisdisfn - Displayable version of the filename.
1.26 www 184:
1.23 foxr 185: sub startpage {
186: my ($r, $uname, $udom, $thisdisfn) = @_;
187:
1.39 www 188: &Apache::loncommon::content_type($r,'text/html');
1.23 foxr 189: $r->send_http_header;
190:
191: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
192:
1.26 www 193: $r->print(&Apache::loncommon::bodytag(undef,undef,undef,1));
1.29 www 194: my $pubdirscript=(<<ENDPUBDIRSCRIPT);
195: <script>
1.37 www 196: // Store directory location for menu bar to find
197:
198: parent.lastknownpriv='/~$uname/$thisdisfn/';
199:
200: // Confirmation dialogues
201:
1.29 www 202: function pubdir(theform) {
203: if (confirm('Publish complete directory?')) {
204: theform.submit();
205: }
206: }
207: function pubrecdir(theform) {
208: if (confirm('Publish directory and all subdirectories?')) {
209: theform.pubrec.value='1';
210: theform.submit();
211: }
212: }
213: </script>
214: ENDPUBDIRSCRIPT
215:
1.39 www 216: $r->print('<h1>'.&mt('Construction Space Directory').' <tt>'.
1.31 albertel 217: $thisdisfn.'/</tt></h1>'.
218: '<script type="text/javascript">top.document.title = \''.
219: $thisdisfn.'/ - LON-CAPA Construction Space\';</script>'.
220: $pubdirscript.
1.26 www 221: '<form method="post" action="/adm/publish" target="_parent">'.
1.35 www 222: '<table><tr><td><input type="hidden" name="filename" value="/~'.
1.26 www 223: $uname.$thisdisfn.'/" />'.
1.40 www 224: '<input type="button" onClick="pubdir(this.form);" value="'.
225: &mt('Publish Directory').'" />'.
1.29 www 226: '<input type="hidden" name="pubrec" value="" />'.
1.40 www 227: '<input type="button" onClick="pubrecdir(this.form);" value="'.
228: &mt('Publish Directory and Sub Directories').'" /></td><td>'.
1.28 www 229: '<input type="button" onClick="window.location='."'/~".
1.40 www 230: $uname.$thisdisfn."/default.meta'".'" value="'.
231: &mt('Edit Directory Catalog Information').'" /></td></tr><tr><td><input type="checkbox" name="forcerepub" /> '.&mt('Force publication of unmodified files').'.</td><td> </td></tr></table></form>');
1.23 foxr 232:
233: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
1.39 www 234: $r->print('<h3>'.&mt('Co-Author').': '.$uname.' at '.$udom.
1.23 foxr 235: '</h3>');
236: }
237: }
238:
239: #
240: # Get the title string or "[untitled]" if the file has no title metadata:
241: # Without the latter substitution, it's impossible to examine metadata for
242: # untitled resources. Resources may be legitimately untitled, to prevent
243: # searches from locating them.
244: #
245: # $str = getTitleString($fullname);
246: # $fullname - Fully qualified filename to check.
247: #
248: sub getTitleString {
249: my $fullname = shift;
250: my $title = &Apache::lonnet::metadata($fullname, 'title');
251:
252: unless ($title) {
1.40 www 253: $title = "[".&mt('untitled')."]";
1.23 foxr 254: }
255: return $title;
256: }
257:
258:
259: #
1.21 foxr 260: # Put out a directory table row:
261: # putdirectory(r, base, here, dirname, modtime)
262: # r - Apache request object.
263: # reqfile - File in request.
264: # here - Where we are in directory tree.
265: # dirname - Name of directory special file.
266: # modtime - Encoded modification time.
267: #
268: sub putdirectory {
269: my ($r, $reqfile, $here, $dirname, $modtime) = @_;
270:
271: # construct the display filename: the directory name unless ..:
272:
273: my $disfilename = $dirname;
274: if ($dirname eq '..') {
1.39 www 275: $disfilename = '<i>'.&mt('Parent Directory').'</i>';
1.21 foxr 276: }
277: unless (( ($dirname eq '..') && ($reqfile eq '')) ||
278: ($dirname eq '.')) {
1.25 www 279: $r->print('<tr bgcolor="#CCCCFF">'.
280: '<td>Go to ...</td>'.
281: '<td><a href="'.$here.'/'.$dirname.'/" target="_top">'.
1.21 foxr 282: $disfilename.'</a></td>'.
283: '<td> </td>'.
284: '<td> </td>'.
285: '<td>'.localtime($modtime).'</td>'.
1.25 www 286: "</tr>\n");
1.21 foxr 287: }
288: return OK;
289: }
1.22 foxr 290: #
291: # Put a table row for a file resource.
292: #
293: sub putresource {
294: my ($r, $uname, $filename, $thisdisfn,
295: $resdir, $targetdir, $linkdir,
296: $cmtime) = @_;
297:
298: my $status='Unpublished';
1.25 www 299: my $bgcolor='#FFCCCC';
1.22 foxr 300: my $title=' ';
301: if (-e $resdir.'/'.$filename) {
302: my ($rdev,$rino,$rmode,$rnlink,
303: $ruid,$rgid,$rrdev,$rsize,
304: $ratime,$rmtime,$rctime,
305: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
306: if ($rmtime>=$cmtime) {
1.41 ! www 307: $status=&mt('Published');
1.25 www 308: $bgcolor='#CCFFCC';
1.40 www 309: if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
1.41 ! www 310: $status=&mt('Obsolete');
1.40 www 311: $bgcolor='#AAAAAA';
312: }
1.23 foxr 313: $title='<a href="/res/'.$targetdir.'/'.$filename.
314: '.meta" target=cat>'.
315: getTitleString($targetdir.'/'.$filename, 'title').'</a>';
1.22 foxr 316: } else {
1.41 ! www 317: $status=&mt('Modified');
1.25 www 318: $bgcolor='#FFFFCC';
1.22 foxr 319: $title='<a href="/res/'.$targetdir.'/'.$filename.'.meta" target=cat>'.
1.25 www 320: getTitleString($targetdir.'/'.$filename,'title').'</a>';
1.22 foxr 321: if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
322: $status.='<br><a href="/adm/diff?filename=/~'.$uname.
323: $thisdisfn.'/'.$filename.
1.41 ! www 324: '&versiontwo=priv" target=cat>'.&mt('Diffs').'</a>';
1.22 foxr 325: }
326: }
327: $status.='<br><a href="/adm/retrieve?filename=/~'.$uname.
1.41 ! www 328: $thisdisfn.'/'.$filename.'" target=cat>'.&mt('Retrieve').'</a>';
1.22 foxr 329: }
1.33 www 330: my $editlink='';
1.38 taceyjo1 331: my $editlink2='';
1.36 www 332: if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
1.39 www 333: $editlink=' (<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_top">'.&mt('Edit').'</a>)';
1.34 www 334: }
335: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
1.39 www 336: $editlink=' (<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_top">'.&mt('EditXML').'</a>)';
337: $editlink2=' (<a href="'.$linkdir.'/'.$filename.'?forceColoredit=1" target="_top">'.&mt('Edit').'</a>)';
1.33 www 338: }
1.25 www 339: $r->print('<tr bgcolor="'.$bgcolor.'">'.
1.22 foxr 340: '<td><a target="_parent" href="/adm/publish?filename=/~'.
1.40 www 341: $uname.$thisdisfn.'/'.$filename.'">'.&mt('Publish').'</a>'.
1.22 foxr 342: '</td>'.
343: '<td>'.
1.25 www 344: '<a href="'.$linkdir.'/'.$filename.'" target="_top">'.
1.38 taceyjo1 345: $filename.'</a>'.$editlink2.$editlink.
1.22 foxr 346: '</td>'.
347: '<td>'.$title.'</td>'.
1.41 ! www 348: '<td>'.$status.'</td>'.
1.22 foxr 349: '<td>'.localtime($cmtime).'</td>'.
1.25 www 350: "</tr>\n");
1.22 foxr 351: return OK;
1.23 foxr 352: }
353: #
354: # Categorize files in the directory.
355: # For each file in a list of files in a file directory,
356: # the file categorized as one of:
357: # - directory
358: # - sequence
359: # - problem
360: # - Other resource.
361: #
362: # For each file the modification date is determined as well.
363: # Returned is a list of sublists:
364: # (directories, sequences, problems, other)
365: # each of the sublists contains entries of the following form (sorted by
366: # filename):
367: # (filename, typecode, lastmodtime)
368: #
369: # $list = CategorizeFiles($location, $files)
370: # $location - Directory in which the files live (relative to our
371: # execution.
372: # $files - list of files.
373: #
374: sub CategorizeFiles {
375: my $location = shift;
376: my $files = shift;
1.22 foxr 377: }
378:
1.4 www 379: 1;
380: __END__
1.17 harris41 381:
382: =head1 NAME
383:
1.32 www 384: Apache::lonpubdir - Construction space directory lister
1.17 harris41 385:
386: =head1 SYNOPSIS
387:
388: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
389:
1.18 harris41 390: <LocationMatch "^/\~.*/$">
391: PerlAccessHandler Apache::loncacc
392: SetHandler perl-script
393: PerlHandler Apache::lonpubdir
394: ErrorDocument 403 /adm/login
395: ErrorDocument 404 /adm/notfound.html
396: ErrorDocument 406 /adm/unauthorized.html
397: ErrorDocument 500 /adm/errorhandler
398: </LocationMatch>
399:
400: <Location /adm/pubdir>
401: PerlAccessHandler Apache::lonacc
402: SetHandler perl-script
403: PerlHandler Apache::lonpubdir
404: ErrorDocument 403 /adm/login
405: ErrorDocument 404 /adm/notfound.html
406: ErrorDocument 406 /adm/unauthorized.html
407: ErrorDocument 500 /adm/errorhandler
408: </Location>
1.17 harris41 409:
410: =head1 INTRODUCTION
411:
1.18 harris41 412: This module publishes a directory of files.
1.17 harris41 413:
414: This is part of the LearningOnline Network with CAPA project
415: described at http://www.lon-capa.org.
416:
417: =head1 HANDLER SUBROUTINE
418:
419: This routine is called by Apache and mod_perl.
420:
421: =over 4
422:
423: =item *
424:
425: read in information
426:
427: =item *
428:
429: start page output
430:
431: =item *
432:
433: run through list of files and attempt to publish unhidden files
434:
435: =back
436:
437: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>