--- loncom/publisher/lonpublisher.pm 2000/11/28 22:15:11 1.1 +++ loncom/publisher/lonpublisher.pm 2000/11/29 12:28:46 1.2 @@ -5,26 +5,111 @@ # # 05/29/00,05/30,10/11 Gerd Kortemeyer) # -# 11/28 Gerd Kortemeyer +# 11/28,11/29 Gerd Kortemeyer package Apache::lonpublisher; use strict; use Apache::File; -use Apache::Constants qw(:common); +use Apache::Constants qw(:common :http :methods); +use HTML::TokeParser; + +sub publish { + my ($source,$target,$style)=@_; + my $logfile; + unless ($logfile=Apache::File->new('>>'.$source.'.log')) { + return 'No write permission to user directory, FAIL'; + } + print $logfile +"\n\n================== Publish ".localtime()." =================\n"; + + my $version=''; + + return 'Version '.$version.', SUCCESS'; +} # ================================================================ Main Handler sub handler { my $r=shift; + + if ($r->header_only) { + $r->content_type('text/html'); + $r->send_http_header; + return OK; + } + +# -------------------------------------------------------------- Check filename + + my $fn=$ENV{'form.filename'}; + + unless ($fn) { + $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. + ' trying to publish empty filename', $r->filename); + return HTTP_NOT_FOUND; + } + + $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/; + + my $targetdir=''; + my $docroot=$r->dir_config('lonDocRoot'); + if ($1 ne $ENV{'user.name'}) { + $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. + ' trying to publish unowned file '.$ENV{'form.filename'}. + ' ('.$fn.')', + $r->filename); + return HTTP_NOT_ACCEPTABLE; + } else { + $targetdir=$docroot.'/res/'.$ENV{'user.domain'}; + } + + + unless (-e $fn) { + $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. + ' trying to publish non-existing file '.$ENV{'form.filename'}. + ' ('.$fn.')', + $r->filename); + return HTTP_NOT_FOUND; + } + +# --------------------------------- File is there and owned, init lookup tables + +# ----------------------------------------------------------- Start page output + $r->content_type('text/html'); $r->send_http_header; - return OK if $r->header_only; - $r->print('LON-CAPA Publishing'); $r->print(''); - $r->print('

'.$ENV{'form.filename'}.'

'); + my $thisfn=$fn; + +# ------------------------------------------------------------- Individual file + { + $thisfn=~/\.(\w+)$/; + my $thistype=$1; + my $thisembstyle=&Apache::lonnet::fileembstyle($thistype); + + my $thistarget=$thisfn; + + $thistarget=~s/^\/home/$targetdir/; + $thistarget=~s/\/public\_html//; + + my $thisdistarget=$thistarget; + $thisdistarget=~s/^$docroot//; + + my $thisdisfn=$thisfn; + $thisdisfn=~s/^\/home\/$ENV{'user.name'}\/public_html\///; + + $r->print('

Publishing '. + &Apache::lonnet::filedescription($thistype).' '. + $thisdisfn.'

Target: '.$thisdistarget.'

'); + +# ------------ We are publishing from $thisfn to $thistarget with $thisembstyle + + $r->print('Result: '.&publish($thisfn,$thistarget,$thisembstyle)); + + } + $r->print(''); return OK;