1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
4: # $Id: lonpubdir.pm,v 1.17 2001/12/15 20:48:47 harris41 Exp $
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/
27: #
28: #
29: # (TeX Content Handler
30: #
31: # YEAR=2000
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
35: # YEAR=2001
36: # 03/23 Guy Albertelli
37: # 03/24,03/29 Gerd Kortemeyer)
38: # 03/31,04/03,05/09,06/23,08/18,08/20 Gerd Kortemeyer
39: # 12/15 Scott Harrison
40: #
41: ###
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);
49: use Apache::loncacc;
50: use Apache::loncommon();
51:
52: sub handler {
53:
54: my $r=shift;
55:
56: my $fn;
57:
58: if ($ENV{'form.filename'}) {
59: $fn=$ENV{'form.filename'};
60: $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
61: $fn=~s/\/[^\/]+$//;
62: } else {
63: $fn=$r->filename();
64: }
65:
66: my $uname;
67: my $udom;
68:
69: ($uname,$udom)=
70: &Apache::loncacc::constructaccess(
71: $fn,$r->dir_config('lonDefDomain'));
72: unless (($uname) && ($udom)) {
73: $r->log_reason($uname.' at '.$udom.
74: ' trying to publish file '.$ENV{'form.filename'}.
75: ' ('.$fn.') - not authorized',
76: $r->filename);
77: return HTTP_NOT_ACCEPTABLE;
78: }
79:
80: $fn=~s/\/$//;
81:
82: unless ($fn) {
83: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
84: ' trying to list empty directory', $r->filename);
85: return HTTP_NOT_FOUND;
86: }
87:
88: # ----------------------------------------------------------- Start page output
89:
90:
91: $r->content_type('text/html');
92: $r->send_http_header;
93:
94: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
95:
96: $r->print(
97: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
98:
99: my $thisdisfn=$fn;
100: $thisdisfn=~s/^\/home\/$uname\/public_html//;
101:
102: $r->print('<h1>Construction Space Directory <tt>'.$thisdisfn.'/</tt></h1>');
103:
104: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
105: $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
106: '</font></h3>');
107: }
108:
109:
110: my $docroot=$r->dir_config('lonDocRoot');
111:
112: my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn;
113: my $linkdir='/~'.$uname.$thisdisfn;
114:
115: $r->print('<table border=2>'.
116: '<tr><th>Filename</th><th>Modified</th><th>Status</th><th> </th></tr>');
117:
118: my $filename;
119: my $dirptr=16384;
120:
121: opendir(DIR,$fn);
122: my @files=sort(readdir(DIR));
123: foreach my $filename (@files) {
124: my ($cdev,$cino,$cmode,$cnlink,
125: $cuid,$cgid,$crdev,$csize,
126: $catime,$cmtime,$cctime,
127: $cblksize,$cblocks)=stat($fn.'/'.$filename);
128:
129: my $extension='';
130: if ($filename=~/\.(\w+)$/) { $extension=$1; }
131: if ($cmode&$dirptr) {
132: my $disfilename=$filename;
133: if ($filename eq '..') {
134: $disfilename='<i>Parent Directory</i>';
135: }
136: unless ((($filename eq '..') && ($thisdisfn eq '')) ||
137: ($filename eq '.')) {
138: $r->print('<tr bgcolor=#BBBBFF'.
139: '><td><a href="'.$linkdir.'/'.$filename.'">'.$disfilename.
140: '</a></td><td>'.localtime($cmtime).'</td><td> </td><td> </td></tr>'
141: );
142: }
143: } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') {
144: my $status='Unpublished';
145: my $bgcol='#FFBBBB';
146: if (-e $resdir.'/'.$filename) {
147: my ($rdev,$rino,$rmode,$rnlink,
148: $ruid,$rgid,$rrdev,$rsize,
149: $ratime,$rmtime,$rctime,
150: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
151: if ($rmtime>=$cmtime) {
152: $status='Published';
153: $bgcol='#BBFFBB';
154: } else {
155: $status='Modified';
156: $bgcol='#FFFFBB';
157: if
158: (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
159: $status.='<br><a href="/adm/diff?filename=/~'.$uname.
160: $thisdisfn.'/'.$filename.
161: '&versionone=priv" target=cat>Diffs</a>';
162: }
163: }
164: $status.='<br><a href="/adm/retrieve?filename=/~'.$uname.
165: $thisdisfn.'/'.$filename.'" target=cat>Retrieve</a>';
166: }
167: $r->print('<tr bgcolor='.$bgcol.
168: '><td><a href="'.$linkdir.'/'.$filename.'">'.$filename.
169: '</a></td><td>'.localtime($cmtime).'</td><td>'.$status.'</td>'.
170: '<td><a target="_parent" href="/adm/publish?filename=/~'.$uname.
171: $thisdisfn.'/'.$filename.'">'.
172: 'Publish</a></td></tr>');
173: } else {
174: # "hidden" extension and not a directory, so hide it away.
175: }
176: }
177: closedir(DIR);
178:
179: $r->print('</table></body></html>');
180: return OK;
181: }
182:
183: 1;
184: __END__
185:
186: =head1 NAME
187:
188: Apache::lonpubdir - Publication Handler for Directories
189:
190: =head1 SYNOPSIS
191:
192: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
193:
194: <LocationMatch "^/\~.*/$">
195: PerlAccessHandler Apache::loncacc
196: SetHandler perl-script
197: PerlHandler Apache::lonpubdir
198: ErrorDocument 403 /adm/login
199: ErrorDocument 404 /adm/notfound.html
200: ErrorDocument 406 /adm/unauthorized.html
201: ErrorDocument 500 /adm/errorhandler
202: </LocationMatch>
203:
204: <Location /adm/pubdir>
205: PerlAccessHandler Apache::lonacc
206: SetHandler perl-script
207: PerlHandler Apache::lonpubdir
208: ErrorDocument 403 /adm/login
209: ErrorDocument 404 /adm/notfound.html
210: ErrorDocument 406 /adm/unauthorized.html
211: ErrorDocument 500 /adm/errorhandler
212: </Location>
213:
214: =head1 INTRODUCTION
215:
216: This module enables cookie based authentication and is used
217: to control access for many different LON-CAPA URIs.
218:
219: Whenever the client sends the cookie back to the server,
220: this cookie is handled by either lonacc.pm or loncacc.pm
221: (see srm.conf for what is invoked when). If
222: the cookie is missing or invalid, the user is re-challenged
223: for login information.
224:
225: This is part of the LearningOnline Network with CAPA project
226: described at http://www.lon-capa.org.
227:
228: =head1 HANDLER SUBROUTINE
229:
230: This routine is called by Apache and mod_perl.
231:
232: =over 4
233:
234: =item *
235:
236: read in information
237:
238: =item *
239:
240: start page output
241:
242: =item *
243:
244: run through list of files and attempt to publish unhidden files
245:
246: =back
247:
248: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>