File:  [LON-CAPA] / loncom / lonnet / perl / lonrep.pm
Revision 1.7: download - view: text, annotated - select for diffs
Wed Mar 2 22:26:36 2005 UTC (19 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
lonnet::repcopy() and lonnet::repcopy_userfile() now return strings rather than constants defined in Apache::Constants.  This allows lonnet::repcopy() to be used for cloning in batch course creation run from a command line script.  If Apache::Constants are to be returned by PerlHandlers these should be set in the appropriate handler rather than in subroutines in lonnet called by the handler, based on the string response from lonnet::repcopy().

    1: # The LearningOnline Network
    2: # Replication Manager
    3: #
    4: # $Id: lonrep.pm,v 1.7 2005/03/02 22:26:36 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (Access Handler for File Transfers
   29: # (lonacc: Cookie Based Access Handler
   30: # 5/21/99,5/22,5/29,5/31,6/15 Gerd Kortemeyer)
   31: # 6/16,6/18 Gerd Kortemeyer)
   32: # 6/18,6/21,6/26,6/28,6/29,6/30,
   33: # 7/2,7/3,7/9,7/10,7/12,
   34: # 01/06,01/14,10/5,
   35: # 06/14/01 Gerd Kortemeyer
   36: 
   37: package Apache::lonrep;
   38: 
   39: use strict;
   40: use Apache::Constants qw(:common :http);
   41: use Apache::lonnet();
   42: use Apache::File();
   43: use CGI::Cookie();
   44: 
   45: sub handler {
   46:     my $r = shift;
   47:     if (-e $r->finfo) {
   48:       return OK;
   49:     } else {
   50:       my $filename=$r->filename.$r->path_info;
   51:       if ($filename=~/\/$/) { return OK; }
   52:       if (-e "$filename.in.transfer") {
   53: 	sleep 10;
   54:         $r->filename($filename);
   55:         if (-e $r->finfo) {
   56: 	   return OK;
   57:         } else {
   58: 	   $r->log_reason("Waiting for file transfer timed out",$filename);
   59: 	   return HTTP_SERVICE_UNAVAILABLE;
   60:         }
   61:       } else {
   62:           my $response=Apache::lonnet::repcopy($filename);
   63:           if ($response eq 'OK') {
   64: 	      $r->filename($filename);
   65:               return OK;
   66:           }
   67:           my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
   68:           my $lonid=$cookies{'lonID'};
   69:           if ($lonid) {
   70: 	     $r->log_reason('Replication failed for '.$lonid->value);
   71:              return $response;
   72: 	  } else {
   73: 	     $r->log_reason('Replication failed for unknown user'); 
   74:              return FORBIDDEN;
   75:           } 
   76:       }
   77:     }
   78: }
   79: 
   80: 1;
   81: __END__
   82: 
   83: 
   84: 
   85: 
   86: 
   87: 
   88: 
   89: 

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