Annotation of loncom/publisher/loncfile.pm, revision 1.6
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: }
1.6 ! www 167: $r->print('<h3><a href="/priv/'.$uname.$fn.'/">Done</a></h3>');
! 168: return;
1.5 www 169: }
170: $r->print('<h3><a href="/priv/'.$uname.$dir.'/">Done</a></h3>');
1.1 www 171: }
172:
173: sub handler {
174:
175: my $r=shift;
176:
177: my $fn;
178:
179: if ($ENV{'form.filename'}) {
180: $fn=$ENV{'form.filename'};
181: $fn=~s/^http\:\/\/[^\/]+//;
182: } else {
183: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
184: ' unspecified filename for cfile', $r->filename);
185: return HTTP_NOT_FOUND;
186: }
187:
188: unless ($fn) {
189: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
190: ' trying to cfile non-existing file', $r->filename);
191: return HTTP_NOT_FOUND;
192: }
193:
194: # ----------------------------------------------------------- Start page output
195: my $uname;
196: my $udom;
197:
198: ($uname,$udom)=
199: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
200: unless (($uname) && ($udom)) {
201: $r->log_reason($uname.' at '.$udom.
1.4 www 202: ' trying to manipulate file '.$ENV{'form.filename'}.
1.1 www 203: ' ('.$fn.') - not authorized',
204: $r->filename);
205: return HTTP_NOT_ACCEPTABLE;
206: }
207:
208: $fn=~s/\/\~(\w+)//;
209:
210: $r->content_type('text/html');
211: $r->send_http_header;
212:
213: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
214:
215: $r->print(
216: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
217:
218:
219: $r->print('<h1>Construction Space <tt>'.$fn.'</tt></h1>');
220:
221: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
222: $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
223: '</font></h3>');
224: }
225:
1.2 www 226: if ($ENV{'form.action'} eq 'delete') {
227: $r->print('<h3>Delete</h3>');
228: } elsif ($ENV{'form.action'} eq 'rename') {
229: $r->print('<h3>Rename</h3>');
230: } elsif ($ENV{'form.action'} eq 'newdir') {
231: $r->print('<h3>New Directory</h3>');
232: } elsif ($ENV{'form.action'} eq 'copy') {
233: $r->print('<h3>Copy</h3>');
234: } else {
235: $r->print('<p>Unknown Action</body></html>');
236: return OK;
237: }
1.1 www 238: if ($ENV{'form.phase'} eq 'two') {
1.4 www 239: &phasetwo($r,$fn,$uname,$udom);
1.1 www 240: } else {
1.3 www 241: &phaseone($r,$fn,$uname,$udom);
1.1 www 242: }
243:
244: $r->print('</body></html>');
245: return OK;
246: }
247:
248: 1;
249: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>