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