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