Annotation of loncom/auth/lonauth.pm, revision 1.121.2.24.2.6
1.1 albertel 1: # The LearningOnline Network
2: # User Authentication Module
1.27 www 3: #
1.121.2.24.2. (raeburn 4:): # $Id: lonauth.pm,v 1.121.2.24.2.5 2022/08/30 12:10:43 raeburn Exp $
1.27 www 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: #
1.1 albertel 28:
29: package Apache::lonauth;
30:
1.18 albertel 31: use strict;
1.121.2.24.2. (raeburn 32:): use LONCAPA qw(:DEFAULT :match);
1.1 albertel 33: use Apache::Constants qw(:common);
34: use CGI qw(:standard);
1.45 matthew 35: use Apache::loncommon();
1.66 albertel 36: use Apache::lonnet;
1.12 www 37: use Apache::lonmenu();
1.90 raeburn 38: use Apache::createaccount;
1.18 albertel 39: use Fcntl qw(:flock);
1.56 www 40: use Apache::lonlocal;
1.119 raeburn 41: use Apache::File();
1.101 raeburn 42: use HTML::Entities;
1.121.2.18 raeburn 43: use Digest::MD5;
1.121.2.24 raeburn 44: use CGI::Cookie();
1.85 albertel 45:
1.1 albertel 46: # ------------------------------------------------------------ Successful login
1.85 albertel 47: sub success {
48: my ($r, $username, $domain, $authhost, $lowerurl, $extra_env,
1.121.2.24.2. (raeburn 49:): $form,$cid,$expirepub,$write_to_opener) = @_;
1.1 albertel 50:
1.85 albertel 51: # ------------------------------------------------------------ Get cookie ready
52: my $cookie =
53: &Apache::loncommon::init_user_environment($r, $username, $domain,
54: $authhost, $form,
1.86 albertel 55: {'extra_env' => $extra_env,});
1.4 www 56:
1.69 albertel 57: my $public=($username eq 'public' && $domain eq 'public');
58:
1.85 albertel 59: if ($public or $lowerurl eq 'noredirect') { return $cookie; }
1.78 albertel 60:
1.7 www 61: # -------------------------------------------------------------------- Log this
62:
1.121.2.21 raeburn 63: my $ip = &Apache::lonnet::get_requestor_ip();
1.7 www 64: &Apache::lonnet::log($domain,$username,$authhost,
1.121.2.21 raeburn 65: "Login $ip");
1.4 www 66:
1.14 www 67: # ------------------------------------------------- Check for critical messages
68:
1.21 www 69: my @what=&Apache::lonnet::dump('critical',$domain,$username);
1.14 www 70: if ($what[0]) {
1.22 www 71: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
1.21 www 72: $lowerurl='/adm/email?critical=display';
1.14 www 73: }
74: }
75:
1.121.2.18 raeburn 76: # ------------------------------------------------------------ Get cookies ready
77: my ($securecookie,$defaultcookie);
78: my $ssl = $r->subprocess_env('https');
79: if ($ssl) {
80: $securecookie="lonSID=$cookie; path=/; HttpOnly; secure";
81: my $lonidsdir=$r->dir_config('lonIDsDir');
82: if (($lonidsdir) && (-e "$lonidsdir/$cookie.id")) {
83: my $linkname=substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 32).'_linked';
84: if (-e "$lonidsdir/$linkname.id") {
85: unlink("$lonidsdir/$linkname.id");
86: }
87: my $made_symlink = eval { symlink("$lonidsdir/$cookie.id",
88: "$lonidsdir/$linkname.id"); 1 };
89: if ($made_symlink) {
90: $defaultcookie = "lonLinkID=$linkname; path=/; HttpOnly;";
91: &Apache::lonnet::appenv({'user.linkedenv' => $linkname});
92: }
93: }
94: } else {
95: $defaultcookie = "lonID=$cookie; path=/; HttpOnly;";
96: }
1.12 www 97: # -------------------------------------------------------- Menu script and info
1.100 raeburn 98: my $destination = $lowerurl;
99:
100: if (defined($form->{role})) {
101: my $envkey = 'user.role.'.$form->{role};
102: my $now=time;
103: my $then=$env{'user.login.time'};
104: my $refresh=$env{'user.refresh.time'};
1.111 raeburn 105: my $update=$env{'user.update.time'};
106: if (!$update) {
107: $update = $then;
108: }
1.100 raeburn 109: if (exists($env{$envkey})) {
110: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus);
1.111 raeburn 111: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.100 raeburn 112: \$trolecode,\$tstatus,\$tstart,\$tend);
113: if ($tstatus eq 'is') {
1.101 raeburn 114: $destination .= ($destination =~ /\?/) ? '&' : '?';
115: my $newrole = &HTML::Entities::encode($form->{role},'"<>&');
116: $destination .= 'selectrole=1&'.$newrole.'=1';
1.100 raeburn 117: }
118: }
1.121.2.24.2. (raeburn 119:): } elsif (defined($form->{display})) {
120:): if ($destination =~ m{^/adm/email($|\?)}) {
121:): $destination .= ($destination =~ /\?/) ? '&' : '?' .'display='.&escape($form->{display});
122:): }
1.100 raeburn 123: }
1.101 raeburn 124: if (defined($form->{symb})) {
125: my $destsymb = $form->{symb};
1.121.2.19 raeburn 126: my $encrypted;
127: if ($destsymb =~ m{^/enc/}) {
128: $encrypted = 1;
129: if ($cid) {
130: $destsymb = &Apache::lonenc::unencrypted($destsymb,$cid);
131: }
132: }
1.101 raeburn 133: $destination .= ($destination =~ /\?/) ? '&' : '?';
134: if ($destsymb =~ /___/) {
135: my ($map,$resid,$desturl)=split(/___/,$destsymb);
1.121.2.13 raeburn 136: $desturl = &Apache::lonnet::clutter($desturl);
1.121.2.19 raeburn 137: if ($encrypted) {
138: $desturl = &Apache::lonenc::encrypted($desturl,1,$cid);
139: $destsymb = $form->{symb};
140: }
1.101 raeburn 141: $desturl = &HTML::Entities::encode($desturl,'"<>&');
142: $destsymb = &HTML::Entities::encode($destsymb,'"<>&');
1.121.2.8 raeburn 143: $destination .= 'destinationurl='.$desturl.
1.101 raeburn 144: '&destsymb='.$destsymb;
1.121.2.19 raeburn 145: } elsif (!$encrypted) {
1.101 raeburn 146: $destsymb = &HTML::Entities::encode($destsymb,'"<>&');
1.121.2.8 raeburn 147: $destination .= 'destinationurl='.$destsymb;
1.101 raeburn 148: }
149: }
1.111 raeburn 150: if ($destination =~ m{^/adm/roles}) {
151: $destination .= ($destination =~ /\?/) ? '&' : '?';
152: $destination .= 'source=login';
153: }
1.100 raeburn 154:
1.121.2.24.2. (raeburn 155:): my $brcrum = [{'href' => '',
156:): 'text' => 'Successful Login'},];
157:): my $args = {'no_inline_link' => 1,
158:): 'bread_crumbs' => $brcrum,};
159:): if (($env{'request.deeplink.login'} eq $lowerurl) &&
160:): (($env{'request.linkprot'}) || ($env{'request.linkkey'} ne ''))) {
161:): my %info;
162:): if ($env{'request.linkprot'}) {
163:): $info{'linkprot'} = $env{'request.linkprot'};
164:): foreach my $item ('linkprotuser','linkprotexit') {
165:): if ($form->{$item}) {
166:): $info{$item} = $form->{$item};
167:): }
168:): }
169:): $args = {'only_body' => 1,};
170:): } elsif ($env{'request.linkkey'} ne '') {
171:): $info{'linkkey'} = $env{'request.linkkey'};
172:): }
173:): $info{'origurl'} = $lowerurl;
174:): my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'link');
175:): unless (($token eq 'con_lost') || ($token eq 'refused') ||
176:): ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
177:): $destination .= (($destination =~ /\?/) ? '&' : '?') . 'ttoken='.$token;
178:): }
179:): }
180:): if ($env{'request.deeplink.login'}) {
181:): if ($env{'environment.remote'} eq 'on') {
182:): &Apache::lonnet::appenv({'environment.remote' => 'off'});
183:): }
184:): }
185:): my $startupremote;
186:): if ($write_to_opener) {
187:): if ($env{'environment.remote'} eq 'on') {
188:): &Apache::lonnet::appenv({'environment.remote' => 'off'});
189:): }
190:): $args->{'redirect'} = [0,$destination,'',$write_to_opener];
191:): } else {
192:): $startupremote=&Apache::lonmenu::startupremote($destination);
193:): }
194:):
1.121.2.1 raeburn 195: my $windowinfo=&Apache::lonmenu::open($env{'browser.os'});
196: my $remoteinfo=&Apache::lonmenu::load_remote_msg($lowerurl);
197: my $setflags=&Apache::lonmenu::setflags();
198: my $maincall=&Apache::lonmenu::maincall();
1.74 albertel 199: my $start_page=&Apache::loncommon::start_page('Successful Login',
1.121.2.24.2. (raeburn 200:): $startupremote,$args);
1.74 albertel 201: my $end_page =&Apache::loncommon::end_page();
202:
1.121.2.1 raeburn 203: my $continuelink;
204: if ($env{'environment.remote'} eq 'off') {
1.121.2.24.2. (raeburn 205:): unless ($write_to_opener) {
206:): $continuelink='<a href="'.$destination.'">'.&mt('Continue').'</a>';
207:): }
1.121.2.1 raeburn 208: }
1.5 www 209: # ------------------------------------------------- Output for successful login
210:
1.74 albertel 211: &Apache::loncommon::content_type($r,'text/html');
1.121.2.18 raeburn 212: if ($securecookie) {
213: $r->headers_out->add('Set-cookie' => $securecookie);
214: }
215: if ($defaultcookie) {
216: $r->headers_out->add('Set-cookie' => $defaultcookie);
217: }
1.121.2.22 raeburn 218: if ($expirepub) {
219: my $c = new CGI::Cookie(-name => 'lonPubID',
220: -value => '',
221: -expires => '-10y',);
222: $r->headers_out->add('Set-cookie' => $c);
223: }
1.74 albertel 224: $r->send_http_header;
1.1 albertel 225:
1.121.2.24.2. (raeburn 226:): if ($env{'request.linkprot'}) {
227:): $r->print(<<END);
228:): $start_page
229:): <br />$continuelink
230:): $end_page
231:): END
232:): } else {
233:): my %lt=&Apache::lonlocal::texthash(
234:): 'wel' => 'Welcome',
235:): 'pro' => 'Login problems?',
236:): );
237:): my $loginhelp = &loginhelpdisplay($domain);
238:): if ($loginhelp) {
239:): $loginhelp = '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>';
240:): }
1.121.2.2 raeburn 241:
1.121.2.24.2. (raeburn 242:): my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>');
243:): $r->print(<<ENDSUCCESS);
1.74 albertel 244: $start_page
1.121.2.1 raeburn 245: $setflags
1.19 www 246: $windowinfo
1.58 www 247: <h1>$lt{'wel'}</h1>
1.121.2.2 raeburn 248: $welcome
249: $loginhelp
1.121.2.1 raeburn 250: $remoteinfo
251: $maincall
1.64 albertel 252: $continuelink
1.74 albertel 253: $end_page
1.1 albertel 254: ENDSUCCESS
1.121.2.24.2. (raeburn 255:): }
1.121.2.11 raeburn 256: return;
1.1 albertel 257: }
258:
259: # --------------------------------------------------------------- Failed login!
260:
261: sub failed {
1.121.2.22 raeburn 262: my ($r,$message,$form,$authhost) = @_;
1.121.2.7 raeburn 263: (undef,undef,undef,my $clientmathml,my $clientunicode) =
264: &Apache::loncommon::decode_user_agent();
265: my $args = {};
266: if ($clientunicode && !$clientmathml) {
267: $args = {'browser.unicode' => 1};
268: }
1.121.2.24.2. (raeburn 269:): if ($form->{firsturl} =~ m{^/tiny/$match_domain/\w+$}) {
270:): if ($form->{linkprot}) {
271:): $args->{only_body} = 1;
272:): }
273:): }
1.121.2.7 raeburn 274:
275: my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args);
276: my $uname = &Apache::loncommon::cleanup_html($form->{'uname'});
277: my $udom = &Apache::loncommon::cleanup_html($form->{'udom'});
278: if (&Apache::lonnet::domain($udom,'description') eq '') {
279: undef($udom);
280: }
281: my $retry = '/adm/login';
282: if ($uname eq $form->{'uname'}) {
283: $retry .= '?username='.$uname;
284: }
285: if ($udom) {
286: $retry .= (($retry=~/\?/)?'&':'?').'domain='.$udom;
287: }
1.121.2.22 raeburn 288: my $lonhost = $r->dir_config('lonHostID');
289: my $querystr;
290: my $result = &set_retry_token($form,$lonhost,\$querystr);
291: if ($result eq 'fail') {
292: if (exists($form->{role})) {
293: my $role = &Apache::loncommon::cleanup_html($form->{role});
294: if ($role ne '') {
295: $retry .= (($retry=~/\?/)?'&':'?').'role='.$role;
296: }
297: }
298: if (exists($form->{symb})) {
299: my $symb = &Apache::loncommon::cleanup_html($form->{symb});
300: if ($symb ne '') {
301: $retry .= (($retry=~/\?/)?'&':'?').'symb='.$symb;
302: }
303: }
304: if (exists($form->{firsturl})) {
305: my $firsturl = &Apache::loncommon::cleanup_html($form->{firsturl});
306: if ($firsturl ne '') {
307: $retry .= (($retry=~/\?/)?'&':'?').'firsturl='.$firsturl;
1.121.2.24.2. (raeburn 308:): if ($form->{firsturl} =~ m{^/tiny/$match_domain/\w+$}) {
309:): unless (exists($form->{linkprot})) {
310:): if (exists($form->{linkkey})) {
311:): $retry .= 'linkkey='.$form->{linkkey};
312:): }
313:): }
314:): }
315:): }
316:): }
317:): if (exists($form->{linkprot})) {
318:): my %info = (
319:): 'linkprot' => $form->{'linkprot'},
320:): );
321:): foreach my $item ('linkprotuser','linkprotexit') {
322:): if ($form->{$item} ne '') {
323:): $info{$item} = $form->{$item};
324:): }
325:): }
326:): my $ltoken = &Apache::lonnet::tmpput(\%info,
327:): $r->dir_config('lonHostID'),'retry');
328:): if ($ltoken) {
329:): $retry .= (($retry =~ /\?/) ? '&' : '?').'ltoken='.$ltoken;
1.121.2.22 raeburn 330: }
1.121.2.7 raeburn 331: }
1.121.2.22 raeburn 332: } elsif ($querystr ne '') {
333: $retry .= (($retry=~/\?/)?'&':'?').$querystr;
1.100 raeburn 334: }
1.121.2.7 raeburn 335: my $end_page = &Apache::loncommon::end_page();
1.74 albertel 336: &Apache::loncommon::content_type($r,'text/html');
337: $r->send_http_header;
1.121.2.9 raeburn 338: my @actions =
339: (&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>'));
1.121.2.7 raeburn 340: my $loginhelp = &loginhelpdisplay($udom);
1.121.2.2 raeburn 341: if ($loginhelp) {
1.121.2.9 raeburn 342: push(@actions, '<a href="'.$loginhelp.'">'.&mt('Login problems?').'</a>');
1.121.2.2 raeburn 343: }
1.121.2.9 raeburn 344: #FIXME: link to helpdesk might be added here
1.121.2.2 raeburn 345:
1.92 bisitz 346: $r->print(
347: $start_page
1.121.2.9 raeburn 348: .'<h2>'.&mt('Sorry ...').'</h2>'
349: .&Apache::lonhtmlcommon::confirm_success(&mt($message),1).'<br /><br />'
350: .&Apache::lonhtmlcommon::actionbox(\@actions)
1.92 bisitz 351: .$end_page
352: );
353: }
1.60 www 354:
1.55 www 355: # ------------------------------------------------------------------ Rerouting!
356:
357: sub reroute {
1.74 albertel 358: my ($r) = @_;
359: &Apache::loncommon::content_type($r,'text/html');
360: $r->send_http_header;
1.121.2.5 raeburn 361: my $msg='<b>'.&mt('Sorry ...').'</b><br />'
1.92 bisitz 362: .&mt('Please [_1]log in again[_2].');
1.121.2.5 raeburn 363: &Apache::loncommon::simple_error_page($r,'Rerouting',$msg,{'no_auto_mt_msg' => 1});
1.55 www 364: }
365:
1.1 albertel 366: # ---------------------------------------------------------------- Main handler
367:
368: sub handler {
369: my $r = shift;
1.120 raeburn 370: my $londocroot = $r->dir_config('lonDocRoot');
1.55 www 371: # Are we re-routing?
1.120 raeburn 372: if (-e "$londocroot/lon-status/reroute.txt") {
1.55 www 373: &reroute($r);
374: return OK;
375: }
1.56 www 376:
1.57 www 377: &Apache::lonlocal::get_language_handle($r);
1.1 albertel 378:
1.59 www 379: # -------------------------------- Prevent users from attempting to login twice
1.89 albertel 380: my $handle = &Apache::lonnet::check_for_valid_session($r);
381: if ($handle ne '') {
1.103 raeburn 382: my $lonidsdir=$r->dir_config('lonIDsDir');
383: if ($handle=~/^publicuser\_/) {
384: # For "public user" - remove it, we apparently really want to login
385: unlink($r->dir_config('lonIDsDir')."/$handle.id");
386: } else {
1.59 www 387: # Indeed, a valid token is found
1.103 raeburn 388: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
389: &Apache::loncommon::content_type($r,'text/html');
390: $r->send_http_header;
391: my $start_page =
392: &Apache::loncommon::start_page('Already logged in');
393: my $end_page =
394: &Apache::loncommon::end_page();
1.105 raeburn 395: my $dest = '/adm/roles';
1.121.2.22 raeburn 396: my %form = &get_form_items($r);
397: if ($form{'logtoken'}) {
398: my $tmpinfo = &Apache::lonnet::reply('tmpget:'.$form{'logtoken'},
399: $form{'serverid'});
400: unless (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||
401: ($tmpinfo eq 'no_such_host')) {
1.121.2.23 raeburn 402: my ($des_key,$firsturl,@rest)=split(/&/,$tmpinfo);
1.121.2.22 raeburn 403: $firsturl = &unescape($firsturl);
404: my %info;
405: foreach my $item (@rest) {
406: my ($key,$value) = split(/=/,$item);
407: $info{$key} = &unescape($value);
408: }
409: if ($firsturl ne '') {
410: $info{'firsturl'} = $firsturl;
411: $dest = $firsturl;
1.121.2.24.2. (raeburn 412:): my $relogin;
413:): if ($dest =~ m{^/tiny/$match_domain/\w+$}) {
414:): if ($env{'request.course.id'}) {
415:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
416:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
417:): my $symb = &Apache::loncommon::symb_from_tinyurl($dest,$cnum,$cdom);
418:): if ($symb) {
419:): unless (&set_deeplink_login(%info) eq 'ok') {
420:): $relogin = 1;
421:): }
422:): }
423:): }
424:): if ($relogin) {
425:): $r->print(
426:): $start_page
427:): .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
428:): .'<p>'.&mt('Please [_1]log out[_2] first, and then try your access again',
429:): '<a href="/adm/logout">','</a>')
430:): .'</p>'
431:): .$end_page);
432:): } else {
433:): if (($info{'linkprot'}) || ($info{'linkkey'} ne '')) {
434:): if (($info{'linkprot'}) && ($info{'linkprotuser'} ne '')) {
435:): unless ($info{'linkprotuser'} eq $env{'user.name'}.':'.$env{'user.domain'}) {
436:): $r->print(
437:): $start_page
438:): .'<p class="LC_warning">'.&mt('You are already logged in, but as a different user from the one expected for the link you followed from another system').'</p>'
439:): .'<p>'.&mt('Please [_1]log out[_2] first, and then try following the link again from the other system',
440:): '<a href="/adm/logout">','</a>')
441:):
442:): .'</p>'
443:): .$end_page);
444:): return OK;
445:): }
446:): }
447:): my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'link');
448:): unless (($token eq 'con_lost') || ($token eq 'refused') ||
449:): ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
450:): $dest .= (($dest =~ /\?/) ? '&' : '?') . 'ttoken='.$token;
451:): }
452:): }
453:): $r->print(
454:): $start_page
455:): .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
456:): .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4] first, and then try your access again',
457:): '<a href="'.$dest.'">','</a>',
458:): '<a href="/adm/logout">','</a>')
459:): .'</p>'
460:): .$end_page);
461:): }
462:): return OK;
463:): }
1.121.2.22 raeburn 464: }
465: }
1.105 raeburn 466: }
1.103 raeburn 467: $r->print(
468: $start_page
1.121.2.4 raeburn 469: .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
1.103 raeburn 470: .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].'
1.105 raeburn 471: ,'<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>')
1.103 raeburn 472: .'</p>'
473: .$end_page
474: );
475: return OK;
476: }
1.59 www 477: }
478:
479: # ---------------------------------------------------- No valid token, continue
480:
1.121.2.22 raeburn 481: my %form = &get_form_items($r);
1.85 albertel 482: if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) {
483: &failed($r,'Username, password and domain need to be specified.',
484: \%form);
1.1 albertel 485: return OK;
486: }
1.61 www 487:
488: # split user logging in and "su"-user
489:
1.121.2.17 raeburn 490: ($form{'uname'},$form{'suname'},$form{'sudom'})=split(/\:/,$form{'uname'});
1.87 albertel 491: $form{'uname'} = &LONCAPA::clean_username($form{'uname'});
492: $form{'suname'}= &LONCAPA::clean_username($form{'suname'});
1.121.2.17 raeburn 493: $form{'udom'} = &LONCAPA::clean_domain($form{'udom'});
494: $form{'sudom'} = &LONCAPA::clean_domain($form{'sudom'});
1.1 albertel 495:
496: my $role = $r->dir_config('lonRole');
497: my $domain = $r->dir_config('lonDefDomain');
498: my $prodir = $r->dir_config('lonUsersDir');
1.93 raeburn 499: my $contact_name = &mt('LON-CAPA helpdesk');
1.1 albertel 500:
1.8 www 501: # ---------------------------------------- Get the information from login token
502:
1.85 albertel 503: my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'},
504: $form{'serverid'});
1.121.2.7 raeburn 505:
1.114 raeburn 506: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||
507: ($tmpinfo eq 'no_such_host')) {
1.85 albertel 508: &failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form);
1.8 www 509: return OK;
1.44 www 510: } else {
1.85 albertel 511: my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'},
512: $form{'serverid'});
1.77 albertel 513: if ( $reply ne 'ok' ) {
1.85 albertel 514: &failed($r,'Session could not be opened.',\%form);
515: &Apache::lonnet::logthis("ERROR got a reply of $reply when trying to contact ". $form{'serverid'}." to get login token");
1.77 albertel 516: return OK;
1.44 www 517: }
1.8 www 518: }
1.100 raeburn 519:
1.93 raeburn 520: if (!&Apache::lonnet::domain($form{'udom'})) {
521: &failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form);
522: return OK;
523: }
1.100 raeburn 524:
1.121.2.22 raeburn 525: my ($des_key,$firsturl,@rest)=split(/&/,$tmpinfo);
526: $firsturl = &unescape($firsturl);
527: foreach my $item (@rest) {
528: my ($key,$value) = split(/=/,$item);
529: $form{$key} = &unescape($value);
1.100 raeburn 530: }
1.121.2.24.2. (raeburn 531:): if ($firsturl =~ m{^/tiny/$match_domain/\w+$}) {
532:): $form{'firsturl'} = $firsturl;
533:): }
1.121.2.23 raeburn 534: my $upass = &Apache::loncommon::des_decrypt($des_key,$form{'upass0'});
1.8 www 535:
1.1 albertel 536: # ---------------------------------------------------------------- Authenticate
1.119 raeburn 537:
1.90 raeburn 538: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});
1.119 raeburn 539: my ($cancreate,$statustocreate) =
540: &Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'});
541: my $defaultauth;
542: if (ref($cancreate) eq 'ARRAY') {
543: if (grep(/^login$/,@{$cancreate})) {
544: $defaultauth = 1;
1.90 raeburn 545: }
546: }
1.105 raeburn 547: my $clientcancheckhost = 1;
1.90 raeburn 548: my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass,
1.105 raeburn 549: $form{'udom'},$defaultauth,
550: $clientcancheckhost);
1.1 albertel 551:
552: # --------------------------------------------------------------------- Failed?
553:
554: if ($authhost eq 'no_host') {
1.121.2.24.2. (raeburn 555:): my $pwdverify;
556:): if (&Apache::lonnet::homeserver($form{'uname'},$form{'udom'}) eq 'no_host') {
557:): my %possunames = &alternate_unames_check($form{'uname'},$form{'udom'});
558:): if (keys(%possunames) > 0) {
559:): foreach my $rulematch (keys(%possunames)) {
560:): my $possuname = $possunames{$rulematch};
561:): if (($possuname ne '') && ($possuname =~ /^$match_username$/)) {
562:): $authhost=Apache::lonnet::authenticate($possuname,$upass,
563:): $form{'udom'},undef,
564:): $clientcancheckhost);
565:): if (($authhost eq 'no_host') || ($authhost eq 'no_account_on_host')) {
566:): next;
567:): } elsif (($authhost ne '') && (&Apache::lonnet::hostname($authhost) ne '')) {
568:): $pwdverify = 1;
569:): &Apache::lonnet::logthis("Authenticated user: $possuname was submitted as: $form{'uname'}");
570:): $form{'uname'} = $possuname;
571:): last;
572:): }
573:): }
574:): }
575:): }
576:): }
577:): unless ($pwdverify) {
578:): &failed($r,'Username and/or password could not be authenticated.',
579:): \%form);
580:): return OK;
581:): }
1.90 raeburn 582: } elsif ($authhost eq 'no_account_on_host') {
1.119 raeburn 583: if ($defaultauth) {
1.105 raeburn 584: my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');
1.110 raeburn 585: unless (&check_can_host($r,\%form,'no_account_on_host',$domdesc)) {
586: return OK;
587: }
1.90 raeburn 588: my $start_page =
1.121.2.1 raeburn 589: &Apache::loncommon::start_page('Create a user account in LON-CAPA',
590: '',{'no_inline_link' => 1,});
1.93 raeburn 591: my $lonhost = $r->dir_config('lonHostID');
592: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
593: my $contacts =
594: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
595: $form{'udom'},$origmail);
596: my ($contact_email) = split(',',$contacts);
1.119 raeburn 597: my $output =
598: &Apache::createaccount::username_check($form{'uname'},$form{'udom'},
599: $domdesc,'',$lonhost,
600: $contact_email,$contact_name,
601: undef,$statustocreate);
1.90 raeburn 602: &Apache::loncommon::content_type($r,'text/html');
603: $r->send_http_header;
604: &Apache::createaccount::print_header($r,$start_page);
1.94 raeburn 605: $r->print('<h3>'.&mt('Account creation').'</h3>'.
606: &mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account at this institution.').'<br />'.
607: $output.&Apache::loncommon::end_page());
1.90 raeburn 608: return OK;
609: } else {
610: &failed($r,'Although your username and password were authenticated, you do not currently have a LON-CAPA account in this domain, and you are not permitted to create one.',\%form);
611: return OK;
612: }
1.1 albertel 613: }
614:
1.59 www 615: if (($firsturl eq '') ||
616: ($firsturl=~/^\/adm\/(logout|remote)/)) {
1.24 www 617: $firsturl='/adm/roles';
1.7 www 618: }
1.121.2.6 raeburn 619:
1.121.2.23 raeburn 620: my ($hosthere,%sessiondata);
1.121.2.6 raeburn 621: if ($form{'iptoken'}) {
1.121.2.23 raeburn 622: %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
1.121.2.12 raeburn 623: my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
1.121.2.6 raeburn 624: if (($sessiondata{'domain'} eq $form{'udom'}) &&
625: ($sessiondata{'username'} eq $form{'uname'})) {
626: $hosthere = 1;
627: }
628: }
629:
1.61 www 630: # --------------------------------- Are we attempting to login as somebody else?
1.85 albertel 631: if ($form{'suname'}) {
1.121.2.17 raeburn 632: my ($suname,$sudom,$sudomref);
633: $suname = $form{'suname'};
634: $sudom = $form{'udom'};
635: if ($form{'sudom'}) {
636: unless ($sudom eq $form{'sudom'}) {
637: if (&Apache::lonnet::domain($form{'sudom'})) {
638: $sudomref = [$form{'sudom'}];
639: $sudom = $form{'sudom'};
640: }
641: }
642: }
1.61 www 643: # ------------ see if the original user has enough privileges to pull this stunt
1.121.2.17 raeburn 644: if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'},$sudomref)) {
1.61 www 645: # ---------------------------------------------------- see if the su-user exists
1.121.2.17 raeburn 646: unless (&Apache::lonnet::homeserver($suname,$sudom) eq 'no_host') {
1.61 www 647: # ------------------------------ see if the su-user is not too highly privileged
1.121.2.17 raeburn 648: if (&Apache::lonnet::privileged($suname,$sudom)) {
649: &Apache::lonnet::logthis('Attempted switch user to privileged user');
650: } else {
651: my $noprivswitch;
652: #
653: # su-user's home server and user's home server must have one of:
654: # (a) same domain
655: # (b) same primary library server for the two domains
656: # (c) same "internet domain" for primary library server(s) for home servers' domains
657: #
658: my $suprim = &Apache::lonnet::domain($sudom,'primary');
659: my $suintdom = &Apache::lonnet::internet_dom($suprim);
660: unless ($sudom eq $form{'udom'}) {
661: my $uprim = &Apache::lonnet::domain($form{'udom'},'primary');
662: my $uintdom = &Apache::lonnet::internet_dom($uprim);
663: unless ($suprim eq $uprim) {
664: unless ($suintdom eq $uintdom) {
665: &Apache::lonnet::logthis('Attempted switch user '
666: .'to user with different "internet domain".');
667: $noprivswitch = 1;
668: }
669: }
670: }
671:
672: unless ($noprivswitch) {
673: #
674: # server where log-in occurs must have same "internet domain" as su-user's home
675: # server
676: #
677: my $lonhost = $r->dir_config('lonHostID');
678: my $hostintdom = &Apache::lonnet::internet_dom($lonhost);
679: if ($hostintdom ne $suintdom) {
680: &Apache::lonnet::logthis('Attempted switch user on a '
681: .'server with a different "internet domain".');
682: } else {
683:
1.61 www 684: # -------------------------------------------------------- actually switch users
1.121.2.17 raeburn 685:
686: &Apache::lonnet::logperm('User '.$form{'uname'}.' at '.
687: $form{'udom'}.' logging in as '.$suname.':'.$sudom);
688: $form{'uname'}=$suname;
689: if ($form{'udom'} ne $sudom) {
690: $form{'udom'}=$sudom;
691: }
692: }
693: }
1.61 www 694: }
695: }
696: } else {
697: &Apache::lonnet::logthis('Non-privileged user attempting switch user');
698: }
699: }
1.85 albertel 700:
1.121.2.24.2. (raeburn 701:): if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
702:): if (($form{'linkprot'}) && ($form{'linkprotuser'} ne '')) {
703:): unless($form{'linkprotuser'} eq $form{'uname'}.':'.$form{'udom'}) {
704:): delete($form{'udom'});
705:): delete($form{'uname'});
706:): &failed($r,'Username and/or domain are different to that expected for the link you followed from another system',
707:): \%form,$authhost);
708:): return OK;
709:): }
710:): }
711:): }
712:):
1.121.2.6 raeburn 713: my ($is_balancer,$otherserver);
714:
715: unless ($hosthere) {
716: ($is_balancer,$otherserver) =
1.121.2.15 raeburn 717: &Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login');
718: if ($is_balancer) {
1.121.2.20 raeburn 719: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
720: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r);
721: if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) {
722: $otherserver = $found_server;
723: }
1.121.2.15 raeburn 724: if ($otherserver eq '') {
725: my $lowest_load;
726: ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'});
727: if ($lowest_load > 100) {
1.121.2.22 raeburn 728: $otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$form{'udom'});
1.121.2.15 raeburn 729: }
730: }
731: if ($otherserver ne '') {
732: my @hosts = &Apache::lonnet::current_machine_ids();
733: if (grep(/^\Q$otherserver\E$/,@hosts)) {
734: $hosthere = $otherserver;
735: }
736: }
737: }
1.121.2.6 raeburn 738: }
1.117 raeburn 739:
1.121.2.15 raeburn 740: if (($is_balancer) && (!$hosthere)) {
1.115 raeburn 741: if ($otherserver) {
742: &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
743: \%form);
1.121.2.8 raeburn 744: my $switchto = '/adm/switchserver?otherserver='.$otherserver;
745: if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
746: $switchto .= '&origurl='.$firsturl;
747: }
748: if ($form{'role'}) {
749: $switchto .= '&role='.$form{'role'};
750: }
751: if ($form{'symb'}) {
752: $switchto .= '&symb='.$form{'symb'};
753: }
1.121.2.24.2. (raeburn 754:): if ($form{'linkprot'}) {
755:): $env{'request.linkprot'} = $form{'linkprot'};
756:): foreach my $item ('linkprotuser','linkprotexit') {
757:): if ($form{$item}) {
758:): $env{'request.'.$item} = $form{$item};
759:): }
760:): }
761:): } elsif ($form{'linkkey'} ne '') {
762:): $env{'request.linkkey'} = $form{'linkkey'};
763:): }
764:): if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
765:): &set_deeplink_login(%form);
766:): } elsif ($firsturl eq '/adm/email') {
767:): if ($form{'display'} && ($form{'mailrecip'} eq "$form{'uname'}:$form{'udom'}")) {
768:): $env{'request.display'} = $form{'display'};
769:): $env{'request.mailrecip'} = $form{'mailrecip'};
770:): }
771:): }
1.121.2.8 raeburn 772: $r->internal_redirect($switchto);
1.115 raeburn 773: } else {
1.121.2.20 raeburn 774: &Apache::loncommon::content_type($r,'text/html');
775: $r->send_http_header;
1.115 raeburn 776: $r->print(&noswitch());
777: }
1.110 raeburn 778: return OK;
1.81 albertel 779: } else {
1.115 raeburn 780: if (!&check_can_host($r,\%form,$authhost)) {
1.118 raeburn 781: my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});
1.115 raeburn 782: if ($otherserver) {
783: &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
784: \%form);
1.121.2.8 raeburn 785: my $switchto = '/adm/switchserver?otherserver='.$otherserver;
786: if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
787: $switchto .= '&origurl='.$firsturl;
788: }
789: if ($form{'role'}) {
790: $switchto .= '&role='.$form{'role'};
791: }
792: if ($form{'symb'}) {
793: $switchto .= '&symb='.$form{'symb'};
794: }
1.121.2.24.2. (raeburn 795:): if ($form{'linkprot'}) {
796:): $env{'request.linkprot'} = $form{'linkprot'};
797:): foreach my $item ('linkprotuser','linkprotexit') {
798:): if ($form{$item}) {
799:): $env{'request.'.$item} = $form{$item};
800:): }
801:): }
802:): } elsif ($form{'linkkey'} ne '') {
803:): $env{'request.linkkey'} = $form{'linkkey'};
804:): }
805:): if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
806:): &set_deeplink_login(%form);
807:): } elsif ($firsturl eq '/adm/email') {
808:): if ($form{'display'} && ($form{'mailrecip'} eq "$form{'uname'}:$form{'udom'}")) {
809:): $env{'request.display'} = $form{'display'};
810:): $env{'request.mailrecip'} = $form{'mailrecip'};
811:): }
812:): }
1.121.2.8 raeburn 813: $r->internal_redirect($switchto);
1.115 raeburn 814: } else {
1.121.2.20 raeburn 815: &Apache::loncommon::content_type($r,'text/html');
816: $r->send_http_header;
1.115 raeburn 817: $r->print(&noswitch());
818: }
819: return OK;
820: }
821:
1.109 raeburn 822: # ------------------------------------------------------- Do the load balancing
823:
824: # ---------------------------------------------------------- Determine own load
825: my $loadlim = $r->dir_config('lonLoadLim');
826: my $loadavg;
827: {
828: my $loadfile=Apache::File->new('/proc/loadavg');
829: $loadavg=<$loadfile>;
830: }
831: $loadavg =~ s/\s.*//g;
832: my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
833: my $userloadpercent=&Apache::lonnet::userload();
834:
835: # ---------------------------------------------------------- Are we overloaded?
836: if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
1.121.2.22 raeburn 837: my $unloaded=Apache::lonnet::spareserver($r,$loadpercent,$userloadpercent,1,$form{'udom'});
1.115 raeburn 838: if (!$unloaded) {
1.118 raeburn 839: ($unloaded) = &Apache::lonnet::choose_server($form{'udom'});
1.115 raeburn 840: }
1.109 raeburn 841: if ($unloaded) {
842: &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',
843: undef,\%form);
1.121.2.24.2. (raeburn 844:): if ($form{'linkprot'}) {
845:): $env{'request.linkprot'} = $form{'linkprot'};
846:): } elsif ($form{'linkkey'} ne '') {
847:): $env{'request.linkkey'} = $form{'linkkey'};
848:): }
849:): if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
850:): &set_deeplink_login(%form);
851:): } elsif ($firsturl eq '/adm/email') {
852:): if ($form{'display'} && ($form{'mailrecip'} eq "$form{'uname'}:$form{'udom'}")) {
853:): $env{'request.display'} = $form{'display'};
854:): $env{'request.mailrecip'} = $form{'mailrecip'};
855:): }
856:): }
1.109 raeburn 857: $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);
1.110 raeburn 858: return OK;
1.109 raeburn 859: }
860: }
1.121.2.15 raeburn 861: if (($is_balancer) && ($hosthere)) {
862: $form{'noloadbalance'} = $hosthere;
863: }
1.121.2.22 raeburn 864: my $extra_env;
865: if (($hosthere) && ($sessiondata{'sessionserver'} ne '')) {
866: if ($sessiondata{'origurl'} ne '') {
867: $firsturl = $sessiondata{'origurl'};
868: $form{'firsturl'} = $sessiondata{'origurl'};
869: my @names = ('role','symb','linkprot','linkkey');
870: foreach my $item (@names) {
871: if ($sessiondata{$item} ne '') {
872: $form{$item} = $sessiondata{$item};
873: }
874: }
1.121.2.24.2. (raeburn 875:): if ($sessiondata{'origurl'} eq '/adm/email') {
876:): if (($sessiondata{'display'}) && ($sessiondata{'mailrecip'})) {
877:): if (&unescape($sessiondata{'mailrecip'}) eq "$form{'uname'}:$form{'udom'}") {
878:): $form{'display'} = &unescape($sessiondata{'display'});
879:): $form{'mailrecip'} = &unescape($sessiondata{'mailrecip'});
880:): }
881:): }
882:): }
1.121.2.22 raeburn 883: }
884: }
1.121.2.24.2. (raeburn 885:): if ($form{'linkprot'}) {
886:): my ($linkprotector,$uri) = split(/:/,$form{'linkprot'},2);
887:): if ($linkprotector) {
888:): $extra_env = {'user.linkprotector' => $linkprotector,
889:): 'user.linkproturi' => $uri};
890:): }
891:): } elsif ($form{'linkkey'} ne '') {
892:): $extra_env = {'user.deeplinkkey' => $form{'linkkey'},
893:): 'user.keyedlinkuri' => $form{'firsturl'}};
894:): }
895:): if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
896:): &set_deeplink_login(%form);
897:): if ($form{'linkprot'}) {
898:): if (ref($extra_env) eq 'HASH') {
899:): %{$extra_env} = ( %{$extra_env}, 'request.linkprot' => $form{'linkprot'} );
900:): } else {
901:): $extra_env = {'request.linkprot' => $form{'linkprot'}};
902:): }
903:): if ($form{'linkprotexit'}) {
904:): $extra_env->{'request.linkprotexit'} = $form{'linkprotexit'};
905:): }
906:): } elsif ($form{'linkkey'} ne '') {
907:): if (ref($extra_env) eq 'HASH') {
908:): %{$extra_env} = ( %{$extra_env}, 'request.linkkey' => $form{'linkkey'} );
909:): } else {
910:): $extra_env = {'request.linkkey' => $form{'linkkey'}};
911:): }
912:): }
913:): if ($env{'request.deeplink.login'}) {
914:): if (ref($extra_env) eq 'HASH') {
915:): %{$extra_env} = ( %{$extra_env}, 'request.deeplink.login' => $form{'firsturl'} );
916:): } else {
917:): $extra_env = {'request.deeplink.login' => $form{'firsturl'}};
918:): }
919:): }
920:): }
921:): &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,$extra_env,
1.109 raeburn 922: \%form);
1.110 raeburn 923: return OK;
1.81 albertel 924: }
1.1 albertel 925: }
926:
1.121.2.22 raeburn 927: sub get_form_items {
928: my ($r) = @_;
929: my $buffer;
930: if ($r->header_in('Content-length') > 0) {
931: $r->read($buffer,$r->header_in('Content-length'),0);
932: }
933: my %form;
934: foreach my $pair (split(/&/,$buffer)) {
935: my ($name,$value) = split(/=/,$pair);
936: $value =~ tr/+/ /;
937: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
938: $form{$name}=$value;
939: }
940: return %form;
941: }
942:
1.121.2.24.2. (raeburn 943:): sub set_deeplink_login {
944:): my (%form) = @_;
945:): my $disallow;
946:): if ($form{'firsturl'} =~ m{^/tiny/($match_domain)/\w+$}) {
947:): my $cdom = $1;
948:): my ($cnum,$symb) = &Apache::loncommon::symb_from_tinyurl($form{'firsturl'},'',$cdom);
949:): if ($symb) {
950:): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
951:): my $deeplink;
952:): if ($symb =~ /\.(page|sequence)$/) {
953:): my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($symb))[2]);
954:): my $navmap = Apache::lonnavmaps::navmap->new();
955:): if (ref($navmap)) {
956:): $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
957:): }
958:): } else {
959:): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
960:): }
961:): if ($deeplink ne '') {
962:): my ($state,$others,$listed,$scope,$protect) = split(/,/,$deeplink);
963:): if (($protect ne 'none') && ($protect ne '')) {
964:): my ($acctype,$item) = split(/:/,$protect);
965:): if ($acctype =~ /lti(c|d)$/) {
966:): unless ($form{'linkprot'} eq $item.$1.':'.$env{'request.deeplink.login'}) {
967:): $disallow = 1;
968:): }
969:): } elsif ($acctype eq 'key') {
970:): unless ($form{'linkkey'} eq $item) {
971:): $disallow = 1;
972:): }
973:): }
974:): }
975:): }
976:): unless ($disallow) {
977:): $env{'request.deeplink.login'} = $form{'firsturl'};
978:): }
979:): } else {
980:): $env{'request.deeplink.login'} = $form{'firsturl'};
981:): }
982:): }
983:): }
984:): if ($disallow) {
985:): return;
986:): }
987:): return 'ok';
988:): }
989:):
1.121.2.22 raeburn 990: sub set_retry_token {
991: my ($form,$lonhost,$querystr) = @_;
992: if (ref($form) eq 'HASH') {
993: my ($firsturl,$token,$extras,@names);
1.121.2.24.2. (raeburn 994:): @names = ('role','symb','linkprotuser','linkprotexit','linkprot','linkkey','iptoken');
1.121.2.22 raeburn 995: foreach my $name (@names) {
996: if ($form->{$name} ne '') {
997: $extras .= '&'.$name.'='.&escape($form->{$name});
998: last if ($name eq 'linkprot');
999: }
1000: }
1001: my $firsturl = $form->{'firsturl'};
1002: if (($firsturl ne '') || ($extras ne '')) {
1003: $extras .= ':retry';
1004: $token = &Apache::lonnet::reply('tmpput:'.&escape($firsturl).
1005: $extras,$lonhost);
1006: if (($token eq 'con_lost') || ($token eq 'no_such_host')) {
1007: return 'fail';
1008: } else {
1009: if (ref($querystr)) {
1010: $$querystr = 'retry='.$token;
1011: }
1012: return 'ok';
1013: }
1014: }
1015: }
1016: return;
1017: }
1018:
1.105 raeburn 1019: sub check_can_host {
1020: my ($r,$form,$authhost,$domdesc) = @_;
1021: return unless (ref($form) eq 'HASH');
1022: my $canhost = 1;
1.106 raeburn 1023: my $lonhost = $r->dir_config('lonHostID');
1.105 raeburn 1024: my $udom = $form->{'udom'};
1.108 raeburn 1025: my @intdoms;
1026: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
1027: if (ref($internet_names) eq 'ARRAY') {
1028: @intdoms = @{$internet_names};
1029: }
1.106 raeburn 1030: my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
1031: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
1032: unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {
1033: my $machine_dom = &Apache::lonnet::host_domain($lonhost);
1034: my $hostname = &Apache::lonnet::hostname($lonhost);
1035: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
1036: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1037: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
1.105 raeburn 1038: my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);
1039: my $loncaparev;
1040: if ($authhost eq 'no_account_on_host') {
1.106 raeburn 1041: $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom);
1.105 raeburn 1042: } else {
1.106 raeburn 1043: $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost);
1.105 raeburn 1044: }
1.106 raeburn 1045: $canhost = &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev,
1046: $udomdefaults{'remotesessions'},
1047: $defdomdefaults{'hostedsessions'});
1.105 raeburn 1048: }
1049: unless ($canhost) {
1050: if ($authhost eq 'no_account_on_host') {
1.115 raeburn 1051: my $checkloginvia = 1;
1052: my ($login_host,$hostname) =
1053: &Apache::lonnet::choose_server($udom,$checkloginvia);
1.105 raeburn 1054: &Apache::loncommon::content_type($r,'text/html');
1055: $r->send_http_header;
1056: if ($login_host ne '') {
1057: my $protocol = $Apache::lonnet::protocol{$login_host};
1058: $protocol = 'http' if ($protocol ne 'https');
1.121.2.22 raeburn 1059: my $alias = &Apache::lonnet::use_proxy_alias($r,$login_host);
1060: $hostname = $alias if ($alias ne '');
1.105 raeburn 1061: my $newurl = $protocol.'://'.$hostname.'/adm/createaccount';
1.121.2.24.2. (raeburn 1062:): #FIXME Should preserve where user was going and linkprot by setting ltoken at $login_host
1.105 raeburn 1063: $r->print(&Apache::loncommon::start_page('Create a user account in LON-CAPA').
1064: '<h3>'.&mt('Account creation').'</h3>'.
1065: &mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.
1066: '<p>'.&mt('You will be able to create one by logging into a LON-CAPA server within the [_1] domain.',$domdesc).'</p>'.
1067: '<p>'.&mt('[_1]Log in[_2]','<a href="'.$newurl.'">','</a>').
1068: &Apache::loncommon::end_page());
1069: } else {
1070: $r->print(&Apache::loncommon::start_page('Access to LON-CAPA unavailable').
1071: '<h3>'.&mt('Account creation unavailable').'</h3>'.
1072: &mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.
1073: '<p>'.&mt('Currently a LON-CAPA server is not available within the [_1] domain for you to log-in to, to create an account.',$domdesc).'</p>'.
1074: &Apache::loncommon::end_page());
1075: }
1076: } else {
1077: &success($r,$form->{'uname'},$udom,$authhost,'noredirect',undef,
1078: $form);
1.121.2.24.2. (raeburn 1079:): if ($form->{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
1080:): $env{'request.deeplink.login'} = $form->{'firsturl'};
1081:): } elsif ($form->{'firsturl'} eq '/adm/email') {
1082:): if ($form->{'display'} && ($form->{'mailrecip'} eq $form->{'uname'}.':'.$form->{'udom'})) {
1083:): $env{'request.display'} = $form->{'mailrecip'};
1084:): $env{'request.mailrecip'} = $form->{'mailrecip'};
1085:): }
1086:): }
1087:): if ($form->{'linkprot'}) {
1088:): $env{'request.linkprot'} = $form->{'linkprot'};
1089:): } elsif ($form->{'linkkey'} ne '') {
1090:): $env{'request.linkkey'} = $form->{'linkkey'};
1091:): }
1.107 raeburn 1092: my ($otherserver) = &Apache::lonnet::choose_server($udom);
1.105 raeburn 1093: $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);
1094: }
1095: }
1.110 raeburn 1096: return $canhost;
1.105 raeburn 1097: }
1098:
1.115 raeburn 1099: sub noswitch {
1100: my $result = &Apache::loncommon::start_page('Access to LON-CAPA unavailable').
1101: '<h3>'.&mt('Session unavailable').'</h3>'.
1102: &mt('This LON-CAPA server is unable to host your session.').'<br />'.
1103: '<p>'.&mt('Currently no other LON-CAPA server is available to host your session either.').'</p>'.
1104: &Apache::loncommon::end_page();
1105: return $result;
1106: }
1107:
1.121.2.2 raeburn 1108: sub loginhelpdisplay {
1109: my ($authdomain) = @_;
1110: my $login_help = 1;
1111: my $lang = &Apache::lonlocal::current_language();
1112: if ($login_help) {
1113: my $dom = $authdomain;
1114: if ($dom eq '') {
1115: $dom = &Apache::lonnet::default_login_domain();
1116: }
1117: my %domconfhash = &Apache::loncommon::get_domainconf($dom);
1118: my $loginhelp_url;
1119: if ($lang) {
1120: $loginhelp_url = $domconfhash{$dom.'.login.helpurl_'.$lang};
1121: if ($loginhelp_url ne '') {
1122: return $loginhelp_url;
1123: }
1124: }
1125: $loginhelp_url = $domconfhash{$dom.'.login.helpurl_nolang'};
1126: if ($loginhelp_url ne '') {
1127: return $loginhelp_url;
1128: } else {
1129: return '/adm/loginproblems.html';
1130: }
1131: }
1132: return;
1133: }
1134:
1.121.2.24.2. (raeburn 1135:): sub alternate_unames_check {
1136:): my ($uname,$udom) = @_;
1137:): my %possunames;
1138:): my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1139:): if (ref($domdefs{'unamemap_rule'}) eq 'ARRAY') {
1140:): if (@{$domdefs{'unamemap_rule'}} > 0) {
1141:): %possunames =
1142:): &Apache::lonnet::inst_rulecheck($udom,$uname,undef,
1143:): 'unamemap',$domdefs{'unamemap_rule'});
1144:): }
1145:): }
1146:): return %possunames;
1147:): }
1148:):
1.1 albertel 1149: 1;
1150: __END__
1.7 www 1151:
1152:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>