Annotation of loncom/publisher/lonretrieve.pm, revision 1.20
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to retrieve an old version of a file
3: #
1.20 ! albertel 4: # $Id: lonretrieve.pm,v 1.19 2002/09/16 13:05:50 www Exp $
1.15 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/
27: #
28: #
1.1 www 29: # (Publication Handler
30: #
31: # (TeX Content Handler
32: #
1.16 harris41 33: # YEAR=2000
1.1 www 34: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
35: #
36: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
1.16 harris41 37: # YEAR=2001
1.1 www 38: # 03/23 Guy Albertelli
39: # 03/24,03/29 Gerd Kortemeyer)
40: #
1.14 www 41: # 03/31,04/03,05/02,05/09,06/23,08/20 Gerd Kortemeyer
1.16 harris41 42: # 12/16 Scott Harrison
43: #
44: ###
1.1 www 45:
46: package Apache::lonretrieve;
47:
48: use strict;
49: use Apache::File;
50: use File::Copy;
51: use Apache::Constants qw(:common :http :methods);
1.10 www 52: use Apache::loncacc;
1.16 harris41 53: use Apache::loncommon();
1.1 www 54:
1.16 harris41 55: # ------------------------------------ Interface for selecting previous version
1.2 www 56: sub phaseone {
57: my ($r,$fn,$uname,$udom)=@_;
58: my $docroot=$r->dir_config('lonDocRoot');
59:
1.3 www 60: my $urldir='/res/'.$udom.'/'.$uname.$fn;
61: $urldir=~s/\/[^\/]+$/\//;
62:
63: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
64: my $resdir=$resfn;
1.2 www 65: $resdir=~s/\/[^\/]+$/\//;
66:
1.6 www 67: $fn=~/\/([^\/]+)\.(\w+)$/;
1.2 www 68: my $main=$1;
69: my $suffix=$2;
1.6 www 70:
71: if (-e $resfn) {
1.3 www 72: $r->print('<form action=/adm/retrieve method=post>'.
1.12 www 73: '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.
1.3 www 74: '<input type=hidden name=phase value=two>'.
75: '<table border=2><tr><th>Select</th><th>Version</th>'.
76: '<th>Became this version on ...</th>'.
77: '<th>Metadata</th></tr>');
1.2 www 78: my $filename;
79: opendir(DIR,$resdir);
80: while ($filename=readdir(DIR)) {
81: if ($filename=~/^$main\.(\d+)\.$suffix$/) {
1.3 www 82: my $version=$1;
83: my ($rdev,$rino,$rmode,$rnlink,
84: $ruid,$rgid,$rrdev,$rsize,
85: $ratime,$rmtime,$rctime,
86: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
87: $r->print('<tr><td><input type=radio name=version value="'.
88: $version.'"></td><th>'.$version.'</th><td>'.
89: localtime($rmtime).'</td><td>'.
90: '<a href="'.$urldir.$filename.'.meta" target=cat>'.
1.9 www 91: 'Metadata Version '.$version.'</a>');
1.16 harris41 92: if (&Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
1.8 www 93: $r->print(
1.11 www 94: ' <a target=cat href="/adm/diff?filename=/~'.
95: $uname.$fn.
1.20 ! albertel 96: '&versiontwo=priv&versiontwo='.$version.
1.8 www 97: '">Diffs with Version '.$version.'</a>');
98: }
99: $r->print('</a></td></tr>');
1.2 www 100: }
101: }
102: closedir(DIR);
1.3 www 103: my ($rdev,$rino,$rmode,$rnlink,
104: $ruid,$rgid,$rrdev,$rsize,
105: $ratime,$rmtime,$rctime,
106: $rblksize,$rblocks)=stat($resfn);
107: $r->print('<tr><td><input type=radio name=version value="new"></td>'.
108: '<th>Current</th><td>'.localtime($rmtime).
109: '</td><td><a href="'.$urldir.$main.'.'.$suffix.'.meta" target=cat>'.
1.9 www 110: 'Metadata current version</a>');
1.16 harris41 111: if (&Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
1.9 www 112: $r->print(
1.11 www 113: ' <a target=cat href="/adm/diff?filename=/~'.
114: $uname.$fn.
1.20 ! albertel 115: '&versiontwo=priv'.
1.9 www 116: '">Diffs with current Version</a>');
117: }
118: $r->print('</td></tr></table><p>'.
1.4 www 119: '<font size=+1 color=red>Retrieval of an old version will '.
120: 'overwrite the file currently in construction space</font><p>'.
1.3 www 121: '<input type=submit value="Retrieve version"></form>');
1.6 www 122: } else {
123: $r->print('<h3>No previous versions published.</h3>');
124: }
1.2 www 125: }
1.1 www 126:
1.16 harris41 127: # ---------------------------------- Interface for presenting specified version
1.4 www 128: sub phasetwo {
129: my ($r,$fn,$uname,$udom)=@_;
130: if ($ENV{'form.version'}) {
131: my $version=$ENV{'form.version'};
132: if ($version eq 'new') {
133: $r->print('<h3>Retrieving current (most recent) version</h3>');
134: } else {
135: $r->print('<h3>Retrieving old version '.$version.'</h3>');
136: }
137: my $logfile;
138: my $ctarget='/home/'.$uname.'/public_html'.$fn;
1.5 www 139: my $vfn=$fn;
140: if ($version ne 'new') {
141: $vfn=~s/\.(\w+)$/\.$version\.$1/;
142: }
143: my $csource=$r->dir_config('lonDocRoot').'/res/'.$udom.'/'.$uname.$vfn;
1.4 www 144: unless ($logfile=Apache::File->new('>>'.$ctarget.'.log')) {
145: $r->print(
146: '<font color=red>No write permission to user directory, FAIL</font>');
147: }
148: print $logfile
149: "\n\n================= Retrieve ".localtime()." ================\n".
1.5 www 150: "Version: $version\nSource: $csource\nTarget: $ctarget\n";
151: $r->print('<p>Copying file: ');
152: if (copy($csource,$ctarget)) {
153: $r->print('ok<p>');
154: print $logfile "Copied sucessfully.\n\n";
155: } else {
156: my $error=$!;
157: $r->print('fail, '.$error.'<p>');
158: print $logfile "Copy failed: $error\n\n";
159: }
160: $r->print('<font size=+2><a href="/priv/'.$uname.$fn.
161: '">Back to '.$fn.'</a></font>');
1.4 www 162: } else {
163: $r->print(
164: '<font size=+1 color=red>Please pick a version to retrieve</font><p>');
165: &phaseone($r,$fn,$uname,$udom);
166: }
167: }
168:
1.16 harris41 169: # ---------------------------------------------------------------- Main Handler
1.1 www 170: sub handler {
171:
172: my $r=shift;
173:
174: my $fn;
1.14 www 175:
176:
177: # Get query string for limited number of parameters
178:
1.17 stredwic 179: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.18 www 180: ['filename']);
1.1 www 181:
182: if ($ENV{'form.filename'}) {
183: $fn=$ENV{'form.filename'};
1.10 www 184: $fn=~s/^http\:\/\/[^\/]+//;
1.1 www 185: } else {
1.2 www 186: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
187: ' unspecified filename for retrieval', $r->filename);
188: return HTTP_NOT_FOUND;
1.1 www 189: }
190:
191: unless ($fn) {
192: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
1.2 www 193: ' trying to retrieve non-existing file', $r->filename);
1.1 www 194: return HTTP_NOT_FOUND;
195: }
196:
197: # ----------------------------------------------------------- Start page output
1.10 www 198: my $uname;
199: my $udom;
1.1 www 200:
1.13 www 201: ($uname,$udom)=
202: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
203: unless (($uname) && ($udom)) {
1.10 www 204: $r->log_reason($uname.' at '.$udom.
205: ' trying to publish file '.$ENV{'form.filename'}.
206: ' ('.$fn.') - not authorized',
207: $r->filename);
208: return HTTP_NOT_ACCEPTABLE;
209: }
210:
211: $fn=~s/\/\~(\w+)//;
1.1 www 212:
213: $r->content_type('text/html');
214: $r->send_http_header;
215:
216: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
217:
1.19 www 218: $r->print(&Apache::loncommon::bodytag('Retrieve Published Resources'));
1.1 www 219:
220:
1.2 www 221: $r->print('<h1>Retrieve previous versions of <tt>'.$fn.'</tt></h1>');
1.10 www 222:
223: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
224: $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
225: '</font></h3>');
226: }
227:
1.1 www 228:
1.2 www 229: if ($ENV{'form.phase'} eq 'two') {
1.4 www 230: &phasetwo($r,$fn,$uname,$udom);
1.2 www 231: } else {
232: &phaseone($r,$fn,$uname,$udom);
233: }
1.1 www 234:
235: $r->print('</body></html>');
236: return OK;
237: }
1.7 www 238:
239: 1;
240: __END__
1.16 harris41 241:
242: =head1 NAME
243:
244: Apache::lonretrieve - retrieves an old version of a file
245:
246: =head1 SYNOPSIS
247:
248: Invoked by /etc/httpd/conf/srm.conf:
249:
250: <Location /adm/retrieve>
251: PerlAccessHandler Apache::lonacc
252: SetHandler perl-script
253: PerlHandler Apache::lonretrieve
254: ErrorDocument 403 /adm/login
255: ErrorDocument 404 /adm/notfound.html
256: ErrorDocument 406 /adm/unauthorized.html
257: ErrorDocument 500 /adm/errorhandler
258: </Location>
259:
260: =head1 INTRODUCTION
261:
262: This module retrieves an old published version of a file.
263:
264: This is part of the LearningOnline Network with CAPA project
265: described at http://www.lon-capa.org.
266:
267: =head1 HANDLER SUBROUTINE
268:
269: This routine is called by Apache and mod_perl.
270:
271: =over 4
272:
273: =item *
274:
275: Get query string for limited number of parameters
276:
277: =item *
278:
279: Start page output
280:
281: =item *
282:
283: print phase relevant output
284:
285: =item *
286:
287: (phase one is to select version; phase two retrieves version)
288:
289: =back
290:
291: =head1 OTHER SUBROUTINES
292:
293: =over 4
294:
295: =item *
296:
297: phaseone() : Interface for selecting previous version.
298:
299: =item *
300:
301: phasetwo() : Interface for presenting specified version.
302:
303: =back
304:
305: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>