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