version 1.1, 2001/04/05 19:35:15
|
version 1.3, 2001/05/25 16:36:36
|
Line 15
|
Line 15
|
# |
# |
# 03/31,04/03 Gerd Kortemeyer) |
# 03/31,04/03 Gerd Kortemeyer) |
# |
# |
# 04/05 Gerd Kortemeyer |
# 04/05,04/09,05/25 Gerd Kortemeyer |
|
|
package Apache::lonupload; |
package Apache::lonupload; |
|
|
Line 23 use strict;
|
Line 23 use strict;
|
use Apache::File; |
use Apache::File; |
use File::Copy; |
use File::Copy; |
use Apache::Constants qw(:common :http :methods); |
use Apache::Constants qw(:common :http :methods); |
|
use Apache::loncacc; |
|
|
sub phaseone { |
sub upfile_store { |
my ($r,$fn,$uname,$udom)=@_; |
my $r=shift; |
my $docroot=$r->dir_config('lonDocRoot'); |
|
|
my $fname=$ENV{'form.upfile.filename'}; |
my $urldir='/res/'.$udom.'/'.$uname.$fn; |
$fname=~s/\W//g; |
$urldir=~s/\/[^\/]+$/\//; |
|
|
chop($ENV{'form.upfile'}); |
my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn; |
|
my $resdir=$resfn; |
|
$resdir=~s/\/[^\/]+$/\//; |
|
|
|
$fn=~/^\/(.+)\.(\w+)$/; |
|
my $main=$1; |
|
my $suffix=$2; |
|
|
|
$r->print('<form action=/adm/retrieve method=post>'. |
my $datatoken=$ENV{'user.name'}.'_'.$ENV{'user.domain'}. |
'<input type=hidden name=filename value="'.$fn.'">'. |
'_upload_'.$fname.'_'.time.'_'.$$; |
'<input type=hidden name=phase value=two>'. |
{ |
'<table border=2><tr><th>Select</th><th>Version</th>'. |
my $fh=Apache::File->new('>'.$r->dir_config('lonDaemons'). |
'<th>Became this version on ...</th>'. |
'/tmp/'.$datatoken.'.tmp'); |
'<th>Metadata</th></tr>'); |
print $fh $ENV{'form.upfile'}; |
my $filename; |
|
opendir(DIR,$resdir); |
|
while ($filename=readdir(DIR)) { |
|
if ($filename=~/^$main\.(\d+)\.$suffix$/) { |
|
my $version=$1; |
|
my ($rdev,$rino,$rmode,$rnlink, |
|
$ruid,$rgid,$rrdev,$rsize, |
|
$ratime,$rmtime,$rctime, |
|
$rblksize,$rblocks)=stat($resdir.'/'.$filename); |
|
$r->print('<tr><td><input type=radio name=version value="'. |
|
$version.'"></td><th>'.$version.'</th><td>'. |
|
localtime($rmtime).'</td><td>'. |
|
'<a href="'.$urldir.$filename.'.meta" target=cat>'. |
|
'Metadata Version '.$version.'</a></td></tr>'); |
|
} |
|
} |
} |
closedir(DIR); |
return $datatoken; |
my ($rdev,$rino,$rmode,$rnlink, |
} |
$ruid,$rgid,$rrdev,$rsize, |
|
$ratime,$rmtime,$rctime, |
|
$rblksize,$rblocks)=stat($resfn); |
sub phaseone { |
$r->print('<tr><td><input type=radio name=version value="new"></td>'. |
my ($r,$fn,$uname,$udom)=@_; |
'<th>Current</th><td>'.localtime($rmtime). |
$fn=~s/\/[^\/]+$//; |
'</td><td><a href="'.$urldir.$main.'.'.$suffix.'.meta" target=cat>'. |
$fn=~s/([^\/])$/$1\//; |
'Metadata current version</a></td></tr></table><p>'. |
$fn.=$ENV{'form.upfile.filename'}; |
'<font size=+1 color=red>Retrieval of an old version will '. |
$fn=~s/^\///; |
'overwrite the file currently in construction space</font><p>'. |
$fn=~s/(\/)+/\//g; |
'<input type=submit value="Retrieve version"></form>'); |
|
|
if (($fn) && ($fn!~/\/$/)) { |
|
$r->print( |
|
'<form action=/adm/upload method=post>'. |
|
'<input type=hidden name=phase value=two>'. |
|
'<input type=hidden name=datatoken value="'.&upfile_store.'">'. |
|
'Store uploaded file as '. |
|
'<input type=text size=50 name=filename value="/priv/'. |
|
$uname.'/'.$fn.'"><br>'. |
|
'<input type=submit value="Store"></form>'); |
|
} else { |
|
$r->print('<font color=red>Illegal filename.</font>'); |
|
} |
} |
} |
|
|
sub phasetwo { |
sub phasetwo { |
my ($r,$fn,$uname,$udom)=@_; |
my ($r,$fn,$uname,$udom)=@_; |
if ($ENV{'form.version'}) { |
my $tfn=$fn; |
my $version=$ENV{'form.version'}; |
$tfn=~s/^\/(\~|priv)\/(\w+)//; |
if ($version eq 'new') { |
my $target='/home/'.$uname.'/public_html'.$tfn; |
$r->print('<h3>Retrieving current (most recent) version</h3>'); |
my $datatoken=$ENV{'form.datatoken'}; |
} else { |
if (($fn) && ($datatoken)) { |
$r->print('<h3>Retrieving old version '.$version.'</h3>'); |
if ((-e $target) && ($ENV{'form.override'} ne 'Yes')) { |
} |
$r->print( |
my $logfile; |
'<form action=/adm/upload method=post>'. |
my $ctarget='/home/'.$uname.'/public_html'.$fn; |
'File <tt>'.$fn.'</tt> exists. Overwrite? '. |
my $vfn=$fn; |
'<input type=hidden name=phase value=two>'. |
if ($version ne 'new') { |
'<input type=hidden name=filename value="'.$fn.'">'. |
$vfn=~s/\.(\w+)$/\.$version\.$1/; |
'<input type=hidden name=datatoken value="'.$datatoken.'">'. |
} |
'<input type=submit name=override value="Yes"></form>'); |
my $csource=$r->dir_config('lonDocRoot').'/res/'.$udom.'/'.$uname.$vfn; |
} else { |
unless ($logfile=Apache::File->new('>>'.$ctarget.'.log')) { |
my $source=$r->dir_config('lonDaemons'). |
$r->print( |
'/tmp/'.$datatoken.'.tmp'; |
'<font color=red>No write permission to user directory, FAIL</font>'); |
if (copy($source,$target)) { |
} |
$r->print('File copied.'); |
print $logfile |
$r->print('<p><font size=+2><a href="'.$fn. |
"\n\n================= Retrieve ".localtime()." ================\n". |
'">View file</a></font>'); |
"Version: $version\nSource: $csource\nTarget: $ctarget\n"; |
} else { |
$r->print('<p>Copying file: '); |
$r->print('Failed to copy: '.$!); |
if (copy($csource,$ctarget)) { |
} |
$r->print('ok<p>'); |
} |
print $logfile "Copied sucessfully.\n\n"; |
|
} else { |
|
my $error=$!; |
|
$r->print('fail, '.$error.'<p>'); |
|
print $logfile "Copy failed: $error\n\n"; |
|
} |
|
$r->print('<font size=+2><a href="/priv/'.$uname.$fn. |
|
'">Back to '.$fn.'</a></font>'); |
|
} else { |
} else { |
$r->print( |
$r->print( |
'<font size=+1 color=red>Please pick a version to retrieve</font><p>'); |
'<font size=+1 color=red>Please pick a filename</font><p>'); |
&phaseone($r,$fn,$uname,$udom); |
&phaseone($r,$fn,$uname,$udom); |
} |
} |
} |
} |
Line 120 sub handler {
|
Line 103 sub handler {
|
|
|
my $r=shift; |
my $r=shift; |
|
|
|
my $uname; |
|
my $udom; |
|
|
|
unless (($uname,$udom)= |
|
&Apache::loncacc::constructaccess( |
|
$ENV{'form.filename'},$r->dir_config('lonDefDomain'))) { |
|
$r->log_reason($uname.' at '.$udom. |
|
' trying to publish file '.$ENV{'form.filename'}. |
|
' - not authorized', |
|
$r->filename); |
|
return HTTP_NOT_ACCEPTABLE; |
|
} |
|
|
my $fn; |
my $fn; |
|
|
if ($ENV{'form.filename'}) { |
if ($ENV{'form.filename'}) { |
$fn=$ENV{'form.filename'}; |
$fn=$ENV{'form.filename'}; |
$fn=~s/^http\:\/\/[^\/]+\/\~(\w+)//; |
$fn=~s/^http\:\/\/[^\/]+\/(\~|priv\/)(\w+)//; |
} else { |
} else { |
$r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. |
$r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. |
' unspecified filename for retrieval', $r->filename); |
' unspecified filename for upload', $r->filename); |
return HTTP_NOT_FOUND; |
return HTTP_NOT_FOUND; |
} |
} |
|
|
unless ($fn) { |
|
$r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. |
|
' trying to retrieve non-existing file', $r->filename); |
|
return HTTP_NOT_FOUND; |
|
} |
|
|
|
# ----------------------------------------------------------- Start page output |
# ----------------------------------------------------------- Start page output |
|
|
my $uname=$ENV{'user.name'}; |
|
my $udom=$ENV{'user.domain'}; |
|
|
|
$r->content_type('text/html'); |
$r->content_type('text/html'); |
$r->send_http_header; |
$r->send_http_header; |
Line 151 sub handler {
|
Line 139 sub handler {
|
'<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>'); |
'<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>'); |
|
|
|
|
$r->print('<h1>Retrieve previous versions of <tt>'.$fn.'</tt></h1>'); |
$r->print('<h1>Upload file to Construction Space</h1>'); |
|
|
|
if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) { |
|
$r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom. |
|
'</font></h3>'); |
|
} |
|
|
|
|
if ($ENV{'form.phase'} eq 'two') { |
if ($ENV{'form.phase'} eq 'two') { |
&phasetwo($r,$fn,$uname,$udom); |
&phasetwo($r,$fn,$uname,$udom); |