File:  [LON-CAPA] / loncom / publisher / lonpublisher.pm
Revision 1.2: download - view: text, annotated - select for diffs
Wed Nov 29 12:28:46 2000 UTC (23 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Checks file, etc

    1: # The LearningOnline Network with CAPA
    2: # Publication Handler
    3: # 
    4: # (TeX Content Handler
    5: #
    6: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
    7: #
    8: # 11/28,11/29 Gerd Kortemeyer
    9: 
   10: package Apache::lonpublisher;
   11: 
   12: use strict;
   13: use Apache::File;
   14: use Apache::Constants qw(:common :http :methods);
   15: use HTML::TokeParser;
   16: 
   17: sub publish {
   18:     my ($source,$target,$style)=@_;
   19:     my $logfile;
   20:     unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
   21: 	return 'No write permission to user directory, FAIL';
   22:     }
   23:     print $logfile 
   24: "\n\n================== Publish ".localtime()." =================\n";
   25: 
   26:     my $version='';
   27:    
   28:     return 'Version '.$version.', SUCCESS';
   29: }
   30: 
   31: # ================================================================ Main Handler
   32: 
   33: sub handler {
   34:   my $r=shift;
   35: 
   36:   if ($r->header_only) {
   37:      $r->content_type('text/html');
   38:      $r->send_http_header;
   39:      return OK;
   40:   }
   41: 
   42: # -------------------------------------------------------------- Check filename
   43: 
   44:   my $fn=$ENV{'form.filename'};
   45: 
   46:   unless ($fn) { 
   47:      $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
   48:          ' trying to publish empty filename', $r->filename); 
   49:      return HTTP_NOT_FOUND;
   50:   } 
   51: 
   52:   $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
   53: 
   54:   my $targetdir='';
   55:   my $docroot=$r->dir_config('lonDocRoot'); 
   56:   if ($1 ne $ENV{'user.name'}) {
   57:      $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
   58:          ' trying to publish unowned file '.$ENV{'form.filename'}.
   59:          ' ('.$fn.')', 
   60:          $r->filename); 
   61:      return HTTP_NOT_ACCEPTABLE;
   62:   } else {
   63:       $targetdir=$docroot.'/res/'.$ENV{'user.domain'};
   64:   }
   65:                                  
   66:   
   67:   unless (-e $fn) { 
   68:      $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
   69:          ' trying to publish non-existing file '.$ENV{'form.filename'}.
   70:          ' ('.$fn.')', 
   71:          $r->filename); 
   72:      return HTTP_NOT_FOUND;
   73:   } 
   74: 
   75: # --------------------------------- File is there and owned, init lookup tables
   76: 
   77: # ----------------------------------------------------------- Start page output
   78: 
   79:   $r->content_type('text/html');
   80:   $r->send_http_header;
   81: 
   82:   $r->print('<html><head><title>LON-CAPA Publishing</title></head>');
   83:   $r->print('<body bgcolor="#FFFFFF">');
   84:   my $thisfn=$fn;
   85:    
   86: # ------------------------------------------------------------- Individual file
   87:   {
   88:       $thisfn=~/\.(\w+)$/;
   89:       my $thistype=$1;
   90:       my $thisembstyle=&Apache::lonnet::fileembstyle($thistype);
   91: 
   92:       my $thistarget=$thisfn;
   93:       
   94:       $thistarget=~s/^\/home/$targetdir/;
   95:       $thistarget=~s/\/public\_html//;
   96: 
   97:       my $thisdistarget=$thistarget;
   98:       $thisdistarget=~s/^$docroot//;
   99: 
  100:       my $thisdisfn=$thisfn;
  101:       $thisdisfn=~s/^\/home\/$ENV{'user.name'}\/public_html\///;
  102: 
  103:       $r->print('<h2>Publishing '.
  104:         &Apache::lonnet::filedescription($thistype).' <tt>'.
  105:         $thisdisfn.'</tt></h2><b>Target:</b> <tt>'.$thisdistarget.'</tt><p>');
  106: 
  107: # ------------ We are publishing from $thisfn to $thistarget with $thisembstyle
  108: 
  109:       $r->print('<b>Result:</b> '.&publish($thisfn,$thistarget,$thisembstyle));
  110:       
  111:   }  
  112: 
  113:   $r->print('</body></html>');
  114: 
  115:   return OK;
  116: }
  117: 
  118: 1;
  119: __END__
  120: 
  121: 
  122: 
  123: 
  124: 
  125: 
  126: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>