Diff for /loncom/auth/lonacc.pm between versions 1.60 and 1.75

version 1.60, 2005/01/28 09:30:40 version 1.75, 2006/04/07 22:42:00
Line 25 Line 25
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
 # YEAR=1999  
 # 5/21/99,5/22,5/29,5/31,6/15,16/11,22/11,  
 # YEAR=2000  
 # 01/06,01/13,05/31,06/01,09/06,09/25,09/28,10/30,11/6,  
 # 12/25,12/26,  
 # YEAR=2001  
 # 01/06/01,05/28,8/11,9/26,11/29 Gerd Kortemeyer  
 # YEAR=2002  
 # 1/4,2/25 Gerd Kortemeyer  
 #  
 ###  ###
   
 package Apache::lonacc;  package Apache::lonacc;
Line 48  use Apache::lonlocal; Line 38  use Apache::lonlocal;
 use CGI::Cookie();  use CGI::Cookie();
 use Fcntl qw(:flock);  use Fcntl qw(:flock);
   
   sub cleanup {
       my ($r)=@_;
       if (! $r->is_initial_req()) { return DECLINED; }
       &Apache::lonnet::save_cache();
       return OK;
   }
   
   sub goodbye {
       my ($r)=@_;
       &Apache::lonnet::goodbye();
       return DONE;
   }
   
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
     my $requrl=$r->uri;      my $requrl=$r->uri;
     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));      my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
     my $lonid=$cookies{'lonID'};      my $lonid=$cookies{'lonID'};
     my $cookie;      my $cookie;
       my $lonidsdir=$r->dir_config('lonIDsDir');
   
       my $handle;
     if ($lonid) {      if ($lonid) {
  my $handle=$lonid->value;   $handle=$lonid->value;
         $handle=~s/\W//g;          $handle=~s/\W//g;
         my $lonidsdir=$r->dir_config('lonIDsDir');      }
         
       if ($r->user 
    && (!$lonid || !-e "$lonidsdir/$handle.id" || $handle eq '') ) {
    my $domain = $r->dir_config('lonDefDomain');
    my $home=&Apache::lonnet::homeserver($r->user,$domain);
    if ($home !~ /(con_lost|no_such_host)/) {
       $handle=&Apache::lonauth::success($r,$r->user,$domain,
        $home,'noredirect');
       $r->header_out('Set-cookie',"lonID=$handle; path=/");
    }
       }
   
       if ($r->dir_config("lonBalancer") eq 'yes') {
    $r->set_handlers('PerlResponseHandler'=>
    [\&Apache::switchserver::handler]);
       }
   
       if ($handle ne '') {
         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {          if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
   
 # ------------------------------------------------------ Initialize Environment  # ------------------------------------------------------ Initialize Environment
Line 71  sub handler { Line 95  sub handler {
 # -------------------------------------------------------------- Resource State  # -------------------------------------------------------------- Resource State
   
             if ($requrl=~/^\/+(res|uploaded)\//) {              if ($requrl=~/^\/+(res|uploaded)\//) {
                $ENV{'request.state'} = "published";                 $env{'request.state'} = "published";
     } else {      } else {
        $ENV{'request.state'} = 'unknown';         $env{'request.state'} = 'unknown';
             }              }
             $ENV{'request.filename'} = $r->filename;              $env{'request.filename'} = $r->filename;
             $ENV{'request.noversionuri'} = &Apache::lonnet::deversion($requrl);              $env{'request.noversionuri'} = &Apache::lonnet::deversion($requrl);
 # -------------------------------------------------------- Load POST parameters  # -------------------------------------------------------- Load POST parameters
   
     &Apache::loncommon::get_posted_cgi($r);      &Apache::loncommon::get_posted_cgi($r);
Line 86  sub handler { Line 110  sub handler {
             if ($requrl!~/^\/adm|public|prtspool\//) {              if ($requrl!~/^\/adm|public|prtspool\//) {
  my $access=&Apache::lonnet::allowed('bre',$requrl);   my $access=&Apache::lonnet::allowed('bre',$requrl);
                 if ($access eq '1') {                  if ($access eq '1') {
    $ENV{'user.error.msg'}="$requrl:bre:0:0:Choose Course";     $env{'user.error.msg'}="$requrl:bre:0:0:Choose Course";
            return HTTP_NOT_ACCEPTABLE;              return HTTP_NOT_ACCEPTABLE; 
                 }                  }
                 if (($access ne '2') && ($access ne 'F')) {                  if (($access ne '2') && ($access ne 'F')) {
    $ENV{'user.error.msg'}="$requrl:bre:1:1:Access Denied";     $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
            return HTTP_NOT_ACCEPTABLE;              return HTTP_NOT_ACCEPTABLE; 
                 }                  }
             }              }
     if ($requrl =~ m|^/prtspool/|) {      if ($requrl =~ m|^/prtspool/|) {
  my $start='/prtspool/'.$ENV{'user.name'}.'_'.   my $start='/prtspool/'.$env{'user.name'}.'_'.
     $ENV{'user.domain'};      $env{'user.domain'};
  if ($requrl !~ /^\Q$start\E/) {   if ($requrl !~ /^\Q$start\E/) {
     $ENV{'user.error.msg'}="$requrl:bre:1:1:Access Denied";      $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
     return HTTP_NOT_ACCEPTABLE;      return HTTP_NOT_ACCEPTABLE;
  }   }
     }      }
       if ($env{'user.name'} eq 'public' && 
    $env{'user.domain'} eq 'public' &&
    $requrl !~ m{^/+(res|public)/} &&
    $requrl !~ m{^/+adm/(help|logout|randomlabel\.png)}) {
    $env{'request.querystring'}=$r->args;
    $env{'request.firsturl'}=$requrl;
    return FORBIDDEN;
       }
 # ------------------------------------------------------------- This is allowed  # ------------------------------------------------------------- This is allowed
           if ($ENV{'request.course.id'}) {            if ($env{'request.course.id'}) {
     &Apache::lonnet::countacc($requrl);      &Apache::lonnet::countacc($requrl);
             $requrl=~/\.(\w+)$/;              $requrl=~/\.(\w+)$/;
             if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||              if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
  ($requrl=~/^\/adm\/.*\/(aboutme|navmaps|smppg|bulletinboard)(\?|$)/) ||   ($requrl=~/^\/adm\/.*\/(aboutme|navmaps|smppg|bulletinboard)(\?|$)/) ||
  ($requrl=~/^\/adm\/wrapper\//) ||   ($requrl=~/^\/adm\/wrapper\//) ||
    ($requrl=~m|^/adm/coursedocs/showdoc/|) ||
  ($requrl=~m|\.problem/smpedit$|) ||   ($requrl=~m|\.problem/smpedit$|) ||
  ($requrl=~/^\/public\/.*\/syllabus$/)) {   ($requrl=~/^\/public\/.*\/syllabus$/)) {
 # ------------------------------------- This is serious stuff, get symb and log  # ------------------------------------- This is serious stuff, get symb and log
Line 117  sub handler { Line 150  sub handler {
                 if ($query) {                  if ($query) {
     &Apache::loncommon::get_unprocessed_cgi($query,['symb']);      &Apache::loncommon::get_unprocessed_cgi($query,['symb']);
                 }                  }
                 if ($ENV{'form.symb'}) {                  if ($env{'form.symb'}) {
     $symb=&Apache::lonnet::symbclean($ENV{'form.symb'});      $symb=&Apache::lonnet::symbclean($env{'form.symb'});
                     if ($requrl =~ m|^/adm/wrapper/|) {                      if ($requrl =~ m|^/adm/wrapper/|
    || $requrl =~ m|^/adm/coursedocs/showdoc/|) {
                         my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);                          my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
                         &Apache::lonnet::symblist($map,$murl => $mid,                          &Apache::lonnet::symblist($map,$murl => [$murl,$mid],
                                                'last_known' => $murl);    'last_known' =>[$murl,$mid]);
                     } elsif ((&Apache::lonnet::symbverify($symb,$requrl)) ||                      } elsif ((&Apache::lonnet::symbverify($symb,$requrl)) ||
      (($requrl=~m|(.*)/smpedit$|) &&       (($requrl=~m|(.*)/smpedit$|) &&
       &Apache::lonnet::symbverify($symb,$1))) {        &Apache::lonnet::symbverify($symb,$1))) {
                       my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);                        my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
                       &Apache::lonnet::symblist($map,$murl => $mid,        &Apache::lonnet::symblist($map,$murl => [$murl,$mid],
                                                'last_known' => $murl);   'last_known' =>[$murl,$mid]);
     } else {      } else {
  $r->log_reason('Invalid symb for '.$requrl.': '.   $r->log_reason('Invalid symb for '.$requrl.': '.
                                        $symb);                                         $symb);
         $ENV{'user.error.msg'}=          $env{'user.error.msg'}=
                                 "$requrl:bre:1:1:Invalid Access";                                  "$requrl:bre:1:1:Invalid Access";
                  return HTTP_NOT_ACCEPTABLE;                    return HTTP_NOT_ACCEPTABLE; 
                     }                      }
Line 141  sub handler { Line 175  sub handler {
     if (&Apache::lonnet::is_on_map($requrl) && $symb &&      if (&Apache::lonnet::is_on_map($requrl) && $symb &&
  !&Apache::lonnet::symbverify($symb,$requrl)) {   !&Apache::lonnet::symbverify($symb,$requrl)) {
  $r->log_reason('Invalid symb for '.$requrl.': '.$symb);   $r->log_reason('Invalid symb for '.$requrl.': '.$symb);
         $ENV{'user.error.msg'}=          $env{'user.error.msg'}=
                                 "$requrl:bre:1:1:Invalid Access";                                  "$requrl:bre:1:1:Invalid Access";
                  return HTTP_NOT_ACCEPTABLE;                    return HTTP_NOT_ACCEPTABLE; 
     }      }
                     my ($map,$mid,$murl)=split(/\_\_\_/,$symb);      if ($symb) {
     &Apache::lonnet::symblist($map,$murl => $mid,   my ($map,$mid,$murl)=
                                               'last_known' => $murl);      &Apache::lonnet::decode_symb($symb);
    &Apache::lonnet::symblist($map,$murl =>[$murl,$mid],
    'last_known' =>[$murl,$mid]);
       }
                 }                  }
                 $ENV{'request.symb'}=$symb;                  $env{'request.symb'}=$symb;
                 &Apache::lonnet::courseacclog($symb);                  &Apache::lonnet::courseacclog($symb);
             } else {              } else {
 # ------------------------------------------------------- This is other content  # ------------------------------------------------------- This is other content
Line 158  sub handler { Line 195  sub handler {
   }    }
             return OK;               return OK; 
         } else {           } else { 
             $r->log_reason("Cookie $handle not valid", $r->filename)               $r->log_reason("Cookie $handle not valid", $r->filename); 
         };          }
     }      }
   
 # -------------------------------------------- See if this is a public resource  # -------------------------------------------- See if this is a public resource
     if ($requrl=~m|^/public/|      if ($requrl=~m|^/public/|
  || (&Apache::lonnet::metadata($requrl,'copyright') eq 'public')) {   || (&Apache::lonnet::metadata($requrl,'copyright') eq 'public')) {
         &Apache::lonnet::logthis('Granting public access: '.$requrl);          &Apache::lonnet::logthis('Granting public access: '.$requrl);
           &Apache::lonlocal::get_language_handle($r);
    my $cookie=
       &Apache::lonauth::success($r,'public','public','public');
           my $lonidsdir=$r->dir_config('lonIDsDir');
    &Apache::lonnet::transfer_profile_to_env($lonidsdir,$cookie);
  &Apache::loncommon::get_posted_cgi($r);   &Apache::loncommon::get_posted_cgi($r);
  $ENV{'user.name'}='public';          $env{'request.state'} = "published";
         $ENV{'user.domain'}='public';          $env{'request.publicaccess'} = 1;
         $ENV{'request.state'} = "published";          $env{'request.filename'} = $r->filename;
         $ENV{'request.publicaccess'} = 1;  
         $ENV{'request.filename'} = $r->filename;  
  my ($httpbrowser,  $clientbrowser, $clientversion,  
     $clientmathml, $clientunicode, $clientos) =  
  &Apache::loncommon::decode_user_agent($r);  
  $ENV{'browser.type'}=$clientbrowser;  
         $ENV{'browser.version'}=$clientversion;  
         $ENV{'browser.mathml'}=$clientmathml;  
         $ENV{'browser.unicode'}=$clientunicode;  
         $ENV{'browser.os'}=$clientos;  
   
    $r->header_out('Set-cookie',"lonID=$cookie; path=/");
         return OK;          return OK;
     }      }
       if ($requrl=~m|^/+adm/+help/+|) {
    return OK;
       }
 # -------------------------------------------------------------- Not authorized  # -------------------------------------------------------------- Not authorized
     $requrl=~/\.(\w+)$/;      $requrl=~/\.(\w+)$/;
     if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||  #    if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
         ($requrl=~/^\/adm\/(roles|logout|email|menu|remote)/) ||  #        ($requrl=~/^\/adm\/(roles|logout|email|menu|remote)/) ||
         ($requrl=~m|^/prtspool/|)) {  #        ($requrl=~m|^/prtspool/|)) {
 # -------------------------- Store where they wanted to go and get login screen  # -------------------------- Store where they wanted to go and get login screen
  $ENV{'request.querystring'}=$r->args;   $env{'request.querystring'}=$r->args;
  $ENV{'request.firsturl'}=$requrl;   $env{'request.firsturl'}=$requrl;
        return FORBIDDEN;         return FORBIDDEN;
    } else {  #   } else {
 # --------------------------------------------------------------------- Goodbye  # --------------------------------------------------------------------- Goodbye
        return HTTP_BAD_REQUEST;  #       return HTTP_BAD_REQUEST;
    }  #   }
 }  }
   
 1;  1;

Removed from v.1.60  
changed lines
  Added in v.1.75


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.