Annotation of loncom/auth/migrateuser.pm, revision 1.64
1.1 albertel 1: # The LearningOnline Network
2: # Starts a user off based of an existing token.
3: #
1.64 ! raeburn 4: # $Id: migrateuser.pm,v 1.63 2022/06/30 21:04:13 raeburn Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
1.2 albertel 29: package Apache::migrateuser;
1.1 albertel 30:
31: use strict;
1.19 raeburn 32: use LONCAPA qw(:DEFAULT :match);
1.50 raeburn 33: use Apache::Constants qw(:common :http :methods :remotehost);
1.1 albertel 34: use Apache::lonauth;
35: use Apache::lonnet;
1.37 raeburn 36: use Apache::loncommon;
1.6 albertel 37: use Apache::lonlocal;
1.18 raeburn 38: use Apache::lonlogin();
1.27 raeburn 39: use Apache::ltiauth;
1.37 raeburn 40: use Apache::switchserver;
1.28 raeburn 41: use CGI::Cookie;
1.1 albertel 42:
43: sub goto_login {
1.27 raeburn 44: my ($r,$domain,$data) = @_;
45: if ((ref($data) eq 'HASH') && ($data->{'lti.login'})) {
46: &Apache::ltiauth::invalid_request($r,'22');
47: } else {
48: &Apache::loncommon::content_type($r,'text/html');
49: $r->send_http_header;
50: my $url = '/adm/login';
51: if ($domain) {
52: $url .= '?domain='.$domain;
53: }
54: $r->print(&Apache::loncommon::start_page('Going to login',undef,
55: {'redirect' => [0,$url],}).
56: '<h1>'.&mt('One moment please...').'</h1>'.
57: '<p>'.&mt('Transferring to login page.').'</p>'.
58: &Apache::loncommon::end_page());
59: }
1.2 albertel 60: return OK;
1.1 albertel 61: }
62:
1.27 raeburn 63: sub sso_check {
1.7 albertel 64: my ($data) = @_;
1.8 albertel 65: my %extra_env;
1.18 raeburn 66: if (ref($data) eq 'HASH') {
67: if ($data->{'sso.login'}) {
68: $extra_env{'request.sso.login'} = $data->{'sso.login'};
69: }
70: if ($data->{'sso.reloginserver'}) {
71: $extra_env{'request.sso.reloginserver'} =
72: $data->{'sso.reloginserver'};
73: }
1.27 raeburn 74: }
75: return \%extra_env;
76: }
77:
78: sub lti_check {
79: my ($data) = @_;
80: my %lti_env;
81: if (ref($data) eq 'HASH') {
1.26 raeburn 82: if ($data->{'lti.login'}) {
1.27 raeburn 83: $lti_env{'request.lti.login'} = $data->{'lti.login'};
84: if ($data->{'lti.reqcrs'}) {
85: $lti_env{'request.lti.reqcrs'} = $data->{'lti.reqcrs'};
86: }
87: if ($data->{'lti.reqrole'}) {
88: $lti_env{'request.lti.reqrole'} = $data->{'lti.reqrole'};
89: }
90: if ($data->{'lti.selfenrollrole'}) {
91: $lti_env{'request.lti.selfenrollrole'} = $data->{'lti.selfenrollrole'};
92: }
1.29 raeburn 93: if ($data->{'lti.uri'}) {
94: $lti_env{'request.lti.uri'} = $data->{'lti.uri'};
95: }
96: if ($data->{'lti.target'}) {
97: $lti_env{'request.lti.target'} = $data->{'lti.target'};
98: }
1.32 raeburn 99: if ($data->{'lti.sourcecrs'}) {
100: $lti_env{'request.lti.sourcecrs'} = $data->{'lti.sourcecrs'};
101: }
1.26 raeburn 102: }
103: if ($data->{'lti.passbackid'}) {
1.27 raeburn 104: $lti_env{'request.lti.passbackid'} = $data->{'lti.passbackid'};
1.26 raeburn 105: }
106: if ($data->{'lti.passbackurl'}) {
1.27 raeburn 107: $lti_env{'request.lti.passbackurl'} = $data->{'lti.passbackurl'};
1.26 raeburn 108: }
109: if ($data->{'lti.rosterid'}) {
1.27 raeburn 110: $lti_env{'request.lti.rosterid'} = $data->{'lti.rosterid'};
1.26 raeburn 111: }
112: if ($data->{'lti.rosterurl'}) {
1.27 raeburn 113: $lti_env{'request.lti.rosterurl'} = $data->{'lti.rosterurl'};
1.26 raeburn 114: }
1.7 albertel 115: }
1.27 raeburn 116: return \%lti_env;
1.18 raeburn 117: }
118:
1.39 raeburn 119: sub canhost {
120: my ($uname,$udom,$lonhost,$loncaparev) = @_;
121: my $canhost;
122: if (&Apache::lonnet::is_library($lonhost)) {
123: my @possdoms = &Apache::lonnet::current_machine_domains();
124: my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles','',['ca','aa'],\@possdoms);
125: if (keys(%roleshash)) {
126: foreach my $key (keys(%roleshash)) {
1.40 raeburn 127: my $audom = (split(/:/,$key))[1];
1.39 raeburn 128: if ((&Apache::lonnet::will_trust('othcoau',$udom,$audom)) &&
129: (&Apache::lonnet::will_trust('coaurem',$audom,$udom))) {
130: $canhost = 1;
131: last;
132: }
133: }
134: }
135: }
136: unless ($canhost) {
137: my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
138: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
139: my @intdoms;
140: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
141: if (ref($internet_names) eq 'ARRAY') {
142: @intdoms = @{$internet_names};
143: }
144: if ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {
145: $canhost = 1;
146: } else {
147: my $hostname = &Apache::lonnet::hostname($lonhost);
148: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
149: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
150: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
151: my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);
152: $canhost =
153: &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev,
154: $udomdefaults{'remotesessions'},
155: $defdomdefaults{'hostedsessions'});
156: }
157: }
158: return $canhost;
159: }
160:
1.18 raeburn 161: sub ip_changed {
1.37 raeburn 162: my ($r,$udom,$camefrom,$idsref,$dataref) = @_;
1.18 raeburn 163: &Apache::loncommon::content_type($r,'text/html');
164: $r->send_http_header;
165: if (ref($dataref) eq 'HASH') {
166: my $title = 'LON-CAPA Session redirected';
167: my $message = &mt('Your internet address has changed since you logged in.');
168: my $rule_in_effect;
1.22 raeburn 169: if ($dataref->{'balancer'}) {
170: my $baldom = &Apache::lonnet::host_domain($camefrom);
171: my $balprimaryid = &Apache::lonnet::domain($baldom,'primary');
172: my $balintdom = &Apache::lonnet::internet_dom($balprimaryid);
173: my $uprimaryid = &Apache::lonnet::domain($udom,'primary');
174: my $uintdom = &Apache::lonnet::internet_dom($uprimaryid);
175: my $dom_in_use;
176: if (($uintdom ne '') && ($uintdom eq $balintdom)) {
177: $dom_in_use = $udom;
178: } else {
179: $dom_in_use = $baldom;
1.21 raeburn 180: }
1.22 raeburn 181: my ($result,$cached)=&Apache::lonnet::is_cached_new('loadbalancing',$dom_in_use);
1.18 raeburn 182: unless (defined($cached)) {
183: my $cachetime = 60*60*24;
184: my %domconfig =
1.22 raeburn 185: &Apache::lonnet::get_dom('configuration',['loadbalancing'],$dom_in_use);
1.18 raeburn 186: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
1.22 raeburn 187: $result = &Apache::lonnet::do_cache_new('loadbalancing',$dom_in_use,
1.18 raeburn 188: $domconfig{'loadbalancing'},$cachetime);
189: }
190: }
191: if (ref($result) eq 'HASH') {
192: (undef,my $currtargets,my $currrules) =
193: &Apache::lonnet::check_balancer_result($result,$dataref->{'server'});
194: if (ref($currrules) eq 'HASH') {
195: if ($dataref->{'sso.login'}) {
196: if ($currrules->{'_LC_ipchangesso'} ne '') {
197: $rule_in_effect = $currrules->{'_LC_ipchangesso'};
198: }
199: } else {
200: if ($currrules->{'_LC_ipchange'} ne '') {
201: $rule_in_effect = $currrules->{'_LC_ipchange'};
202: }
203: }
204: }
205: }
206: }
207: my $url;
208: my $lonhost= $r->dir_config('lonHostID');
209: my $switchto = $lonhost;
1.23 raeburn 210: if ($rule_in_effect ne 'offloadedto') {
1.37 raeburn 211: my ($hosthere,@ids);
212: if (ref($idsref) eq 'ARRAY') {
213: @ids=@{$idsref};
214: }
1.23 raeburn 215: unless ($rule_in_effect eq 'balancer') {
216: if (grep(/^\Q$rule_in_effect\E$/,@ids)) {
217: $hosthere = 1;
218: }
219: }
220: unless ($hosthere) {
221: if ($dataref->{'role'}) {
222: my ($adom,$aname);
223: if ($dataref->{'role'} =~ m{^au\./($match_domain)/$}) {
224: $adom = $1;
225: $aname = $dataref->{'username'};
226: } elsif ($dataref->{'role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
227: $adom = $1;
228: $aname = $2;
229: }
230: if ($adom ne '' && $aname ne '') {
231: my $ahome = &Apache::lonnet::homeserver($aname,$adom);
232: unless ($ahome eq 'no_host') {
233: if ($ahome && grep(/^\Q$ahome\E$/,@ids)) {
234: $hosthere = 1;
235: }
1.18 raeburn 236: }
237: }
238: }
239: }
1.23 raeburn 240: unless ($hosthere) {
241: my $hostname;
242: if ($rule_in_effect eq 'balancer') {
243: $hostname = &Apache::lonnet::hostname($dataref->{'server'});
244: if ($hostname) {
245: $switchto = $dataref->{'server'};
246: }
247: } else {
248: $hostname = &Apache::lonnet::hostname($rule_in_effect);
249: if ($hostname) {
250: $switchto = $rule_in_effect;
251: }
252: }
1.18 raeburn 253: if ($hostname) {
254: my $protocol = $Apache::lonnet::protocol{$switchto};
255: $protocol = 'http' if ($protocol ne 'https');
1.50 raeburn 256: my $alias = &Apache::lonnet::use_proxy_alias($r,$switchto);
257: $hostname = $alias if ($alias ne '');
1.18 raeburn 258: $url = $protocol.'://'.$hostname;
1.23 raeburn 259: if ($rule_in_effect eq 'balancer') {
260: $message .= '<br />'.
261: &mt('As a result, your LON-CAPA session is being redirected to the server where you originally logged in.');
262: } else {
263: $message .= '<br />'.
264: &mt('As a result, your LON-CAPA session is being redirected.');
265: }
1.18 raeburn 266: }
267: }
1.35 raeburn 268: unless ($hosthere) {
269: if (($dataref->{'balancer'}) && ($dataref->{'balcookie'})) {
270: &Apache::lonnet::delbalcookie($dataref->{'balcookie'},$dataref->{'balancer'});
271: }
272: }
1.18 raeburn 273: }
274: if ($dataref->{'sso.login'}) {
1.21 raeburn 275: $url .= '/adm/roles';
1.18 raeburn 276: } else {
1.21 raeburn 277: $url .= '/adm/login';
1.24 raeburn 278: if ($udom) {
279: $url .= '?domain='.$udom;
280: }
1.20 raeburn 281: $message .= '<br />'.&mt('You will need to provide your password one more time.');
1.18 raeburn 282: }
283: my %info= (
1.24 raeburn 284: 'domain' => $udom,
1.18 raeburn 285: 'username' => $dataref->{'username'},
286: 'sessionserver' => $lonhost,
287: );
1.63 raeburn 288: my @names = ('origurl','symb','role','linkprotuser','linkprotexit','linkprot','linkkey');
1.54 raeburn 289: foreach my $name (@names) {
290: if ($dataref->{$name} ne '') {
291: $info{$name} = $dataref->{$name};
292: }
1.18 raeburn 293: }
1.54 raeburn 294: my $iptoken = &Apache::lonnet::tmpput(\%info,$switchto,'link');
1.18 raeburn 295: unless ($iptoken eq 'conlost') {
1.54 raeburn 296: $url .= (($url =~ /\?/) ? '&' : '?') . 'iptoken='.$iptoken;
1.18 raeburn 297: }
298: $r->print(&Apache::loncommon::start_page($title,undef,
299: {'redirect' =>
300: [2,$url],}).
301: '<h1>'.&mt('One moment please...').'</h1>'.
302: '<p class="LC_warning">'.$message.'</p>'.
303: &Apache::loncommon::end_page());
304: } else {
305: return &goto_login($r);
1.10 raeburn 306: }
1.18 raeburn 307: return OK;
1.7 albertel 308: }
309:
1.28 raeburn 310: sub logout {
1.61 raeburn 311: my ($r,$ip,$handle,$data,$lti_env,$linkprot_info) = @_;
1.34 raeburn 312: my $lonidsdir=$r->dir_config('lonIDsDir');
313: if (unlink("$lonidsdir/$handle.id")) {
314: if (($env{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
315: (-l "$lonidsdir/$env{'user.linkedenv'}.id") &&
316: (readlink("$lonidsdir/$env{'user.linkedenv'}.id") eq "$lonidsdir/$handle.id")) {
317: unlink("$lonidsdir/$env{'user.linkedenv'}.id");
1.28 raeburn 318: }
319: }
320: my %temp=('logout' => time);
321: &Apache::lonnet::put('email_status',\%temp);
322: &Apache::lonnet::log($env{'user.domain'},
323: $env{'user.name'},
324: $env{'user.home'},
1.49 raeburn 325: "Logout $ip");
1.28 raeburn 326:
327: &Apache::loncommon::content_type($r,'text/html');
328:
1.34 raeburn 329: #expire the cookies
330: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
331: foreach my $name (keys(%cookies)) {
332: next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
333: my $c = new CGI::Cookie(-name => $name,
334: -value => '',
335: -expires => '-10y',);
336: $r->headers_out->add('Set-cookie' => $c);
1.28 raeburn 337: }
338: my $lonhost = $r->dir_config('lonHostID');
1.62 raeburn 339: my ($url,$token,$delay,%info,%user_info);
1.28 raeburn 340: if (ref($data) eq 'HASH') {
1.49 raeburn 341: %user_info=('ip' => $ip,
1.28 raeburn 342: 'domain' => $data->{'domain'},
343: 'username' => $data->{'username'},
1.36 raeburn 344: 'home' => $data->{'home'},
1.28 raeburn 345: 'role' => $data->{'role'},
346: 'origurl' => $data->{'origurl'},
347: 'symb' => $data->{'symb'},
348: 'server' => $lonhost);
349: }
1.62 raeburn 350: $delay = 0.1;
1.61 raeburn 351: if (ref($linkprot_info) eq 'HASH') {
352: if ($linkprot_info->{'linkprotuser'} ne '') {
353: $token = &Apache::lonnet::tmpput($linkprot_info,$lonhost);
354: $url = '/adm/login?ltoken='.$token;
355: } else {
356: foreach my $key (keys(%user_info)) {
357: if ($user_info{$key} eq '') {
358: delete($user_info{$key});
359: }
360: }
361: %info = (%user_info,%{$linkprot_info});
362: $token = &Apache::lonnet::tmpput(\%info,$lonhost);
363: $url = '/adm/migrateuser?token='.$token;
364: }
1.62 raeburn 365: $delay = 0;
1.61 raeburn 366: } else {
367: my %lti_info;
368: if (ref($lti_env) eq 'HASH') {
369: foreach my $key (sort(keys(%{$lti_env}))) {
370: if ($key =~ /^request\.(.+)$/) {
371: $lti_info{$1} = $lti_env->{$key};
372: }
373: }
374: }
375: %info = (%user_info,%lti_info);
376: $token = &Apache::lonnet::tmpput(\%info,$lonhost);
377: $url = '/adm/migrateuser?token='.$token;
378: }
1.28 raeburn 379: $r->send_http_header;
380: $r->print(
381: &Apache::loncommon::start_page('Updating Session ...',undef,
1.62 raeburn 382: {'redirect' => [$delay,$url],
1.28 raeburn 383: 'only_body' => 1,}).
384: &Apache::loncommon::end_page());
1.44 raeburn 385: if ($env{'request.balancercookie'}) {
386: my ($balancer,$cookie) = split(/:/,$env{'request.balancercookie'});
387: if ((&Apache::lonnet::hostname($balancer)) && ($cookie =~ /^[a-f0-9]{32}$/)) {
388: $cookie = $env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cookie;
389: &Apache::lonnet::delbalcookie($cookie,$balancer);
390: }
391: }
1.28 raeburn 392: $r->register_cleanup(\&flush_course_logs);
393: return;
394: }
395:
1.36 raeburn 396: sub conlost_userhome {
397: my ($r,$idsref,$dataref) = @_;
398: return unless ((ref($idsref) eq 'ARRAY') && (ref($dataref) eq 'HASH'));
399: my @ids = @{$idsref};
400: my %data = %{$dataref};
1.37 raeburn 401: my ($lonhost,$lowest_load,$otherserver,$is_balancer,%conlost,%posstargets);
402: $lonhost = $r->dir_config('lonHostID');
403: if (grep(/^\Q$lonhost\E$/,split(/,/,$data{'dom_balancers'}))) {
404: $is_balancer = 1;
405: }
406: $lowest_load = 30000;
1.36 raeburn 407: if ($data{'conlost'} ne '') {
408: map { $conlost{$_} = 1; } split(/,/,$data{'conlost'});
409: }
1.37 raeburn 410: if ($data{'loncfail'}) {
1.38 raeburn 411: if ($lonhost ne $data{'from_balancer'}) {
412: my ($is_balancer,$posshost,$setcookie,$offloadto,$dom_balancers) =
413: &Apache::lonnet::check_loadbalancing($data{'username'},$data{'domain'});
414: if ($is_balancer) {
415: if (ref($offloadto) eq 'HASH') {
416: $data{'offloadto'} = '';
417: foreach my $key (keys(%{$offloadto})) {
418: if (ref($offloadto->{$key}) eq 'ARRAY') {
419: $data{'offloadto'} .= $key.'='.join(',',@{$offloadto->{$key}}).'&';
1.37 raeburn 420: }
421: }
1.38 raeburn 422: $data{'offloadto'} =~ s/\&$//;
423: } elsif (ref($offloadto) eq 'ARRAY') {
424: $data{'offloadto'} = join(',',@{$offloadto});
1.37 raeburn 425: }
426: }
427: }
428: } else {
429: $conlost{$lonhost} = 1;
430: $data{'conlost'} = join(',',sort(keys(%conlost)));
431: }
1.36 raeburn 432: if ($data{'offloadto'} =~ /\&/) {
1.37 raeburn 433: foreach my $item (split(/\&/,$data{'offloadto'})) {
1.36 raeburn 434: my ($type,$targets) = split(/\=/,$item);
435: @{$posstargets{$type}} = split(/,/,$targets);
436: }
437: } elsif ($data{'offloadto'} =~ /=/) {
438: my ($type,$targets) = split(/\=/,$data{'offloadto'});
439: @{$posstargets{$type}} = split(/,/,$targets);
440: } else {
441: @{$posstargets{'default'}} = split(/,/,$data{'offloadto'});
442: }
443: if (ref($posstargets{'primary'}) eq 'ARRAY') {
444: foreach my $try_server (@{$posstargets{'primary'}}) {
445: next if ($conlost{$try_server});
1.37 raeburn 446: next if ((grep(/^\Q$try_server\E$/,@ids)) && !$data{'loncfail'});
1.36 raeburn 447: ($otherserver,$lowest_load) =
448: &Apache::lonnet::compare_server_load($try_server,
449: $otherserver,
450: $lowest_load);
451: }
452: }
453: my $found_server = ($otherserver ne '' && $lowest_load < 100);
454: if (!$found_server) {
455: if (ref($posstargets{'default'}) eq 'ARRAY') {
456: foreach my $try_server (@{$posstargets{'default'}}) {
1.37 raeburn 457: next if ($conlost{$try_server});
458: next if ((grep(/^\Q$try_server\E$/,@ids)) && !$data{'loncfail'});
1.36 raeburn 459: ($otherserver,$lowest_load) =
1.37 raeburn 460: &Apache::lonnet::compare_server_load($try_server,
461: $otherserver,
462: $lowest_load);
1.36 raeburn 463: }
464: }
465: }
466: if ($otherserver ne '') {
467: my $switchto = &Apache::lonnet::hostname($otherserver);
468: if ($switchto ne '') {
469: $data{'server'} = $lonhost;
1.37 raeburn 470: if ($data{'loncfail'}) {
471: delete($data{'loncfail'});
472: }
1.36 raeburn 473: if (grep(/^\Q$otherserver\E$/,split(/,/,$data{'dom_balancers'}))) {
1.37 raeburn 474: $data{'noloadbalance'} = $otherserver;
1.36 raeburn 475: }
1.37 raeburn 476: &do_server_switch($r,$otherserver,$switchto,$is_balancer,\%data);
1.36 raeburn 477: return $otherserver;
1.37 raeburn 478: } else {
479: #FIXME Contents of $data{offloadto} contains invalid hostID.
480: }
481: } else {
482: my (%poss_balancers,%tried_balancers);
483: map { $poss_balancers{$_} = 1; } split(/,/,$data{'dom_balancers'});
484: map { $tried_balancers{$_} = 1; } split(/,/,$data{'tried_balancers'});
485: if (keys(%poss_balancers)) {
486: foreach my $try_server (sort(keys(%poss_balancers))) {
487: next if (grep(/^\Q$try_server\E$/,@ids));
488: next if (($data{'loncfail'}) && ($tried_balancers{$try_server}));
489: my $alreadytried;
490: foreach my $key (keys(%posstargets)) {
491: if ((ref($posstargets{$key}) eq 'ARRAY') &&
492: (grep(/^\Q$try_server\E$/,@{$posstargets{$key}}))) {
493: $alreadytried = 1;
494: last;
495: }
496: }
497: unless ($alreadytried) {
498: if (&Apache::lonnet::reply('ping',$try_server) eq $try_server) {
499: $otherserver = $try_server;
500: last;
501: }
502: }
503: }
504: }
505: if ($otherserver ne '') {
506: my $switchto = &Apache::lonnet::hostname($otherserver);
507: if ($switchto ne '') {
508: $data{'server'} = $lonhost;
509: $data{'loncfail'} = $lonhost;
510: $tried_balancers{$otherserver} = 1;
511: $data{'tried_balancers'} = join(',',sort(keys(%tried_balancers)));
512: &do_server_switch($r,$otherserver,$switchto,$is_balancer,\%data);
513: return $otherserver;
514: } else {
515: #FIXME Contents of $data{'dom_balancers'} contains invalid hostID.
1.39 raeburn 516: }
1.37 raeburn 517: } else {
518: if ($data{'loncfail'}) {
519: #FIXME Nowhere to go.
520: } else {
521: # FIXME Send back to a balancer (no token); different balancer if this is a balancer.
522: # Send command to balancer to exclude this host using http instead on lonc/lond
523: }
1.36 raeburn 524: }
525: }
1.37 raeburn 526: return;
527: }
528:
529: sub do_server_switch {
530: my ($r,$otherserver,$switchto,$is_balancer,$dataref) = @_;
531: if (ref($dataref) eq 'HASH') {
532: my $domain = $dataref->{'domain'};
533: my $username = $dataref->{'username'};
534: # If this is a balancer set a balancer cookie unless browser already sent
535: # LON-CAPA load balancer cookie which points at the target server.
536: if ($is_balancer) {
537: my $newcookieid;
538: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
539: unless (($found_server eq $otherserver) &&
540: ($balancer_cookie =~ /^\Q$domain\E_\Q$username\E_/)) {
541: $newcookieid =
542: &Apache::switchserver::balancer_cookieid($r,$otherserver,$username,$domain);
543: if ($newcookieid) {
544: $dataref->{'balcookie'} = $newcookieid;
545: }
546: }
547: }
548: my $token = &Apache::lonnet::tmpput($dataref,$otherserver);
549: my $protocol = $Apache::lonnet::protocol{$otherserver};
550: $protocol = 'http' if ($protocol ne 'https');
551: my $url = $protocol.'://'.$switchto.'/adm/login?domain='.$domain.
552: '&username='.$username.'&token='.$token;
553: $r->send_http_header;
554: $r->print(
555: &Apache::loncommon::start_page('Switching Server ...',undef,
556: {'redirect' => [0.1,$url]}).
557: &Apache::loncommon::end_page());
558: }
559: return;
1.36 raeburn 560: }
561:
562: sub log_switch {
1.49 raeburn 563: my ($r,$data,$lti_env,$ip) = @_;
1.36 raeburn 564: my $lonhost = $r->dir_config('lonHostID');
565: return unless ((ref($data) eq 'HASH') && (ref($lti_env) eq 'HASH'));
566: my $now = time;
567: my %temp=('switchserver' => $now.':'.$lonhost,$data->{'role'});
568: &Apache::lonnet::put('email_status',\%temp);
569: my $logmsg = "Switch Server to $lonhost";
570: if ($data->{'role'}) {
571: $logmsg .= " with role: ".$data->{'role'};
572: } elsif (($lti_env->{'reqcrs'}) && ($lti_env->{'reqrole'} eq 'cc')) {
573: $logmsg .= " to create new LTI course";
574: } elsif ($lti_env->{'selfenrollrole'}) {
575: $logmsg .= " to selfenroll with role: ".$lti_env->{'selfenrollrole'};
576: } else {
577: $logmsg .= " (no role)";
578: }
1.49 raeburn 579: $logmsg .= ' '.$ip;
1.36 raeburn 580: &Apache::lonnet::log($data->{'domain'},$data->{'username'},$data->{'home'},$logmsg);
581: }
582:
1.28 raeburn 583: sub flush_course_logs {
584: &Apache::lonnet::flushcourselogs();
585: return OK;
586: }
587:
1.1 albertel 588: sub handler {
589: my ($r) = @_;
590:
591: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token']);
1.4 albertel 592: my %data = &Apache::lonnet::tmpget($env{'form.token'});
1.13 raeburn 593: if (keys(%data) == 0) {
594: return &goto_login($r);
595: }
1.4 albertel 596: my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
597:
1.6 albertel 598: &Apache::lonlocal::get_language_handle($r);
599:
1.4 albertel 600: if ($delete ne 'ok') {
1.27 raeburn 601: return &goto_login($r,undef,\%data);
1.4 albertel 602: }
1.2 albertel 603:
1.18 raeburn 604: if (!defined($data{'username'}) || !defined($data{'domain'})) {
1.27 raeburn 605: return &goto_login($r,undef,\%data);
1.18 raeburn 606: }
1.37 raeburn 607: my ($home,@ids);
608: @ids=&Apache::lonnet::current_machine_ids();
1.50 raeburn 609: my $ip = &Apache::lonnet::get_requestor_ip($r,REMOTE_NOLOOKUP);
1.49 raeburn 610: if ($data{'ip'} ne $ip) {
1.24 raeburn 611: &Apache::lonnet::logthis('IP change when session migration requested -- was: '.
1.49 raeburn 612: $data{'ip'}.'; now: '.$ip.' for '.$data{'username'}.':'.$data{'domain'});
1.37 raeburn 613: return &ip_changed($r,$data{'domain'},$data{'server'},\@ids,\%data);
1.2 albertel 614: }
1.37 raeburn 615: if ($data{'loncfail'}) {
616: &Apache::lonnet::logthis('Returned from '.$data{'server'}.' -- no connection to library node or other access node(s)');
617: my $otherserver = &conlost_userhome($r,\@ids,\%data);
618: if ($otherserver ne '') {
619: &Apache::lonnet::logthis("Switching to $otherserver");
620: }
621: return OK;
622: } else {
623: $home=&Apache::lonnet::homeserver($data{'username'},$data{'domain'});
624: if ($home eq 'no_host') {
625: if (($data{'home'} ne '') && (&Apache::lonnet::hostname($data{'home'}))) {
626: &Apache::lonnet::reconlonc($data{'home'});
627: $home=&Apache::lonnet::homeserver($data{'username'},$data{'domain'});
628: if ($home eq 'no_host') {
629: unless (grep(/^\Q$data{'home'}\E$/,@ids)) {
630: if (&Apache::lonnet::reply('ping',$data{'home'}) eq 'con_lost') {
631: my $otherserver = &conlost_userhome($r,\@ids,\%data);
632: if ($otherserver ne '') {
633: &Apache::lonnet::logthis("No connection to home server ($data{'home'}) for $data{'username'}:$data{'domain'}. Switching to $otherserver");
634: }
1.36 raeburn 635: return OK;
636: }
637: }
638: }
639: }
640: }
641: }
642:
1.24 raeburn 643: my $udom;
644: if (&Apache::lonnet::domain($data{'domain'})) {
645: $udom=$data{'domain'};
646: }
1.36 raeburn 647: if ($home eq 'no_host') { return &goto_login($r,$udom,\%data); }
1.38 raeburn 648: if (&Apache::lonnet::hostname($home) eq '') { return &goto_login($r,$udom,\%data); }
1.36 raeburn 649:
1.39 raeburn 650: unless (grep(/^\Q$home\E$/,@ids)) {
651: my $lonhost = $r->dir_config('lonHostID');
652: my $loncaparev = $r->dir_config('lonVersion');
653: unless (&canhost($data{'username'},$data{'domain'},$lonhost,$loncaparev)) {
654: return &goto_login($r,$udom,\%data);
655: }
656: }
1.41 raeburn 657:
1.36 raeburn 658: my $rolemsg;
659: if ($data{'role'}) {
1.38 raeburn 660: $rolemsg = "role: $data{'role'}";
1.36 raeburn 661: } else {
662: $rolemsg = '(no role)';
663: }
664:
665: &Apache::lonnet::logthis("Allowing access for $data{'username'}:$data{'domain'} $rolemsg");
1.27 raeburn 666:
667: my $sso_env = &sso_check(\%data);
668: my $lti_env = <i_check(\%data);
1.2 albertel 669:
1.27 raeburn 670: my $extra_env;
671: if ((ref($sso_env) eq 'HASH') && (keys(%{$sso_env}))) {
672: $extra_env = $sso_env;
673: } elsif ((ref($lti_env) eq 'HASH') && (keys(%{$lti_env}))) {
674: $extra_env = $lti_env;
675: }
1.45 raeburn 676: if (($data{'balancer'}) && ($data{'server'}) && ($data{'balcookie'})) {
677: if (ref($extra_env) eq 'HASH') {
678: $extra_env->{'request.balancercookie'} = $data{'server'}.':'.$data{'balcookie'};
679: } else {
680: $extra_env = { 'request.balancercookie' => $data{'server'}.':'.$data{'balcookie'} };
681: }
1.48 raeburn 682: } elsif (($data{'server'}) && ($data{'otherbalcookie'})) {
683: my ($balancer,$balcookie) = split(/:/,$data{'otherbalcookie'});
684: if (defined(&Apache::lonnet::hostname($balancer)) && $balcookie =~ /^[a-f0-9]{32}$/) {
685: my $baldom = &Apache::lonnet::host_domain($balancer);
686: if (&Apache::lonnet::shared_institution($baldom)) {
687: my $cookieid = join('_',$udom,$data{'username'},$balcookie);
688: &Apache::lonnet::updatebalcookie($cookieid,$balancer,$data{'server'});
689: if (ref($extra_env) eq 'HASH') {
690: $extra_env->{'request.balancercookie'} = $data{'otherbalcookie'};
691: } else {
692: $extra_env = { 'request.balancercookie' => $data{'otherbalcookie'} };
693: }
694: }
695: }
1.45 raeburn 696: }
1.8 albertel 697:
1.37 raeburn 698: if (($data{'conlost'}) && ($data{'server'})) {
699: my @conlosts = split(/,/,$data{'conlost'});
700: my $switchfrom = $data{'server'};
701: if (@conlosts) {
702: if (grep(/^\Q$switchfrom\E$/,@conlosts)) {
1.49 raeburn 703: &log_switch($r,\%data,$extra_env,$ip);
1.37 raeburn 704: }
705: }
706: }
707:
1.46 raeburn 708: my (%form,$cid);
1.16 raeburn 709: if ($data{'symb'} ne '') {
710: $form{'symb'} = $data{'symb'};
711: }
1.21 raeburn 712: if ($data{'iptoken'} ne '') {
713: $form{'iptoken'} = $data{'iptoken'};
714: }
1.25 raeburn 715: if ($data{'noloadbalance'} ne '') {
716: $form{'noloadbalance'} = $data{'noloadbalance'};
717: }
1.46 raeburn 718: if ($data{'role'}) {
719: if ($data{'role'} =~ m{\./($match_domain)/($match_courseid)(?:/\w+|$)}) {
720: unless (&Apache::lonnet::homeserver($2,$1) eq 'no_host') {
721: $cid = $1.'_'.$2;
722: }
723: }
724: } else {
1.55 raeburn 725: my ($handle,$expirepub);
726: $handle = &Apache::lonnet::check_for_valid_session($r);
727:
1.56 raeburn 728: # For "public user" - remove any existing "public" cookie so actual user is logged in.
1.55 raeburn 729: if ($handle) {
730: if ($handle=~/^publicuser\_/) {
731: my $lonidsdir=$r->dir_config('lonIDsDir');
732: if ($lonidsdir ne '') {
733: unlink("$lonidsdir/$handle.id");
734: }
735: undef($handle);
736: $expirepub = 1;
737: }
738: }
1.12 albertel 739: if ($handle) {
1.11 albertel 740: &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
741: $handle);
1.54 raeburn 742: my $checklaunch;
743: if ($data{'origurl'} =~ m{^/tiny/$match_domain/\w+$}) {
1.58 raeburn 744: unless ($env{'request.linkprot'} eq $data{'linkprot'}) {
745: $checklaunch = 1;
746: }
1.64 ! raeburn 747: unless ($env{'request.linkprotexit'} eq $data{'linkprotexit'}) {
! 748: $checklaunch = 1;
! 749: }
1.58 raeburn 750: unless ($env{'request.linkkey'} eq $data{'linkkey'}) {
751: $checklaunch = 1;
1.54 raeburn 752: }
1.58 raeburn 753: unless ($env{'request.deeplink.login'} eq $data{'deeplink.login'}) {
754: $checklaunch = 1;
1.54 raeburn 755: }
756: }
1.42 raeburn 757: if ($data{'linkprot'} ne '') {
1.57 raeburn 758: if (($env{'user.name'} ne $data{'username'}) ||
759: ($env{'user.domain'} ne $data{'domain'})) {
760: my %linkprot_env;
1.64 ! raeburn 761: foreach my $item ('linkprot','linkprotexit','deeplink.login') {
1.57 raeburn 762: if ($data{$item}) {
1.61 raeburn 763: $linkprot_env{$item} = $data{$item};
1.57 raeburn 764: }
765: }
1.61 raeburn 766: &logout($r,$ip,$handle,\%data,undef,\%linkprot_env);
1.57 raeburn 767: return OK;
768: }
1.52 raeburn 769: &Apache::lonnet::appenv({'request.linkprot' => $data{'linkprot'}});
1.64 ! raeburn 770: if ($data{'linkprotexit'}) {
! 771: &Apache::lonnet::appenv({'request.linkprotexit' => $data{'linkprotexit'}});
! 772: }
1.54 raeburn 773: if ($env{'request.linkkey'}) {
774: &Apache::lonnet::delenv('request.linkkey');
775: }
1.42 raeburn 776: my ($linkprotector,$deeplink) = split(/:/,$data{'linkprot'},2);
777: if ($env{'user.linkprotector'}) {
778: my @protectors = split(/,/,$env{'user.linkprotector'});
779: unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
780: push(@protectors,$linkprotector);
781: @protectors = sort { $a <=> $b } @protectors;
782: &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
783: }
784: } else {
785: &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
1.43 raeburn 786: }
1.42 raeburn 787: if ($env{'user.linkproturi'}) {
788: my @proturis = split(/,/,$env{'user.linkproturi'});
789: unless(grep(/^\Q$deeplink\E$/,@proturis)) {
790: push(@proturis,$deeplink);
791: @proturis = sort @proturis;
792: &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
793: }
794: } else {
795: &Apache::lonnet::appenv({'user.linkproturi' => $deeplink});
796: }
1.53 raeburn 797: } elsif ($data{'linkkey'} ne '') {
1.52 raeburn 798: &Apache::lonnet::appenv({'request.linkkey' => $data{'linkkey'}});
1.54 raeburn 799: if ($env{'request.linkprot'}) {
800: &Apache::lonnet::delenv('request.linkprot');
801: }
1.43 raeburn 802: my $deeplink = $data{'deeplink.login'};
1.51 raeburn 803: my $linkkey = $data{'linkkey'};
1.53 raeburn 804: if ($env{'user.deeplinkkey'} ne '') {
1.51 raeburn 805: my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
806: unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
807: push(@linkkeys,$linkkey);
808: &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});
1.43 raeburn 809: }
1.51 raeburn 810: } else {
811: &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
812: }
1.52 raeburn 813: if ($deeplink) {
1.43 raeburn 814: if ($env{'user.keyedlinkuri'}) {
815: my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
816: unless (grep(/^\Q$deeplink\E$/,@keyeduris)) {
817: push(@keyeduris,$deeplink);
818: &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
819: }
820: } else {
821: &Apache::lonnet::appenv({'user.keyedlinkuri' => $deeplink});
822: }
823: }
1.51 raeburn 824: }
825: if ($data{'deeplink.login'}) {
1.43 raeburn 826: &Apache::lonnet::appenv({'request.deeplink.login' => $data{'deeplink.login'}});
1.42 raeburn 827: }
1.27 raeburn 828: if ($data{'lti.login'}) {
1.28 raeburn 829: my $needslogout;
830: if ($env{'request.lti.login'}) {
831: if (($env{'user.name'} ne $data{'username'}) ||
832: ($env{'user.domain'} ne $data{'domain'})) {
833: $needslogout = 1;
834: }
835: } else {
836: $needslogout = 1;
837: }
838: # If access is via LTI, and user already has a non-LTI session cookie
839: # (and session) or has an LTI session cookie for a different username,
840: # logout the existing session, and start a new one
841: if ($needslogout) {
1.50 raeburn 842: &logout($r,$ip,$handle,\%data,$lti_env);
1.28 raeburn 843: } elsif (($data{'lti.reqcrs'}) && ($data{'lti.reqrole'} eq 'cc')) {
1.27 raeburn 844: $form{'lti.reqcrs'} = $data{'lti.reqcrs'};
845: $form{'lti.reqrole'} = $data{'lti.reqrole'};
846: $form{'lti.sourcecrs'} = $data{'lti.sourcecrs'};
1.29 raeburn 847: $form{'lti.uri'} = $data{'lti.uri'};
1.28 raeburn 848: if ($data{'lti.passbackid'}) {
849: $form{'lti.passbackid'} = $data{'lti.passbackid'};
850: }
851: if ($data{'lti.passbackurl'}) {
852: $form{'lti.passbackurl'} = $data{'lti.passbackurl'};
853: }
854: if ($data{'lti.rosterid'}) {
855: $form{'lti.rosterid'} = $data{'lti.rosterid'};
856: }
857: if ($data{'lti.rosterurl'}) {
858: $form{'lti.rosterurl'} = $data{'lti.rosterurl'};
859: }
1.29 raeburn 860: if ($data{'lti.target'}) {
861: $form{'lti.target'} = $data{'lti.target'};
862: }
1.27 raeburn 863: &Apache::loncommon::content_type($r,'text/html');
864: $r->send_http_header;
865: &Apache::ltiauth::lti_reqcrs($r,$data{'domain'},\%form,$data{'username'},$data{'domain'});
1.28 raeburn 866: } else {
867: if (ref($lti_env) eq 'HASH') {
868: delete($lti_env->{'reqcrs'});
869: delete($lti_env->{'reqrole'});
870: delete($lti_env->{'selfenrollrole'});
871: }
872: if ($data{'lti.selfenrollrole'}) {
1.32 raeburn 873: if (&Apache::ltiauth::lti_enroll($data{'username'},$data{'domain'},
1.28 raeburn 874: $data{'lti.selfenrollrole'}) eq 'ok') {
875: my $url = '/adm/roles?selectrole=1&'.
876: &escape($data{'lti.selfenrollrole'}).'=1';
877: if ($data{'origurl'} =~ m{/default_\d+\.sequence$}) {
878: $url .= '&orgurl='.$data{'origurl'}.'&navmap=1';
879: } elsif ($data{'origurl'} ne '') {
880: $url .= '&orgurl='.$data{'origurl'};
881: }
882: if (ref($lti_env) eq 'HASH') {
883: &Apache::lonnet::appenv($lti_env);
884: }
885: $r->internal_redirect($url);
886: } else {
887: &Apache::ltiauth::invalid_request($r,23);
888: }
889: } elsif ($data{'origurl'} ne '') {
890: my $url = $data{'origurl'};
891: if ($url =~ m{/default_\d+\.sequence$}) {
892: $url .= (($url =~/\?/)?'&':'?').'navmap=1';
893: }
894: if (ref($lti_env) eq 'HASH') {
895: &Apache::lonnet::appenv($lti_env);
1.27 raeburn 896: }
897: $r->internal_redirect($url);
898: } else {
1.28 raeburn 899: if (ref($lti_env) eq 'HASH') {
900: &Apache::lonnet::appenv($lti_env);
901: }
1.27 raeburn 902: }
903: }
904: } elsif ($data{'origurl'} ne '') {
1.54 raeburn 905: my $dest = $data{'origurl'};
906: if (($env{'request.deeplink.login'} eq $data{'origurl'}) &&
907: (($env{'request.linkprot'}) || ($env{'request.linkkey'} ne ''))) {
908: my %info;
909: if ($env{'request.linkprot'}) {
910: $info{'linkprot'} = $env{'request.linkprot'};
1.63 raeburn 911: foreach my $item ('linkprotuser','linkprotexit') {
912: if ($data{$item}) {
913: $info{$item} = $data{$item};
914: }
1.62 raeburn 915: }
1.54 raeburn 916: } elsif ($env{'request.linkkey'} ne '') {
917: $info{'linkkey'} = $env{'request.linkkey'};
918: }
919: $info{'origurl'} = $data{'origurl'};
920: if ($checklaunch) {
921: $info{'checklaunch'} = 1;
922: }
923: my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'link');
1.61 raeburn 924: unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
1.54 raeburn 925: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
926: $dest .= (($dest =~ /\?/) ? '&' : '?') . 'ttoken='.$token;
927: }
928: }
929: $r->internal_redirect($dest);
1.14 raeburn 930: } elsif ($env{'request.course.id'}) {
931: $r->internal_redirect('/adm/navmaps');
1.11 albertel 932: } else {
933: $r->internal_redirect('/adm/roles');
934: }
935: } else {
1.14 raeburn 936: my $desturl = '/adm/roles';
1.52 raeburn 937: if ($data{'lti.login'}) {
1.47 raeburn 938: if ($data{'lti.selfenrollrole'}) {
939: $desturl .= '?selectrole=1&'.
940: &escape($data{'lti.selfenrollrole'}).'=1';
941: if ($data{'origurl'} ne '') {
942: $desturl .= '&orgurl='.$data{'origurl'};
943: if ($data{'origurl'} =~ m{/default_\d+\.sequence$}) {
944: $desturl .= '&navmap=1';
945: }
946: }
947: } elsif ($data{'origurl'} ne '') {
948: $desturl = $data{'origurl'};
1.27 raeburn 949: if ($desturl =~ m{/default_\d+\.sequence$}) {
950: $desturl .= (($desturl =~/\?/)?'&':'?').'navmap=1';
951: }
952: }
1.47 raeburn 953: } elsif ($data{'origurl'} ne '') {
954: $desturl = $data{'origurl'};
1.42 raeburn 955: if ($data{'linkprot'}) {
956: my ($linkprotector,$linkuri) = split(/:/,$data{'linkprot'},2);
957: if ($linkprotector) {
958: if (ref($extra_env) eq 'HASH') {
959: $extra_env->{'user.linkprotector'} = $linkprotector;
960: $extra_env->{'user.linkproturi'} = $linkuri;
1.52 raeburn 961: $extra_env->{'request.linkprot'} = $data{'linkprot'};
1.42 raeburn 962: } else {
963: $extra_env = {'user.linkprotector' => $linkprotector,
1.52 raeburn 964: 'user.linkproturi' => $linkuri,
965: 'request.linkprot' => $data{'linkprot'}};
1.42 raeburn 966: }
1.64 ! raeburn 967: if ($data{'linkprotexit'}) {
! 968: $extra_env->{'request.linkprotexit'} = $data{'linkprotexit'};
! 969: }
1.42 raeburn 970: }
1.63 raeburn 971: foreach my $item ('linkprotuser','linkprotexit') {
972: if ($data{$item} ne '') {
973: $form{$item} = $data{$item};
974: }
1.62 raeburn 975: }
1.53 raeburn 976: } elsif ($data{'linkkey'} ne '') {
1.52 raeburn 977: if (ref($extra_env) eq 'HASH') {
978: $extra_env->{'user.deeplinkkey'} = $data{'linkkey'};
979: $extra_env->{'user.keyedlinkuri'} = $data{'deeplink.login'};
980: $extra_env->{'request.linkkey'} = $data{'linkkey'};
981: } else {
982: $extra_env = {'user.deeplinkkey' => $data{'linkkey'},
983: 'user.keyedlinkuri' => $data{'deeplink.login'},
984: 'request.linkkey' => $data{'linkkey'}};
1.43 raeburn 985: }
1.52 raeburn 986: }
987: if ($data{'deeplink.login'}) {
988: if (ref($extra_env) eq 'HASH') {
1.54 raeburn 989: $extra_env->{'request.deeplink.login'} = $data{'deeplink.login'};
1.43 raeburn 990: } else {
991: $extra_env = {'request.deeplink.login' => $data{'deeplink.login'}};
992: }
1.42 raeburn 993: }
1.27 raeburn 994: }
995: my $skipcritical;
1.44 raeburn 996: if ($data{'lti.login'}) {
997: if ((($data{'lti.reqcrs'}) &&
998: ($data{'lti.reqrole'} eq 'cc')) ||
999: ($data{'lti.selfenrollrole'})) {
1000: $skipcritical = 1;
1001: }
1.14 raeburn 1002: }
1.11 albertel 1003: &Apache::lonauth::success($r,$data{'username'},$data{'domain'},
1.55 raeburn 1004: $home,$desturl,$extra_env,\%form,$skipcritical,'',
1005: $expirepub);
1.11 albertel 1006: }
1.1 albertel 1007: return OK;
1008: }
1.6 albertel 1009:
1.44 raeburn 1010: if ($data{'lti.login'}) {
1011: my $handle = &Apache::lonnet::check_for_valid_session($r);
1012: if ($handle) {
1013: &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
1014: $handle);
1015: my $needslogout;
1016: if ($env{'request.lti.login'}) {
1017: if (($env{'user.name'} ne $data{'username'}) ||
1018: ($env{'user.domain'} ne $data{'domain'})) {
1019: $needslogout = 1;
1020: }
1021: } else {
1022: $needslogout = 1;
1023: }
1024: if ($needslogout) {
1.50 raeburn 1025: &logout($r,$ip,$handle,\%data,$lti_env);
1.44 raeburn 1026: return OK;
1.30 raeburn 1027: }
1028: }
1.15 raeburn 1029: }
1.44 raeburn 1030:
1031: # check if current user, and role match those expected.
1032: my ($next_url,$reuse_session);
1033: if (($env{'user.name'} eq $data{'username'}) && ($env{'user.domain'} eq $data{'domain'}) &&
1034: ($env{'request.role'} eq $data{'role'}) && ($data{'origurl'} ne '')) {
1035: $next_url = $data{'origurl'};
1036: $reuse_session = 1;
1.52 raeburn 1037: } elsif ($data{'origurl'} =~ m{^/tiny/$match_domain/\w+$}) {
1038: $next_url=$data{'origurl'};
1.44 raeburn 1039: } else {
1.60 raeburn 1040: if ($data{'lti.login'}) {
1041: $next_url='/adm/roles?selectrole=1&'.&escape($data{'role'}).'=1';
1042: if ($data{'origurl'} ne '') {
1043: $next_url .= '&orgurl='.&escape($data{'origurl'});
1044: }
1045: } else {
1046: $next_url='/adm/roles?selectrole=1&'.&escape($data{'role'}).'=1';
1047: if ($data{'origurl'} ne '') {
1048: $next_url .= '&orgurl='.&escape($data{'origurl'});
1049: }
1.44 raeburn 1050: }
1051: }
1052: if ($data{'lti.login'}) {
1053: if (($data{'origurl'} =~ m{/default_\d+\.sequence$}) ||
1054: ($data{'origurl'} =~ m{^/res/.+\.sequence$})) {
1.60 raeburn 1055: if ($reuse_session) {
1056: $next_url .= '&navmap=1';
1057: } else {
1058: $next_url .= '&navmap=1';
1059: }
1.44 raeburn 1060: }
1061: }
1062: if ($reuse_session) {
1063: $r->internal_redirect($next_url);
1.59 raeburn 1064: } else {
1065: if ($data{'deeplink.login'}) {
1066: if (ref($extra_env) eq 'HASH') {
1067: $extra_env->{'request.deeplink.login'} = $data{'deeplink.login'};
1068: } else {
1069: $extra_env = {'request.deeplink.login' => $data{'deeplink.login'}};
1070: }
1071: if ($data{'linkprot'}) {
1072: $extra_env->{'request.linkprot'} = $data{'linkprot'};
1.64 ! raeburn 1073: if ($data{'linkprotexit'}) {
! 1074: $extra_env->{'request.linkprotexit'} = $data{'linkprotexit'};
! 1075: }
1.63 raeburn 1076: foreach my $item ('linkprotuser','linkprotexit') {
1077: if ($data{$item}) {
1078: $form{'request.'.$item} = $data{$item};
1079: }
1.62 raeburn 1080: }
1.59 raeburn 1081: } elsif ($data{'linkkey'} ne '') {
1082: $extra_env->{'request.linkkey'} = $data{'linkkey'};
1083: }
1.52 raeburn 1084: }
1.44 raeburn 1085: &Apache::lonauth::success($r,$data{'username'},$data{'domain'},$home,
1.46 raeburn 1086: $next_url,$extra_env,\%form,'',$cid);
1.44 raeburn 1087: }
1.6 albertel 1088: return OK;
1.1 albertel 1089: }
1090:
1091: 1;
1092: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>