Diff for /loncom/auth/lonacc.pm between versions 1.92 and 1.113

version 1.92, 2006/08/08 17:20:15 version 1.113, 2007/11/06 02:42:40
Line 36  use Apache::lonnet; Line 36  use Apache::lonnet;
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::restrictedaccess();  use Apache::restrictedaccess();
 use CGI::Cookie();  use Apache::blockedaccess(); 
 use Fcntl qw(:flock);  use Fcntl qw(:flock);
 use LONCAPA;  use LONCAPA;
   
Line 44  sub cleanup { Line 44  sub cleanup {
     my ($r)=@_;      my ($r)=@_;
     if (! $r->is_initial_req()) { return DECLINED; }      if (! $r->is_initial_req()) { return DECLINED; }
     &Apache::lonnet::save_cache();      &Apache::lonnet::save_cache();
       &Apache::lontexconvert::jsMath_reset();
     return OK;      return OK;
 }  }
   
Line 62  sub get_posted_cgi { Line 63  sub get_posted_cgi {
     if ($r->header_in('Content-length')) {      if ($r->header_in('Content-length')) {
  $r->read($buffer,$r->header_in('Content-length'),0);   $r->read($buffer,$r->header_in('Content-length'),0);
     }      }
     unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) {      my $content_type = $r->header_in('Content-type');
       if ($content_type !~ m{^multipart/form-data}) {
  my @pairs=split(/&/,$buffer);   my @pairs=split(/&/,$buffer);
  my $pair;   my $pair;
  foreach $pair (@pairs) {   foreach $pair (@pairs) {
Line 74  sub get_posted_cgi { Line 76  sub get_posted_cgi {
     &Apache::loncommon::add_to_env("form.$name",$value);      &Apache::loncommon::add_to_env("form.$name",$value);
  }   }
     } else {      } else {
  my $contentsep=$1;   my ($contentsep) = ($content_type =~ /boundary=\"?([^\";,]+)\"?/);
  my @lines = split (/\n/,$buffer);   my @lines = split (/\n/,$buffer);
  my $name='';   my $name='';
  my $value='';   my $value='';
Line 82  sub get_posted_cgi { Line 84  sub get_posted_cgi {
  my $fmime='';   my $fmime='';
  my $i;   my $i;
  for ($i=0;$i<=$#lines;$i++) {   for ($i=0;$i<=$#lines;$i++) {
     if ($lines[$i]=~/^$contentsep/) {      if ($lines[$i]=~/^--\Q$contentsep\E/) {
  if ($name) {   if ($name) {
     chomp($value);      chomp($value);
     if ($fname) {      if ($fname) {
Line 137  sub get_posted_cgi { Line 139  sub get_posted_cgi {
     $r->headers_in->unset('Content-length');      $r->headers_in->unset('Content-length');
 }  }
   
 sub handler {  # handle the case of the single sign on user, at this point $r->user 
     my $r = shift;  # will be set and valid now need to find the loncapa user info and possibly
     my $requrl=$r->uri;  # balance them
     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));  # returns OK if it was a SSO and user was handled
     my $lonid=$cookies{'lonID'};  #         undef if not SSO or no means to hanle the user
     my $cookie;  sub sso_login {
       my ($r,$handle) = @_;
   
     my $lonidsdir=$r->dir_config('lonIDsDir');      my $lonidsdir=$r->dir_config('lonIDsDir');
       if (!($r->user 
     && (!defined($env{'user.name'}) && !defined($env{'user.domain'}))
     && ($handle eq ''))) {
    # not an SSO case or already logged in
    return undef;
       }
   
       my ($user) = ($r->user =~ m/([a-zA-Z0-9_\-@.]*)/);
   
     my $handle;      my $domain = $r->dir_config('lonDefDomain');
     if ($lonid) {      my $home=&Apache::lonnet::homeserver($user,$domain);
  $handle=$lonid->value;      if ($home !~ /(con_lost|no_host|no_such_host)/) {
         $handle=~s/\W//g;   &Apache::lonnet::logthis(" SSO authorized user $user ");
     }   if ($r->dir_config("lonBalancer") eq 'yes') {
             # login but immeaditly go to switch server to find us a new 
     my ($sso_login);      # machine
     if ($r->user       &Apache::lonauth::success($r,$user,$domain,$home,'noredirect');
  && (!$lonid || !-e "$lonidsdir/$handle.id" || $handle eq '') ) {              $env{'request.sso.login'} = 1;
  $sso_login = 1;              if (defined($r->dir_config("lonSSOReloginServer"))) {
  my $domain = $r->dir_config('lonDefDomain');                  $env{'request.sso.reloginserver'} =
  my $home=&Apache::lonnet::homeserver($r->user,$domain);                      $r->dir_config('lonSSOReloginServer');
  if ($home !~ /(con_lost|no_such_host)/) {              }
     $handle=&Apache::lonauth::success($r,$r->user,$domain,      $r->internal_redirect('/adm/switchserver');
      $home,'noredirect');      $r->set_handlers('PerlHandler'=> undef);
     $r->header_out('Set-cookie',"lonID=$handle; path=/");   } else {
       # need to login them in, so generate the need data that
       # migrate expects to do login
       my %info=('ip'        => $r->connection->remote_ip(),
         'domain'    => $domain,
         'username'  => $user,
         'server'    => $r->dir_config('lonHostID'),
         'sso.login' => 1
         );
               if (defined($r->dir_config("lonSSOReloginServer"))) {
                   $info{'sso.reloginserver'} = 
                       $r->dir_config('lonSSOReloginServer'); 
               }
       my $token = 
    &Apache::lonnet::tmpput(\%info,
    $r->dir_config('lonHostID'));
       $env{'form.token'} = $token;
       $r->internal_redirect('/adm/migrateuser');
       $r->set_handlers('PerlHandler'=> undef);
  }   }
    return OK;
       } elsif (defined($r->dir_config('lonSSOUserUnknownRedirect'))) {
    &Apache::lonnet::logthis(" SSO authorized unknown user $user ");
           $r->subprocess_env->set('SSOUserUnknown' => $user);
           $r->subprocess_env->set('SSOUserDomain' => $domain);
    $r->internal_redirect($r->dir_config('lonSSOUserUnknownRedirect'));
    $r->set_handlers('PerlHandler'=> undef);
    return OK;
       }
       return undef;
   }
   
   sub handler {
       my $r = shift;
       my $requrl=$r->uri;
       if (&Apache::lonnet::is_domainimage($requrl)) {
           return OK;
     }      }
   
     if ($sso_login) {      
  &Apache::lonnet::appenv('request.sso.login' => 1);      my $handle = &Apache::lonnet::check_for_valid_session($r);
   
       my $result = &sso_login($r,$handle);
       if (defined($result)) {
    return $result
     }      }
   
   
     if ($r->dir_config("lonBalancer") eq 'yes') {      if ($r->dir_config("lonBalancer") eq 'yes') {
  $r->set_handlers('PerlResponseHandler'=>   $r->set_handlers('PerlResponseHandler'=>
  [\&Apache::switchserver::handler]);   [\&Apache::switchserver::handler]);
Line 175  sub handler { Line 227  sub handler {
           
     if ($handle eq '') {      if ($handle eq '') {
  $r->log_reason("Cookie $handle not valid", $r->filename);    $r->log_reason("Cookie $handle not valid", $r->filename); 
     } elsif ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {      } elsif ($handle ne '') {
   
 # ------------------------------------------------------ Initialize Environment  # ------------------------------------------------------ Initialize Environment
    my $lonidsdir=$r->dir_config('lonIDsDir');
  &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);   &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   
 # --------------------------------------------------------- Initialize Language  # --------------------------------------------------------- Initialize Language
Line 204  sub handler { Line 256  sub handler {
   
 # ---------------------------------------------------------------- Check access  # ---------------------------------------------------------------- Check access
  my $now = time;   my $now = time;
  if ($requrl!~/^\/adm|public|prtspool\//) {   if ($requrl !~ m{^/(?:adm|public|prtspool)/}
       || $requrl =~ /^\/adm\/.*\/(smppg|bulletinboard)(\?|$ )/x) {
     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";
Line 214  sub handler { Line 267  sub handler {
  &Apache::restrictedaccess::setup_handler($r);   &Apache::restrictedaccess::setup_handler($r);
  return OK;   return OK;
     }      }
               if ($access eq 'B') {
                   &Apache::blockedaccess::setup_handler($r);
                   return OK;
               }
     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; 
Line 224  sub handler { Line 281  sub handler {
  $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;
       }
    }
    if ($requrl =~ m|^/zipspool/|) {
       my $start='/zipspool/zipout/'.$env{'user.name'}.":".
    $env{'user.domain'};
       if ($requrl !~ /^\Q$start\E/) {
    $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
  return HTTP_NOT_ACCEPTABLE;   return HTTP_NOT_ACCEPTABLE;
     }      }
  }   }

Removed from v.1.92  
changed lines
  Added in v.1.113


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