version 1.121.2.24.2.5, 2022/08/30 12:10:43
|
version 1.147, 2017/08/08 18:17:13
|
Line 1
|
Line 1
|
# The LearningOnline Network |
# The LearningOnline Network
|
# User Authentication Module |
# User Authentication Module
|
# |
#
|
# $Id$ |
# $Id$
|
# |
#
|
# Copyright Michigan State University Board of Trustees |
# Copyright Michigan State University Board of Trustees
|
# |
#
|
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
|
# |
#
|
# LON-CAPA is free software; you can redistribute it and/or modify |
# LON-CAPA is free software; you can redistribute it and/or modify
|
# it under the terms of the GNU General Public License as published by |
# it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation; either version 2 of the License, or |
# the Free Software Foundation; either version 2 of the License, or
|
# (at your option) any later version. |
# (at your option) any later version.
|
# |
#
|
# LON-CAPA is distributed in the hope that it will be useful, |
# LON-CAPA is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# GNU General Public License for more details. |
# GNU General Public License for more details.
|
# |
#
|
# You should have received a copy of the GNU General Public License |
# You should have received a copy of the GNU General Public License
|
# along with LON-CAPA; if not, write to the Free Software |
# along with LON-CAPA; if not, write to the Free Software
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# |
#
|
# /home/httpd/html/adm/gpl.txt |
# /home/httpd/html/adm/gpl.txt
|
# |
#
|
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/
|
# |
#
|
|
|
package Apache::lonauth; |
package Apache::lonauth;
|
|
|
use strict; |
use strict;
|
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match);
|
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common);
|
use CGI qw(:standard); |
use CGI qw(:standard);
|
use Apache::loncommon(); |
use Apache::loncommon();
|
use Apache::lonnet; |
use Apache::lonnet;
|
use Apache::lonmenu(); |
use Apache::lonmenu();
|
use Apache::createaccount; |
use Apache::createaccount;
|
use Fcntl qw(:flock); |
use Fcntl qw(:flock);
|
use Apache::lonlocal; |
use Apache::lonlocal;
|
use Apache::File(); |
use Apache::File();
|
use HTML::Entities; |
use HTML::Entities;
|
use Digest::MD5; |
use Digest::MD5;
|
use CGI::Cookie(); |
|
|
# ------------------------------------------------------------ Successful login
|
# ------------------------------------------------------------ Successful login |
sub success {
|
sub success { |
my ($r, $username, $domain, $authhost, $lowerurl, $extra_env,
|
my ($r, $username, $domain, $authhost, $lowerurl, $extra_env, |
$form) = @_;
|
$form,$cid,$expirepub,$write_to_opener) = @_; |
|
|
# ------------------------------------------------------------ Get cookie ready
|
# ------------------------------------------------------------ Get cookie ready |
my $cookie =
|
my $cookie = |
&Apache::loncommon::init_user_environment($r, $username, $domain,
|
&Apache::loncommon::init_user_environment($r, $username, $domain, |
$authhost, $form,
|
$authhost, $form, |
{'extra_env' => $extra_env,});
|
{'extra_env' => $extra_env,}); |
|
|
my $public=($username eq 'public' && $domain eq 'public');
|
my $public=($username eq 'public' && $domain eq 'public'); |
|
|
if ($public or $lowerurl eq 'noredirect') { return $cookie; }
|
if ($public or $lowerurl eq 'noredirect') { return $cookie; } |
|
|
# -------------------------------------------------------------------- Log this
|
# -------------------------------------------------------------------- Log this |
|
|
&Apache::lonnet::log($domain,$username,$authhost,
|
my $ip = &Apache::lonnet::get_requestor_ip(); |
"Login $ENV{'REMOTE_ADDR'}");
|
&Apache::lonnet::log($domain,$username,$authhost, |
|
"Login $ip"); |
# ------------------------------------------------- Check for critical messages
|
|
|
# ------------------------------------------------- Check for critical messages |
my @what=&Apache::lonnet::dump('critical',$domain,$username);
|
|
if ($what[0]) {
|
my @what=&Apache::lonnet::dump('critical',$domain,$username); |
if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
|
if ($what[0]) { |
$lowerurl='/adm/email?critical=display';
|
if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) { |
}
|
$lowerurl='/adm/email?critical=display'; |
}
|
} |
|
} |
# ----------------------------------------------------------- Get cookies ready
|
|
my ($securecookie,$defaultcookie);
|
# ------------------------------------------------------------ Get cookies ready |
if ($ENV{'SERVER_PORT'} == 443) {
|
my ($securecookie,$defaultcookie); |
$securecookie="lonID=$cookie; path=/; HttpOnly; secure";
|
my $ssl = $r->subprocess_env('https'); |
my $lonidsdir=$r->dir_config('lonIDsDir');
|
if ($ssl) { |
if (($lonidsdir) && (-e "$lonidsdir/$cookie.id")) {
|
$securecookie="lonSID=$cookie; path=/; HttpOnly; secure"; |
my $linkname=substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 32).'_linked';
|
my $lonidsdir=$r->dir_config('lonIDsDir'); |
if (-e "$lonidsdir/$linkname.id") {
|
if (($lonidsdir) && (-e "$lonidsdir/$cookie.id")) { |
unlink("$lonidsdir/$linkname.id");
|
my $linkname=substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 32).'_linked'; |
}
|
if (-e "$lonidsdir/$linkname.id") { |
my $made_symlink = eval { symlink("$lonidsdir/$cookie.id",
|
unlink("$lonidsdir/$linkname.id"); |
"$lonidsdir/$linkname.id"); 1 };
|
} |
if ($made_symlink) {
|
my $made_symlink = eval { symlink("$lonidsdir/$cookie.id", |
$defaultcookie = "lonLinkID=$linkname; path=/; HttpOnly;";
|
"$lonidsdir/$linkname.id"); 1 }; |
&Apache::lonnet::appenv({'user.linkedenv' => "$lonidsdir/$linkname.id"});
|
if ($made_symlink) { |
}
|
$defaultcookie = "lonLinkID=$linkname; path=/; HttpOnly;"; |
}
|
&Apache::lonnet::appenv({'user.linkedenv' => $linkname}); |
} else {
|
} |
$defaultcookie = "lonID=$cookie; path=/; HttpOnly;";
|
} |
}
|
} else { |
# -------------------------------------------------------- Menu script and info
|
$defaultcookie = "lonID=$cookie; path=/; HttpOnly;"; |
my $destination = $lowerurl;
|
} |
|
# -------------------------------------------------------- Menu script and info |
if (defined($form->{role})) {
|
my $destination = $lowerurl; |
my $envkey = 'user.role.'.$form->{role};
|
|
my $now=time;
|
if (defined($form->{role})) { |
my $then=$env{'user.login.time'};
|
my $envkey = 'user.role.'.$form->{role}; |
my $refresh=$env{'user.refresh.time'};
|
my $now=time; |
my $update=$env{'user.update.time'};
|
my $then=$env{'user.login.time'}; |
if (!$update) {
|
my $refresh=$env{'user.refresh.time'}; |
$update = $then;
|
my $update=$env{'user.update.time'}; |
}
|
if (!$update) { |
if (exists($env{$envkey})) {
|
$update = $then; |
my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus);
|
} |
&Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
|
if (exists($env{$envkey})) { |
\$trolecode,\$tstatus,\$tstart,\$tend);
|
my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus); |
if ($tstatus eq 'is') {
|
&Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where, |
$destination .= ($destination =~ /\?/) ? '&' : '?';
|
\$trolecode,\$tstatus,\$tstart,\$tend); |
my $newrole = &HTML::Entities::encode($form->{role},'"<>&');
|
if ($tstatus eq 'is') { |
$destination .= 'selectrole=1&'.$newrole.'=1';
|
$destination .= ($destination =~ /\?/) ? '&' : '?'; |
}
|
my $newrole = &HTML::Entities::encode($form->{role},'"<>&'); |
}
|
$destination .= 'selectrole=1&'.$newrole.'=1'; |
}
|
} |
if (defined($form->{symb})) {
|
} |
my $destsymb = $form->{symb};
|
} |
$destination .= ($destination =~ /\?/) ? '&' : '?';
|
if (defined($form->{symb})) { |
if ($destsymb =~ /___/) {
|
my $destsymb = $form->{symb}; |
# FIXME Need to deal with encrypted symbs and urls as needed.
|
my $encrypted; |
my ($map,$resid,$desturl)=split(/___/,$destsymb);
|
if ($destsymb =~ m{^/enc/}) { |
$desturl = &Apache::lonnet::clutter($desturl);
|
$encrypted = 1; |
$desturl = &HTML::Entities::encode($desturl,'"<>&');
|
if ($cid) { |
$destsymb = &HTML::Entities::encode($destsymb,'"<>&');
|
$destsymb = &Apache::lonenc::unencrypted($destsymb,$cid); |
$destination .= 'destinationurl='.$desturl.
|
} |
'&destsymb='.$destsymb;
|
} |
} else {
|
$destination .= ($destination =~ /\?/) ? '&' : '?'; |
$destsymb = &HTML::Entities::encode($destsymb,'"<>&');
|
if ($destsymb =~ /___/) { |
$destination .= 'destinationurl='.$destsymb;
|
my ($map,$resid,$desturl)=split(/___/,$destsymb); |
}
|
$desturl = &Apache::lonnet::clutter($desturl); |
}
|
if ($encrypted) { |
if ($destination =~ m{^/adm/roles}) {
|
$desturl = &Apache::lonenc::encrypted($desturl,1,$cid); |
$destination .= ($destination =~ /\?/) ? '&' : '?';
|
$destsymb = $form->{symb}; |
$destination .= 'source=login';
|
} |
}
|
$desturl = &HTML::Entities::encode($desturl,'"<>&'); |
|
$destsymb = &HTML::Entities::encode($destsymb,'"<>&'); |
my $windowinfo = Apache::lonhtmlcommon::scripttag('self.name="loncapaclient";');
|
$destination .= 'destinationurl='.$desturl. |
my $header = '<meta HTTP-EQUIV="Refresh" CONTENT="0; url='.$destination.'" />';
|
'&destsymb='.$destsymb; |
my $brcrum = [{'href' => '',
|
} elsif (!$encrypted) { |
'text' => 'Successful Login'},];
|
$destsymb = &HTML::Entities::encode($destsymb,'"<>&'); |
my $args = {'bread_crumbs' => $brcrum,};
|
$destination .= 'destinationurl='.$destsymb; |
unless ((defined($form->{role})) || (defined($form->{symb}))) {
|
} |
my $update=$env{'user.update.time'};
|
} |
if (!$update) {
|
if ($destination =~ m{^/adm/roles}) { |
$update = $env{'user.login.time'};
|
$destination .= ($destination =~ /\?/) ? '&' : '?'; |
}
|
$destination .= 'source=login'; |
my %roles_in_env;
|
} |
my $showcount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
|
|
if ($showcount == 1) {
|
my $brcrum = [{'href' => '', |
foreach my $rolecode (keys(%roles_in_env)) {
|
'text' => 'Successful Login'},]; |
my ($cid) = ($rolecode =~ m{^\Quser.role.st./\E($match_domain/$match_courseid)(?:/|$)});
|
my $args = {'no_inline_link' => 1, |
if ($cid) {
|
'bread_crumbs' => $brcrum,}; |
my %coursedescription =
|
if (($env{'request.deeplink.login'} eq $lowerurl) && |
&Apache::lonnet::coursedescription($cid,{'one_time' => '1'});
|
(($env{'request.linkprot'}) || ($env{'request.linkkey'} ne ''))) { |
if ($coursedescription{'type'} eq 'Placement') {
|
my %info; |
$args->{'crstype'} = 'Placement';
|
if ($env{'request.linkprot'}) { |
}
|
$info{'linkprot'} = $env{'request.linkprot'}; |
last;
|
foreach my $item ('linkprotuser','linkprotexit') { |
}
|
if ($form->{$item}) { |
}
|
$info{$item} = $form->{$item}; |
}
|
} |
}
|
} |
my $start_page=&Apache::loncommon::start_page('Successful Login',
|
$args = {'only_body' => 1,}; |
$header,$args);
|
} elsif ($env{'request.linkkey'} ne '') { |
my $end_page =&Apache::loncommon::end_page();
|
$info{'linkkey'} = $env{'request.linkkey'}; |
|
} |
my $continuelink='<a href="'.$destination.'">'.&mt('Continue').'</a>';
|
$info{'origurl'} = $lowerurl; |
# ------------------------------------------------- Output for successful login
|
my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'link'); |
|
unless (($token eq 'con_lost') || ($token eq 'refused') || |
&Apache::loncommon::content_type($r,'text/html');
|
($token eq 'unknown_cmd') || ($token eq 'no_such_host')) { |
if ($securecookie) {
|
$destination .= (($destination =~ /\?/) ? '&' : '?') . 'ttoken='.$token; |
$r->headers_out->add('Set-cookie' => $securecookie);
|
} |
}
|
} |
if ($defaultcookie) {
|
if ($env{'request.deeplink.login'}) { |
$r->headers_out->add('Set-cookie' => $defaultcookie);
|
if ($env{'environment.remote'} eq 'on') { |
}
|
&Apache::lonnet::appenv({'environment.remote' => 'off'}); |
$r->send_http_header;
|
} |
|
} |
my %lt=&Apache::lonlocal::texthash(
|
my $startupremote; |
'wel' => 'Welcome',
|
if ($write_to_opener) { |
'pro' => 'Login problems?',
|
if ($env{'environment.remote'} eq 'on') { |
);
|
&Apache::lonnet::appenv({'environment.remote' => 'off'}); |
my $loginhelp = &loginhelpdisplay($domain);
|
} |
if ($loginhelp) {
|
$args->{'redirect'} = [0,$destination,'',$write_to_opener]; |
$loginhelp = '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>';
|
} else { |
}
|
$startupremote=&Apache::lonmenu::startupremote($destination); |
|
} |
my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>');
|
|
$r->print(<<ENDSUCCESS);
|
my $windowinfo=&Apache::lonmenu::open($env{'browser.os'}); |
$start_page
|
my $remoteinfo=&Apache::lonmenu::load_remote_msg($lowerurl); |
$windowinfo
|
my $setflags=&Apache::lonmenu::setflags(); |
<h1>$lt{'wel'}</h1>
|
my $maincall=&Apache::lonmenu::maincall(); |
$welcome
|
my $start_page=&Apache::loncommon::start_page('Successful Login', |
$loginhelp
|
$startupremote,$args); |
$continuelink
|
my $end_page =&Apache::loncommon::end_page(); |
$end_page
|
|
ENDSUCCESS
|
my $continuelink; |
return;
|
if ($env{'environment.remote'} eq 'off') { |
}
|
unless ($write_to_opener) { |
|
$continuelink='<a href="'.$destination.'">'.&mt('Continue').'</a>'; |
# --------------------------------------------------------------- Failed login!
|
} |
|
} |
sub failed {
|
# ------------------------------------------------- Output for successful login |
my ($r,$message,$form) = @_;
|
|
(undef,undef,undef,my $clientmathml,my $clientunicode) =
|
&Apache::loncommon::content_type($r,'text/html'); |
&Apache::loncommon::decode_user_agent();
|
if ($securecookie) { |
my $args = {};
|
$r->headers_out->add('Set-cookie' => $securecookie); |
if ($clientunicode && !$clientmathml) {
|
} |
$args = {'browser.unicode' => 1};
|
if ($defaultcookie) { |
}
|
$r->headers_out->add('Set-cookie' => $defaultcookie); |
|
} |
my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args);
|
if ($expirepub) { |
my $uname = &Apache::loncommon::cleanup_html($form->{'uname'});
|
my $c = new CGI::Cookie(-name => 'lonPubID', |
my $udom = &Apache::loncommon::cleanup_html($form->{'udom'});
|
-value => '', |
if (&Apache::lonnet::domain($udom,'description') eq '') {
|
-expires => '-10y',); |
undef($udom);
|
$r->headers_out->add('Set-cookie' => $c); |
}
|
} |
my $retry = '/adm/login';
|
$r->send_http_header; |
if ($uname eq $form->{'uname'}) {
|
|
$retry .= '?username='.$uname;
|
if ($env{'request.linkprot'}) { |
}
|
$r->print(<<END); |
if ($udom) {
|
$start_page |
$retry .= (($retry=~/\?/)?'&':'?').'domain='.$udom;
|
<br />$continuelink |
}
|
$end_page |
if (exists($form->{role})) {
|
END |
my $role = &Apache::loncommon::cleanup_html($form->{role});
|
} else { |
if ($role ne '') {
|
my %lt=&Apache::lonlocal::texthash( |
$retry .= (($retry=~/\?/)?'&':'?').'role='.$role;
|
'wel' => 'Welcome', |
}
|
'pro' => 'Login problems?', |
}
|
); |
if (exists($form->{symb})) {
|
my $loginhelp = &loginhelpdisplay($domain); |
my $symb = &Apache::loncommon::cleanup_html($form->{symb});
|
if ($loginhelp) { |
if ($symb ne '') {
|
$loginhelp = '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>'; |
$retry .= (($retry=~/\?/)?'&':'?').'symb='.$symb;
|
} |
}
|
|
}
|
my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>'); |
my $end_page = &Apache::loncommon::end_page();
|
$r->print(<<ENDSUCCESS); |
&Apache::loncommon::content_type($r,'text/html');
|
$start_page |
$r->send_http_header;
|
$setflags |
my @actions =
|
$windowinfo |
(&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>'));
|
<h1>$lt{'wel'}</h1> |
my $loginhelp = &loginhelpdisplay($udom);
|
$welcome |
if ($loginhelp) {
|
$loginhelp |
push(@actions, '<a href="'.$loginhelp.'">'.&mt('Login problems?').'</a>');
|
$remoteinfo |
}
|
$maincall |
#FIXME: link to helpdesk might be added here
|
$continuelink |
|
$end_page |
$r->print(
|
ENDSUCCESS |
$start_page
|
} |
.'<h2>'.&mt('Sorry ...').'</h2>'
|
return; |
.&Apache::lonhtmlcommon::confirm_success(&mt($message),1).'<br /><br />'
|
} |
.&Apache::lonhtmlcommon::actionbox(\@actions)
|
|
.$end_page
|
# --------------------------------------------------------------- Failed login! |
);
|
|
}
|
sub failed { |
|
my ($r,$message,$form,$authhost) = @_; |
# ------------------------------------------------------------------ Rerouting!
|
(undef,undef,undef,my $clientmathml,my $clientunicode) = |
|
&Apache::loncommon::decode_user_agent(); |
sub reroute {
|
my $args = {}; |
my ($r) = @_;
|
if ($clientunicode && !$clientmathml) { |
&Apache::loncommon::content_type($r,'text/html');
|
$args = {'browser.unicode' => 1}; |
$r->send_http_header;
|
} |
my $msg='<b>'.&mt('Sorry ...').'</b><br />'
|
if ($form->{firsturl} =~ m{^/tiny/$match_domain/\w+$}) { |
.&mt('Please [_1]log in again[_2].');
|
if ($form->{linkprot}) { |
&Apache::loncommon::simple_error_page($r,'Rerouting',$msg,{'no_auto_mt_msg' => 1});
|
$args->{only_body} = 1; |
}
|
} |
|
} |
# ---------------------------------------------------------------- Main handler
|
|
|
my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args); |
sub handler {
|
my $uname = &Apache::loncommon::cleanup_html($form->{'uname'}); |
my $r = shift;
|
my $udom = &Apache::loncommon::cleanup_html($form->{'udom'}); |
my $londocroot = $r->dir_config('lonDocRoot');
|
if (&Apache::lonnet::domain($udom,'description') eq '') { |
# Are we re-routing?
|
undef($udom); |
if (-e "$londocroot/lon-status/reroute.txt") {
|
} |
&reroute($r);
|
my $retry = '/adm/login'; |
return OK;
|
if ($uname eq $form->{'uname'}) { |
}
|
$retry .= '?username='.$uname; |
|
} |
&Apache::lonlocal::get_language_handle($r);
|
if ($udom) { |
|
$retry .= (($retry=~/\?/)?'&':'?').'domain='.$udom; |
# -------------------------------- Prevent users from attempting to login twice
|
} |
my $handle = &Apache::lonnet::check_for_valid_session($r);
|
my $lonhost = $r->dir_config('lonHostID'); |
if ($handle ne '') {
|
my $querystr; |
my $lonidsdir=$r->dir_config('lonIDsDir');
|
my $result = &set_retry_token($form,$lonhost,\$querystr); |
if ($handle=~/^publicuser\_/) {
|
if ($result eq 'fail') { |
# For "public user" - remove it, we apparently really want to login
|
if (exists($form->{role})) { |
unlink($r->dir_config('lonIDsDir')."/$handle.id");
|
my $role = &Apache::loncommon::cleanup_html($form->{role}); |
} else {
|
if ($role ne '') { |
# Indeed, a valid token is found
|
$retry .= (($retry=~/\?/)?'&':'?').'role='.$role; |
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
|
} |
&Apache::loncommon::content_type($r,'text/html');
|
} |
$r->send_http_header;
|
if (exists($form->{symb})) { |
my $start_page =
|
my $symb = &Apache::loncommon::cleanup_html($form->{symb}); |
&Apache::loncommon::start_page('Already logged in');
|
if ($symb ne '') { |
my $end_page =
|
$retry .= (($retry=~/\?/)?'&':'?').'symb='.$symb; |
&Apache::loncommon::end_page();
|
} |
my $dest = '/adm/roles';
|
} |
if ($env{'form.firsturl'} ne '') {
|
if (exists($form->{firsturl})) { |
$dest = $env{'form.firsturl'};
|
my $firsturl = &Apache::loncommon::cleanup_html($form->{firsturl}); |
}
|
if ($firsturl ne '') { |
$r->print(
|
$retry .= (($retry=~/\?/)?'&':'?').'firsturl='.$firsturl; |
$start_page
|
if ($form->{firsturl} =~ m{^/tiny/$match_domain/\w+$}) { |
.'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
|
unless (exists($form->{linkprot})) { |
.'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].'
|
if (exists($form->{linkkey})) { |
,'<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>')
|
$retry .= 'linkkey='.$form->{linkkey}; |
.'</p>'
|
} |
.$end_page
|
} |
);
|
} |
return OK;
|
} |
}
|
} |
}
|
if (exists($form->{linkprot})) { |
|
my %info = ( |
# ---------------------------------------------------- No valid token, continue
|
'linkprot' => $form->{'linkprot'}, |
|
); |
|
foreach my $item ('linkprotuser','linkprotexit') { |
my $buffer;
|
if ($form->{$item} ne '') { |
if ($r->header_in('Content-length') > 0) {
|
$info{$item} = $form->{$item}; |
$r->read($buffer,$r->header_in('Content-length'),0);
|
} |
}
|
} |
my %form;
|
my $ltoken = &Apache::lonnet::tmpput(\%info, |
foreach my $pair (split(/&/,$buffer)) {
|
$r->dir_config('lonHostID'),'retry'); |
my ($name,$value) = split(/=/,$pair);
|
if ($ltoken) { |
$value =~ tr/+/ /;
|
$retry .= (($retry =~ /\?/) ? '&' : '?').'ltoken='.$ltoken; |
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
|
} |
$form{$name}=$value;
|
} |
}
|
} elsif ($querystr ne '') { |
|
$retry .= (($retry=~/\?/)?'&':'?').$querystr; |
if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) {
|
} |
&failed($r,'Username, password and domain need to be specified.',
|
my $end_page = &Apache::loncommon::end_page(); |
\%form);
|
&Apache::loncommon::content_type($r,'text/html'); |
return OK;
|
$r->send_http_header; |
}
|
my @actions = |
|
(&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>')); |
# split user logging in and "su"-user
|
my $loginhelp = &loginhelpdisplay($udom); |
|
if ($loginhelp) { |
($form{'uname'},$form{'suname'},$form{'sudom'})=split(/\:/,$form{'uname'});
|
push(@actions, '<a href="'.$loginhelp.'">'.&mt('Login problems?').'</a>'); |
$form{'uname'} = &LONCAPA::clean_username($form{'uname'});
|
} |
$form{'suname'}= &LONCAPA::clean_username($form{'suname'});
|
#FIXME: link to helpdesk might be added here |
$form{'udom'} = &LONCAPA::clean_domain($form{'udom'});
|
|
$form{'sudom'} = &LONCAPA::clean_domain($form{'sudom'});
|
$r->print( |
|
$start_page |
my $role = $r->dir_config('lonRole');
|
.'<h2>'.&mt('Sorry ...').'</h2>' |
my $domain = $r->dir_config('lonDefDomain');
|
.&Apache::lonhtmlcommon::confirm_success(&mt($message),1).'<br /><br />' |
my $prodir = $r->dir_config('lonUsersDir');
|
.&Apache::lonhtmlcommon::actionbox(\@actions) |
my $contact_name = &mt('LON-CAPA helpdesk');
|
.$end_page |
|
); |
# ---------------------------------------- Get the information from login token
|
} |
|
|
my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'},
|
# ------------------------------------------------------------------ Rerouting! |
$form{'serverid'});
|
|
|
sub reroute { |
if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||
|
my ($r) = @_; |
($tmpinfo eq 'no_such_host')) {
|
&Apache::loncommon::content_type($r,'text/html'); |
&failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form);
|
$r->send_http_header; |
return OK;
|
my $msg='<b>'.&mt('Sorry ...').'</b><br />' |
} else {
|
.&mt('Please [_1]log in again[_2].'); |
my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'},
|
&Apache::loncommon::simple_error_page($r,'Rerouting',$msg,{'no_auto_mt_msg' => 1}); |
$form{'serverid'});
|
} |
if ( $reply ne 'ok' ) {
|
|
&failed($r,'Session could not be opened.',\%form);
|
# ---------------------------------------------------------------- Main handler |
&Apache::lonnet::logthis("ERROR got a reply of $reply when trying to contact ". $form{'serverid'}." to get login token");
|
|
return OK;
|
sub handler { |
}
|
my $r = shift; |
}
|
my $londocroot = $r->dir_config('lonDocRoot'); |
|
# Are we re-routing? |
if (!&Apache::lonnet::domain($form{'udom'})) {
|
if (-e "$londocroot/lon-status/reroute.txt") { |
&failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form);
|
&reroute($r); |
return OK;
|
return OK; |
}
|
} |
|
|
my ($key,$firsturl,$rolestr,$symbstr,$iptokenstr)=split(/&/,$tmpinfo);
|
&Apache::lonlocal::get_language_handle($r); |
if ($rolestr) {
|
|
$rolestr = &unescape($rolestr);
|
# -------------------------------- Prevent users from attempting to login twice |
}
|
my $handle = &Apache::lonnet::check_for_valid_session($r); |
if ($symbstr) {
|
if ($handle ne '') { |
$symbstr= &unescape($symbstr);
|
my $lonidsdir=$r->dir_config('lonIDsDir'); |
}
|
if ($handle=~/^publicuser\_/) { |
if ($iptokenstr) {
|
# For "public user" - remove it, we apparently really want to login |
$iptokenstr = &unescape($iptokenstr);
|
unlink($r->dir_config('lonIDsDir')."/$handle.id"); |
}
|
} else { |
if ($rolestr =~ /^role=/) {
|
# Indeed, a valid token is found |
(undef,$form{'role'}) = split('=',$rolestr);
|
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); |
}
|
&Apache::loncommon::content_type($r,'text/html'); |
if ($symbstr =~ /^symb=/) {
|
$r->send_http_header; |
(undef,$form{'symb'}) = split('=',$symbstr);
|
my $start_page = |
}
|
&Apache::loncommon::start_page('Already logged in'); |
if ($iptokenstr =~ /^iptoken=/) {
|
my $end_page = |
(undef,$form{'iptoken'}) = split('=',$iptokenstr);
|
&Apache::loncommon::end_page(); |
}
|
my $dest = '/adm/roles'; |
|
my %form = &get_form_items($r); |
my $upass = $ENV{HTTPS} ? $form{'upass0'}
|
if ($form{'logtoken'}) { |
: &Apache::loncommon::des_decrypt($key,$form{'upass0'});
|
my $tmpinfo = &Apache::lonnet::reply('tmpget:'.$form{'logtoken'}, |
|
$form{'serverid'}); |
# ---------------------------------------------------------------- Authenticate
|
unless (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') || |
|
($tmpinfo eq 'no_such_host')) { |
my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});
|
my ($des_key,$firsturl,@rest)=split(/&/,$tmpinfo); |
my ($cancreate,$statustocreate) =
|
$firsturl = &unescape($firsturl); |
&Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'});
|
my %info; |
my $defaultauth;
|
foreach my $item (@rest) { |
if (ref($cancreate) eq 'ARRAY') {
|
my ($key,$value) = split(/=/,$item); |
if (grep(/^login$/,@{$cancreate})) {
|
$info{$key} = &unescape($value); |
$defaultauth = 1;
|
} |
}
|
if ($firsturl ne '') { |
}
|
$info{'firsturl'} = $firsturl; |
my $clientcancheckhost = 1;
|
$dest = $firsturl; |
my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass,
|
my $relogin; |
$form{'udom'},$defaultauth,
|
if ($dest =~ m{^/tiny/$match_domain/\w+$}) { |
$clientcancheckhost);
|
if ($env{'request.course.id'}) { |
|
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
# --------------------------------------------------------------------- Failed?
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
|
my $symb = &Apache::loncommon::symb_from_tinyurl($dest,$cnum,$cdom); |
if ($authhost eq 'no_host') {
|
if ($symb) { |
&failed($r,'Username and/or password could not be authenticated.',
|
unless (&set_deeplink_login(%info) eq 'ok') { |
\%form);
|
$relogin = 1; |
return OK;
|
} |
} elsif ($authhost eq 'no_account_on_host') {
|
} |
if ($defaultauth) {
|
} |
my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');
|
if ($relogin) { |
unless (&check_can_host($r,\%form,'no_account_on_host',$domdesc)) {
|
$r->print( |
return OK;
|
$start_page |
}
|
.'<p class="LC_warning">'.&mt('You are already logged in!').'</p>' |
my $start_page =
|
.'<p>'.&mt('Please [_1]log out[_2] first, and then try your access again', |
&Apache::loncommon::start_page('Create a user account in LON-CAPA');
|
'<a href="/adm/logout">','</a>') |
my $lonhost = $r->dir_config('lonHostID');
|
.'</p>' |
my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
|
.$end_page); |
my $contacts =
|
} else { |
&Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
|
if (($info{'linkprot'}) || ($info{'linkkey'} ne '')) { |
$form{'udom'},$origmail);
|
if (($info{'linkprot'}) && ($info{'linkprotuser'} ne '')) { |
my ($contact_email) = split(',',$contacts);
|
unless ($info{'linkprotuser'} eq $env{'user.name'}.':'.$env{'user.domain'}) { |
my $output =
|
$r->print( |
&Apache::createaccount::username_check($form{'uname'},$form{'udom'},
|
$start_page |
$domdesc,'',$lonhost,
|
.'<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>' |
$contact_email,$contact_name,
|
.'<p>'.&mt('Please [_1]log out[_2] first, and then try following the link again from the other system', |
undef,$statustocreate);
|
'<a href="/adm/logout">','</a>') |
&Apache::loncommon::content_type($r,'text/html');
|
|
$r->send_http_header;
|
.'</p>' |
&Apache::createaccount::print_header($r,$start_page);
|
.$end_page); |
$r->print('<h3>'.&mt('Account creation').'</h3>'.
|
return OK; |
&mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account at this institution.').'<br />'.
|
} |
$output.&Apache::loncommon::end_page());
|
} |
return OK;
|
my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'link'); |
} else {
|
unless (($token eq 'con_lost') || ($token eq 'refused') || |
&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);
|
($token eq 'unknown_cmd') || ($token eq 'no_such_host')) { |
return OK;
|
$dest .= (($dest =~ /\?/) ? '&' : '?') . 'ttoken='.$token; |
}
|
} |
}
|
} |
|
$r->print( |
if (($firsturl eq '') ||
|
$start_page |
($firsturl=~/^\/adm\/(logout|remote)/)) {
|
.'<p class="LC_warning">'.&mt('You are already logged in!').'</p>' |
$firsturl='/adm/roles';
|
.'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4] first, and then try your access again', |
}
|
'<a href="'.$dest.'">','</a>', |
|
'<a href="/adm/logout">','</a>') |
my $hosthere;
|
.'</p>' |
if ($form{'iptoken'}) {
|
.$end_page); |
my %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
|
} |
my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
|
return OK; |
if (($sessiondata{'domain'} eq $form{'udom'}) &&
|
} |
($sessiondata{'username'} eq $form{'uname'})) {
|
} |
$hosthere = 1;
|
} |
}
|
} |
}
|
$r->print( |
|
$start_page |
# --------------------------------- Are we attempting to login as somebody else?
|
.'<p class="LC_warning">'.&mt('You are already logged in!').'</p>' |
if ($form{'suname'}) {
|
.'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].' |
my ($suname,$sudom,$sudomref);
|
,'<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>') |
$suname = $form{'suname'};
|
.'</p>' |
$sudom = $form{'udom'};
|
.$end_page |
if ($form{'sudom'}) {
|
); |
unless ($sudom eq $form{'sudom'}) {
|
return OK; |
if (&Apache::lonnet::domain($form{'sudom'})) {
|
} |
$sudomref = [$form{'sudom'}];
|
} |
$sudom = $form{'sudom'};
|
|
}
|
# ---------------------------------------------------- No valid token, continue |
}
|
|
}
|
my %form = &get_form_items($r); |
# ------------ see if the original user has enough privileges to pull this stunt
|
if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) { |
if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'},$sudomref)) {
|
&failed($r,'Username, password and domain need to be specified.', |
# ---------------------------------------------------- see if the su-user exists
|
\%form); |
unless (&Apache::lonnet::homeserver($suname,$sudom) eq 'no_host') {
|
return OK; |
# ------------------------------ see if the su-user is not too highly privileged
|
} |
if (&Apache::lonnet::privileged($suname,$sudom)) {
|
|
&Apache::lonnet::logthis('Attempted switch user to privileged user');
|
# split user logging in and "su"-user |
} else {
|
|
my $noprivswitch;
|
($form{'uname'},$form{'suname'},$form{'sudom'})=split(/\:/,$form{'uname'}); |
#
|
$form{'uname'} = &LONCAPA::clean_username($form{'uname'}); |
# su-user's home server and user's home server must have one of:
|
$form{'suname'}= &LONCAPA::clean_username($form{'suname'}); |
# (a) same domain
|
$form{'udom'} = &LONCAPA::clean_domain($form{'udom'}); |
# (b) same primary library server for the two domains
|
$form{'sudom'} = &LONCAPA::clean_domain($form{'sudom'}); |
# (c) same "internet domain" for primary library server(s) for home servers' domains
|
|
#
|
my $role = $r->dir_config('lonRole'); |
my $uprim = &Apache::lonnet::domain($sudom,'primary');
|
my $domain = $r->dir_config('lonDefDomain'); |
my $uintdom = &Apache::lonnet::internet_dom($uprim);
|
my $prodir = $r->dir_config('lonUsersDir'); |
unless ($sudom eq $form{'udom'}) {
|
my $contact_name = &mt('LON-CAPA helpdesk'); |
my $suprim = &Apache::lonnet::domain($sudom,'primary');
|
|
my $suintdom = &Apache::lonnet::internet_dom($suprim);
|
# ---------------------------------------- Get the information from login token |
unless ($suprim eq $uprim) {
|
|
unless ($suintdom eq $uintdom) {
|
my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'}, |
&Apache::lonnet::logthis('Attempted switch user '
|
$form{'serverid'}); |
.'to user with different "internet domain".');
|
|
$noprivswitch = 1;
|
if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') || |
}
|
($tmpinfo eq 'no_such_host')) { |
}
|
&failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form); |
}
|
return OK; |
|
} else { |
unless ($noprivswitch) {
|
my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'}, |
#
|
$form{'serverid'}); |
# server where log-in occurs must have same "internet domain" as su-user's home
|
if ( $reply ne 'ok' ) { |
# server
|
&failed($r,'Session could not be opened.',\%form); |
#
|
&Apache::lonnet::logthis("ERROR got a reply of $reply when trying to contact ". $form{'serverid'}." to get login token"); |
my $lonhost = $r->dir_config('lonHostID');
|
return OK; |
my $hostintdom = &Apache::lonnet::internet_dom($lonhost);
|
} |
if ($hostintdom ne $uintdom) {
|
} |
&Apache::lonnet::logthis('Attempted switch user on a '
|
|
.'server with a different "internet domain".');
|
if (!&Apache::lonnet::domain($form{'udom'})) { |
} else {
|
&failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form); |
|
return OK; |
# -------------------------------------------------------- actually switch users
|
} |
|
|
&Apache::lonnet::logperm('User '.$form{'uname'}.' at '.
|
my ($des_key,$firsturl,@rest)=split(/&/,$tmpinfo); |
$form{'udom'}.' logging in as '.$suname.':'.$sudom);
|
$firsturl = &unescape($firsturl); |
$form{'uname'}=$suname;
|
foreach my $item (@rest) { |
if ($form{'udom'} ne $sudom) {
|
my ($key,$value) = split(/=/,$item); |
$form{'udom'}=$sudom;
|
$form{$key} = &unescape($value); |
}
|
} |
}
|
if ($firsturl =~ m{^/tiny/$match_domain/\w+$}) { |
}
|
$form{'firsturl'} = $firsturl; |
}
|
} |
}
|
my $upass = &Apache::loncommon::des_decrypt($des_key,$form{'upass0'}); |
} else {
|
|
&Apache::lonnet::logthis('Non-privileged user attempting switch user');
|
# ---------------------------------------------------------------- Authenticate |
}
|
|
}
|
my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'}); |
|
my ($cancreate,$statustocreate) = |
my ($is_balancer,$otherserver);
|
&Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'}); |
|
my $defaultauth; |
unless ($hosthere) {
|
if (ref($cancreate) eq 'ARRAY') { |
($is_balancer,$otherserver) =
|
if (grep(/^login$/,@{$cancreate})) { |
&Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login');
|
$defaultauth = 1; |
if ($is_balancer) {
|
} |
if ($otherserver eq '') {
|
} |
my $lowest_load;
|
my $clientcancheckhost = 1; |
($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'});
|
my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass, |
if ($lowest_load > 100) {
|
$form{'udom'},$defaultauth, |
$otherserver = &Apache::lonnet::spareserver($lowest_load,$lowest_load,1,$form{'udom'});
|
$clientcancheckhost); |
}
|
|
}
|
# --------------------------------------------------------------------- Failed? |
if ($otherserver ne '') {
|
|
my @hosts = &Apache::lonnet::current_machine_ids();
|
if ($authhost eq 'no_host') { |
if (grep(/^\Q$otherserver\E$/,@hosts)) {
|
my $pwdverify; |
$hosthere = $otherserver;
|
if (&Apache::lonnet::homeserver($form{'uname'},$form{'udom'}) eq 'no_host') { |
}
|
my %possunames = &alternate_unames_check($form{'uname'},$form{'udom'}); |
}
|
if (keys(%possunames) > 0) { |
}
|
foreach my $rulematch (keys(%possunames)) { |
}
|
my $possuname = $possunames{$rulematch}; |
|
if (($possuname ne '') && ($possuname =~ /^$match_username$/)) { |
if (($is_balancer) && (!$hosthere)) {
|
$authhost=Apache::lonnet::authenticate($possuname,$upass, |
if ($otherserver) {
|
$form{'udom'},undef, |
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
|
$clientcancheckhost); |
\%form);
|
if (($authhost eq 'no_host') || ($authhost eq 'no_account_on_host')) { |
my $switchto = '/adm/switchserver?otherserver='.$otherserver;
|
next; |
if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
|
} elsif (($authhost ne '') && (&Apache::lonnet::hostname($authhost) ne '')) { |
$switchto .= '&origurl='.$firsturl;
|
$pwdverify = 1; |
}
|
&Apache::lonnet::logthis("Authenticated user: $possuname was submitted as: $form{'uname'}"); |
if ($form{'role'}) {
|
$form{'uname'} = $possuname; |
$switchto .= '&role='.$form{'role'};
|
last; |
}
|
} |
if ($form{'symb'}) {
|
} |
$switchto .= '&symb='.$form{'symb'};
|
} |
}
|
} |
$r->internal_redirect($switchto);
|
} |
} else {
|
unless ($pwdverify) { |
$r->print(&noswitch());
|
&failed($r,'Username and/or password could not be authenticated.', |
}
|
\%form); |
return OK;
|
return OK; |
} else {
|
} |
if (!&check_can_host($r,\%form,$authhost)) {
|
} elsif ($authhost eq 'no_account_on_host') { |
my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});
|
if ($defaultauth) { |
if ($otherserver) {
|
my $domdesc = &Apache::lonnet::domain($form{'udom'},'description'); |
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
|
unless (&check_can_host($r,\%form,'no_account_on_host',$domdesc)) { |
\%form);
|
return OK; |
my $switchto = '/adm/switchserver?otherserver='.$otherserver;
|
} |
if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
|
my $start_page = |
$switchto .= '&origurl='.$firsturl;
|
&Apache::loncommon::start_page('Create a user account in LON-CAPA', |
}
|
'',{'no_inline_link' => 1,}); |
if ($form{'role'}) {
|
my $lonhost = $r->dir_config('lonHostID'); |
$switchto .= '&role='.$form{'role'};
|
my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; |
}
|
my $contacts = |
if ($form{'symb'}) {
|
&Apache::loncommon::build_recipient_list(undef,'helpdeskmail', |
$switchto .= '&symb='.$form{'symb'};
|
$form{'udom'},$origmail); |
}
|
my ($contact_email) = split(',',$contacts); |
$r->internal_redirect($switchto);
|
my $output = |
} else {
|
&Apache::createaccount::username_check($form{'uname'},$form{'udom'}, |
$r->print(&noswitch());
|
$domdesc,'',$lonhost, |
}
|
$contact_email,$contact_name, |
return OK;
|
undef,$statustocreate); |
}
|
&Apache::loncommon::content_type($r,'text/html'); |
|
$r->send_http_header; |
# ------------------------------------------------------- Do the load balancing
|
&Apache::createaccount::print_header($r,$start_page); |
|
$r->print('<h3>'.&mt('Account creation').'</h3>'. |
# ---------------------------------------------------------- Determine own load
|
&mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account at this institution.').'<br />'. |
my $loadlim = $r->dir_config('lonLoadLim');
|
$output.&Apache::loncommon::end_page()); |
my $loadavg;
|
return OK; |
{
|
} else { |
my $loadfile=Apache::File->new('/proc/loadavg');
|
&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); |
$loadavg=<$loadfile>;
|
return OK; |
}
|
} |
$loadavg =~ s/\s.*//g;
|
} |
my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
|
|
my $userloadpercent=&Apache::lonnet::userload();
|
if (($firsturl eq '') || |
|
($firsturl=~/^\/adm\/(logout|remote)/)) { |
# ---------------------------------------------------------- Are we overloaded?
|
$firsturl='/adm/roles'; |
if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
|
} |
my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent,1,$form{'udom'});
|
|
if (!$unloaded) {
|
my ($hosthere,%sessiondata); |
($unloaded) = &Apache::lonnet::choose_server($form{'udom'});
|
if ($form{'iptoken'}) { |
}
|
%sessiondata = &Apache::lonnet::tmpget($form{'iptoken'}); |
if ($unloaded) {
|
my $delete = &Apache::lonnet::tmpdel($form{'iptoken'}); |
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',
|
if (($sessiondata{'domain'} eq $form{'udom'}) && |
undef,\%form);
|
($sessiondata{'username'} eq $form{'uname'})) { |
$r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);
|
$hosthere = 1; |
return OK;
|
} |
}
|
} |
}
|
|
if (($is_balancer) && ($hosthere)) {
|
# --------------------------------- Are we attempting to login as somebody else? |
$form{'noloadbalance'} = $hosthere;
|
if ($form{'suname'}) { |
}
|
my ($suname,$sudom,$sudomref); |
&success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,
|
$suname = $form{'suname'}; |
\%form);
|
$sudom = $form{'udom'}; |
return OK;
|
if ($form{'sudom'}) { |
}
|
unless ($sudom eq $form{'sudom'}) { |
}
|
if (&Apache::lonnet::domain($form{'sudom'})) { |
|
$sudomref = [$form{'sudom'}]; |
sub check_can_host {
|
$sudom = $form{'sudom'}; |
my ($r,$form,$authhost,$domdesc) = @_;
|
} |
return unless (ref($form) eq 'HASH');
|
} |
my $canhost = 1;
|
} |
my $lonhost = $r->dir_config('lonHostID');
|
# ------------ see if the original user has enough privileges to pull this stunt |
my $udom = $form->{'udom'};
|
if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'},$sudomref)) { |
my @intdoms;
|
# ---------------------------------------------------- see if the su-user exists |
my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
|
unless (&Apache::lonnet::homeserver($suname,$sudom) eq 'no_host') { |
if (ref($internet_names) eq 'ARRAY') {
|
# ------------------------------ see if the su-user is not too highly privileged |
@intdoms = @{$internet_names};
|
if (&Apache::lonnet::privileged($suname,$sudom)) { |
}
|
&Apache::lonnet::logthis('Attempted switch user to privileged user'); |
my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
|
} else { |
my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
|
my $noprivswitch; |
unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {
|
# |
my $machine_dom = &Apache::lonnet::host_domain($lonhost);
|
# su-user's home server and user's home server must have one of: |
my $hostname = &Apache::lonnet::hostname($lonhost);
|
# (a) same domain |
my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
|
# (b) same primary library server for the two domains |
my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
|
# (c) same "internet domain" for primary library server(s) for home servers' domains |
my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
|
# |
my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);
|
my $suprim = &Apache::lonnet::domain($sudom,'primary'); |
my $loncaparev;
|
my $suintdom = &Apache::lonnet::internet_dom($suprim); |
if ($authhost eq 'no_account_on_host') {
|
unless ($sudom eq $form{'udom'}) { |
$loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom);
|
my $uprim = &Apache::lonnet::domain($form{'udom'},'primary'); |
} else {
|
my $uintdom = &Apache::lonnet::internet_dom($uprim); |
$loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost);
|
unless ($suprim eq $uprim) { |
}
|
unless ($suintdom eq $uintdom) { |
$canhost = &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev,
|
&Apache::lonnet::logthis('Attempted switch user ' |
$udomdefaults{'remotesessions'},
|
.'to user with different "internet domain".'); |
$defdomdefaults{'hostedsessions'});
|
$noprivswitch = 1; |
}
|
} |
unless ($canhost) {
|
} |
if ($authhost eq 'no_account_on_host') {
|
} |
my $checkloginvia = 1;
|
|
my ($login_host,$hostname) =
|
unless ($noprivswitch) { |
&Apache::lonnet::choose_server($udom,$checkloginvia);
|
# |
&Apache::loncommon::content_type($r,'text/html');
|
# server where log-in occurs must have same "internet domain" as su-user's home |
$r->send_http_header;
|
# server |
if ($login_host ne '') {
|
# |
my $protocol = $Apache::lonnet::protocol{$login_host};
|
my $lonhost = $r->dir_config('lonHostID'); |
$protocol = 'http' if ($protocol ne 'https');
|
my $hostintdom = &Apache::lonnet::internet_dom($lonhost); |
my $newurl = $protocol.'://'.$hostname.'/adm/createaccount';
|
if ($hostintdom ne $suintdom) { |
$r->print(&Apache::loncommon::start_page('Create a user account in LON-CAPA').
|
&Apache::lonnet::logthis('Attempted switch user on a ' |
'<h3>'.&mt('Account creation').'</h3>'.
|
.'server with a different "internet domain".'); |
&mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.
|
} else { |
'<p>'.&mt('You will be able to create one by logging into a LON-CAPA server within the [_1] domain.',$domdesc).'</p>'.
|
|
'<p>'.&mt('[_1]Log in[_2]','<a href="'.$newurl.'">','</a>').
|
# -------------------------------------------------------- actually switch users |
&Apache::loncommon::end_page());
|
|
} else {
|
&Apache::lonnet::logperm('User '.$form{'uname'}.' at '. |
$r->print(&Apache::loncommon::start_page('Access to LON-CAPA unavailable').
|
$form{'udom'}.' logging in as '.$suname.':'.$sudom); |
'<h3>'.&mt('Account creation unavailable').'</h3>'.
|
$form{'uname'}=$suname; |
&mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.
|
if ($form{'udom'} ne $sudom) { |
'<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>'.
|
$form{'udom'}=$sudom; |
&Apache::loncommon::end_page());
|
} |
}
|
} |
} else {
|
} |
&success($r,$form->{'uname'},$udom,$authhost,'noredirect',undef,
|
} |
$form);
|
} |
my ($otherserver) = &Apache::lonnet::choose_server($udom);
|
} else { |
$r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);
|
&Apache::lonnet::logthis('Non-privileged user attempting switch user'); |
}
|
} |
}
|
} |
return $canhost;
|
|
}
|
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
|
if (($form{'linkprot'}) && ($form{'linkprotuser'} ne '')) { |
sub noswitch {
|
unless($form{'linkprotuser'} eq $form{'uname'}.':'.$form{'udom'}) { |
my $result = &Apache::loncommon::start_page('Access to LON-CAPA unavailable').
|
delete($form{'udom'}); |
'<h3>'.&mt('Session unavailable').'</h3>'.
|
delete($form{'uname'}); |
&mt('This LON-CAPA server is unable to host your session.').'<br />'.
|
&failed($r,'Username and/or domain are different to that expected for the link you followed from another system', |
'<p>'.&mt('Currently no other LON-CAPA server is available to host your session either.').'</p>'.
|
\%form,$authhost); |
&Apache::loncommon::end_page();
|
return OK; |
return $result;
|
} |
}
|
} |
|
} |
sub loginhelpdisplay {
|
|
my ($authdomain) = @_;
|
my ($is_balancer,$otherserver); |
my $login_help = 1;
|
|
my $lang = &Apache::lonlocal::current_language();
|
unless ($hosthere) { |
if ($login_help) {
|
($is_balancer,$otherserver) = |
my $dom = $authdomain;
|
&Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login'); |
if ($dom eq '') {
|
if ($is_balancer) { |
$dom = &Apache::lonnet::default_login_domain();
|
# Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer) |
}
|
my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r); |
my %domconfhash = &Apache::loncommon::get_domainconf($dom);
|
if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) { |
my $loginhelp_url;
|
$otherserver = $found_server; |
if ($lang) {
|
} |
$loginhelp_url = $domconfhash{$dom.'.login.helpurl_'.$lang};
|
if ($otherserver eq '') { |
if ($loginhelp_url ne '') {
|
my $lowest_load; |
return $loginhelp_url;
|
($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'}); |
}
|
if ($lowest_load > 100) { |
}
|
$otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$form{'udom'}); |
$loginhelp_url = $domconfhash{$dom.'.login.helpurl_nolang'};
|
} |
if ($loginhelp_url ne '') {
|
} |
return $loginhelp_url;
|
if ($otherserver ne '') { |
} else {
|
my @hosts = &Apache::lonnet::current_machine_ids(); |
return '/adm/loginproblems.html';
|
if (grep(/^\Q$otherserver\E$/,@hosts)) { |
}
|
$hosthere = $otherserver; |
}
|
} |
return;
|
} |
}
|
} |
|
} |
1;
|
|
__END__
|
if (($is_balancer) && (!$hosthere)) { |
|
if ($otherserver) { |
|
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef, |
|
\%form); |
|
my $switchto = '/adm/switchserver?otherserver='.$otherserver; |
|
if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) { |
|
$switchto .= '&origurl='.$firsturl; |
|
} |
|
if ($form{'role'}) { |
|
$switchto .= '&role='.$form{'role'}; |
|
} |
|
if ($form{'symb'}) { |
|
$switchto .= '&symb='.$form{'symb'}; |
|
} |
|
if ($form{'linkprot'}) { |
|
$env{'request.linkprot'} = $form{'linkprot'}; |
|
foreach my $item ('linkprotuser','linkprotexit') { |
|
if ($form{$item}) { |
|
$env{'request.'.$item} = $form{$item}; |
|
} |
|
} |
|
} elsif ($form{'linkkey'} ne '') { |
|
$env{'request.linkkey'} = $form{'linkkey'}; |
|
} |
|
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
|
&set_deeplink_login(%form); |
|
} |
|
$r->internal_redirect($switchto); |
|
} else { |
|
&Apache::loncommon::content_type($r,'text/html'); |
|
$r->send_http_header; |
|
$r->print(&noswitch()); |
|
} |
|
return OK; |
|
} else { |
|
if (!&check_can_host($r,\%form,$authhost)) { |
|
my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'}); |
|
if ($otherserver) { |
|
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef, |
|
\%form); |
|
my $switchto = '/adm/switchserver?otherserver='.$otherserver; |
|
if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) { |
|
$switchto .= '&origurl='.$firsturl; |
|
} |
|
if ($form{'role'}) { |
|
$switchto .= '&role='.$form{'role'}; |
|
} |
|
if ($form{'symb'}) { |
|
$switchto .= '&symb='.$form{'symb'}; |
|
} |
|
if ($form{'linkprot'}) { |
|
$env{'request.linkprot'} = $form{'linkprot'}; |
|
foreach my $item ('linkprotuser','linkprotexit') { |
|
if ($form{$item}) { |
|
$env{'request.'.$item} = $form{$item}; |
|
} |
|
} |
|
} elsif ($form{'linkkey'} ne '') { |
|
$env{'request.linkkey'} = $form{'linkkey'}; |
|
} |
|
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
|
&set_deeplink_login(%form); |
|
} |
|
$r->internal_redirect($switchto); |
|
} else { |
|
&Apache::loncommon::content_type($r,'text/html'); |
|
$r->send_http_header; |
|
$r->print(&noswitch()); |
|
} |
|
return OK; |
|
} |
|
|
|
# ------------------------------------------------------- Do the load balancing |
|
|
|
# ---------------------------------------------------------- Determine own load |
|
my $loadlim = $r->dir_config('lonLoadLim'); |
|
my $loadavg; |
|
{ |
|
my $loadfile=Apache::File->new('/proc/loadavg'); |
|
$loadavg=<$loadfile>; |
|
} |
|
$loadavg =~ s/\s.*//g; |
|
my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim); |
|
my $userloadpercent=&Apache::lonnet::userload(); |
|
|
|
# ---------------------------------------------------------- Are we overloaded? |
|
if ((($userloadpercent>100.0)||($loadpercent>100.0))) { |
|
my $unloaded=Apache::lonnet::spareserver($r,$loadpercent,$userloadpercent,1,$form{'udom'}); |
|
if (!$unloaded) { |
|
($unloaded) = &Apache::lonnet::choose_server($form{'udom'}); |
|
} |
|
if ($unloaded) { |
|
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect', |
|
undef,\%form); |
|
if ($form{'linkprot'}) { |
|
$env{'request.linkprot'} = $form{'linkprot'}; |
|
} elsif ($form{'linkkey'} ne '') { |
|
$env{'request.linkkey'} = $form{'linkkey'}; |
|
} |
|
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
|
&set_deeplink_login(%form); |
|
} |
|
$r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl); |
|
return OK; |
|
} |
|
} |
|
if (($is_balancer) && ($hosthere)) { |
|
$form{'noloadbalance'} = $hosthere; |
|
} |
|
my $extra_env; |
|
if (($hosthere) && ($sessiondata{'sessionserver'} ne '')) { |
|
if ($sessiondata{'origurl'} ne '') { |
|
$firsturl = $sessiondata{'origurl'}; |
|
$form{'firsturl'} = $sessiondata{'origurl'}; |
|
my @names = ('role','symb','linkprot','linkkey'); |
|
foreach my $item (@names) { |
|
if ($sessiondata{$item} ne '') { |
|
$form{$item} = $sessiondata{$item}; |
|
} |
|
} |
|
} |
|
} |
|
if ($form{'linkprot'}) { |
|
my ($linkprotector,$uri) = split(/:/,$form{'linkprot'},2); |
|
if ($linkprotector) { |
|
$extra_env = {'user.linkprotector' => $linkprotector, |
|
'user.linkproturi' => $uri}; |
|
} |
|
} elsif ($form{'linkkey'} ne '') { |
|
$extra_env = {'user.deeplinkkey' => $form{'linkkey'}, |
|
'user.keyedlinkuri' => $form{'firsturl'}}; |
|
} |
|
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
|
&set_deeplink_login(%form); |
|
if ($form{'linkprot'}) { |
|
if (ref($extra_env) eq 'HASH') { |
|
%{$extra_env} = ( %{$extra_env}, 'request.linkprot' => $form{'linkprot'} ); |
|
} else { |
|
$extra_env = {'request.linkprot' => $form{'linkprot'}}; |
|
} |
|
if ($form{'linkprotexit'}) { |
|
$extra_env->{'request.linkprotexit'} = $form{'linkprotexit'}; |
|
} |
|
} elsif ($form{'linkkey'} ne '') { |
|
if (ref($extra_env) eq 'HASH') { |
|
%{$extra_env} = ( %{$extra_env}, 'request.linkkey' => $form{'linkkey'} ); |
|
} else { |
|
$extra_env = {'request.linkkey' => $form{'linkkey'}}; |
|
} |
|
} |
|
if ($env{'request.deeplink.login'}) { |
|
if (ref($extra_env) eq 'HASH') { |
|
%{$extra_env} = ( %{$extra_env}, 'request.deeplink.login' => $form{'firsturl'} ); |
|
} else { |
|
$extra_env = {'request.deeplink.login' => $form{'firsturl'}}; |
|
} |
|
} |
|
} |
|
&success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,$extra_env, |
|
\%form); |
|
return OK; |
|
} |
|
} |
|
|
|
sub get_form_items { |
|
my ($r) = @_; |
|
my $buffer; |
|
if ($r->header_in('Content-length') > 0) { |
|
$r->read($buffer,$r->header_in('Content-length'),0); |
|
} |
|
my %form; |
|
foreach my $pair (split(/&/,$buffer)) { |
|
my ($name,$value) = split(/=/,$pair); |
|
$value =~ tr/+/ /; |
|
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; |
|
$form{$name}=$value; |
|
} |
|
return %form; |
|
} |
|
|
|
sub set_deeplink_login { |
|
my (%form) = @_; |
|
my $disallow; |
|
if ($form{'firsturl'} =~ m{^/tiny/($match_domain)/\w+$}) { |
|
my $cdom = $1; |
|
my ($cnum,$symb) = &Apache::loncommon::symb_from_tinyurl($form{'firsturl'},'',$cdom); |
|
if ($symb) { |
|
if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { |
|
my $deeplink; |
|
if ($symb =~ /\.(page|sequence)$/) { |
|
my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($symb))[2]); |
|
my $navmap = Apache::lonnavmaps::navmap->new(); |
|
if (ref($navmap)) { |
|
$deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink'); |
|
} |
|
} else { |
|
$deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb); |
|
} |
|
if ($deeplink ne '') { |
|
my ($state,$others,$listed,$scope,$protect) = split(/,/,$deeplink); |
|
if (($protect ne 'none') && ($protect ne '')) { |
|
my ($acctype,$item) = split(/:/,$protect); |
|
if ($acctype =~ /lti(c|d)$/) { |
|
unless ($form{'linkprot'} eq $item.$1.':'.$env{'request.deeplink.login'}) { |
|
$disallow = 1; |
|
} |
|
} elsif ($acctype eq 'key') { |
|
unless ($form{'linkkey'} eq $item) { |
|
$disallow = 1; |
|
} |
|
} |
|
} |
|
} |
|
unless ($disallow) { |
|
$env{'request.deeplink.login'} = $form{'firsturl'}; |
|
} |
|
} else { |
|
$env{'request.deeplink.login'} = $form{'firsturl'}; |
|
} |
|
} |
|
} |
|
if ($disallow) { |
|
return; |
|
} |
|
return 'ok'; |
|
} |
|
|
|
sub set_retry_token { |
|
my ($form,$lonhost,$querystr) = @_; |
|
if (ref($form) eq 'HASH') { |
|
my ($firsturl,$token,$extras,@names); |
|
@names = ('role','symb','linkprotuser','linkprotexit','linkprot','linkkey','iptoken'); |
|
foreach my $name (@names) { |
|
if ($form->{$name} ne '') { |
|
$extras .= '&'.$name.'='.&escape($form->{$name}); |
|
last if ($name eq 'linkprot'); |
|
} |
|
} |
|
my $firsturl = $form->{'firsturl'}; |
|
if (($firsturl ne '') || ($extras ne '')) { |
|
$extras .= ':retry'; |
|
$token = &Apache::lonnet::reply('tmpput:'.&escape($firsturl). |
|
$extras,$lonhost); |
|
if (($token eq 'con_lost') || ($token eq 'no_such_host')) { |
|
return 'fail'; |
|
} else { |
|
if (ref($querystr)) { |
|
$$querystr = 'retry='.$token; |
|
} |
|
return 'ok'; |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
sub check_can_host { |
|
my ($r,$form,$authhost,$domdesc) = @_; |
|
return unless (ref($form) eq 'HASH'); |
|
my $canhost = 1; |
|
my $lonhost = $r->dir_config('lonHostID'); |
|
my $udom = $form->{'udom'}; |
|
my @intdoms; |
|
my $internet_names = &Apache::lonnet::get_internet_names($lonhost); |
|
if (ref($internet_names) eq 'ARRAY') { |
|
@intdoms = @{$internet_names}; |
|
} |
|
my $uprimary_id = &Apache::lonnet::domain($udom,'primary'); |
|
my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id); |
|
unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) { |
|
my $machine_dom = &Apache::lonnet::host_domain($lonhost); |
|
my $hostname = &Apache::lonnet::hostname($lonhost); |
|
my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname); |
|
my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID); |
|
my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom); |
|
my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom); |
|
my $loncaparev; |
|
if ($authhost eq 'no_account_on_host') { |
|
$loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom); |
|
} else { |
|
$loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost); |
|
} |
|
$canhost = &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev, |
|
$udomdefaults{'remotesessions'}, |
|
$defdomdefaults{'hostedsessions'}); |
|
} |
|
unless ($canhost) { |
|
if ($authhost eq 'no_account_on_host') { |
|
my $checkloginvia = 1; |
|
my ($login_host,$hostname) = |
|
&Apache::lonnet::choose_server($udom,$checkloginvia); |
|
&Apache::loncommon::content_type($r,'text/html'); |
|
$r->send_http_header; |
|
if ($login_host ne '') { |
|
my $protocol = $Apache::lonnet::protocol{$login_host}; |
|
$protocol = 'http' if ($protocol ne 'https'); |
|
my $alias = &Apache::lonnet::use_proxy_alias($r,$login_host); |
|
$hostname = $alias if ($alias ne ''); |
|
my $newurl = $protocol.'://'.$hostname.'/adm/createaccount'; |
|
#FIXME Should preserve where user was going and linkprot by setting ltoken at $login_host |
|
$r->print(&Apache::loncommon::start_page('Create a user account in LON-CAPA'). |
|
'<h3>'.&mt('Account creation').'</h3>'. |
|
&mt('You do not currently have a LON-CAPA account at this institution.').'<br />'. |
|
'<p>'.&mt('You will be able to create one by logging into a LON-CAPA server within the [_1] domain.',$domdesc).'</p>'. |
|
'<p>'.&mt('[_1]Log in[_2]','<a href="'.$newurl.'">','</a>'). |
|
&Apache::loncommon::end_page()); |
|
} else { |
|
$r->print(&Apache::loncommon::start_page('Access to LON-CAPA unavailable'). |
|
'<h3>'.&mt('Account creation unavailable').'</h3>'. |
|
&mt('You do not currently have a LON-CAPA account at this institution.').'<br />'. |
|
'<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>'. |
|
&Apache::loncommon::end_page()); |
|
} |
|
} else { |
|
&success($r,$form->{'uname'},$udom,$authhost,'noredirect',undef, |
|
$form); |
|
if ($form->{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
|
$env{'request.deeplink.login'} = $form->{'firsturl'}; |
|
} |
|
if ($form->{'linkprot'}) { |
|
$env{'request.linkprot'} = $form->{'linkprot'}; |
|
} elsif ($form->{'linkkey'} ne '') { |
|
$env{'request.linkkey'} = $form->{'linkkey'}; |
|
} |
|
my ($otherserver) = &Apache::lonnet::choose_server($udom); |
|
$r->internal_redirect('/adm/switchserver?otherserver='.$otherserver); |
|
} |
|
} |
|
return $canhost; |
|
} |
|
|
|
sub noswitch { |
|
my $result = &Apache::loncommon::start_page('Access to LON-CAPA unavailable'). |
|
'<h3>'.&mt('Session unavailable').'</h3>'. |
|
&mt('This LON-CAPA server is unable to host your session.').'<br />'. |
|
'<p>'.&mt('Currently no other LON-CAPA server is available to host your session either.').'</p>'. |
|
&Apache::loncommon::end_page(); |
|
return $result; |
|
} |
|
|
|
sub loginhelpdisplay { |
|
my ($authdomain) = @_; |
|
my $login_help = 1; |
|
my $lang = &Apache::lonlocal::current_language(); |
|
if ($login_help) { |
|
my $dom = $authdomain; |
|
if ($dom eq '') { |
|
$dom = &Apache::lonnet::default_login_domain(); |
|
} |
|
my %domconfhash = &Apache::loncommon::get_domainconf($dom); |
|
my $loginhelp_url; |
|
if ($lang) { |
|
$loginhelp_url = $domconfhash{$dom.'.login.helpurl_'.$lang}; |
|
if ($loginhelp_url ne '') { |
|
return $loginhelp_url; |
|
} |
|
} |
|
$loginhelp_url = $domconfhash{$dom.'.login.helpurl_nolang'}; |
|
if ($loginhelp_url ne '') { |
|
return $loginhelp_url; |
|
} else { |
|
return '/adm/loginproblems.html'; |
|
} |
|
} |
|
return; |
|
} |
|
|
|
sub alternate_unames_check { |
|
my ($uname,$udom) = @_; |
|
my %possunames; |
|
my %domdefs = &Apache::lonnet::get_domain_defaults($udom); |
|
if (ref($domdefs{'unamemap_rule'}) eq 'ARRAY') { |
|
if (@{$domdefs{'unamemap_rule'}} > 0) { |
|
%possunames = |
|
&Apache::lonnet::inst_rulecheck($udom,$uname,undef, |
|
'unamemap',$domdefs{'unamemap_rule'}); |
|
} |
|
} |
|
return %possunames; |
|
} |
|
|
|
1; |
|
__END__ |
|
|
|
|
|