Annotation of loncom/publisher/lonretrieve.pm, revision 1.15
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to retrieve an old version of a file
3: #
1.15 ! albertel 4: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www 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: #
1.1 www 29: # (Publication Handler
30: #
31: # (TeX Content Handler
32: #
33: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
34: #
35: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
36: # 03/23 Guy Albertelli
37: # 03/24,03/29 Gerd Kortemeyer)
38: #
1.14 www 39: # 03/31,04/03,05/02,05/09,06/23,08/20 Gerd Kortemeyer
1.1 www 40:
41: package Apache::lonretrieve;
42:
43: use strict;
44: use Apache::File;
45: use File::Copy;
46: use Apache::Constants qw(:common :http :methods);
1.10 www 47: use Apache::loncacc;
1.1 www 48:
1.2 www 49: sub phaseone {
50: my ($r,$fn,$uname,$udom)=@_;
51: my $docroot=$r->dir_config('lonDocRoot');
52:
1.3 www 53: my $urldir='/res/'.$udom.'/'.$uname.$fn;
54: $urldir=~s/\/[^\/]+$/\//;
55:
56: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
57: my $resdir=$resfn;
1.2 www 58: $resdir=~s/\/[^\/]+$/\//;
59:
1.6 www 60: $fn=~/\/([^\/]+)\.(\w+)$/;
1.2 www 61: my $main=$1;
62: my $suffix=$2;
1.6 www 63:
64: if (-e $resfn) {
1.3 www 65: $r->print('<form action=/adm/retrieve method=post>'.
1.12 www 66: '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.
1.3 www 67: '<input type=hidden name=phase value=two>'.
68: '<table border=2><tr><th>Select</th><th>Version</th>'.
69: '<th>Became this version on ...</th>'.
70: '<th>Metadata</th></tr>');
1.2 www 71: my $filename;
72: opendir(DIR,$resdir);
73: while ($filename=readdir(DIR)) {
74: if ($filename=~/^$main\.(\d+)\.$suffix$/) {
1.3 www 75: my $version=$1;
76: my ($rdev,$rino,$rmode,$rnlink,
77: $ruid,$rgid,$rrdev,$rsize,
78: $ratime,$rmtime,$rctime,
79: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
80: $r->print('<tr><td><input type=radio name=version value="'.
81: $version.'"></td><th>'.$version.'</th><td>'.
82: localtime($rmtime).'</td><td>'.
83: '<a href="'.$urldir.$filename.'.meta" target=cat>'.
1.9 www 84: 'Metadata Version '.$version.'</a>');
1.8 www 85: if (&Apache::lonnet::fileembstyle($suffix) eq 'ssi') {
86: $r->print(
1.11 www 87: ' <a target=cat href="/adm/diff?filename=/~'.
88: $uname.$fn.
1.8 www 89: '&versionone=priv&versiontwo='.$version.
90: '">Diffs with Version '.$version.'</a>');
91: }
92: $r->print('</a></td></tr>');
1.2 www 93: }
94: }
95: closedir(DIR);
1.3 www 96: my ($rdev,$rino,$rmode,$rnlink,
97: $ruid,$rgid,$rrdev,$rsize,
98: $ratime,$rmtime,$rctime,
99: $rblksize,$rblocks)=stat($resfn);
100: $r->print('<tr><td><input type=radio name=version value="new"></td>'.
101: '<th>Current</th><td>'.localtime($rmtime).
102: '</td><td><a href="'.$urldir.$main.'.'.$suffix.'.meta" target=cat>'.
1.9 www 103: 'Metadata current version</a>');
104: if (&Apache::lonnet::fileembstyle($suffix) eq 'ssi') {
105: $r->print(
1.11 www 106: ' <a target=cat href="/adm/diff?filename=/~'.
107: $uname.$fn.
1.9 www 108: '&versionone=priv'.
109: '">Diffs with current Version</a>');
110: }
111: $r->print('</td></tr></table><p>'.
1.4 www 112: '<font size=+1 color=red>Retrieval of an old version will '.
113: 'overwrite the file currently in construction space</font><p>'.
1.3 www 114: '<input type=submit value="Retrieve version"></form>');
1.6 www 115: } else {
116: $r->print('<h3>No previous versions published.</h3>');
117: }
1.2 www 118: }
1.1 www 119:
1.4 www 120: sub phasetwo {
121: my ($r,$fn,$uname,$udom)=@_;
122: if ($ENV{'form.version'}) {
123: my $version=$ENV{'form.version'};
124: if ($version eq 'new') {
125: $r->print('<h3>Retrieving current (most recent) version</h3>');
126: } else {
127: $r->print('<h3>Retrieving old version '.$version.'</h3>');
128: }
129: my $logfile;
130: my $ctarget='/home/'.$uname.'/public_html'.$fn;
1.5 www 131: my $vfn=$fn;
132: if ($version ne 'new') {
133: $vfn=~s/\.(\w+)$/\.$version\.$1/;
134: }
135: my $csource=$r->dir_config('lonDocRoot').'/res/'.$udom.'/'.$uname.$vfn;
1.4 www 136: unless ($logfile=Apache::File->new('>>'.$ctarget.'.log')) {
137: $r->print(
138: '<font color=red>No write permission to user directory, FAIL</font>');
139: }
140: print $logfile
141: "\n\n================= Retrieve ".localtime()." ================\n".
1.5 www 142: "Version: $version\nSource: $csource\nTarget: $ctarget\n";
143: $r->print('<p>Copying file: ');
144: if (copy($csource,$ctarget)) {
145: $r->print('ok<p>');
146: print $logfile "Copied sucessfully.\n\n";
147: } else {
148: my $error=$!;
149: $r->print('fail, '.$error.'<p>');
150: print $logfile "Copy failed: $error\n\n";
151: }
152: $r->print('<font size=+2><a href="/priv/'.$uname.$fn.
153: '">Back to '.$fn.'</a></font>');
1.4 www 154: } else {
155: $r->print(
156: '<font size=+1 color=red>Please pick a version to retrieve</font><p>');
157: &phaseone($r,$fn,$uname,$udom);
158: }
159: }
160:
1.1 www 161: sub handler {
162:
163: my $r=shift;
164:
165: my $fn;
1.14 www 166:
167:
168: # Get query string for limited number of parameters
169:
170: map {
171: my ($name, $value) = split(/=/,$_);
172: $value =~ tr/+/ /;
173: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
174: if ($name eq 'filename') {
175: unless ($ENV{'form.'.$name}) {
176: $ENV{'form.'.$name}=$value;
177: }
178: }
179: } (split(/&/,$ENV{'QUERY_STRING'}));
180:
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:
218: $r->print(
219: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
220:
221:
1.2 www 222: $r->print('<h1>Retrieve previous versions of <tt>'.$fn.'</tt></h1>');
1.10 www 223:
224: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
225: $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
226: '</font></h3>');
227: }
228:
1.1 www 229:
1.2 www 230: if ($ENV{'form.phase'} eq 'two') {
1.4 www 231: &phasetwo($r,$fn,$uname,$udom);
1.2 www 232: } else {
233: &phaseone($r,$fn,$uname,$udom);
234: }
1.1 www 235:
236: $r->print('</body></html>');
237: return OK;
238: }
1.7 www 239:
240: 1;
241: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>