Annotation of loncom/auth/migrateuser.pm, revision 1.25.2.5.2.6
1.1 albertel 1: # The LearningOnline Network
2: # Starts a user off based of an existing token.
3: #
1.25.2.5.2.6! raeburn 4: # $Id: migrateuser.pm,v 1.25.2.5.2.5 2022/06/18 01:01:42 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.25.2.5 raeburn 33: use Apache::Constants qw(:common :http :methods :remotehost);
1.1 albertel 34: use Apache::lonauth;
35: use Apache::lonnet;
1.6 albertel 36: use Apache::lonlocal;
1.18 raeburn 37: use Apache::lonlogin();
1.25.2.5.2.2 raeburn 38: use CGI::Cookie;
1.1 albertel 39:
40: sub goto_login {
1.24 raeburn 41: my ($r,$domain) = @_;
1.2 albertel 42: &Apache::loncommon::content_type($r,'text/html');
43: $r->send_http_header;
1.24 raeburn 44: my $url = '/adm/login';
45: if ($domain) {
46: $url .= '?domain='.$domain;
47: }
1.5 albertel 48: $r->print(&Apache::loncommon::start_page('Going to login',undef,
1.24 raeburn 49: {'redirect' => [0,$url],}).
1.5 albertel 50: '<h1>'.&mt('One moment please...').'</h1>'.
51: '<p>'.&mt('Transferring to login page.').'</p>'.
52: &Apache::loncommon::end_page());
1.2 albertel 53: return OK;
1.1 albertel 54: }
55:
1.7 albertel 56: sub sso_check {
57: my ($data) = @_;
1.8 albertel 58: my %extra_env;
1.18 raeburn 59: if (ref($data) eq 'HASH') {
60: if ($data->{'sso.login'}) {
61: $extra_env{'request.sso.login'} = $data->{'sso.login'};
62: }
63: if ($data->{'sso.reloginserver'}) {
64: $extra_env{'request.sso.reloginserver'} =
65: $data->{'sso.reloginserver'};
66: }
1.7 albertel 67: }
1.18 raeburn 68: return \%extra_env;
69: }
70:
71: sub ip_changed {
72: my ($r,$udom,$camefrom,$dataref) = @_;
73: &Apache::loncommon::content_type($r,'text/html');
74: $r->send_http_header;
75: if (ref($dataref) eq 'HASH') {
76: my $title = 'LON-CAPA Session redirected';
77: my $message = &mt('Your internet address has changed since you logged in.');
78: my $rule_in_effect;
1.22 raeburn 79: if ($dataref->{'balancer'}) {
80: my $baldom = &Apache::lonnet::host_domain($camefrom);
81: my $balprimaryid = &Apache::lonnet::domain($baldom,'primary');
82: my $balintdom = &Apache::lonnet::internet_dom($balprimaryid);
83: my $uprimaryid = &Apache::lonnet::domain($udom,'primary');
84: my $uintdom = &Apache::lonnet::internet_dom($uprimaryid);
85: my $dom_in_use;
86: if (($uintdom ne '') && ($uintdom eq $balintdom)) {
87: $dom_in_use = $udom;
88: } else {
89: $dom_in_use = $baldom;
1.21 raeburn 90: }
1.22 raeburn 91: my ($result,$cached)=&Apache::lonnet::is_cached_new('loadbalancing',$dom_in_use);
1.18 raeburn 92: unless (defined($cached)) {
93: my $cachetime = 60*60*24;
94: my %domconfig =
1.22 raeburn 95: &Apache::lonnet::get_dom('configuration',['loadbalancing'],$dom_in_use);
1.18 raeburn 96: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
1.22 raeburn 97: $result = &Apache::lonnet::do_cache_new('loadbalancing',$dom_in_use,
1.18 raeburn 98: $domconfig{'loadbalancing'},$cachetime);
99: }
100: }
101: if (ref($result) eq 'HASH') {
102: (undef,my $currtargets,my $currrules) =
103: &Apache::lonnet::check_balancer_result($result,$dataref->{'server'});
104: if (ref($currrules) eq 'HASH') {
105: if ($dataref->{'sso.login'}) {
106: if ($currrules->{'_LC_ipchangesso'} ne '') {
107: $rule_in_effect = $currrules->{'_LC_ipchangesso'};
108: }
109: } else {
110: if ($currrules->{'_LC_ipchange'} ne '') {
111: $rule_in_effect = $currrules->{'_LC_ipchange'};
112: }
113: }
114: }
115: }
116: }
117: my $url;
118: my $lonhost= $r->dir_config('lonHostID');
119: my $switchto = $lonhost;
1.23 raeburn 120: if ($rule_in_effect ne 'offloadedto') {
1.18 raeburn 121: my $hosthere;
1.23 raeburn 122: my @ids=&Apache::lonnet::current_machine_ids();
123: unless ($rule_in_effect eq 'balancer') {
124: if (grep(/^\Q$rule_in_effect\E$/,@ids)) {
125: $hosthere = 1;
126: }
127: }
128: unless ($hosthere) {
129: if ($dataref->{'role'}) {
130: my ($adom,$aname);
131: if ($dataref->{'role'} =~ m{^au\./($match_domain)/$}) {
132: $adom = $1;
133: $aname = $dataref->{'username'};
134: } elsif ($dataref->{'role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
135: $adom = $1;
136: $aname = $2;
137: }
138: if ($adom ne '' && $aname ne '') {
139: my $ahome = &Apache::lonnet::homeserver($aname,$adom);
140: unless ($ahome eq 'no_host') {
141: if ($ahome && grep(/^\Q$ahome\E$/,@ids)) {
142: $hosthere = 1;
143: }
1.18 raeburn 144: }
145: }
146: }
147: }
1.23 raeburn 148: unless ($hosthere) {
149: my $hostname;
150: if ($rule_in_effect eq 'balancer') {
151: $hostname = &Apache::lonnet::hostname($dataref->{'server'});
152: if ($hostname) {
153: $switchto = $dataref->{'server'};
154: }
155: } else {
156: $hostname = &Apache::lonnet::hostname($rule_in_effect);
157: if ($hostname) {
158: $switchto = $rule_in_effect;
159: }
160: }
1.18 raeburn 161: if ($hostname) {
162: my $protocol = $Apache::lonnet::protocol{$switchto};
163: $protocol = 'http' if ($protocol ne 'https');
1.25.2.5 raeburn 164: my $alias = &Apache::lonnet::use_proxy_alias($r,$switchto);
165: $hostname = $alias if ($alias ne '');
1.18 raeburn 166: $url = $protocol.'://'.$hostname;
1.23 raeburn 167: if ($rule_in_effect eq 'balancer') {
168: $message .= '<br />'.
169: &mt('As a result, your LON-CAPA session is being redirected to the server where you originally logged in.');
170: } else {
171: $message .= '<br />'.
172: &mt('As a result, your LON-CAPA session is being redirected.');
173: }
1.18 raeburn 174: }
175: }
1.25.2.1 raeburn 176: unless ($hosthere) {
177: if (($dataref->{'balancer'}) && ($dataref->{'balcookie'})) {
178: &Apache::lonnet::delbalcookie($dataref->{'balcookie'},$dataref->{'balancer'});
179: }
180: }
1.18 raeburn 181: }
182: if ($dataref->{'sso.login'}) {
1.21 raeburn 183: $url .= '/adm/roles';
1.18 raeburn 184: } else {
1.21 raeburn 185: $url .= '/adm/login';
1.24 raeburn 186: if ($udom) {
187: $url .= '?domain='.$udom;
188: }
1.20 raeburn 189: $message .= '<br />'.&mt('You will need to provide your password one more time.');
1.18 raeburn 190: }
191: my %info= (
1.24 raeburn 192: 'domain' => $udom,
1.18 raeburn 193: 'username' => $dataref->{'username'},
194: 'sessionserver' => $lonhost,
195: );
1.25.2.5.2.6! raeburn 196: my @names = ('origurl','symb','role','linkprotuser','linkprotexit','linkprot','linkkey');
1.25.2.5 raeburn 197: foreach my $name (@names) {
198: if ($dataref->{$name} ne '') {
199: $info{$name} = $dataref->{$name};
200: }
1.18 raeburn 201: }
1.25.2.5 raeburn 202: my $iptoken = &Apache::lonnet::tmpput(\%info,$switchto,'link');
1.18 raeburn 203: unless ($iptoken eq 'conlost') {
1.25.2.5 raeburn 204: $url .= (($url =~ /\?/) ? '&' : '?') . 'iptoken='.$iptoken;
1.18 raeburn 205: }
206: $r->print(&Apache::loncommon::start_page($title,undef,
207: {'redirect' =>
208: [2,$url],}).
209: '<h1>'.&mt('One moment please...').'</h1>'.
210: '<p class="LC_warning">'.$message.'</p>'.
211: &Apache::loncommon::end_page());
212: } else {
213: return &goto_login($r);
1.10 raeburn 214: }
1.18 raeburn 215: return OK;
1.7 albertel 216: }
217:
1.25.2.5.2.2 raeburn 218: sub logout {
1.25.2.5.2.6! raeburn 219: my ($r,$ip,$handle,$data,$lti_env,$linkprot_info) = @_;
1.25.2.5.2.2 raeburn 220: my $lonidsdir=$r->dir_config('lonIDsDir');
221: if (unlink("$lonidsdir/$handle.id")) {
222: if (($env{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
223: (-l "$lonidsdir/$env{'user.linkedenv'}.id") &&
224: (readlink("$lonidsdir/$env{'user.linkedenv'}.id") eq "$lonidsdir/$handle.id")) {
225: unlink("$lonidsdir/$env{'user.linkedenv'}.id");
226: }
227: }
228: my %temp=('logout' => time);
229: &Apache::lonnet::put('email_status',\%temp);
230: &Apache::lonnet::log($env{'user.domain'},
231: $env{'user.name'},
232: $env{'user.home'},
233: "Logout $ip");
234:
235: &Apache::loncommon::content_type($r,'text/html');
236:
237: #expire the cookies
238: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
239: foreach my $name (keys(%cookies)) {
240: next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
241: my $c = new CGI::Cookie(-name => $name,
242: -value => '',
243: -expires => '-10y',);
244: $r->headers_out->add('Set-cookie' => $c);
245: }
246: my $lonhost = $r->dir_config('lonHostID');
1.25.2.5.2.6! raeburn 247: my ($url,$token,$delay,%info,%user_info);
1.25.2.5.2.2 raeburn 248: if (ref($data) eq 'HASH') {
249: %user_info=('ip' => $ip,
250: 'domain' => $data->{'domain'},
251: 'username' => $data->{'username'},
252: 'home' => $data->{'home'},
253: 'role' => $data->{'role'},
254: 'origurl' => $data->{'origurl'},
255: 'symb' => $data->{'symb'},
256: 'server' => $lonhost);
257: }
1.25.2.5.2.6! raeburn 258: $delay = 0.1;
! 259: if (ref($linkprot_info) eq 'HASH') {
! 260: if ($linkprot_info->{'linkprotuser'} ne '') {
! 261: $token = &Apache::lonnet::tmpput($linkprot_info,$lonhost);
! 262: $url = '/adm/login?ltoken='.$token;
! 263: } else {
! 264: foreach my $key (keys(%user_info)) {
! 265: if ($user_info{$key} eq '') {
! 266: delete($user_info{$key});
! 267: }
! 268: }
! 269: %info = (%user_info,%{$linkprot_info});
! 270: $token = &Apache::lonnet::tmpput(\%info,$lonhost);
! 271: $url = '/adm/migrateuser?token='.$token;
! 272: }
! 273: $delay = 0;
! 274: } else {
! 275: my %lti_info;
! 276: if (ref($lti_env) eq 'HASH') {
! 277: foreach my $key (sort(keys(%{$lti_env}))) {
! 278: if ($key =~ /^request\.(.+)$/) {
! 279: $lti_info{$1} = $lti_env->{$key};
! 280: }
! 281: }
! 282: }
! 283: %info = (%user_info,%lti_info);
! 284: $token = &Apache::lonnet::tmpput(\%info,$lonhost);
! 285: $url = '/adm/migrateuser?token='.$token;
! 286: }
1.25.2.5.2.2 raeburn 287: $r->send_http_header;
288: $r->print(
289: &Apache::loncommon::start_page('Updating Session ...',undef,
1.25.2.5.2.6! raeburn 290: {'redirect' => [$delay,$url],
1.25.2.5.2.2 raeburn 291: 'only_body' => 1,}).
292: &Apache::loncommon::end_page());
293: if ($env{'request.balancercookie'}) {
294: my ($balancer,$cookie) = split(/:/,$env{'request.balancercookie'});
295: if ((&Apache::lonnet::hostname($balancer)) && ($cookie =~ /^[a-f0-9]{32}$/)) {
296: $cookie = $env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cookie;
297: &Apache::lonnet::delbalcookie($cookie,$balancer);
298: }
299: }
300: $r->register_cleanup(\&flush_course_logs);
301: return;
302: }
303:
1.25.2.5.2.5 raeburn 304: sub flush_course_logs {
305: &Apache::lonnet::flushcourselogs();
306: return OK;
307: }
308:
1.1 albertel 309: sub handler {
310: my ($r) = @_;
1.25.2.5.2.1 raeburn 311:
1.1 albertel 312: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token']);
1.4 albertel 313: my %data = &Apache::lonnet::tmpget($env{'form.token'});
1.13 raeburn 314: if (keys(%data) == 0) {
315: return &goto_login($r);
316: }
1.4 albertel 317: my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
318:
1.6 albertel 319: &Apache::lonlocal::get_language_handle($r);
320:
1.4 albertel 321: if ($delete ne 'ok') {
322: return &goto_login($r);
323: }
1.2 albertel 324:
1.18 raeburn 325: if (!defined($data{'username'}) || !defined($data{'domain'})) {
326: return &goto_login($r);
327: }
1.25.2.5 raeburn 328: my $ip = &Apache::lonnet::get_requestor_ip($r,REMOTE_NOLOOKUP);
1.25.2.4 raeburn 329: if ($data{'ip'} ne $ip) {
1.24 raeburn 330: &Apache::lonnet::logthis('IP change when session migration requested -- was: '.
1.25.2.4 raeburn 331: $data{'ip'}.'; now: '.$ip.' for '.$data{'username'}.':'.$data{'domain'});
1.18 raeburn 332: return &ip_changed($r,$data{'domain'},$data{'server'},\%data);
1.2 albertel 333: }
334:
1.17 raeburn 335: &Apache::lonnet::logthis("Allowing access for $data{'username'}:$data{'domain'} to $data{'role'}");
1.2 albertel 336: my $home=&Apache::lonnet::homeserver($data{'username'},$data{'domain'});
1.24 raeburn 337: my $udom;
338: if (&Apache::lonnet::domain($data{'domain'})) {
339: $udom=$data{'domain'};
340: }
341: if ($home =~ /(con_lost|no_such_host)/) { return &goto_login($r,$udom); }
1.2 albertel 342:
1.8 albertel 343: my $extra_env = &sso_check(\%data);
1.25.2.1 raeburn 344: if (($data{'balancer'}) && ($data{'server'}) && ($data{'balcookie'})) {
345: if (ref($extra_env) eq 'HASH') {
346: $extra_env->{'request.balancercookie'} = $data{'server'}.':'.$data{'balcookie'};
347: } else {
348: $extra_env = { 'request.balancercookie' => $data{'server'}.':'.$data{'balcookie'} };
349: }
1.25.2.3 raeburn 350: } elsif (($data{'server'}) && ($data{'otherbalcookie'})) {
351: my ($balancer,$balcookie) = split(/:/,$data{'otherbalcookie'});
352: if (defined(&Apache::lonnet::hostname($balancer)) && $balcookie =~ /^[a-f0-9]{32}$/) {
353: my $baldom = &Apache::lonnet::host_domain($balancer);
354: if (&Apache::lonnet::shared_institution($baldom)) {
355: my $cookieid = join('_',$udom,$data{'username'},$balcookie);
356: &Apache::lonnet::updatebalcookie($cookieid,$balancer,$data{'server'});
357: if (ref($extra_env) eq 'HASH') {
358: $extra_env->{'request.balancercookie'} = $data{'otherbalcookie'};
359: } else {
360: $extra_env = { 'request.balancercookie' => $data{'otherbalcookie'} };
361: }
362: }
363: }
1.25.2.1 raeburn 364: }
1.8 albertel 365:
1.25.2.2 raeburn 366: my (%form,$cid);
1.16 raeburn 367: if ($data{'symb'} ne '') {
368: $form{'symb'} = $data{'symb'};
369: }
1.21 raeburn 370: if ($data{'iptoken'} ne '') {
371: $form{'iptoken'} = $data{'iptoken'};
372: }
1.25 raeburn 373: if ($data{'noloadbalance'} ne '') {
374: $form{'noloadbalance'} = $data{'noloadbalance'};
375: }
1.25.2.2 raeburn 376: if ($data{'role'}) {
377: if ($data{'role'} =~ m{\./($match_domain)/($match_courseid)(?:/\w+|$)}) {
378: unless (&Apache::lonnet::homeserver($2,$1) eq 'no_host') {
379: $cid = $1.'_'.$2;
380: }
381: }
382: } else {
1.25.2.5 raeburn 383: my ($handle,$expirepub);
1.25.2.5.2.1 raeburn 384: $handle = &Apache::lonnet::check_for_valid_session($r);
1.25.2.5 raeburn 385:
386: # For "public user" - remove any existing "public" cookie so actual user is logged in.
387: if ($handle) {
388: if ($handle=~/^publicuser\_/) {
389: my $lonidsdir=$r->dir_config('lonIDsDir');
390: if ($lonidsdir ne '') {
391: unlink("$lonidsdir/$handle.id");
392: }
393: undef($handle);
394: $expirepub = 1;
395: }
396: }
1.12 albertel 397: if ($handle) {
1.11 albertel 398: &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
399: $handle);
1.25.2.5.2.1 raeburn 400: my $checklaunch;
401: if ($data{'origurl'} =~ m{^/tiny/$match_domain/\w+$}) {
1.25.2.5.2.3 raeburn 402: unless ($env{'request.linkprot'} eq $data{'linkprot'}) {
403: $checklaunch = 1;
1.25.2.5.2.1 raeburn 404: }
1.25.2.5.2.6! raeburn 405: unless ($env{'request.linkprotexit'} eq $data{'linkprotexit'}) {
! 406: $checklaunch = 1;
! 407: }
1.25.2.5.2.3 raeburn 408: unless ($env{'request.linkkey'} eq $data{'linkkey'}) {
409: $checklaunch = 1;
410: }
411: unless ($env{'request.deeplink.login'} eq $data{'deeplink.login'}) {
412: $checklaunch = 1;
1.25.2.5.2.1 raeburn 413: }
414: }
415: if ($data{'linkprot'} ne '') {
1.25.2.5.2.2 raeburn 416: if (($env{'user.name'} ne $data{'username'}) ||
417: ($env{'user.domain'} ne $data{'domain'})) {
418: my %linkprot_env;
1.25.2.5.2.6! raeburn 419: foreach my $item ('linkprot','linkprotexit','deeplink.login') {
1.25.2.5.2.2 raeburn 420: if ($data{$item}) {
1.25.2.5.2.6! raeburn 421: $linkprot_env{$item} = $data{$item};
1.25.2.5.2.2 raeburn 422: }
423: }
1.25.2.5.2.6! raeburn 424: &logout($r,$ip,$handle,\%data,undef,\%linkprot_env);
1.25.2.5.2.2 raeburn 425: return OK;
426: }
1.25.2.5.2.1 raeburn 427: &Apache::lonnet::appenv({'request.linkprot' => $data{'linkprot'}});
1.25.2.5.2.6! raeburn 428: if ($data{'linkprotexit'}) {
! 429: &Apache::lonnet::appenv({'request.linkprotexit' => $data{'linkprotexit'}});
! 430: }
1.25.2.5.2.1 raeburn 431: if ($env{'request.linkkey'}) {
432: &Apache::lonnet::delenv('request.linkkey');
433: }
434: my ($linkprotector,$deeplink) = split(/:/,$data{'linkprot'},2);
435: if ($env{'user.linkprotector'}) {
436: my @protectors = split(/,/,$env{'user.linkprotector'});
437: unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
438: push(@protectors,$linkprotector);
439: @protectors = sort { $a <=> $b } @protectors;
440: &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
441: }
442: } else {
443: &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
444: }
445: if ($env{'user.linkproturi'}) {
446: my @proturis = split(/,/,$env{'user.linkproturi'});
447: unless(grep(/^\Q$deeplink\E$/,@proturis)) {
448: push(@proturis,$deeplink);
449: @proturis = sort @proturis;
450: &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
451: }
452: } else {
453: &Apache::lonnet::appenv({'user.linkproturi' => $deeplink});
454: }
455: } elsif ($data{'linkkey'} ne '') {
456: &Apache::lonnet::appenv({'request.linkkey' => $data{'linkkey'}});
457: if ($env{'request.linkprot'}) {
458: &Apache::lonnet::delenv('request.linkprot');
459: }
460: my $deeplink = $data{'deeplink.login'};
461: my $linkkey = $data{'linkkey'};
462: if ($env{'user.deeplinkkey'} ne '') {
463: my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
464: unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
465: push(@linkkeys,$linkkey);
466: &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});
467: }
468: } else {
469: &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
470: }
471: if ($deeplink) {
472: if ($env{'user.keyedlinkuri'}) {
473: my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
474: unless (grep(/^\Q$deeplink\E$/,@keyeduris)) {
475: push(@keyeduris,$deeplink);
476: &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
477: }
478: } else {
479: &Apache::lonnet::appenv({'user.keyedlinkuri' => $deeplink});
480: }
481: }
482: }
483: if ($data{'deeplink.login'}) {
484: &Apache::lonnet::appenv({'request.deeplink.login' => $data{'deeplink.login'}});
1.25.2.5.2.4 raeburn 485: if ($env{'environment.remote'} eq 'on') {
486: &Apache::lonnet::appenv({'environment.remote' => 'off'});
487: }
1.25.2.5.2.1 raeburn 488: }
1.14 raeburn 489: if ($data{'origurl'} ne '') {
1.25.2.5.2.1 raeburn 490: my $dest = $data{'origurl'};
491: if (($env{'request.deeplink.login'} eq $data{'origurl'}) &&
492: (($env{'request.linkprot'}) || ($env{'request.linkkey'} ne ''))) {
493: my %info;
494: if ($env{'request.linkprot'}) {
495: $info{'linkprot'} = $env{'request.linkprot'};
1.25.2.5.2.6! raeburn 496: foreach my $item ('linkprotuser','linkprotexit') {
! 497: if ($data{$item}) {
! 498: $info{$item} = $data{$item};
! 499: }
! 500: }
1.25.2.5.2.1 raeburn 501: } elsif ($env{'request.linkkey'} ne '') {
502: $info{'linkkey'} = $env{'request.linkkey'};
503: }
504: $info{'origurl'} = $data{'origurl'};
505: if ($checklaunch) {
506: $info{'checklaunch'} = 1;
507: }
508: my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'link');
1.25.2.5.2.6! raeburn 509: unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
1.25.2.5.2.1 raeburn 510: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
511: $dest .= (($dest =~ /\?/) ? '&' : '?') . 'ttoken='.$token;
512: }
513: }
514: $r->internal_redirect($dest);
1.14 raeburn 515: } elsif ($env{'request.course.id'}) {
516: $r->internal_redirect('/adm/navmaps');
1.11 albertel 517: } else {
518: $r->internal_redirect('/adm/roles');
519: }
520: } else {
1.14 raeburn 521: my $desturl = '/adm/roles';
522: if ($data{'origurl'} ne '') {
523: $desturl = $data{'origurl'};
1.25.2.5.2.1 raeburn 524: if ($data{'linkprot'}) {
525: my ($linkprotector,$linkuri) = split(/:/,$data{'linkprot'},2);
526: if ($linkprotector) {
527: if (ref($extra_env) eq 'HASH') {
528: $extra_env->{'user.linkprotector'} = $linkprotector;
529: $extra_env->{'user.linkproturi'} = $linkuri;
530: $extra_env->{'request.linkprot'} = $data{'linkprot'};
531: } else {
532: $extra_env = {'user.linkprotector' => $linkprotector,
533: 'user.linkproturi' => $linkuri,
534: 'request.linkprot' => $data{'linkprot'}};
535: }
1.25.2.5.2.6! raeburn 536: if ($data{'linkprotexit'}) {
! 537: $extra_env->{'request.linkprotexit'} = $data{'linkprotexit'};
! 538: }
! 539: }
! 540: foreach my $item ('linkprotuser','linkprotexit') {
! 541: if ($data{$item} ne '') {
! 542: $form{$item} = $data{$item};
! 543: }
1.25.2.5.2.1 raeburn 544: }
545: } elsif ($data{'linkkey'}) {
546: if (ref($extra_env) eq 'HASH') {
547: $extra_env->{'user.deeplinkkey'} = $data{'linkkey'};
548: $extra_env->{'user.keyedlinkuri'} = $data{'deeplink.login'};
549: $extra_env->{'request.linkkey'} = $data{'linkkey'};
550: } else {
551: $extra_env = {'user.deeplinkkey' => $data{'linkkey'},
552: 'user.keyedlinkuri' => $data{'deeplink.login'},
553: 'request.linkkey' => $data{'linkkey'}};
554: }
555: }
556: if ($data{'deeplink.login'}) {
557: if (ref($extra_env) eq 'HASH') {
558: $extra_env->{'request.deeplink.login'} = $data{'deeplink.login'};
559: } else {
560: $extra_env = {'request.deeplink.login' => $data{'deeplink.login'}};
561: }
562: }
1.14 raeburn 563: }
1.11 albertel 564: &Apache::lonauth::success($r,$data{'username'},$data{'domain'},
1.25.2.5 raeburn 565: $home,$desturl,$extra_env,\%form,'',
566: $expirepub);
1.11 albertel 567: }
1.1 albertel 568: return OK;
569: }
1.6 albertel 570:
571: my $next_url='/adm/roles?selectrole=1&'.&escape($data{'role'}).'=1';
1.15 raeburn 572: if ($data{'origurl'} ne '') {
573: $next_url .= '&orgurl='.&escape($data{'origurl'});
574: }
1.25.2.5.2.1 raeburn 575: if ($data{'deeplink.login'}) {
576: if (ref($extra_env) eq 'HASH') {
577: $extra_env->{'request.deeplink.login'} = $data{'deeplink.login'};
578: } else {
579: $extra_env = {'request.deeplink.login' => $data{'deeplink.login'}};
580: }
581: if ($data{'linkprot'}) {
582: $extra_env->{'request.linkprot'} = $data{'linkprot'};
1.25.2.5.2.6! raeburn 583: if ($data{'linkprotexit'}) {
! 584: $extra_env->{'request.linkprotexit'} = $data{'linkprotexit'};
! 585: }
! 586: foreach my $item ('linkprotuser','linkprotexit') {
! 587: if ($data{$item}) {
! 588: $form{'request.'.$item} = $data{$item};
! 589: }
! 590: }
1.25.2.5.2.1 raeburn 591: } elsif ($data{'linkkey'} ne '') {
592: $extra_env->{'request.linkkey'} = $data{'linkkey'};
593: }
594: }
1.6 albertel 595: &Apache::lonauth::success($r,$data{'username'},$data{'domain'},$home,
1.25.2.2 raeburn 596: $next_url,$extra_env,\%form,$cid);
1.6 albertel 597: return OK;
1.1 albertel 598: }
599:
600: 1;
601: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>