Diff for /loncom/cgi/enrollqueued.pl between versions 1.1 and 1.3

version 1.1, 2014/04/01 21:39:18 version 1.3, 2014/04/14 01:45:49
Line 79  use Apache::lonuserutils(); Line 79  use Apache::lonuserutils();
 use Apache::loncoursequeueadmin();  use Apache::loncoursequeueadmin();
 use Apache::lonlocal;  use Apache::lonlocal;
 use LONCAPA;  use LONCAPA;
   use IO::Socket;
   
 &main();  &main();
 exit 0;  exit 0;
Line 95  Inputs: None Line 96  Inputs: None
 Returns: Nothing  Returns: Nothing
   
 Description: Main program. Determines if requesting IP is the IP   Description: Main program. Determines if requesting IP is the IP 
              of the server enrollqueued.pl. Side effects               of the of the validation server (as specified in 
              prints content (with text/plain HTTP header).               the domain configuration for self-enrollment).
              Content is URL self-enrolling user should user               Side effects are to print content (with text/plain 
              to access the course.                HTTP header).  Content is the URL self-enrolling user
                should use to access the course.
   
 =cut  =cut
   
Line 164  sub main { Line 166  sub main {
     if (ref($domconfig{'selfenrollment'}) eq 'HASH') {      if (ref($domconfig{'selfenrollment'}) eq 'HASH') {
         if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {          if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
             if ($domconfig{'selfenrollment'}{'validation'}{'url'} =~ m{^https?://([^/]+)/}) {              if ($domconfig{'selfenrollment'}{'validation'}{'url'} =~ m{^https?://([^/]+)/}) {
                 my $validator_ip = gethostbyname($1);                  my $ip = gethostbyname($1);
                 if (($validator_ip ne '') && ($remote_ip eq $validator_ip)) {                  if ($ip ne '') {
                     $allowed = 1;                      my $validator_ip = inet_ntoa($ip);
                       if (($validator_ip ne '') && ($remote_ip eq $validator_ip)) {
                           $allowed = 1;
                       }
                   }
               } elsif ($domconfig{'selfenrollment'}{'validation'}{'url'} =~ m{^/}) {
                   if ($remote_ip ne '') {
                       if (($remote_ip eq '127.0.0.1') || ($remote_ip eq $ENV{'SERVER_ADDR'})) {
                           $allowed = 1;
                       }
                 }                  }
             }              }
         }          }
     }      }
   
     my (%params,@fields,$numrequired);      my (%params,@fields,$numrequired);
     if ($allowed ne '') {      if ($allowed) {
         &Apache::lonlocal::get_language_handle();          &Apache::lonlocal::get_language_handle();
         my ($validreq,@fields);          my ($validreq,@fields);
         if (ref($domconfig{'selfenrollment'}) eq 'HASH') {          if (ref($domconfig{'selfenrollment'}) eq 'HASH') {
             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {              if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                 if (ref($domconfig{'selfenrollment'}{'validation'}{'fields'}) eq 'ARRAY') {                  if (ref($domconfig{'selfenrollment'}{'validation'}{'fields'}) eq 'ARRAY') {
                     $numrequired = @fields;                      $numrequired = scalar(@{$domconfig{'selfenrollment'}{'validation'}{'fields'}});
                     foreach my $field (@{$domconfig{'selfenrollment'}{'validation'}{'fields'}}) {                      foreach my $field (@{$domconfig{'selfenrollment'}{'validation'}{'fields'}}) {
                         $params{$field} = $query->param($field);                          $params{$field} = $query->param($field);
                         if ($field eq 'username') {                          if ($field eq 'username') {
Line 187  sub main { Line 199  sub main {
                             }                              }
                         }                          }
                         if ($field eq 'domain') {                          if ($field eq 'domain') {
                             if ($query->param($field) =~ /^LONCAPA::match_username$/) {                              if ($query->param($field) =~ /^LONCAPA::match_domain$/) {
                                 $params{$field} = $query->param($field);                                  $params{$field} = $query->param($field);
                             }                              }
                         }                          }
Line 206  sub main { Line 218  sub main {
                                 $params{$field} = $query->param($field);                                  $params{$field} = $query->param($field);
                             }                              }
                         }                          }
                           if ($field eq 'description') {
                               $params{$field} = $query->param($field);
                           }
                     }                      }
                     if ($numrequired == scalar(keys(%params))) {                      if ($numrequired == scalar(keys(%params))) {
                         $validreq = 1;                          $validreq = 1;
Line 261  sub process_enrollment { Line 276  sub process_enrollment {
     my $udom = $params->{'domain'};      my $udom = $params->{'domain'};
     my $token = $params->{'token'};      my $token = $params->{'token'};
     my $uhome = &Apache::lonnet::homeserver($uname,$udom);      my $uhome = &Apache::lonnet::homeserver($uname,$udom);
     return if ($uhome eq 'nohost');      return if ($uhome eq 'no_host');
     my %courseinfo;      my %courseinfo;
     if ($cid eq '') {      if ($cid eq '') {
         if ($params->{'uniquecode'}) {          if ($params->{'uniquecode'}) {
Line 285  sub process_enrollment { Line 300  sub process_enrollment {
                 if ($requesthash{$cid}{status} eq 'pending') {                  if ($requesthash{$cid}{status} eq 'pending') {
                     my ($lonhost,$hostname,$handle);                      my ($lonhost,$hostname,$handle);
                     $lonhost = $requesthash{$cid}{'lonhost'};                      $lonhost = $requesthash{$cid}{'lonhost'};
                     if ($lonhost eq '') {                      if ($lonhost ne '') {
                         $hostname = &Apache::lonnet::hostname($lonhost);                          $hostname = &Apache::lonnet::hostname($lonhost);
                     }                      }
                     my $savedtoken = $requesthash{$cid}{'token'};                      my $savedtoken = $requesthash{$cid}{'token'};
Line 309  sub process_enrollment { Line 324  sub process_enrollment {
                                 return;                                  return;
                             }                              }
                         }                          }
                           $Apache::lonnet::env{'user.name'} = $uname;
                           $Apache::lonnet::env{'user.domain'} = $udom;
                         my $result =                          my $result =
                             &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,                              &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
                                 undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',                                  undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',
                                 undef,$cid,1);                                  undef,$cid,1);
                           delete($Apache::lonnet::env{'user.name'});
                           delete($Apache::lonnet::env{'user.domain'});
                         if ($result eq 'ok') {                          if ($result eq 'ok') {
                             my %userrequest = (                              my %userrequest = (
                                 $cdom.'_'.$cnum => {                                  $cdom.'_'.$cnum => {
Line 330  sub process_enrollment { Line 349  sub process_enrollment {
 #  #
                             my @hosts = &Apache::lonnet::current_machine_ids();                              my @hosts = &Apache::lonnet::current_machine_ids();
                             if (grep(/^\Q$lonhost\E$/,@hosts) && ($handle) && ($hostname)) {                              if (grep(/^\Q$lonhost\E$/,@hosts) && ($handle) && ($hostname)) {
                                 if ($lonidsdir ne '') {                                      if ($lonidsdir ne '') {
                                     if (-e "$lonidsdir/$handle.id") {                                      if (-e "$lonidsdir/$handle.id") {
                                         my $protocol = $Apache::lonnet::protocol{$lonhost};                                          my $protocol = $Apache::lonnet::protocol{$lonhost};
                                         $protocol = 'http' if ($protocol ne 'https');                                          $protocol = 'http' if ($protocol ne 'https');
Line 338  sub process_enrollment { Line 357  sub process_enrollment {
                                     }                                      }
                                 }                                  }
                             }                              }
            
 #  #
 # otherwise point at default portal, or if non specified, at /adm/login?querystring where   # otherwise point at default portal, or if non specified, at /adm/login?querystring where 
 # querystring contains role=st./$cdom/$cnum  # querystring contains role=st./$cdom/$cnum

Removed from v.1.1  
changed lines
  Added in v.1.3


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