Annotation of loncom/publisher/loncfile.pm, revision 1.5
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to rename files, etc, in construction space
3: #
4: # (Handler to retrieve an old version of a file
5: #
6: # (Publication Handler
7: #
8: # (TeX Content Handler
9: #
10: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
11: #
12: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
13: # 03/23 Guy Albertelli
14: # 03/24,03/29 Gerd Kortemeyer)
15: #
1.5 ! www 16: # 03/31,04/03,05/02,05/09,06/23,06/24 Gerd Kortemeyer)
1.1 www 17: #
18: # 06/23 Gerd Kortemeyer
19:
20: package Apache::loncfile;
21:
22: use strict;
23: use Apache::File;
24: use File::Copy;
25: use Apache::Constants qw(:common :http :methods);
26: use Apache::loncacc;
27:
28: sub phaseone {
29: my ($r,$fn,$uname,$udom)=@_;
30:
1.3 www 31: $fn=~/(.*)\/([^\/]+)\.(\w+)$/;
32: my $dir=$1;
33: my $main=$2;
34: my $suffix=$3;
1.1 www 35:
1.3 www 36: my $conspace='/home/'.$uname.'/public_html'.$fn;
1.1 www 37:
1.3 www 38: $r->print('<form action=/adm/cfile method=post>'.
1.1 www 39: '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.
40: '<input type=hidden name=phase value=two>'.
1.3 www 41: '<input type=hidden name=action value='.$ENV{'form.action'}.'>');
42: if ($ENV{'form.action'} eq 'rename') {
43: if (-e $conspace) {
44: if ($ENV{'form.newfilename'}) {
45: $ENV{'form.newfilename'}=~/(.*)\/([^\/]+)\.(\w+)$/;
46: if ($3 ne $suffix) {
47: $r->print(
48: '<p><font color=red>Warning: change of MIME type!</font>');
49: }
50: if (-e
51: '/home/httpd/'.$uname.'/'.$dir.'/'.$ENV{'form.newfilename'}) {
52: $r->print(
53: '<p><font color=red>Warning: target file exists!</font>');
54: }
1.4 www 55: $r->print('<input type=hidden name=newfilename value="'.
56: $ENV{'form.newfilename'}.
57: '"><p>Rename <tt>'.$fn.'</tt> to <tt>'.
1.3 www 58: $dir.'/'.$ENV{'form.newfilename'}.'</tt>?');
59: } else {
60: $r->print('<p>No new filename specified.</form>');
61: return;
62: }
63: } else {
64: $r->print('<p>No such file.</form>');
65: return;
66: }
67: } elsif ($ENV{'form.action'} eq 'delete') {
68: if (-e $conspace) {
69: $r->print('<p>Delete <tt>'.$fn.'</tt>?');
70: } else {
71: $r->print('<p>No such file.</form>');
72: return;
1.1 www 73: }
1.3 www 74: } elsif ($ENV{'form.action'} eq 'copy') {
75: if (-e $conspace) {
76: if ($ENV{'form.newfilename'}) {
77: $ENV{'form.newfilename'}=~/(.*)\/([^\/]+)\.(\w+)$/;
78: if ($3 ne $suffix) {
79: $r->print(
80: '<p><font color=red>Warning: change of MIME type!</font>');
81: }
82: if (-e
83: '/home/httpd/'.$uname.'/'.$dir.'/'.$ENV{'form.newfilename'}) {
84: $r->print(
85: '<p><font color=red>Warning: target file exists!</font>');
86: }
1.4 www 87: $r->print('<input type=hidden name=newfilename value="'.
88: $ENV{'form.newfilename'}.
89: '"><p>Copy <tt>'.$fn.'</tt> to <tt>'.
1.3 www 90: $dir.'/'.$ENV{'form.newfilename'}.'</tt>?');
91: } else {
92: $r->print('<p>No new filename specified.</form>');
93: return;
94: }
95: } else {
96: $r->print('<p>No such file.</form>');
97: return;
98: }
99: } elsif ($ENV{'form.action'} eq 'newdir') {
1.4 www 100: my $newdir='/home/'.$uname.'/public_html/'.
101: $fn.$ENV{'form.newfilename'};
102: if (-e $newdir) {
1.3 www 103: $r->print('<p>Directory exists.</form>');
104: return;
105: }
1.4 www 106: $r->print('<input type=hidden name=newfilename value="'.
107: $ENV{'form.newfilename'}.
108: '"><p>Make new directory <tt>'.
109: $fn.$ENV{'form.newfilename'}.'</tt>?');
1.3 www 110:
1.1 www 111: }
1.3 www 112: $r->print('<p><input type=submit value=Continue></form>');
1.1 www 113: }
114:
115: sub phasetwo {
116: my ($r,$fn,$uname,$udom)=@_;
1.5 ! www 117:
! 118: $fn=~/(.*)\/([^\/]+)\.(\w+)$/;
! 119: my $dir=$1;
! 120: my $main=$2;
! 121: my $suffix=$3;
! 122:
! 123: my $conspace='/home/'.$uname.'/public_html'.$fn;
! 124:
! 125: if ($ENV{'form.action'} eq 'rename') {
! 126: if (-e $conspace) {
! 127: if ($ENV{'form.newfilename'}) {
! 128: unless (rename('/home/'.$uname.'/public_html'.$fn,
! 129: '/home/'.$uname.'/public_html'.$dir.'/'.$ENV{'form.newfilename'})) {
! 130: $r->print('<font color=red>Error: '.$!.'</font>');
! 131: }
! 132: }
! 133: } else {
! 134: $r->print('<p>No such file.</form>');
! 135: return;
! 136: }
! 137: } elsif ($ENV{'form.action'} eq 'delete') {
! 138: if (-e $conspace) {
! 139: unless (unlink('/home/'.$uname.'/public_html'.$fn)) {
! 140: $r->print('<font color=red>Error: '.$!.'</font>');
! 141: }
! 142: } else {
! 143: $r->print('<p>No such file.</form>');
! 144: return;
! 145: }
! 146: } elsif ($ENV{'form.action'} eq 'copy') {
! 147: if (-e $conspace) {
! 148: if ($ENV{'form.newfilename'}) {
! 149: unless (copy('/home/'.$uname.'/public_html'.$fn,
! 150: '/home/'.$uname.'/public_html'.$dir.'/'.$ENV{'form.newfilename'})) {
! 151: $r->print('<font color=red>Error: '.$!.'</font>');
! 152: }
! 153: } else {
! 154: $r->print('<p>No new filename specified.</form>');
! 155: return;
! 156: }
! 157: } else {
! 158: $r->print('<p>No such file.</form>');
! 159: return;
! 160: }
! 161: } elsif ($ENV{'form.action'} eq 'newdir') {
! 162: my $newdir='/home/'.$uname.'/public_html/'.
! 163: $fn.$ENV{'form.newfilename'};
! 164: unless (mkdir($newdir,0770)) {
! 165: $r->print('<font color=red>Error: '.$!.'</font>');
! 166: }
! 167: }
! 168: $r->print('<h3><a href="/priv/'.$uname.$dir.'/">Done</a></h3>');
1.1 www 169: }
170:
171: sub handler {
172:
173: my $r=shift;
174:
175: my $fn;
176:
177: if ($ENV{'form.filename'}) {
178: $fn=$ENV{'form.filename'};
179: $fn=~s/^http\:\/\/[^\/]+//;
180: } else {
181: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
182: ' unspecified filename for cfile', $r->filename);
183: return HTTP_NOT_FOUND;
184: }
185:
186: unless ($fn) {
187: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
188: ' trying to cfile non-existing file', $r->filename);
189: return HTTP_NOT_FOUND;
190: }
191:
192: # ----------------------------------------------------------- Start page output
193: my $uname;
194: my $udom;
195:
196: ($uname,$udom)=
197: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
198: unless (($uname) && ($udom)) {
199: $r->log_reason($uname.' at '.$udom.
1.4 www 200: ' trying to manipulate file '.$ENV{'form.filename'}.
1.1 www 201: ' ('.$fn.') - not authorized',
202: $r->filename);
203: return HTTP_NOT_ACCEPTABLE;
204: }
205:
206: $fn=~s/\/\~(\w+)//;
207:
208: $r->content_type('text/html');
209: $r->send_http_header;
210:
211: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
212:
213: $r->print(
214: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
215:
216:
217: $r->print('<h1>Construction Space <tt>'.$fn.'</tt></h1>');
218:
219: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
220: $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
221: '</font></h3>');
222: }
223:
1.2 www 224: if ($ENV{'form.action'} eq 'delete') {
225: $r->print('<h3>Delete</h3>');
226: } elsif ($ENV{'form.action'} eq 'rename') {
227: $r->print('<h3>Rename</h3>');
228: } elsif ($ENV{'form.action'} eq 'newdir') {
229: $r->print('<h3>New Directory</h3>');
230: } elsif ($ENV{'form.action'} eq 'copy') {
231: $r->print('<h3>Copy</h3>');
232: } else {
233: $r->print('<p>Unknown Action</body></html>');
234: return OK;
235: }
1.1 www 236: if ($ENV{'form.phase'} eq 'two') {
1.4 www 237: &phasetwo($r,$fn,$uname,$udom);
1.1 www 238: } else {
1.3 www 239: &phaseone($r,$fn,$uname,$udom);
1.1 www 240: }
241:
242: $r->print('</body></html>');
243: return OK;
244: }
245:
246: 1;
247: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>