version 1.31, 2022/02/02 00:31:16
|
version 1.32, 2022/02/06 21:37:00
|
Line 79 sub handler {
|
Line 79 sub handler {
|
} |
} |
|
|
unless (keys(%{$params})) { |
unless (keys(%{$params})) { |
&invalid_request($r,1); |
&invalid_request($r,'No parameters included in launch request'); |
return OK; |
return OK; |
} |
} |
|
|
Line 89 sub handler {
|
Line 89 sub handler {
|
$params->{'oauth_version'} && |
$params->{'oauth_version'} && |
$params->{'oauth_signature'} && |
$params->{'oauth_signature'} && |
$params->{'oauth_signature_method'}) { |
$params->{'oauth_signature_method'}) { |
&invalid_request($r,2); |
&invalid_request($r,'One or more required parameters missing from launch request'); |
return OK; |
return OK; |
} |
} |
|
|
Line 142 sub handler {
|
Line 142 sub handler {
|
# where url was /adm/launch/tiny/$cdom/$uniqueid |
# where url was /adm/launch/tiny/$cdom/$uniqueid |
# |
# |
|
|
my ($itemid,$ltitype,%crslti); |
my ($itemid,$ltitype,%crslti,%lti_in_use); |
$itemid = &get_lti_itemid($requri,$hostname,$params,$cdom,$cnum,'deeplink'); |
$itemid = &get_lti_itemid($requri,$hostname,$params,$cdom,$cnum,'deeplink'); |
if ($itemid) { |
if ($itemid) { |
%crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider'); |
%crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider'); |
} |
} |
if (($itemid) && (ref($crslti{$itemid}) eq 'HASH')) { |
if (($itemid) && (ref($crslti{$itemid}) eq 'HASH')) { |
$ltitype = 'c'; |
$ltitype = 'c'; |
unless (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'}, |
if (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'}, |
$crslti{$itemid}{'lifetime'},$cdom,$r->dir_config('lonLTIDir'))) { |
$crslti{$itemid}{'lifetime'},$cdom,$r->dir_config('lonLTIDir'))) { |
&invalid_request($r,3); |
%lti_in_use = %{$crslti{$itemid}}; |
|
} else { |
|
&invalid_request($r,'Time limit exceeded for launch request credentials'); |
return OK; |
return OK; |
} |
} |
} else { |
} else { |
my %lti; |
|
$itemid = &get_lti_itemid($requri,$hostname,$params,$cdom,'','deeplink'); |
$itemid = &get_lti_itemid($requri,$hostname,$params,$cdom,'','deeplink'); |
|
my %lti; |
if ($itemid) { |
if ($itemid) { |
%lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); |
%lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); |
} |
} |
if (($itemid) && (ref($lti{$itemid}) eq 'HASH')) { |
if (($itemid) && (ref($lti{$itemid}) eq 'HASH')) { |
$ltitype = 'd'; |
$ltitype = 'd'; |
unless (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'}, |
if (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'}, |
$lti{$itemid}{'lifetime'},$cdom, |
$lti{$itemid}{'lifetime'},$cdom, |
$r->dir_config('lonLTIDir'))) { |
$r->dir_config('lonLTIDir'))) { |
&invalid_request($r,4); |
%lti_in_use = %{$lti{$itemid}}; |
|
} else { |
|
&invalid_request($r,'Time limit exceeded for launch request credentials'); |
return OK; |
return OK; |
} |
} |
} |
} |
} |
} |
|
if (($itemid) && ($lti_in_use{'requser'})) { |
|
my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum); |
|
my $ltiauth; |
|
if (exists($courseinfo{'internal.ltiauth'})) { |
|
$ltiauth = $courseinfo{'internal.ltiauth'}; |
|
} else { |
|
my %domdefs = &Apache::lonnet::get_domain_defaults($cdom); |
|
$ltiauth = $domdefs{'crsltiauth'}; |
|
} |
|
if ($ltiauth) { |
|
my $possuname; |
|
my $mapuser = $crslti{$itemid}{'mapuser'}; |
|
if ($mapuser eq 'sourcedid') { |
|
if ($params->{'lis_person_sourcedid'} =~ /^$match_username$/) { |
|
$possuname = $params->{'lis_person_sourcedid'}; |
|
} |
|
} elsif ($mapuser eq 'email') { |
|
if ($params->{'lis_person_contact_email_primary'} =~ /^$match_username$/) { |
|
$possuname = $params->{'lis_person_contact_email_primary'}; |
|
} |
|
} elsif (exists($params->{$mapuser})) { |
|
if ($params->{$mapuser} =~ /^$match_username$/) { |
|
$possuname = $params->{$mapuser}; |
|
} |
|
} |
|
if ($possuname ne '') { |
|
my $uhome = &Apache::lonnet::homeserver($possuname,$cdom); |
|
unless ($uhome eq 'no_host') { |
|
my $uname = $possuname; |
|
my ($is_student,$is_nonstudent); |
|
my %course_roles = |
|
&Apache::lonnet::get_my_roles($uname,$cdom,,'userroles',['active'], |
|
['cc','co','in','ta','ep','ad','st','cr'], |
|
[$cdom]); |
|
foreach my $key (keys(%course_roles)) { |
|
my ($trest,$tdomain,$trole,$sec) = split(/:/,$key); |
|
if (($trest eq $cnum) && ($tdomain eq $cdom)) { |
|
if ($trole eq 'st') { |
|
$is_student = 1; |
|
} else { |
|
$is_nonstudent = 1; |
|
last; |
|
} |
|
} |
|
} |
|
if (($is_student) && (!$is_nonstudent)) { |
|
unless (&Apache::lonnet::is_advanced_user($uname,$cdom)) { |
|
foreach my $key (%{$params}) { |
|
delete($env{'form.'.$key}); |
|
} |
|
&linkprot_session($r,$uname,$cnum,$cdom,$uhome,$itemid,$ltitype,$tail,$lonhost); |
|
return OK; |
|
} |
|
} |
|
} |
|
} |
|
if ($lti_in_use{'notstudent'} eq 'reject') { |
|
&invalid_request($r,'Information for valid user missing from launch request'); |
|
} |
|
} |
|
} |
if ($itemid) { |
if ($itemid) { |
foreach my $key (%{$params}) { |
foreach my $key (%{$params}) { |
delete($env{'form.'.$key}); |
delete($env{'form.'.$key}); |
Line 180 sub handler {
|
Line 245 sub handler {
|
$r->internal_redirect($tail.'?ltoken='.$ltoken); |
$r->internal_redirect($tail.'?ltoken='.$ltoken); |
$r->set_handlers('PerlHandler'=> undef); |
$r->set_handlers('PerlHandler'=> undef); |
} else { |
} else { |
&invalid_request($r,5); |
&invalid_request($r,'Failed to store information from launch request'); |
} |
} |
} else { |
} else { |
&invalid_request($r,6); |
&invalid_request($r,'Launch request could not be validated'); |
} |
} |
} else { |
} else { |
&invalid_request($r,7); |
&invalid_request($r,'Launch unavailable on this LON-CAPA server'); |
} |
} |
} else { |
} else { |
&invalid_request($r,8); |
&invalid_request($r,'Launch unavailable for this domain'); |
} |
} |
} else { |
} else { |
&invalid_request($r,9); |
&invalid_request($r,'Invalid launch URL'); |
} |
} |
} else { |
} else { |
&invalid_request($r,10); |
&invalid_request($r,'Invalid launch URL'); |
} |
} |
return OK; |
return OK; |
} |
} |
Line 296 sub handler {
|
Line 361 sub handler {
|
if ($tail =~ m{^/uploaded/($match_domain)/($match_courseid)/(?:default|supplemental)(?:|_\d+)\.(?:sequence|page)(|___\d+___.+)$}) { |
if ($tail =~ m{^/uploaded/($match_domain)/($match_courseid)/(?:default|supplemental)(?:|_\d+)\.(?:sequence|page)(|___\d+___.+)$}) { |
($urlcdom,$urlcnum,my $rest) = ($1,$2,$3); |
($urlcdom,$urlcnum,my $rest) = ($1,$2,$3); |
if (($cdom ne '') && ($cdom ne $urlcdom)) { |
if (($cdom ne '') && ($cdom ne $urlcdom)) { |
&invalid_request($r,11); |
&invalid_request($r,'Incorrect domain in requested URL'); |
return OK; |
return OK; |
} |
} |
if ($rest eq '') { |
if ($rest eq '') { |
Line 315 sub handler {
|
Line 380 sub handler {
|
} elsif ($tail =~ m{^/($match_domain)/($match_courseid)$}) { |
} elsif ($tail =~ m{^/($match_domain)/($match_courseid)$}) { |
($urlcdom,$urlcnum) = ($1,$2); |
($urlcdom,$urlcnum) = ($1,$2); |
if (($cdom ne '') && ($cdom ne $urlcdom)) { |
if (($cdom ne '') && ($cdom ne $urlcdom)) { |
&invalid_request($r,12); |
&invalid_request($r,'Incorrect domain in requested URL'); |
return OK; |
return OK; |
} |
} |
} elsif ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) { |
} elsif ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) { |
($urlcdom,$urlcnum) = &course_from_tinyurl($tail); |
($urlcdom,$urlcnum) = &course_from_tinyurl($tail); |
if (($urlcdom eq '') || ($urlcnum eq '')) { |
if (($urlcdom eq '') || ($urlcnum eq '')) { |
&invalid_request($r,13); |
&invalid_request($r,'Invalid URL shortcut'); |
return OK; |
return OK; |
} |
} |
} |
} |
Line 367 sub handler {
|
Line 432 sub handler {
|
# configuration in LON-CAPA for that LTI Consumer. |
# configuration in LON-CAPA for that LTI Consumer. |
# |
# |
unless (($itemid) && (ref($lti{$itemid}) eq 'HASH')) { |
unless (($itemid) && (ref($lti{$itemid}) eq 'HASH')) { |
&invalid_request($r,14); |
&invalid_request($r,'Launch request could not be validated'); |
return OK; |
return OK; |
} |
} |
|
|
Line 377 sub handler {
|
Line 442 sub handler {
|
# |
# |
unless (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'}, |
unless (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'}, |
$lti{$itemid}{'lifetime'},$cdom,$r->dir_config('lonLTIDir'))) { |
$lti{$itemid}{'lifetime'},$cdom,$r->dir_config('lonLTIDir'))) { |
&invalid_request($r,15); |
&invalid_request($r,'Time limit exceeded for launch request credentials'); |
return OK; |
return OK; |
} |
} |
|
|
Line 398 sub handler {
|
Line 463 sub handler {
|
$r->internal_redirect($tail.'?ltoken='.$ltoken); |
$r->internal_redirect($tail.'?ltoken='.$ltoken); |
$r->set_handlers('PerlHandler'=> undef); |
$r->set_handlers('PerlHandler'=> undef); |
} else { |
} else { |
&invalid_request($r,16); |
&invalid_request($r,'Failed to store information from launch request'); |
} |
} |
} else { |
} else { |
&invalid_request($r,17); |
&invalid_request($r,'Launch URL invalid for matched launch credentials'); |
} |
} |
return OK; |
return OK; |
} |
} |
Line 463 sub handler {
|
Line 528 sub handler {
|
my $storedcnum = $1; |
my $storedcnum = $1; |
my $crshome = &Apache::lonnet::homeserver($storedcnum,$cdom); |
my $crshome = &Apache::lonnet::homeserver($storedcnum,$cdom); |
if ($crshome =~ /(con_lost|no_host|no_such_host)/) { |
if ($crshome =~ /(con_lost|no_host|no_such_host)/) { |
&invalid_request($r,18); |
&invalid_request($r,'Invalid courseID included in launch data'); |
return OK; |
return OK; |
} else { |
} else { |
$posscnum = $storedcnum; |
$posscnum = $storedcnum; |
Line 475 sub handler {
|
Line 540 sub handler {
|
if ($urlcnum ne '') { |
if ($urlcnum ne '') { |
if ($posscnum ne '') { |
if ($posscnum ne '') { |
if ($posscnum ne $urlcnum) { |
if ($posscnum ne $urlcnum) { |
&invalid_request($r,19); |
&invalid_request($r,'Course ID included in launch data incompatible with URL'); |
return OK; |
return OK; |
} else { |
} else { |
$cnum = $posscnum; |
$cnum = $posscnum; |
Line 483 sub handler {
|
Line 548 sub handler {
|
} else { |
} else { |
my $crshome = &Apache::lonnet::homeserver($urlcnum,$cdom); |
my $crshome = &Apache::lonnet::homeserver($urlcnum,$cdom); |
if ($crshome =~ /(con_lost|no_host|no_such_host)/) { |
if ($crshome =~ /(con_lost|no_host|no_such_host)/) { |
&invalid_request($r,20); |
&invalid_request($r,'Valid course ID could not be extracted from requested URL'); |
return OK; |
return OK; |
} else { |
} else { |
$cnum = $urlcnum; |
$cnum = $urlcnum; |
Line 548 sub handler {
|
Line 613 sub handler {
|
$domdesc,\%data,\%alerts,\%rulematch, |
$domdesc,\%data,\%alerts,\%rulematch, |
\%inst_results,\%curr_rules,%got_rules); |
\%inst_results,\%curr_rules,%got_rules); |
if ($result eq 'notallowed') { |
if ($result eq 'notallowed') { |
&invalid_request($r,21); |
&invalid_request($r,'Account creation not permitted for this user'); |
} elsif ($result eq 'ok') { |
} elsif ($result eq 'ok') { |
if (($ltiroles[0] eq 'Instructor') && ($lcroles[0] eq 'cc') && ($lti{$itemid}{'mapcrs'}) && |
if (($ltiroles[0] eq 'Instructor') && ($lcroles[0] eq 'cc') && ($lti{$itemid}{'mapcrs'}) && |
($lti{$itemid}{'makecrs'})) { |
($lti{$itemid}{'makecrs'})) { |
Line 557 sub handler {
|
Line 622 sub handler {
|
} |
} |
} |
} |
} else { |
} else { |
&invalid_request($r,22); |
&invalid_request($r,'An error occurred during account creation'); |
return OK; |
return OK; |
} |
} |
} else { |
} else { |
&invalid_request($r,23); |
&invalid_request($r,'Account creation not permitted'); |
return OK; |
return OK; |
} |
} |
} |
} |
} else { |
} else { |
&invalid_request($r,24); |
&invalid_request($r,'Could not determine username and/or domain for user'); |
return OK; |
return OK; |
} |
} |
|
|
Line 589 sub handler {
|
Line 654 sub handler {
|
$symb,$cdom,$cnum,$params,\@ltiroles,$lti{$itemid},\@lcroles, |
$symb,$cdom,$cnum,$params,\@ltiroles,$lti{$itemid},\@lcroles, |
$reqcrs,$sourcecrs); |
$reqcrs,$sourcecrs); |
} else { |
} else { |
&invalid_request($r,25); |
&invalid_request($r,'No LON-CAPA course available, and creation is not permitted for this user'); |
} |
} |
} else { |
} else { |
&invalid_request($r,26); |
&invalid_request($r,'No LON-CAPA course available, and creation is not permitted'); |
} |
} |
} else { |
} else { |
<i_session($r,$itemid,$uname,$udom,$uhome,$lonhost,undef,$mapurl,$tail, |
<i_session($r,$itemid,$uname,$udom,$uhome,$lonhost,undef,$mapurl,$tail, |
Line 683 sub handler {
|
Line 748 sub handler {
|
} |
} |
} |
} |
if ($reqrole eq '') { |
if ($reqrole eq '') { |
&invalid_request($r,27); |
&invalid_request($r,'No matching role available in LON-CAPA course, and not permitted to self-enroll'); |
return OK; |
return OK; |
} else { |
} else { |
unless (%crsenv) { |
unless (%crsenv) { |
Line 693 sub handler {
|
Line 758 sub handler {
|
my $default_enrollment_end_date = $crsenv{'default_enrollment_end_date'}; |
my $default_enrollment_end_date = $crsenv{'default_enrollment_end_date'}; |
my $now = time; |
my $now = time; |
if ($default_enrollment_end_date && $default_enrollment_end_date <= $now) { |
if ($default_enrollment_end_date && $default_enrollment_end_date <= $now) { |
&invalid_request($r,28); |
&invalid_request($r,'No active role available in LON-CAPA course, and past end date for self-enrollment'); |
return OK; |
return OK; |
} elsif ($default_enrollment_start_date && $default_enrollment_start_date >$now) { |
} elsif ($default_enrollment_start_date && $default_enrollment_start_date >$now) { |
&invalid_request($r,29); |
&invalid_request($r,'No active role available in LON-CAPA course, and brefor start date for self-enrollment'); |
return OK; |
return OK; |
} else { |
} else { |
$selfenrollrole = $reqrole.'./'.$cdom.'/'.$cnum; |
$selfenrollrole = $reqrole.'./'.$cdom.'/'.$cnum; |
Line 828 sub lti_session {
|
Line 893 sub lti_session {
|
} else { |
} else { |
&Apache::lonnet::logthis(" LTI authorized user ($itemid): $uname:$udom, course dom: $cdom"); |
&Apache::lonnet::logthis(" LTI authorized user ($itemid): $uname:$udom, course dom: $cdom"); |
} |
} |
my ($is_balancer,$otherserver,$hosthere); |
my ($is_balancer,$otherserver,$hosthere) = &check_balancer($r,$uname,$udom); |
($is_balancer,$otherserver) = |
|
&Apache::lonnet::check_loadbalancing($uname,$udom,'login'); |
|
if ($is_balancer) { |
|
if ($otherserver eq '') { |
|
my $lowest_load; |
|
($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($udom); |
|
if ($lowest_load > 100) { |
|
$otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$udom); |
|
} |
|
} |
|
if ($otherserver ne '') { |
|
my @hosts = &Apache::lonnet::current_machine_ids(); |
|
if (grep(/^\Q$otherserver\E$/,@hosts)) { |
|
$hosthere = $otherserver; |
|
} |
|
} |
|
} |
|
my $protocol = 'http'; |
my $protocol = 'http'; |
if ($ENV{'SERVER_PORT'} == 443) { |
if ($ENV{'SERVER_PORT'} == 443) { |
$protocol = 'https'; |
$protocol = 'https'; |
Line 924 sub lti_session {
|
Line 972 sub lti_session {
|
$r->internal_redirect($redirecturl); |
$r->internal_redirect($redirecturl); |
$r->set_handlers('PerlHandler'=> undef); |
$r->set_handlers('PerlHandler'=> undef); |
} else { |
} else { |
# need to login them in, so generate the need data that |
# need to login them in, so generate the data migrate expects to do login |
# migrate expects to do login |
|
foreach my $key (keys(%{$params})) { |
foreach my $key (keys(%{$params})) { |
delete($env{'form.'.$key}); |
delete($env{'form.'.$key}); |
} |
} |
Line 1003 sub lti_session {
|
Line 1050 sub lti_session {
|
return; |
return; |
} |
} |
|
|
|
sub linkprot_session { |
|
my ($r,$uname,$cnum,$cdom,$uhome,$itemid,$ltitype,$dest,$lonhost) = @_; |
|
$r->user($uname); |
|
if ($ltitype eq 'c') { |
|
&Apache::lonnet::logthis("Course Link Protector ($itemid) authorized student: $uname:$cdom, course: $cdom\_$cnum"); |
|
} elsif ($ltitype eq 'd') { |
|
&Apache::lonnet::logthis("Domain LTI for link protection ($itemid) authorized student: $uname:$cdom, course: $cdom\_$cnum"); |
|
} |
|
my ($is_balancer,$otherserver,$hosthere) = &check_balancer($r,$uname,$cdom); |
|
if (($is_balancer) && (!$hosthere)) { |
|
# login but immediately go to switch server |
|
$env{'form.origurl'} = $dest; |
|
$env{'request.linkprot'} = $itemid.$ltitype.':'.$dest; |
|
$env{'request.deeplink.login'} = $dest; |
|
my $redirecturl = '/adm/switchserver'; |
|
if ($otherserver ne '') { |
|
$redirecturl .= '?otherserver='.$otherserver; |
|
} |
|
$r->internal_redirect($redirecturl); |
|
$r->set_handlers('PerlHandler'=> undef); |
|
} else { |
|
# need to login them in, so generate the data migrate expects to do login |
|
my $ip = $r->get_remote_host(); |
|
my %info=('ip' => $ip, |
|
'domain' => $cdom, |
|
'username' => $uname, |
|
'server' => $lonhost, |
|
'linkprot' => $itemid.$ltitype.':'.$dest, |
|
'home' => $uhome, |
|
'origurl' => $dest, |
|
'deeplink.login' => $dest, |
|
); |
|
my $token = &Apache::lonnet::tmpput(\%info,$lonhost); |
|
$env{'form.token'} = $token; |
|
$r->internal_redirect('/adm/migrateuser'); |
|
$r->set_handlers('PerlHandler'=> undef); |
|
} |
|
return; |
|
} |
|
|
|
sub check_balancer { |
|
my ($r,$uname,$udom) = @_; |
|
my ($is_balancer,$otherserver,$hosthere); |
|
($is_balancer,$otherserver) = |
|
&Apache::lonnet::check_loadbalancing($uname,$udom,'login'); |
|
if ($is_balancer) { |
|
if ($otherserver eq '') { |
|
my $lowest_load; |
|
($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($udom); |
|
if ($lowest_load > 100) { |
|
$otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$udom); |
|
} |
|
} |
|
if ($otherserver ne '') { |
|
my @hosts = &Apache::lonnet::current_machine_ids(); |
|
if (grep(/^\Q$otherserver\E$/,@hosts)) { |
|
$hosthere = $otherserver; |
|
} |
|
} |
|
} |
|
return ($is_balancer,$otherserver,$hosthere); |
|
} |
|
|
sub invalid_request { |
sub invalid_request { |
my ($r,$num) = @_; |
my ($r,$msg) = @_; |
&Apache::loncommon::content_type($r,'text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
$r->send_http_header; |
$r->send_http_header; |
if ($r->header_only) { |
if ($r->header_only) { |
Line 1013 sub invalid_request {
|
Line 1123 sub invalid_request {
|
&Apache::lonlocal::get_language_handle($r); |
&Apache::lonlocal::get_language_handle($r); |
$r->print( |
$r->print( |
&Apache::loncommon::start_page('Invalid LTI call','',{ 'only_body' => 1,}). |
&Apache::loncommon::start_page('Invalid LTI call','',{ 'only_body' => 1,}). |
&mt('Invalid LTI call [_1]',$num). |
'<h3>'.&mt('Invalid LTI launch request').'</h3>'. |
|
'<p class="LC_warning">'. |
|
&mt('Launch of LON-CAPA is unavailable from the "external tool" link you had followed in another web application.'). |
|
&mt('Launch failed for the following reason:'). |
|
'</p>'. |
|
'<p class="LC_error">'.$msga'.</p>'. |
&Apache::loncommon::end_page()); |
&Apache::loncommon::end_page()); |
return; |
return; |
} |
} |