Annotation of loncom/publisher/lonretrieve.pm, revision 1.16
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to retrieve an old version of a file
3: #
1.16 ! harris41 4: # $Id: lonretrieve.pm,v 1.15 2001/12/04 15:34:57 albertel 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.8 www 96: '&versionone=priv&versiontwo='.$version.
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.9 www 115: '&versionone=priv'.
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.16 ! harris41 179: foreach (split(/&/,$ENV{'QUERY_STRING'})) {
1.14 www 180: my ($name, $value) = split(/=/,$_);
181: $value =~ tr/+/ /;
182: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
183: if ($name eq 'filename') {
184: unless ($ENV{'form.'.$name}) {
185: $ENV{'form.'.$name}=$value;
186: }
187: }
1.16 ! harris41 188: }
1.14 www 189:
1.1 www 190:
191: if ($ENV{'form.filename'}) {
192: $fn=$ENV{'form.filename'};
1.10 www 193: $fn=~s/^http\:\/\/[^\/]+//;
1.1 www 194: } else {
1.2 www 195: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
196: ' unspecified filename for retrieval', $r->filename);
197: return HTTP_NOT_FOUND;
1.1 www 198: }
199:
200: unless ($fn) {
201: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
1.2 www 202: ' trying to retrieve non-existing file', $r->filename);
1.1 www 203: return HTTP_NOT_FOUND;
204: }
205:
206: # ----------------------------------------------------------- Start page output
1.10 www 207: my $uname;
208: my $udom;
1.1 www 209:
1.13 www 210: ($uname,$udom)=
211: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
212: unless (($uname) && ($udom)) {
1.10 www 213: $r->log_reason($uname.' at '.$udom.
214: ' trying to publish file '.$ENV{'form.filename'}.
215: ' ('.$fn.') - not authorized',
216: $r->filename);
217: return HTTP_NOT_ACCEPTABLE;
218: }
219:
220: $fn=~s/\/\~(\w+)//;
1.1 www 221:
222: $r->content_type('text/html');
223: $r->send_http_header;
224:
225: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
226:
227: $r->print(
228: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
229:
230:
1.2 www 231: $r->print('<h1>Retrieve previous versions of <tt>'.$fn.'</tt></h1>');
1.10 www 232:
233: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
234: $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
235: '</font></h3>');
236: }
237:
1.1 www 238:
1.2 www 239: if ($ENV{'form.phase'} eq 'two') {
1.4 www 240: &phasetwo($r,$fn,$uname,$udom);
1.2 www 241: } else {
242: &phaseone($r,$fn,$uname,$udom);
243: }
1.1 www 244:
245: $r->print('</body></html>');
246: return OK;
247: }
1.7 www 248:
249: 1;
250: __END__
1.16 ! harris41 251:
! 252: =head1 NAME
! 253:
! 254: Apache::lonretrieve - retrieves an old version of a file
! 255:
! 256: =head1 SYNOPSIS
! 257:
! 258: Invoked by /etc/httpd/conf/srm.conf:
! 259:
! 260: <Location /adm/retrieve>
! 261: PerlAccessHandler Apache::lonacc
! 262: SetHandler perl-script
! 263: PerlHandler Apache::lonretrieve
! 264: ErrorDocument 403 /adm/login
! 265: ErrorDocument 404 /adm/notfound.html
! 266: ErrorDocument 406 /adm/unauthorized.html
! 267: ErrorDocument 500 /adm/errorhandler
! 268: </Location>
! 269:
! 270: =head1 INTRODUCTION
! 271:
! 272: This module retrieves an old published version of a file.
! 273:
! 274: This is part of the LearningOnline Network with CAPA project
! 275: described at http://www.lon-capa.org.
! 276:
! 277: =head1 HANDLER SUBROUTINE
! 278:
! 279: This routine is called by Apache and mod_perl.
! 280:
! 281: =over 4
! 282:
! 283: =item *
! 284:
! 285: Get query string for limited number of parameters
! 286:
! 287: =item *
! 288:
! 289: Start page output
! 290:
! 291: =item *
! 292:
! 293: print phase relevant output
! 294:
! 295: =item *
! 296:
! 297: (phase one is to select version; phase two retrieves version)
! 298:
! 299: =back
! 300:
! 301: =head1 OTHER SUBROUTINES
! 302:
! 303: =over 4
! 304:
! 305: =item *
! 306:
! 307: phaseone() : Interface for selecting previous version.
! 308:
! 309: =item *
! 310:
! 311: phasetwo() : Interface for presenting specified version.
! 312:
! 313: =back
! 314:
! 315: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>