version 1.9, 2018/04/21 20:34:50
|
version 1.29, 2022/02/01 19:54:36
|
Line 42 use LONCAPA::ltiutils;
|
Line 42 use LONCAPA::ltiutils;
|
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
my $requri = $r->uri; |
my $requri = $r->uri; |
|
my $hostname = $r->hostname; |
# |
# |
# Check for existing session, and temporarily delete any form items |
# Check for existing session, and temporarily delete any form items |
# in %env, if session exists |
# in %env, if session exists |
Line 57 sub handler {
|
Line 58 sub handler {
|
} |
} |
} |
} |
# |
# |
# Retrieve data POSTed by LTI Consumer on launch |
# Retrieve data POSTed by LTI launch |
# |
# |
&Apache::lonacc::get_posted_cgi($r); |
&Apache::lonacc::get_posted_cgi($r); |
my $params = {}; |
my $params = {}; |
Line 67 sub handler {
|
Line 68 sub handler {
|
} |
} |
} |
} |
# |
# |
# Check for existing session, and restored temporarily |
# Check for existing session, and restore temporarily |
# deleted form items to %env, if session exists. |
# deleted form items to %env, if session exists. |
# |
# |
if ($handle ne '') { |
if ($handle ne '') { |
Line 97 sub handler {
|
Line 98 sub handler {
|
# Retrieve "internet domains" for all this institution's LON-CAPA |
# Retrieve "internet domains" for all this institution's LON-CAPA |
# nodes. |
# nodes. |
# |
# |
my ($udom,$uname,$uhome,$cdom,$cnum,$symb,$mapurl,@intdoms); |
my @intdoms; |
my $lonhost = $r->dir_config('lonHostID'); |
my $lonhost = $r->dir_config('lonHostID'); |
my $internet_names = &Apache::lonnet::get_internet_names($lonhost); |
my $internet_names = &Apache::lonnet::get_internet_names($lonhost); |
if (ref($internet_names) eq 'ARRAY') { |
if (ref($internet_names) eq 'ARRAY') { |
@intdoms = @{$internet_names}; |
@intdoms = @{$internet_names}; |
} |
} |
|
# |
|
# Determine course's domain in LON-CAPA |
|
# for basic launch using key and secret managed |
|
# in LON-CAPA course (i.e., uri begins /adm/launch) |
|
# |
|
|
|
my ($cdom,$cnum); |
|
|
|
# Note: "internet domain" for course's domain must be one of the |
|
# internet domains for the institution's LON-CAPA servers. |
|
# |
|
if ($requri =~ m{^/adm/launch(|/.*)$}) { |
|
my $tail = $1; |
|
if ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) { |
|
my ($urlcdom,$urlcnum) = &course_from_tinyurl($tail); |
|
if (($urlcdom ne '') && ($urlcnum ne '')) { |
|
$cdom = $urlcdom; |
|
$cnum = $urlcnum; |
|
my $primary_id = &Apache::lonnet::domain($cdom,'primary'); |
|
if ($primary_id ne '') { |
|
my $intdom = &Apache::lonnet::internet_dom($primary_id); |
|
if (($intdom ne '') && (grep(/^\Q$intdom\E$/,@intdoms))) { |
|
# |
|
# Retrieve information for LTI link protectors in course |
|
# where url was /adm/launch/tiny/$cdom/$uniqueid |
|
# |
|
my (%crslti,%crslti_by_key,$itemid,$ltitype); |
|
%crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider'); |
|
if (keys(%crslti)) { |
|
foreach my $id (keys(%crslti)) { |
|
if (ref($crslti{$id}) eq 'HASH') { |
|
my $key = $crslti{$id}{'key'}; |
|
push(@{$crslti_by_key{$key}},$id); |
|
} |
|
} |
|
} |
|
# |
|
# Verify the signed request using the secret for LTI link |
|
# protectors for which the key in the POSTed data matches |
|
# keys in the course configuration. |
|
# |
|
# Request is invalid if the signed request could not be verified |
|
# for the key and secret from LON-CAPA course configuration for |
|
# LTI link protectors or from LON-CAPA configuration for the |
|
# course's domain if there are LTI Providers which may be used. |
|
# |
|
# Determine if nonce in POSTed data has expired. |
|
# If unexpired, confirm it has not already been used. |
|
# |
|
if (keys(%crslti)) { |
|
$itemid = &get_lti_itemid($requri,$hostname,$params,\%crslti,\%crslti_by_key); |
|
} |
|
if (($itemid) && (ref($crslti{$itemid}) eq 'HASH')) { |
|
$ltitype = 'c'; |
|
unless (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'}, |
|
$crslti{$itemid}{'lifetime'},$cdom,$r->dir_config('lonLTIDir'))) { |
|
&invalid_request($r,3); |
|
return OK; |
|
} |
|
} else { |
|
my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); |
|
unless (keys(%lti) > 0) { |
|
&invalid_request($r,4); |
|
return OK; |
|
} |
|
my (%domlti_by_key,%domlti); |
|
foreach my $id (keys(%lti)) { |
|
if (ref($lti{$id}) eq 'HASH') { |
|
my $key = $lti{$id}{'key'}; |
|
if (!$lti{$itemid}{'requser'}) { |
|
push(@{$domlti_by_key{$key}},$id); |
|
$domlti{$id} = $lti{$id}; |
|
} |
|
} |
|
} |
|
if (keys(%domlti)) { |
|
$itemid = &get_lti_itemid($requri,$hostname,$params,\%domlti,\%domlti_by_key); |
|
} |
|
if (($itemid) && (ref($domlti{$itemid}) eq 'HASH')) { |
|
$ltitype = 'd'; |
|
unless (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'}, |
|
$domlti{$itemid}{'lifetime'},$cdom, |
|
$r->dir_config('lonLTIDir'))) { |
|
&invalid_request($r,5); |
|
return OK; |
|
} |
|
} |
|
} |
|
if ($itemid) { |
|
foreach my $key (%{$params}) { |
|
delete($env{'form.'.$key}); |
|
} |
|
my $ltoken = &Apache::lonnet::tmpput({'linkprot' => $itemid.$ltitype.':'.$tail}, |
|
$lonhost,'link'); |
|
if ($ltoken) { |
|
$r->internal_redirect($tail.'?ltoken='.$ltoken); |
|
$r->set_handlers('PerlHandler'=> undef); |
|
} else { |
|
&invalid_request($r,6); |
|
} |
|
} else { |
|
&invalid_request($r,7); |
|
} |
|
} else { |
|
&invalid_request($r,8); |
|
} |
|
} else { |
|
&invalid_request($r,9); |
|
} |
|
} else { |
|
&invalid_request($r,10); |
|
} |
|
} else { |
|
&invalid_request($r,11); |
|
} |
|
return OK; |
|
} |
|
|
|
my ($udom,$uname,$uhome,$symb,$mapurl); |
|
|
# |
# |
# For user who launched LTI in Consumer, determine user's domain in |
# For user who launched LTI in Consumer, determine user's domain in |
Line 198 sub handler {
|
Line 318 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,3); |
&invalid_request($r,12); |
return OK; |
return OK; |
} |
} |
if ($rest eq '') { |
if ($rest eq '') { |
$mapurl = $tail; |
$mapurl = $tail; |
} else { |
} else { |
$symb = $tail; |
$symb = $tail; |
$symb =~ s{^/+}{}; |
$symb =~ s{^/}{}; |
} |
} |
} elsif ($tail =~ m{^/res/(?:$match_domain)/(?:$match_username)/.+\.(?:sequence|page)(|___\d+___.+)$}) { |
} elsif ($tail =~ m{^/res/(?:$match_domain)/(?:$match_username)/.+\.(?:sequence|page)(|___\d+___.+)$}) { |
if ($1 eq '') { |
if ($1 eq '') { |
$mapurl = $tail; |
$mapurl = $tail; |
} else { |
} else { |
$symb = $tail; |
$symb = $tail; |
$symb =~ s{^/+}{}; |
$symb =~ s{^/res/}{}; |
} |
} |
} 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,4); |
&invalid_request($r,13); |
return OK; |
return OK; |
} |
} |
} elsif ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) { |
} elsif ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) { |
($urlcdom,my $key) = ($1,$2); |
($urlcdom,$urlcnum) = &course_from_tinyurl($tail); |
if (($cdom ne '') && ($cdom ne $urlcdom)) { |
if (($urlcdom eq '') || ($urlcnum eq '')) { |
&invalid_request($r,5); |
&invalid_request($r,14); |
return OK; |
return OK; |
} |
} |
my $tinyurl; |
|
my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$urlcdom."\0".$key); |
|
if (defined($cached)) { |
|
$tinyurl = $result; |
|
} else { |
|
my $configuname = &Apache::lonnet::get_domainconfiguser($urlcdom); |
|
my %currtiny = &Apache::lonnet::get('tiny',[$key],$urlcdom,$configuname); |
|
if ($currtiny{$key} ne '') { |
|
$tinyurl = $currtiny{$key}; |
|
&Apache::lonnet::do_cache_new('tiny',$urlcdom."\0".$key,$currtiny{$key},600); |
|
} |
|
} |
|
if ($tinyurl ne '') { |
|
$urlcnum = (split(/\&/,$tinyurl))[0]; |
|
} |
|
} |
} |
if (($cdom eq '') && ($urlcdom ne '')) { |
if (($cdom eq '') && ($urlcdom ne '')) { |
my $cprimary_id = &Apache::lonnet::domain($urlcdom,'primary'); |
my $cprimary_id = &Apache::lonnet::domain($urlcdom,'primary'); |
Line 263 sub handler {
|
Line 368 sub handler {
|
} |
} |
|
|
# |
# |
# Retrieve information for LTI Consumers in course domain |
# Retrieve information for LTI Consumers in course's domain |
# and populate hash -- %lti_by_key -- for which keys |
# and populate hash -- %lti_by_key -- for which keys |
# are those defined in domain configuration for LTI. |
# are those defined in domain configuration for LTI. |
# |
# |
|
|
my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); |
my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); |
unless (keys(%lti) > 0) { |
unless (keys(%lti) > 0) { |
&invalid_request($r,6); |
&invalid_request($r,15); |
return OK; |
return OK; |
} |
} |
my %lti_by_key; |
my %lti_by_key; |
Line 286 sub handler {
|
Line 391 sub handler {
|
# |
# |
# Verify the signed request using the secret for those |
# Verify the signed request using the secret for those |
# Consumers for which the key in the POSTed data matches |
# Consumers for which the key in the POSTed data matches |
# keys in the domain configuration for LTI. |
# keys in the course configuration or the domain configuration |
|
# for LTI. |
# |
# |
my $hostname = $r->hostname; |
|
my $protocol = 'http'; |
|
if ($ENV{'SERVER_PORT'} == 443) { |
|
$protocol = 'https'; |
|
} |
|
|
|
my ($itemid,$consumer_key,$secret); |
my $itemid = &get_lti_itemid($requri,$hostname,$params,\%lti,\%lti_by_key); |
$consumer_key = $params->{'oauth_consumer_key'}; |
|
if (ref($lti_by_key{$consumer_key}) eq 'ARRAY') { |
|
foreach my $id (@{$lti_by_key{$consumer_key}}) { |
|
if (ref($lti{$id}) eq 'HASH') { |
|
$secret = $lti{$id}{'secret'}; |
|
my $request = Net::OAuth->request('request token')->from_hash($params, |
|
request_url => $protocol.'://'.$hostname.$requri, |
|
request_method => $env{'request.method'}, |
|
consumer_secret => $secret,); |
|
if ($request->verify()) { |
|
$itemid = $id; |
|
last; |
|
} |
|
} |
|
} |
|
} |
|
|
|
# |
# |
# Request is invalid if the signed request could not be verified |
# Request is invalid if the signed request could not be verified |
Line 318 sub handler {
|
Line 403 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,7); |
&invalid_request($r,16); |
return OK; |
return OK; |
} |
} |
|
|
Line 328 sub handler {
|
Line 413 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,8); |
&invalid_request($r,17); |
|
return OK; |
|
} |
|
|
|
# |
|
# Determine if a username is required from the domain |
|
# configuration for the specific LTI Consumer |
|
# |
|
|
|
if (!$lti{$itemid}{'requser'}) { |
|
if ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) { |
|
my $ltitype = 'd'; |
|
foreach my $key (%{$params}) { |
|
delete($env{'form.'.$key}); |
|
} |
|
my $ltoken = &Apache::lonnet::tmpput({'linkprot' => $itemid.$ltitype.':'.$tail}, |
|
$lonhost); |
|
if ($ltoken) { |
|
$r->internal_redirect($tail.'?ltoken='.$ltoken); |
|
$r->set_handlers('PerlHandler'=> undef); |
|
} else { |
|
&invalid_request($r,18); |
|
} |
|
} else { |
|
&invalid_request($r,19); |
|
} |
return OK; |
return OK; |
} |
} |
|
|
Line 385 sub handler {
|
Line 495 sub handler {
|
if ($sourcecrs ne '') { |
if ($sourcecrs ne '') { |
%consumers = &Apache::lonnet::get_dom('lticonsumers',[$sourcecrs],$cdom); |
%consumers = &Apache::lonnet::get_dom('lticonsumers',[$sourcecrs],$cdom); |
if (exists($consumers{$sourcecrs})) { |
if (exists($consumers{$sourcecrs})) { |
if ($consumers{$sourcecrs} =~ /^$match_courseid$/) { |
if ($consumers{$sourcecrs} =~ /^\Q$itemid:\E($match_courseid)$/) { |
my $crshome = &Apache::lonnet::homeserver($consumers{$sourcecrs},$cdom); |
my $storedcnum = $1; |
|
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,9); |
&invalid_request($r,20); |
return OK; |
return OK; |
} else { |
} else { |
$posscnum = $consumers{$sourcecrs}; |
$posscnum = $storedcnum; |
} |
} |
} |
} |
} |
} |
Line 400 sub handler {
|
Line 511 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,10); |
&invalid_request($r,21); |
return OK; |
return OK; |
} else { |
} else { |
$cnum = $posscnum; |
$cnum = $posscnum; |
Line 408 sub handler {
|
Line 519 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,11); |
&invalid_request($r,22); |
return OK; |
return OK; |
} else { |
} else { |
$cnum = $urlcnum; |
$cnum = $urlcnum; |
Line 428 sub handler {
|
Line 539 sub handler {
|
# |
# |
|
|
my (@ltiroles,@lcroles); |
my (@ltiroles,@lcroles); |
|
|
my @lcroleorder = ('cc','in','ta','ep','st'); |
my @lcroleorder = ('cc','in','ta','ep','st'); |
my @ltiroleorder = ('Instructor','TeachingAssistant','Mentor','Learner'); |
my ($lcrolesref,$ltirolesref) = |
if ($params->{'roles'} =~ /,/) { |
&LONCAPA::ltiutils::get_lc_roles($params->{'roles'}, |
my @possltiroles = split(/\s*,\s*/,$params->{'role'}); |
\@lcroleorder, |
foreach my $ltirole (@ltiroleorder) { |
$lti{$itemid}{maproles}); |
if (grep(/^\Q$ltirole\E$/,@possltiroles)) { |
if (ref($lcrolesref) eq 'ARRAY') { |
push(@ltiroles,$ltirole); |
@lcroles = @{$lcrolesref}; |
} |
|
} |
|
} else { |
|
my $singlerole = $params->{'roles'}; |
|
$singlerole =~ s/^\s|\s+$//g; |
|
if (grep(/^\Q$singlerole\E$/,@ltiroleorder)) { |
|
@ltiroles = ($singlerole); |
|
} |
|
} |
} |
if (@ltiroles) { |
if (ref($ltirolesref) eq 'ARRAY') { |
if (ref($lti{$itemid}{maproles}) eq 'HASH') { |
@ltiroles = @{$ltirolesref}; |
my %possroles; |
|
map { $possroles{$lti{$itemid}{maproles}{$_}} = 1; } @ltiroles; |
|
if (keys(%possroles) > 0) { |
|
foreach my $item (@lcroleorder) { |
|
if ($possroles{$item}) { |
|
push(@lcroles,$item); |
|
} |
|
} |
|
} |
|
} |
|
} |
} |
|
|
# |
# |
Line 479 sub handler {
|
Line 571 sub handler {
|
} |
} |
} |
} |
if ($selfcreate) { |
if ($selfcreate) { |
my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts,%info); |
my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts); |
my $checkhash = { "$uname:$udom" => { 'newuser' => 1, }, }; |
my $domdesc = &Apache::lonnet::domain($udom,'description'); |
my $checks = { 'username' => 1, }; |
my %data = ( |
&Apache::loncommon::user_rule_check($checkhash,$checks,\%alerts,\%rulematch, |
'permanentemail' => $env{'form.lis_person_contact_email_primary'}, |
\%inst_results,\%curr_rules,\%got_rules); |
'firstname' => $env{'form.lis_person_name_given'}, |
my ($userchkmsg,$lcauth,$lcauthparm); |
'lastname' => $env{'form.lis_person_name_family'}, |
my $allowed = 1; |
'fullname' => $env{'form.lis_person_name_full'}, |
if (ref($alerts{'username'}) eq 'HASH') { |
); |
if (ref($alerts{'username'}{$udom}) eq 'HASH') { |
|
my $domdesc = |
|
&Apache::lonnet::domain($udom,'description'); |
|
if ($alerts{'username'}{$udom}{$uname}) { |
|
if (ref($curr_rules{$udom}) eq 'HASH') { |
|
$userchkmsg = |
|
&Apache::loncommon::instrule_disallow_msg('username',$domdesc,1). |
|
&Apache::loncommon::user_rule_formats($udom,$domdesc, |
|
$curr_rules{$udom}{'username'}, |
|
'username'); |
|
} |
|
$allowed = 0; |
|
} |
|
} |
|
} |
|
if ($allowed) { |
|
if (ref($rulematch{$uname.':'.$udom}) eq 'HASH') { |
|
my $matchedrule = $rulematch{$uname.':'.$udom}{'username'}; |
|
my ($rules,$ruleorder) = |
|
&Apache::lonnet::inst_userrules($udom,'username'); |
|
if (ref($rules) eq 'HASH') { |
|
if (ref($rules->{$matchedrule}) eq 'HASH') { |
|
$lcauth = $rules->{$matchedrule}{'authtype'}; |
|
$lcauthparm = $rules->{$matchedrule}{'authparm'}; |
|
} |
|
} |
|
} |
|
if ($lcauth eq '') { |
|
$lcauth = $lti{$itemid}{'lcauth'}; |
|
if ($lcauth eq 'internal') { |
|
$lcauthparm = &create_passwd(); |
|
} else { |
|
$lcauthparm = $lti{$itemid}{'lcauthparm'}; |
|
} |
|
} |
|
} else { |
|
&invalid_request($r,12); |
|
} |
|
my @userinfo = ('firstname','middlename','lastname','generation', |
|
'permanentemail','id'); |
|
my %useinstdata; |
|
if (ref($lti{$itemid}{'instdata'}) eq 'ARRAY') { |
|
map { $useinstdata{$_} = 1; } @{$lti{$itemid}{'instdata'}}; |
|
} |
|
foreach my $item (@userinfo) { |
|
if (($useinstdata{$item}) && (ref($inst_results{$uname.':'.$udom}) eq 'HASH') && |
|
($inst_results{$uname.':'.$udom}{$item} ne '')) { |
|
$info{$item} = $inst_results{$uname.':'.$udom}{$item}; |
|
} else { |
|
if ($item eq 'permanentemail') { |
|
if ($env{'form.lis_person_contact_email_primary'} =~/^[^\@]+\@[^@]+$/) { |
|
$info{$item} = $env{'form.lis_person_contact_email_primary'}; |
|
} |
|
} elsif ($item eq 'firstname') { |
|
$info{$item} = $env{'form.lis_person_name_given'}; |
|
} elsif ($item eq 'lastname') { |
|
$info{$item} = $env{'form.lis_person_name_family'}; |
|
} |
|
} |
|
} |
|
if (($info{'middlename'} eq '') && ($env{'form.lis_person_name_full'} ne '')) { |
|
unless ($useinstdata{'middlename'}) { |
|
my $fullname = $env{'form.lis_person_name_full'}; |
|
if ($info{'firstname'}) { |
|
$fullname =~ s/^\s*\Q$info{'firstname'}\E\s*//i; |
|
} |
|
if ($info{'lastname'}) { |
|
$fullname =~ s/\s*\Q$info{'lastname'}\E\s*$//i; |
|
} |
|
if ($fullname ne '') { |
|
$fullname =~ s/^\s+|\s+$//g; |
|
if ($fullname ne '') { |
|
$info{'middlename'} = $fullname; |
|
} |
|
} |
|
} |
|
} |
|
if (ref($inst_results{$uname.':'.$udom}{'inststatus'}) eq 'ARRAY') { |
|
my @inststatuses = @{$inst_results{$uname.':'.$udom}{'inststatus'}}; |
|
$info{'inststatus'} = join(':',map { &escape($_); } @inststatuses); |
|
} |
|
my $result = |
my $result = |
&Apache::lonnet::modifyuser($udom,$uname,$info{'id'}, |
&LONCAPA::ltiutils::create_user($lti{$itemid},$uname,$udom, |
$lcauth,$lcauthparm,$info{'firstname'}, |
$domdesc,\%data,\%alerts,\%rulematch, |
$info{'middlename'},$info{'lastname'}, |
\%inst_results,\%curr_rules,%got_rules); |
$info{'generation'},undef,undef, |
if ($result eq 'notallowed') { |
$info{'permanentemail'},$info{'inststatus'}); |
&invalid_request($r,23); |
if ($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'})) { |
unless (&Apache::lonnet::usertools_access($uname,$udom,'lti','reload','requestcourses')) { |
unless (&Apache::lonnet::usertools_access($uname,$udom,'lti','reload','requestcourses')) { |
&Apache::lonnet::put('environment',{ 'requestcourses.lti' => 1, },$udom,$uname); |
&Apache::lonnet::put('environment',{ 'requestcourses.lti' => 'autolimit=', },$udom,$uname); |
} |
} |
} |
} |
} else { |
} else { |
&invalid_request($r,13); |
&invalid_request($r,24); |
return OK; |
return OK; |
} |
} |
} else { |
} else { |
&invalid_request($r,14); |
&invalid_request($r,25); |
return OK; |
return OK; |
} |
} |
} |
} |
} else { |
} else { |
&invalid_request($r,15); |
&invalid_request($r,26); |
return OK; |
return OK; |
} |
} |
|
|
Line 603 sub handler {
|
Line 614 sub handler {
|
|
|
my $reqcrs; |
my $reqcrs; |
if ($cnum eq '') { |
if ($cnum eq '') { |
if ((@ltiroles) && ($lti{$itemid}{'mapcrs'}) && |
if ($lti{$itemid}{'crsinc'}) { |
($ltiroles[0] eq 'Instructor') && ($lcroles[0] eq 'cc') && ($lti{$itemid}{'makecrs'})) { |
if ((@ltiroles) && ($lti{$itemid}{'mapcrs'}) && |
my (%can_request,%request_domains); |
($ltiroles[0] eq 'Instructor') && ($lcroles[0] eq 'cc') && ($lti{$itemid}{'makecrs'})) { |
&Apache::lonnet::check_can_request($cdom,\%can_request,\%request_domains,$uname,$udom); |
my (%can_request,%request_domains); |
if ($can_request{'lti'}) { |
&Apache::lonnet::check_can_request($cdom,\%can_request,\%request_domains,$uname,$udom); |
$reqcrs = 1; |
if ($can_request{'lti'}) { |
<i_session($r,$itemid,$uname,$udom,$uhome,$lonhost,undef,$mapurl,$tail, |
$reqcrs = 1; |
$symb,$cdom,$cnum,$params,\@ltiroles,$lti{$itemid},\@lcroles, |
<i_session($r,$itemid,$uname,$udom,$uhome,$lonhost,undef,$mapurl,$tail, |
$reqcrs,$sourcecrs); |
$symb,$cdom,$cnum,$params,\@ltiroles,$lti{$itemid},\@lcroles, |
|
$reqcrs,$sourcecrs); |
|
} else { |
|
&invalid_request($r,27); |
|
} |
} else { |
} else { |
&invalid_request($r,16); |
&invalid_request($r,28); |
} |
} |
} else { |
} else { |
&invalid_request($r,17); |
<i_session($r,$itemid,$uname,$udom,$uhome,$lonhost,undef,$mapurl,$tail, |
|
$symb,$cdom,$cnum,$params,\@ltiroles,$lti{$itemid},\@lcroles, |
|
$reqcrs,$sourcecrs); |
} |
} |
return OK; |
return OK; |
} |
} |
Line 624 sub handler {
|
Line 641 sub handler {
|
# |
# |
# If LON-CAPA course is a Community, and LON-CAPA role |
# If LON-CAPA course is a Community, and LON-CAPA role |
# indicated is cc, change role indicated to co. |
# indicated is cc, change role indicated to co. |
# |
# |
|
|
my %crsenv; |
my %crsenv; |
if ($lcroles[0] eq 'cc') { |
if ($lcroles[0] eq 'cc') { |
Line 702 sub handler {
|
Line 719 sub handler {
|
} |
} |
} |
} |
if ($reqrole eq '') { |
if ($reqrole eq '') { |
&invalid_request($r,18); |
&invalid_request($r,29); |
return OK; |
return OK; |
} else { |
} else { |
unless (%crsenv) { |
unless (%crsenv) { |
Line 712 sub handler {
|
Line 729 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,19); |
&invalid_request($r,30); |
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,20); |
&invalid_request($r,31); |
return OK; |
return OK; |
} else { |
} else { |
$selfenrollrole = $reqrole.'./'.$cdom.'/'.$cnum; |
$selfenrollrole = $reqrole.'./'.$cdom.'/'.$cnum; |
Line 729 sub handler {
|
Line 746 sub handler {
|
} |
} |
|
|
# |
# |
# Store consumer-to-LON-CAPA course mapping |
# Retrieve course type of LON-CAPA course to check if mapping from a Consumer |
|
# course identifier permitted for this type of course (one of: official, |
|
# unofficial, community, textbook, placement or lti. |
|
# |
|
|
|
unless (%crsenv) { |
|
%crsenv = &Apache::lonnet::coursedescription($cdom.'_'.$cnum); |
|
} |
|
my $crstype = lc($crsenv{'type'}); |
|
if ($crstype eq '') { |
|
$crstype = 'course'; |
|
} |
|
if ($crstype eq 'course') { |
|
if ($crsenv{'internal.coursecode'}) { |
|
$crstype = 'official'; |
|
} elsif ($crsenv{'internal.textbook'}) { |
|
$crstype = 'textbook'; |
|
} elsif ($crsenv{'internal.lti'}) { |
|
$crstype = 'lti'; |
|
} else { |
|
$crstype = 'unofficial'; |
|
} |
|
} |
|
|
|
# |
|
# Store consumer-to-LON-CAPA course mapping if permitted |
# |
# |
|
|
if (($sourcecrs ne '') && ($consumers{$sourcecrs} eq '') && ($cnum ne '')) { |
if (($lti{$itemid}{'storecrs'}) && ($sourcecrs ne '') && |
&Apache::lonnet::put_dom('lticonsumers',{ $sourcecrs => $cnum },$cdom); |
($consumers{$sourcecrs} eq '') && ($cnum ne '')) { |
|
if (ref($lti{$itemid}{'mapcrstype'}) eq 'ARRAY') { |
|
if (grep(/^$crstype$/,@{$lti{$itemid}{'mapcrstype'}})) { |
|
&Apache::lonnet::put_dom('lticonsumers',{ $sourcecrs => $itemid.':'.$cnum },$cdom); |
|
} |
|
} |
} |
} |
|
|
# |
# |
Line 746 sub handler {
|
Line 793 sub handler {
|
return OK; |
return OK; |
} |
} |
|
|
|
sub get_lti_itemid { |
|
my ($requri,$hostname,$params,$lti,$lti_by_key) = @_; |
|
return unless ((ref($params) eq 'HASH') && (ref($lti) eq 'HASH') && (ref($lti_by_key) eq 'HASH')); |
|
|
|
if (exists($params->{'oauth_callback'})) { |
|
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; |
|
} else { |
|
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0; |
|
} |
|
|
|
my $protocol = 'http'; |
|
if ($ENV{'SERVER_PORT'} == 443) { |
|
$protocol = 'https'; |
|
} |
|
|
|
my ($itemid,$consumer_key,$secret); |
|
my $consumer_key = $params->{'oauth_consumer_key'}; |
|
if (ref($lti_by_key->{$consumer_key}) eq 'ARRAY') { |
|
foreach my $id (@{$lti_by_key->{$consumer_key}}) { |
|
if (ref($lti->{$id}) eq 'HASH') { |
|
$secret = $lti->{$id}{'secret'}; |
|
my $request = Net::OAuth->request('request token')->from_hash($params, |
|
request_url => $protocol.'://'.$hostname.$requri, |
|
request_method => $env{'request.method'}, |
|
consumer_secret => $secret,); |
|
if ($request->verify()) { |
|
$itemid = $id; |
|
last; |
|
} |
|
} |
|
} |
|
} |
|
return $itemid; |
|
} |
|
|
sub lti_enroll { |
sub lti_enroll { |
my ($uname,$udom,$selfenrollrole) = @_; |
my ($uname,$udom,$selfenrollrole) = @_; |
my $enrollresult; |
my $enrollresult; |
Line 757 sub lti_enroll {
|
Line 839 sub lti_enroll {
|
my %coursehash = &Apache::lonnet::coursedescription($cdom.'_'.$cnum); |
my %coursehash = &Apache::lonnet::coursedescription($cdom.'_'.$cnum); |
my $start = $coursehash{'default_enrollment_start_date'}; |
my $start = $coursehash{'default_enrollment_start_date'}; |
my $end = $coursehash{'default_enrollment_end_date'}; |
my $end = $coursehash{'default_enrollment_end_date'}; |
my $area = "/$cdom/$cnum"; |
$enrollresult = &LONCAPA::ltiutils::enrolluser($udom,$uname,$role,$cdom,$cnum,$sec, |
if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) { |
$start,$end,1); |
$area .= '/'.$sec; |
|
} |
|
my $spec = $role.'.'.$area; |
|
my $instcid; |
|
if ($role eq 'st') { |
|
$enrollresult = |
|
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef, |
|
undef,undef,$sec,$end,$start, |
|
'ltienroll',undef,$cdom.'_'.$cnum,1, |
|
'ltienroll','',$instcid); |
|
} elsif ($role =~ /^(cc|in|ta|ep)$/) { |
|
$enrollresult = |
|
&Apache::lonnet::assignrole($udom,$uname,$area,$role,$end,$start, |
|
undef,1,'ltienroll'); |
|
} |
|
if ($enrollresult eq 'ok') { |
|
my (%userroles,%newrole,%newgroups); |
|
&Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum, |
|
$area); |
|
&Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups); |
|
$userroles{'user.role.'.$spec} = $start.'.'.$end; |
|
&Apache::lonnet::appenv(\%userroles,[$role,'cm']); |
|
} |
|
} |
} |
} |
} |
return $enrollresult; |
return $enrollresult; |
Line 832 sub lti_session {
|
Line 891 sub lti_session {
|
my $lowest_load; |
my $lowest_load; |
($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($udom); |
($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($udom); |
if ($lowest_load > 100) { |
if ($lowest_load > 100) { |
$otherserver = &Apache::lonnet::spareserver($lowest_load,$lowest_load,1,$udom); |
$otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$udom); |
} |
} |
} |
} |
if ($otherserver ne '') { |
if ($otherserver ne '') { |
Line 842 sub lti_session {
|
Line 901 sub lti_session {
|
} |
} |
} |
} |
} |
} |
|
my $protocol = 'http'; |
|
if ($ENV{'SERVER_PORT'} == 443) { |
|
$protocol = 'https'; |
|
} |
if (($is_balancer) && (!$hosthere)) { |
if (($is_balancer) && (!$hosthere)) { |
# login but immediately go to switch server. |
# login but immediately go to switch server. |
&Apache::lonauth::success($r,$uname,$udom,$uhome,'noredirect'); |
&Apache::lonauth::success($r,$uname,$udom,$uhome,'noredirect'); |
|
if (($ltihash->{'callback'}) && ($params->{$ltihash->{'callback'}})) { |
|
&LONCAPA::ltiutils::setup_logout_callback($uname,$udom,$otherserver, |
|
$ltihash->{'key'}, |
|
$ltihash->{'secret'}, |
|
$params->{$ltihash->{'callback'}}, |
|
$r->dir_config('ltiIDsDir'), |
|
$protocol,$r->hostname); |
|
} |
if ($symb) { |
if ($symb) { |
$env{'form.symb'} = $symb; |
$env{'form.symb'} = $symb; |
$env{'request.lti.uri'} = $symb; |
$env{'request.lti.uri'} = $tail; |
} else { |
} else { |
if ($mapurl) { |
if ($mapurl) { |
$env{'form.origurl'} = $mapurl; |
$env{'form.origurl'} = $mapurl; |
Line 860 sub lti_session {
|
Line 931 sub lti_session {
|
$env{'request.lti.uri'} = $tail; |
$env{'request.lti.uri'} = $tail; |
} else { |
} else { |
unless ($tail eq '/adm/roles') { |
unless ($tail eq '/adm/roles') { |
$env{'form.origurl'} = '/adm/navmaps'; |
if ($cnum) { |
|
$env{'form.origurl'} = '/adm/navmaps'; |
|
} |
} |
} |
} |
} |
} |
} |
Line 873 sub lti_session {
|
Line 946 sub lti_session {
|
$env{'request.lti.sourcecrs'} = $sourcecrs; |
$env{'request.lti.sourcecrs'} = $sourcecrs; |
} |
} |
if ($selfenrollrole) { |
if ($selfenrollrole) { |
$env{'request.lti.selfenroll'} = $selfenrollrole; |
$env{'request.lti.selfenrollrole'} = $selfenrollrole; |
$env{'request.lti.sourcecrs'} = $sourcecrs; |
$env{'request.lti.sourcecrs'} = $sourcecrs; |
} |
} |
if ($ltihash->{'passback'}) { |
if ($ltihash->{'passback'}) { |
Line 892 sub lti_session {
|
Line 965 sub lti_session {
|
$env{'request.lti.rosterurl'} = $params->{'ext_ims_lis_memberships_url'}; |
$env{'request.lti.rosterurl'} = $params->{'ext_ims_lis_memberships_url'}; |
} |
} |
} |
} |
$env{'request.lti.login'} = 1; |
$env{'request.lti.login'} = $itemid; |
if ($params->{'launch_presentation_document_target'}) { |
if ($params->{'launch_presentation_document_target'}) { |
$env{'request.lti.target'} = $params->{'launch_presentation_document_target'}; |
$env{'request.lti.target'} = $params->{'launch_presentation_document_target'}; |
} |
} |
foreach my $key (%{$params}) { |
foreach my $key (keys(%{$params})) { |
delete($env{'form.'.$key}); |
delete($env{'form.'.$key}); |
} |
} |
my $redirecturl = '/adm/switchserver'; |
my $redirecturl = '/adm/switchserver'; |
Line 908 sub lti_session {
|
Line 981 sub lti_session {
|
} else { |
} else { |
# need to login them in, so generate the need data that |
# need to login them in, so generate the need data that |
# migrate expects to do login |
# migrate expects to do login |
foreach my $key (%{$params}) { |
foreach my $key (keys(%{$params})) { |
delete($env{'form.'.$key}); |
delete($env{'form.'.$key}); |
} |
} |
|
if (($ltihash->{'callback'}) && ($params->{$ltihash->{'callback'}})) { |
|
&LONCAPA::ltiutils::setup_logout_callback($uname,$udom,$lonhost, |
|
$ltihash->{'key'}, |
|
$ltihash->{'secret'}, |
|
$params->{$ltihash->{'callback'}}, |
|
$r->dir_config('ltiIDsDir'), |
|
$protocol,$r->hostname); |
|
} |
my $ip = $r->get_remote_host(); |
my $ip = $r->get_remote_host(); |
my %info=('ip' => $ip, |
my %info=('ip' => $ip, |
'domain' => $udom, |
'domain' => $udom, |
'username' => $uname, |
'username' => $uname, |
'server' => $lonhost, |
'server' => $lonhost, |
'lti.login' => 1, |
'lti.login' => $itemid, |
'lti.uri' => $tail, |
'lti.uri' => $tail, |
); |
); |
if ($role) { |
if ($role) { |
Line 960 sub lti_session {
|
Line 1041 sub lti_session {
|
$info{'origurl'} = $tail; |
$info{'origurl'} = $tail; |
} else { |
} else { |
unless ($tail eq '/adm/roles') { |
unless ($tail eq '/adm/roles') { |
$info{'origurl'} = '/adm/navmaps'; |
if ($cnum) { |
|
$info{'origurl'} = '/adm/navmaps'; |
|
} |
} |
} |
} |
} |
} |
} |
Line 984 sub invalid_request {
|
Line 1067 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'). |
&Apache::loncommon::start_page('Invalid LTI call','',{ 'only_body' => 1,}). |
&mt('Invalid LTI call [_1]',$num). |
&mt('Invalid LTI call [_1]',$num). |
&Apache::loncommon::end_page()); |
&Apache::loncommon::end_page()); |
return; |
return; |
} |
} |
|
|
sub create_passwd { |
sub course_from_tinyurl { |
my $passwd = ''; |
my ($tail) = @_; |
my @letts = ("a".."z"); |
my ($urlcdom,$urlcnum); |
for (my $i=0; $i<8; $i++) { |
if ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) { |
my $lettnum = int(rand(2)); |
($urlcdom,my $key) = ($1,$2); |
my $item = ''; |
my $tinyurl; |
if ($lettnum) { |
my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$urlcdom."\0".$key); |
$item = $letts[int(rand(26))]; |
if (defined($cached)) { |
my $uppercase = int(rand(2)); |
$tinyurl = $result; |
if ($uppercase) { |
|
$item =~ tr/a-z/A-Z/; |
|
} |
|
} else { |
} else { |
$item = int(rand(10)); |
my $configuname = &Apache::lonnet::get_domainconfiguser($urlcdom); |
|
my %currtiny = &Apache::lonnet::get('tiny',[$key],$urlcdom,$configuname); |
|
if ($currtiny{$key} ne '') { |
|
$tinyurl = $currtiny{$key}; |
|
&Apache::lonnet::do_cache_new('tiny',$urlcdom."\0".$key,$currtiny{$key},600); |
|
} |
|
} |
|
if ($tinyurl ne '') { |
|
$urlcnum = (split(/\&/,$tinyurl))[0]; |
} |
} |
$passwd .= $item; |
|
} |
} |
return ($passwd); |
return ($urlcdom,$urlcnum); |
} |
} |
|
|
1; |
1; |