version 1.121.2.24.2.4, 2022/07/08 15:40:03
|
version 1.166, 2021/08/10 15:28: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 Apache::ltiauth;
|
use Apache::lonlocal; |
use Fcntl qw(:flock);
|
use Apache::File(); |
use Apache::lonlocal;
|
use HTML::Entities; |
use Apache::File();
|
use Digest::MD5; |
use HTML::Entities;
|
use CGI::Cookie(); |
use Digest::MD5;
|
|
|
# ------------------------------------------------------------ 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,$cid,$expirepub) = @_; |
$form,$skipcritical,$cid) = @_;
|
|
|
# ------------------------------------------------------------ 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
|
|
|
my $ip = &Apache::lonnet::get_requestor_ip(); |
my $ip = &Apache::lonnet::get_requestor_ip();
|
&Apache::lonnet::log($domain,$username,$authhost, |
&Apache::lonnet::log($domain,$username,$authhost,
|
"Login $ip"); |
"Login $ip");
|
|
|
# ------------------------------------------------- Check for critical messages |
# ------------------------------------------------- Check for critical messages
|
|
|
my @what=&Apache::lonnet::dump('critical',$domain,$username); |
unless ($skipcritical) {
|
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); |
|
my $ssl = $r->subprocess_env('https'); |
# ----------------------------------------------------------- Get cookies ready
|
if ($ssl) { |
my ($securecookie,$defaultcookie);
|
$securecookie="lonSID=$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' => $linkname}); |
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}; |
if ($env{'request.lti.login'}) {
|
my $now=time; |
if (($env{'request.lti.reqcrs'}) && ($env{'request.lti.reqrole'} eq 'cc')) {
|
my $then=$env{'user.login.time'}; |
&Apache::loncommon::content_type($r,'text/html');
|
my $refresh=$env{'user.refresh.time'}; |
if ($securecookie) {
|
my $update=$env{'user.update.time'}; |
$r->headers_out->add('Set-cookie' => $securecookie);
|
if (!$update) { |
}
|
$update = $then; |
if ($defaultcookie) {
|
} |
$r->headers_out->add('Set-cookie' => $defaultcookie);
|
if (exists($env{$envkey})) { |
}
|
my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus); |
$r->send_http_header;
|
&Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where, |
if (ref($form) eq 'HASH') {
|
\$trolecode,\$tstatus,\$tstart,\$tend); |
$form->{'lti.login'} = $env{'request.lti.login'};
|
if ($tstatus eq 'is') { |
$form->{'lti.reqcrs'} = $env{'request.lti.reqcrs'};
|
$destination .= ($destination =~ /\?/) ? '&' : '?'; |
$form->{'lti.reqrole'} = $env{'request.lti.reqrole'};
|
my $newrole = &HTML::Entities::encode($form->{role},'"<>&'); |
$form->{'lti.sourcecrs'} = $env{'request.lti.sourcecrs'};
|
$destination .= 'selectrole=1&'.$newrole.'=1'; |
}
|
} |
&Apache::ltiauth::lti_reqcrs($r,$domain,$form,$username,$domain);
|
} |
return;
|
} |
}
|
if (defined($form->{symb})) { |
if ($env{'request.lti.selfenrollrole'}) {
|
my $destsymb = $form->{symb}; |
if (&Apache::ltiauth::lti_enroll($username,$domain,
|
my $encrypted; |
$env{'request.lti.selfenrollrole'}) eq 'ok') {
|
if ($destsymb =~ m{^/enc/}) { |
$form->{'role'} = $env{'request.lti.selfenrollrole'};
|
$encrypted = 1; |
&Apache::lonnet::delenv('request.lti.selfenrollrole');
|
if ($cid) { |
} else {
|
$destsymb = &Apache::lonenc::unencrypted($destsymb,$cid); |
&Apache::ltiauth::invalid_request($r,24);
|
} |
}
|
} |
}
|
$destination .= ($destination =~ /\?/) ? '&' : '?'; |
}
|
if ($destsymb =~ /___/) { |
if (defined($form->{role})) {
|
my ($map,$resid,$desturl)=split(/___/,$destsymb); |
my $envkey = 'user.role.'.$form->{role};
|
$desturl = &Apache::lonnet::clutter($desturl); |
my $now=time;
|
if ($encrypted) { |
my $then=$env{'user.login.time'};
|
$desturl = &Apache::lonenc::encrypted($desturl,1,$cid); |
my $refresh=$env{'user.refresh.time'};
|
$destsymb = $form->{symb}; |
my $update=$env{'user.update.time'};
|
} |
if (!$update) {
|
$desturl = &HTML::Entities::encode($desturl,'"<>&'); |
$update = $then;
|
$destsymb = &HTML::Entities::encode($destsymb,'"<>&'); |
}
|
$destination .= 'destinationurl='.$desturl. |
if (exists($env{$envkey})) {
|
'&destsymb='.$destsymb; |
my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus);
|
} elsif (!$encrypted) { |
&Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
|
$destsymb = &HTML::Entities::encode($destsymb,'"<>&'); |
\$trolecode,\$tstatus,\$tstart,\$tend);
|
$destination .= 'destinationurl='.$destsymb; |
if ($tstatus eq 'is') {
|
} |
$destination .= ($destination =~ /\?/) ? '&' : '?';
|
} |
my $newrole = &HTML::Entities::encode($form->{role},'"<>&');
|
if ($destination =~ m{^/adm/roles}) { |
$destination .= 'selectrole=1&'.$newrole.'=1';
|
$destination .= ($destination =~ /\?/) ? '&' : '?'; |
}
|
$destination .= 'source=login'; |
}
|
} |
}
|
|
if (defined($form->{symb})) {
|
my $brcrum = [{'href' => '', |
my $destsymb = $form->{symb};
|
'text' => 'Successful Login'},]; |
my $encrypted;
|
my $args = {'no_inline_link' => 1, |
if ($destsymb =~ m{^/enc/}) {
|
'bread_crumbs' => $brcrum,}; |
$encrypted = 1;
|
if (($env{'request.deeplink.login'} eq $lowerurl) && |
if ($cid) {
|
(($env{'request.linkprot'}) || ($env{'request.linkkey'} ne ''))) { |
$destsymb = &Apache::lonenc::unencrypted($destsymb,$cid);
|
my %info; |
}
|
if ($env{'request.linkprot'}) { |
}
|
$info{'linkprot'} = $env{'request.linkprot'}; |
$destination .= ($destination =~ /\?/) ? '&' : '?';
|
foreach my $item ('linkprotuser','linkprotexit') { |
if ($destsymb =~ /___/) {
|
if ($form->{$item}) { |
my ($map,$resid,$desturl)=split(/___/,$destsymb);
|
$info{$item} = $form->{$item}; |
$desturl = &Apache::lonnet::clutter($desturl);
|
} |
if ($encrypted) {
|
} |
$desturl = &Apache::lonenc::encrypted($desturl,1,$cid);
|
$args = {'only_body' => 1,}; |
$destsymb = $form->{symb};
|
} elsif ($env{'request.linkkey'} ne '') { |
}
|
$info{'linkkey'} = $env{'request.linkkey'}; |
$desturl = &HTML::Entities::encode($desturl,'"<>&');
|
} |
$destsymb = &HTML::Entities::encode($destsymb,'"<>&');
|
$info{'origurl'} = $lowerurl; |
$destination .= 'destinationurl='.$desturl.
|
my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'link'); |
'&destsymb='.$destsymb;
|
unless (($token eq 'con_lost') || ($token eq 'refused') || |
} elsif (!$encrypted) {
|
($token eq 'unknown_cmd') || ($token eq 'no_such_host')) { |
$destsymb = &HTML::Entities::encode($destsymb,'"<>&');
|
$destination .= (($destination =~ /\?/) ? '&' : '?') . 'ttoken='.$token; |
$destination .= 'destinationurl='.$destsymb;
|
} |
}
|
} |
}
|
if ($env{'request.deeplink.login'}) { |
if ($destination =~ m{^/adm/roles}) {
|
if ($env{'environment.remote'} eq 'on') { |
$destination .= ($destination =~ /\?/) ? '&' : '?';
|
&Apache::lonnet::appenv({'environment.remote' => 'off'}); |
$destination .= 'source=login';
|
} |
}
|
} |
|
|
my $windowname = 'loncapaclient';
|
my $windowinfo=&Apache::lonmenu::open($env{'browser.os'}); |
if ($env{'request.lti.login'}) {
|
my $startupremote=&Apache::lonmenu::startupremote($destination); |
$windowname .= 'lti';
|
my $remoteinfo=&Apache::lonmenu::load_remote_msg($lowerurl); |
}
|
my $setflags=&Apache::lonmenu::setflags(); |
my $windowinfo = Apache::lonhtmlcommon::scripttag('self.name="'.$windowname.'";');
|
my $maincall=&Apache::lonmenu::maincall(); |
my $brcrum = [{'href' => '',
|
my $start_page=&Apache::loncommon::start_page('Successful Login', |
'text' => 'Successful Login'},];
|
$startupremote,$args); |
my $args = {'bread_crumbs' => $brcrum,};
|
my $end_page =&Apache::loncommon::end_page(); |
unless ((defined($form->{role})) || (defined($form->{symb}))) {
|
|
my $update=$env{'user.update.time'};
|
my $continuelink; |
if (!$update) {
|
if ($env{'environment.remote'} eq 'off') { |
$update = $env{'user.login.time'};
|
$continuelink='<a href="'.$destination.'">'.&mt('Continue').'</a>'; |
}
|
} |
my %roles_in_env;
|
# ------------------------------------------------- Output for successful login |
my $showcount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
|
|
if ($showcount == 1) {
|
&Apache::loncommon::content_type($r,'text/html'); |
foreach my $rolecode (keys(%roles_in_env)) {
|
if ($securecookie) { |
my ($cid) = ($rolecode =~ m{^\Quser.role.st./\E($match_domain/$match_courseid)(?:/|$)});
|
$r->headers_out->add('Set-cookie' => $securecookie); |
if ($cid) {
|
} |
my %coursedescription =
|
if ($defaultcookie) { |
&Apache::lonnet::coursedescription($cid,{'one_time' => '1'});
|
$r->headers_out->add('Set-cookie' => $defaultcookie); |
if ($coursedescription{'type'} eq 'Placement') {
|
} |
$args->{'crstype'} = 'Placement';
|
if ($expirepub) { |
}
|
my $c = new CGI::Cookie(-name => 'lonPubID', |
last;
|
-value => '', |
}
|
-expires => '-10y',); |
}
|
$r->headers_out->add('Set-cookie' => $c); |
}
|
} |
}
|
$r->send_http_header; |
|
|
# ------------------------------------------------- Output for successful login
|
if ($env{'request.linkprot'}) { |
|
$r->print(<<END); |
&Apache::loncommon::content_type($r,'text/html');
|
$start_page |
if ($securecookie) {
|
<br />$continuelink |
$r->headers_out->add('Set-cookie' => $securecookie);
|
$end_page |
}
|
END |
if ($defaultcookie) {
|
} else { |
$r->headers_out->add('Set-cookie' => $defaultcookie);
|
my %lt=&Apache::lonlocal::texthash( |
}
|
'wel' => 'Welcome', |
$r->send_http_header;
|
'pro' => 'Login problems?', |
|
); |
my ($start_page,$js,$pagebody,$end_page);
|
my $loginhelp = &loginhelpdisplay($domain); |
if ($env{'request.lti.login'}) {
|
if ($loginhelp) { |
$args = {'only_body' => 1};
|
$loginhelp = '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>'; |
if ($env{'request.lti.target'} eq '') {
|
} |
my $ltitarget = (($destination =~ /\?/) ? '&' : '?').
|
|
'ltitarget=iframe';
|
my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>'); |
$js = <<"ENDJS";
|
$r->print(<<ENDSUCCESS); |
|
$start_page |
<script type="text/javascript">
|
$setflags |
// <![CDATA[
|
$windowinfo |
function setLTItarget() {
|
<h1>$lt{'wel'}</h1> |
var newloc = '$destination';
|
$welcome |
if (parent !== window) {
|
$loginhelp |
newloc += '$ltitarget';
|
$remoteinfo |
}
|
$maincall |
window.location.href=newloc;
|
$continuelink |
}
|
$end_page |
// ]]>
|
ENDSUCCESS |
</script>
|
} |
|
return; |
ENDJS
|
} |
$args->{'add_entries'} = {'onload' => "javascript:setLTItarget();"};
|
|
$pagebody = '<noscript><span class="LC_warning">'
|
# --------------------------------------------------------------- Failed login! |
.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
|
|
.'</span></noscript>';
|
sub failed { |
} else {
|
my ($r,$message,$form,$authhost) = @_; |
$args->{'redirect'} = [0,$destination,1];
|
(undef,undef,undef,my $clientmathml,my $clientunicode) = |
}
|
&Apache::loncommon::decode_user_agent(); |
$start_page=&Apache::loncommon::start_page('',$js,$args);
|
my $args = {}; |
} else {
|
if ($clientunicode && !$clientmathml) { |
$args->{'redirect'} = [0,$destination];
|
$args = {'browser.unicode' => 1}; |
$start_page=&Apache::loncommon::start_page('Successful Login',
|
} |
$js,$args);
|
if ($form->{firsturl} =~ m{^/tiny/$match_domain/\w+$}) { |
|
if ($form->{linkprot}) { |
my %lt=&Apache::lonlocal::texthash(
|
$args->{only_body} = 1; |
'wel' => 'Welcome',
|
} |
'pro' => 'Login problems?',
|
} |
);
|
|
$pagebody = "<h1>$lt{'wel'}</h1>\n".
|
my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args); |
&mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>');
|
my $uname = &Apache::loncommon::cleanup_html($form->{'uname'}); |
my $loginhelp = &loginhelpdisplay($domain);
|
my $udom = &Apache::loncommon::cleanup_html($form->{'udom'}); |
if ($loginhelp) {
|
if (&Apache::lonnet::domain($udom,'description') eq '') { |
$pagebody .= '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>';
|
undef($udom); |
}
|
} |
}
|
my $retry = '/adm/login'; |
$end_page = &Apache::loncommon::end_page();
|
if ($uname eq $form->{'uname'}) { |
$r->print(<<ENDSUCCESS);
|
$retry .= '?username='.$uname; |
$start_page
|
} |
$windowinfo
|
if ($udom) { |
$pagebody
|
$retry .= (($retry=~/\?/)?'&':'?').'domain='.$udom; |
$end_page
|
} |
ENDSUCCESS
|
my $lonhost = $r->dir_config('lonHostID'); |
return;
|
my $querystr; |
}
|
my $result = &set_retry_token($form,$lonhost,\$querystr); |
|
if ($result eq 'fail') { |
# --------------------------------------------------------------- Failed login!
|
if (exists($form->{role})) { |
|
my $role = &Apache::loncommon::cleanup_html($form->{role}); |
sub failed {
|
if ($role ne '') { |
my ($r,$message,$form) = @_;
|
$retry .= (($retry=~/\?/)?'&':'?').'role='.$role; |
(undef,undef,undef,my $clientmathml,my $clientunicode) =
|
} |
&Apache::loncommon::decode_user_agent();
|
} |
my $args = {};
|
if (exists($form->{symb})) { |
if ($clientunicode && !$clientmathml) {
|
my $symb = &Apache::loncommon::cleanup_html($form->{symb}); |
$args = {'browser.unicode' => 1};
|
if ($symb ne '') { |
}
|
$retry .= (($retry=~/\?/)?'&':'?').'symb='.$symb; |
|
} |
my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args);
|
} |
my $uname = &Apache::loncommon::cleanup_html($form->{'uname'});
|
if (exists($form->{firsturl})) { |
my $udom = &Apache::loncommon::cleanup_html($form->{'udom'});
|
my $firsturl = &Apache::loncommon::cleanup_html($form->{firsturl}); |
if (&Apache::lonnet::domain($udom,'description') eq '') {
|
if ($firsturl ne '') { |
undef($udom);
|
$retry .= (($retry=~/\?/)?'&':'?').'firsturl='.$firsturl; |
}
|
if ($form->{firsturl} =~ m{^/tiny/$match_domain/\w+$}) { |
my $retry = '/adm/login';
|
unless (exists($form->{linkprot})) { |
if ($uname eq $form->{'uname'}) {
|
if (exists($form->{linkkey})) { |
$retry .= '?username='.$uname;
|
$retry .= 'linkkey='.$form->{linkkey}; |
}
|
} |
if ($udom) {
|
} |
$retry .= (($retry=~/\?/)?'&':'?').'domain='.$udom;
|
} |
}
|
} |
if (exists($form->{role})) {
|
} |
my $role = &Apache::loncommon::cleanup_html($form->{role});
|
if (exists($form->{linkprot})) { |
if ($role ne '') {
|
my %info = ( |
$retry .= (($retry=~/\?/)?'&':'?').'role='.$role;
|
'linkprot' => $form->{'linkprot'}, |
}
|
); |
}
|
foreach my $item ('linkprotuser','linkprotexit') { |
if (exists($form->{symb})) {
|
if ($form->{$item} ne '') { |
my $symb = &Apache::loncommon::cleanup_html($form->{symb});
|
$info{$item} = $form->{$item}; |
if ($symb ne '') {
|
} |
$retry .= (($retry=~/\?/)?'&':'?').'symb='.$symb;
|
} |
}
|
my $ltoken = &Apache::lonnet::tmpput(\%info, |
}
|
$r->dir_config('lonHostID'),'retry'); |
if (exists($form->{firsturl})) {
|
if ($ltoken) { |
my $firsturl = &Apache::loncommon::cleanup_html($form->{firsturl});
|
$retry .= (($retry =~ /\?/) ? '&' : '?').'ltoken='.$ltoken; |
if ($firsturl ne '') {
|
} |
$retry .= (($retry=~/\?/)?'&':'?').'firsturl='.$firsturl;
|
} |
if ($firsturl =~ m{^/tiny/$match_domain/\w+$}) {
|
} elsif ($querystr ne '') { |
unless (exists($form->{linkprot})) {
|
$retry .= (($retry=~/\?/)?'&':'?').$querystr; |
if (exists($form->{linkkey})) {
|
} |
$retry .= 'linkkey='.$form->{linkkey};
|
my $end_page = &Apache::loncommon::end_page(); |
}
|
&Apache::loncommon::content_type($r,'text/html'); |
}
|
$r->send_http_header; |
}
|
my @actions = |
}
|
(&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>')); |
}
|
my $loginhelp = &loginhelpdisplay($udom); |
if (exists($form->{linkprot})) {
|
if ($loginhelp) { |
my $ltoken = &Apache::lonnet::tmpput({linkprot => $form->{'linkprot'}},
|
push(@actions, '<a href="'.$loginhelp.'">'.&mt('Login problems?').'</a>'); |
$r->dir_config('lonHostID'));
|
} |
if ($ltoken) {
|
#FIXME: link to helpdesk might be added here |
$retry .= (($retry =~ /\?/) ? '&' : '?').'ltoken='.$ltoken;
|
|
}
|
$r->print( |
}
|
$start_page |
my $end_page = &Apache::loncommon::end_page();
|
.'<h2>'.&mt('Sorry ...').'</h2>' |
&Apache::loncommon::content_type($r,'text/html');
|
.&Apache::lonhtmlcommon::confirm_success(&mt($message),1).'<br /><br />' |
$r->send_http_header;
|
.&Apache::lonhtmlcommon::actionbox(\@actions) |
my @actions =
|
.$end_page |
(&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>'));
|
); |
my $loginhelp = &loginhelpdisplay($udom);
|
} |
if ($loginhelp) {
|
|
push(@actions, '<a href="'.$loginhelp.'">'.&mt('Login problems?').'</a>');
|
# ------------------------------------------------------------------ Rerouting! |
}
|
|
#FIXME: link to helpdesk might be added here
|
sub reroute { |
|
my ($r) = @_; |
$r->print(
|
&Apache::loncommon::content_type($r,'text/html'); |
$start_page
|
$r->send_http_header; |
.'<h2>'.&mt('Sorry ...').'</h2>'
|
my $msg='<b>'.&mt('Sorry ...').'</b><br />' |
.&Apache::lonhtmlcommon::confirm_success(&mt($message),1).'<br /><br />'
|
.&mt('Please [_1]log in again[_2].'); |
.&Apache::lonhtmlcommon::actionbox(\@actions)
|
&Apache::loncommon::simple_error_page($r,'Rerouting',$msg,{'no_auto_mt_msg' => 1}); |
.$end_page
|
} |
);
|
|
}
|
# ---------------------------------------------------------------- Main handler |
|
|
# ------------------------------------------------------------------ Rerouting!
|
sub handler { |
|
my $r = shift; |
sub reroute {
|
my $londocroot = $r->dir_config('lonDocRoot'); |
my ($r) = @_;
|
# Are we re-routing? |
&Apache::loncommon::content_type($r,'text/html');
|
if (-e "$londocroot/lon-status/reroute.txt") { |
$r->send_http_header;
|
&reroute($r); |
my $msg='<b>'.&mt('Sorry ...').'</b><br />'
|
return OK; |
.&mt('Please [_1]log in again[_2].');
|
} |
&Apache::loncommon::simple_error_page($r,'Rerouting',$msg,{'no_auto_mt_msg' => 1});
|
|
}
|
&Apache::lonlocal::get_language_handle($r); |
|
|
# ---------------------------------------------------------------- Main handler
|
# -------------------------------- Prevent users from attempting to login twice |
|
my $handle = &Apache::lonnet::check_for_valid_session($r); |
sub handler {
|
if ($handle ne '') { |
my $r = shift;
|
my $lonidsdir=$r->dir_config('lonIDsDir'); |
my $londocroot = $r->dir_config('lonDocRoot');
|
if ($handle=~/^publicuser\_/) { |
# Are we re-routing?
|
# For "public user" - remove it, we apparently really want to login |
if (-e "$londocroot/lon-status/reroute.txt") {
|
unlink($r->dir_config('lonIDsDir')."/$handle.id"); |
&reroute($r);
|
} else { |
return OK;
|
# Indeed, a valid token is found |
}
|
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); |
|
&Apache::loncommon::content_type($r,'text/html'); |
&Apache::lonlocal::get_language_handle($r);
|
$r->send_http_header; |
|
my $start_page = |
# -------------------------------- Prevent users from attempting to login twice
|
&Apache::loncommon::start_page('Already logged in'); |
my $handle = &Apache::lonnet::check_for_valid_session($r);
|
my $end_page = |
if ($handle ne '') {
|
&Apache::loncommon::end_page(); |
my $lonidsdir=$r->dir_config('lonIDsDir');
|
my $dest = '/adm/roles'; |
if ($handle=~/^publicuser\_/) {
|
my %form = &get_form_items($r); |
# For "public user" - remove it, we apparently really want to login
|
if ($form{'logtoken'}) { |
unlink($r->dir_config('lonIDsDir')."/$handle.id");
|
my $tmpinfo = &Apache::lonnet::reply('tmpget:'.$form{'logtoken'}, |
} else {
|
$form{'serverid'}); |
# Indeed, a valid token is found
|
unless (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') || |
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
|
($tmpinfo eq 'no_such_host')) { |
&Apache::loncommon::content_type($r,'text/html');
|
my ($des_key,$firsturl,@rest)=split(/&/,$tmpinfo); |
$r->send_http_header;
|
$firsturl = &unescape($firsturl); |
my $start_page =
|
my %info; |
&Apache::loncommon::start_page('Already logged in');
|
foreach my $item (@rest) { |
my $end_page =
|
my ($key,$value) = split(/=/,$item); |
&Apache::loncommon::end_page();
|
$info{$key} = &unescape($value); |
my $dest = '/adm/roles';
|
} |
if ($env{'form.firsturl'} ne '') {
|
if ($firsturl ne '') { |
$dest = $env{'form.firsturl'};
|
$info{'firsturl'} = $firsturl; |
if (($dest =~ m{^/tiny/$match_domain/\w+$}) && ($env{'request.course.id'})) {
|
$dest = $firsturl; |
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
|
my $relogin; |
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
|
if ($dest =~ m{^/tiny/$match_domain/\w+$}) { |
my $symb = &Apache::loncommon::symb_from_tinyurl($dest,$cnum,$cdom);
|
if ($env{'request.course.id'}) { |
if ($symb) {
|
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
my $buffer;
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
if ($r->header_in('Content-length') > 0) {
|
my $symb = &Apache::loncommon::symb_from_tinyurl($dest,$cnum,$cdom); |
$r->read($buffer,$r->header_in('Content-length'),0);
|
if ($symb) { |
}
|
unless (&set_deeplink_login(%info) eq 'ok') { |
my %form;
|
$relogin = 1; |
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;
|
if ($relogin) { |
$form{$name}=$value;
|
$r->print( |
}
|
$start_page |
&set_deeplink_login(%form);
|
.'<p class="LC_warning">'.&mt('You are already logged in!').'</p>' |
} else {
|
.'<p>'.&mt('Please [_1]log out[_2] first, and then try your access again', |
$r->print(
|
'<a href="/adm/logout">','</a>') |
$start_page
|
.'</p>' |
.'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
|
.$end_page); |
.'<p>'.&mt('Please [_1]log out[_2] first, and then try your access again',
|
} else { |
'<a href="/adm/logout">','</a>')
|
if (($info{'linkprot'}) || ($info{'linkkey'} ne '')) { |
.'</p>'
|
if (($info{'linkprot'}) && ($info{'linkprotuser'} ne '')) { |
.$end_page);
|
unless ($info{'linkprotuser'} eq $env{'user.name'}.':'.$env{'user.domain'}) { |
return OK;
|
$r->print( |
}
|
$start_page |
}
|
.'<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>' |
}
|
.'<p>'.&mt('Please [_1]log out[_2] first, and then try following the link again from the other system', |
$r->print(
|
'<a href="/adm/logout">','</a>') |
$start_page
|
|
.'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
|
.'</p>' |
.'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].'
|
.$end_page); |
,'<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>')
|
return OK; |
.'</p>'
|
} |
.$end_page
|
} |
);
|
my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'link'); |
return OK;
|
unless (($token eq 'con_lost') || ($token eq 'refused') || |
}
|
($token eq 'unknown_cmd') || ($token eq 'no_such_host')) { |
}
|
$dest .= (($dest =~ /\?/) ? '&' : '?') . 'ttoken='.$token; |
|
} |
# ---------------------------------------------------- No valid token, continue
|
} |
|
$r->print( |
|
$start_page |
my $buffer;
|
.'<p class="LC_warning">'.&mt('You are already logged in!').'</p>' |
if ($r->header_in('Content-length') > 0) {
|
.'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4] first, and then try your access again', |
$r->read($buffer,$r->header_in('Content-length'),0);
|
'<a href="'.$dest.'">','</a>', |
}
|
'<a href="/adm/logout">','</a>') |
my %form;
|
.'</p>' |
foreach my $pair (split(/&/,$buffer)) {
|
.$end_page); |
my ($name,$value) = split(/=/,$pair);
|
} |
$value =~ tr/+/ /;
|
return OK; |
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
|
} |
$form{$name}=$value;
|
} |
}
|
} |
|
} |
if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) {
|
$r->print( |
&failed($r,'Username, password and domain need to be specified.',
|
$start_page |
\%form);
|
.'<p class="LC_warning">'.&mt('You are already logged in!').'</p>' |
return OK;
|
.'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].' |
}
|
,'<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>') |
|
.'</p>' |
# split user logging in and "su"-user
|
.$end_page |
|
); |
($form{'uname'},$form{'suname'},$form{'sudom'})=split(/\:/,$form{'uname'});
|
return OK; |
$form{'uname'} = &LONCAPA::clean_username($form{'uname'});
|
} |
$form{'suname'}= &LONCAPA::clean_username($form{'suname'});
|
} |
$form{'udom'} = &LONCAPA::clean_domain($form{'udom'});
|
|
$form{'sudom'} = &LONCAPA::clean_domain($form{'sudom'});
|
# ---------------------------------------------------- No valid token, continue |
|
|
my $role = $r->dir_config('lonRole');
|
my %form = &get_form_items($r); |
my $domain = $r->dir_config('lonDefDomain');
|
if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) { |
my $prodir = $r->dir_config('lonUsersDir');
|
&failed($r,'Username, password and domain need to be specified.', |
my $contact_name = &mt('LON-CAPA helpdesk');
|
\%form); |
|
return OK; |
# ---------------------------------------- Get the information from login token
|
} |
|
|
my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'},
|
# split user logging in and "su"-user |
$form{'serverid'});
|
|
|
($form{'uname'},$form{'suname'},$form{'sudom'})=split(/\:/,$form{'uname'}); |
if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||
|
$form{'uname'} = &LONCAPA::clean_username($form{'uname'}); |
($tmpinfo eq 'no_such_host')) {
|
$form{'suname'}= &LONCAPA::clean_username($form{'suname'}); |
&failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form);
|
$form{'udom'} = &LONCAPA::clean_domain($form{'udom'}); |
return OK;
|
$form{'sudom'} = &LONCAPA::clean_domain($form{'sudom'}); |
} else {
|
|
my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'},
|
my $role = $r->dir_config('lonRole'); |
$form{'serverid'});
|
my $domain = $r->dir_config('lonDefDomain'); |
if ( $reply ne 'ok' ) {
|
my $prodir = $r->dir_config('lonUsersDir'); |
&failed($r,'Session could not be opened.',\%form);
|
my $contact_name = &mt('LON-CAPA helpdesk'); |
&Apache::lonnet::logthis("ERROR got a reply of $reply when trying to contact ". $form{'serverid'}." to get login token");
|
|
return OK;
|
# ---------------------------------------- Get the information from login token |
}
|
|
}
|
my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'}, |
|
$form{'serverid'}); |
if (!&Apache::lonnet::domain($form{'udom'})) {
|
|
&failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form);
|
if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') || |
return OK;
|
($tmpinfo eq 'no_such_host')) { |
}
|
&failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form); |
|
return OK; |
my ($key,$firsturl,$rolestr,$symbstr,$iptokenstr,$linkstr)=split(/&/,$tmpinfo);
|
} else { |
if ($rolestr) {
|
my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'}, |
$rolestr = &unescape($rolestr);
|
$form{'serverid'}); |
}
|
if ( $reply ne 'ok' ) { |
if ($symbstr) {
|
&failed($r,'Session could not be opened.',\%form); |
$symbstr= &unescape($symbstr);
|
&Apache::lonnet::logthis("ERROR got a reply of $reply when trying to contact ". $form{'serverid'}." to get login token"); |
}
|
return OK; |
if ($iptokenstr) {
|
} |
$iptokenstr = &unescape($iptokenstr);
|
} |
}
|
|
if ($linkstr) {
|
if (!&Apache::lonnet::domain($form{'udom'})) { |
$linkstr = &unescape($linkstr);
|
&failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form); |
}
|
return OK; |
if ($firsturl =~ m{^/tiny/$match_domain/\w+$}) {
|
} |
$form{'firsturl'} = $firsturl;
|
|
}
|
my ($des_key,$firsturl,@rest)=split(/&/,$tmpinfo); |
if ($rolestr =~ /^role=/) {
|
$firsturl = &unescape($firsturl); |
(undef,$form{'role'}) = split('=',$rolestr);
|
foreach my $item (@rest) { |
}
|
my ($key,$value) = split(/=/,$item); |
if ($symbstr =~ /^symb=/) {
|
$form{$key} = &unescape($value); |
(undef,$form{'symb'}) = split('=',$symbstr);
|
} |
}
|
if ($firsturl =~ m{^/tiny/$match_domain/\w+$}) { |
if ($iptokenstr =~ /^iptoken=/) {
|
$form{'firsturl'} = $firsturl; |
(undef,$form{'iptoken'}) = split('=',$iptokenstr);
|
} |
}
|
my $upass = &Apache::loncommon::des_decrypt($des_key,$form{'upass0'}); |
if ($linkstr =~ /^linkprot=/) {
|
|
(undef,$form{'linkprot'}) = split('=',$linkstr);
|
# ---------------------------------------------------------------- Authenticate |
} elsif ($linkstr =~ /^linkkey=/) {
|
|
(undef,$form{'linkkey'}) = split('=',$linkstr);
|
my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'}); |
}
|
my ($cancreate,$statustocreate) = |
|
&Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'}); |
my $upass = $ENV{HTTPS} ? $form{'upass0'}
|
my $defaultauth; |
: &Apache::loncommon::des_decrypt($key,$form{'upass0'});
|
if (ref($cancreate) eq 'ARRAY') { |
|
if (grep(/^login$/,@{$cancreate})) { |
# ---------------------------------------------------------------- Authenticate
|
$defaultauth = 1; |
|
} |
my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});
|
} |
my ($cancreate,$statustocreate) =
|
my $clientcancheckhost = 1; |
&Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'});
|
my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass, |
my $defaultauth;
|
$form{'udom'},$defaultauth, |
if (ref($cancreate) eq 'ARRAY') {
|
$clientcancheckhost); |
if (grep(/^login$/,@{$cancreate})) {
|
|
$defaultauth = 1;
|
# --------------------------------------------------------------------- Failed? |
}
|
|
}
|
if ($authhost eq 'no_host') { |
my $clientcancheckhost = 1;
|
my $pwdverify; |
my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass,
|
if (&Apache::lonnet::homeserver($form{'uname'},$form{'udom'}) eq 'no_host') { |
$form{'udom'},$defaultauth,
|
my %possunames = &alternate_unames_check($form{'uname'},$form{'udom'}); |
$clientcancheckhost);
|
if (keys(%possunames) > 0) { |
|
foreach my $rulematch (keys(%possunames)) { |
# --------------------------------------------------------------------- Failed?
|
my $possuname = $possunames{$rulematch}; |
|
if (($possuname ne '') && ($possuname =~ /^$match_username$/)) { |
if ($authhost eq 'no_host') {
|
$authhost=Apache::lonnet::authenticate($possuname,$upass, |
&failed($r,'Username and/or password could not be authenticated.',
|
$form{'udom'},undef, |
\%form);
|
$clientcancheckhost); |
return OK;
|
if (($authhost eq 'no_host') || ($authhost eq 'no_account_on_host')) { |
} elsif ($authhost eq 'no_account_on_host') {
|
next; |
if ($defaultauth) {
|
} elsif (($authhost ne '') && (&Apache::lonnet::hostname($authhost) ne '')) { |
my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');
|
$pwdverify = 1; |
unless (&check_can_host($r,\%form,'no_account_on_host',$domdesc)) {
|
&Apache::lonnet::logthis("Authenticated user: $possuname was submitted as: $form{'uname'}"); |
return OK;
|
$form{'uname'} = $possuname; |
}
|
last; |
my $start_page =
|
} |
&Apache::loncommon::start_page('Create a user account in LON-CAPA');
|
} |
my $lonhost = $r->dir_config('lonHostID');
|
} |
my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
|
} |
my $contacts =
|
} |
&Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
|
unless ($pwdverify) { |
$form{'udom'},$origmail);
|
&failed($r,'Username and/or password could not be authenticated.', |
my ($contact_email) = split(',',$contacts);
|
\%form); |
my $output =
|
return OK; |
&Apache::createaccount::username_check($form{'uname'},$form{'udom'},
|
} |
$domdesc,'',$lonhost,
|
} elsif ($authhost eq 'no_account_on_host') { |
$contact_email,$contact_name,
|
if ($defaultauth) { |
undef,$statustocreate);
|
my $domdesc = &Apache::lonnet::domain($form{'udom'},'description'); |
&Apache::loncommon::content_type($r,'text/html');
|
unless (&check_can_host($r,\%form,'no_account_on_host',$domdesc)) { |
$r->send_http_header;
|
return OK; |
&Apache::createaccount::print_header($r,$start_page);
|
} |
$r->print('<h3>'.&mt('Account creation').'</h3>'.
|
my $start_page = |
&mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account at this institution.').'<br />'.
|
&Apache::loncommon::start_page('Create a user account in LON-CAPA', |
$output.&Apache::loncommon::end_page());
|
'',{'no_inline_link' => 1,}); |
return OK;
|
my $lonhost = $r->dir_config('lonHostID'); |
} else {
|
my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; |
&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);
|
my $contacts = |
return OK;
|
&Apache::loncommon::build_recipient_list(undef,'helpdeskmail', |
}
|
$form{'udom'},$origmail); |
}
|
my ($contact_email) = split(',',$contacts); |
|
my $output = |
if (($firsturl eq '') ||
|
&Apache::createaccount::username_check($form{'uname'},$form{'udom'}, |
($firsturl=~/^\/adm\/(logout|remote)/)) {
|
$domdesc,'',$lonhost, |
$firsturl='/adm/roles';
|
$contact_email,$contact_name, |
}
|
undef,$statustocreate); |
|
&Apache::loncommon::content_type($r,'text/html'); |
my $hosthere;
|
$r->send_http_header; |
if ($form{'iptoken'}) {
|
&Apache::createaccount::print_header($r,$start_page); |
my %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
|
$r->print('<h3>'.&mt('Account creation').'</h3>'. |
my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
|
&mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account at this institution.').'<br />'. |
if (($sessiondata{'domain'} eq $form{'udom'}) &&
|
$output.&Apache::loncommon::end_page()); |
($sessiondata{'username'} eq $form{'uname'})) {
|
return OK; |
$hosthere = 1;
|
} else { |
}
|
&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); |
}
|
return OK; |
|
} |
# --------------------------------- Are we attempting to login as somebody else?
|
} |
if ($form{'suname'}) {
|
|
my ($suname,$sudom,$sudomref);
|
if (($firsturl eq '') || |
$suname = $form{'suname'};
|
($firsturl=~/^\/adm\/(logout|remote)/)) { |
$sudom = $form{'udom'};
|
$firsturl='/adm/roles'; |
if ($form{'sudom'}) {
|
} |
unless ($sudom eq $form{'sudom'}) {
|
|
if (&Apache::lonnet::domain($form{'sudom'})) {
|
my ($hosthere,%sessiondata); |
$sudomref = [$form{'sudom'}];
|
if ($form{'iptoken'}) { |
$sudom = $form{'sudom'};
|
%sessiondata = &Apache::lonnet::tmpget($form{'iptoken'}); |
}
|
my $delete = &Apache::lonnet::tmpdel($form{'iptoken'}); |
}
|
if (($sessiondata{'domain'} eq $form{'udom'}) && |
}
|
($sessiondata{'username'} eq $form{'uname'})) { |
# ------------ see if the original user has enough privileges to pull this stunt
|
$hosthere = 1; |
if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'},$sudomref)) {
|
} |
# ---------------------------------------------------- see if the su-user exists
|
} |
unless (&Apache::lonnet::homeserver($suname,$sudom) eq 'no_host') {
|
|
# ------------------------------ see if the su-user is not too highly privileged
|
# --------------------------------- Are we attempting to login as somebody else? |
if (&Apache::lonnet::privileged($suname,$sudom)) {
|
if ($form{'suname'}) { |
&Apache::lonnet::logthis('Attempted switch user to privileged user');
|
my ($suname,$sudom,$sudomref); |
} else {
|
$suname = $form{'suname'}; |
my $noprivswitch;
|
$sudom = $form{'udom'}; |
#
|
if ($form{'sudom'}) { |
# su-user's home server and user's home server must have one of:
|
unless ($sudom eq $form{'sudom'}) { |
# (a) same domain
|
if (&Apache::lonnet::domain($form{'sudom'})) { |
# (b) same primary library server for the two domains
|
$sudomref = [$form{'sudom'}]; |
# (c) same "internet domain" for primary library server(s) for home servers' domains
|
$sudom = $form{'sudom'}; |
#
|
} |
my $suprim = &Apache::lonnet::domain($sudom,'primary');
|
} |
my $suintdom = &Apache::lonnet::internet_dom($suprim);
|
} |
unless ($sudom eq $form{'udom'}) {
|
# ------------ see if the original user has enough privileges to pull this stunt |
my $uprim = &Apache::lonnet::domain($form{'udom'},'primary');
|
if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'},$sudomref)) { |
my $uintdom = &Apache::lonnet::internet_dom($uprim);
|
# ---------------------------------------------------- see if the su-user exists |
unless ($suprim eq $uprim) {
|
unless (&Apache::lonnet::homeserver($suname,$sudom) eq 'no_host') { |
unless ($suintdom eq $uintdom) {
|
# ------------------------------ see if the su-user is not too highly privileged |
&Apache::lonnet::logthis('Attempted switch user '
|
if (&Apache::lonnet::privileged($suname,$sudom)) { |
.'to user with different "internet domain".');
|
&Apache::lonnet::logthis('Attempted switch user to privileged user'); |
$noprivswitch = 1;
|
} else { |
}
|
my $noprivswitch; |
}
|
# |
}
|
# su-user's home server and user's home server must have one of: |
|
# (a) same domain |
unless ($noprivswitch) {
|
# (b) same primary library server for the two domains |
#
|
# (c) same "internet domain" for primary library server(s) for home servers' domains |
# server where log-in occurs must have same "internet domain" as su-user's home
|
# |
# server
|
my $suprim = &Apache::lonnet::domain($sudom,'primary'); |
#
|
my $suintdom = &Apache::lonnet::internet_dom($suprim); |
my $lonhost = $r->dir_config('lonHostID');
|
unless ($sudom eq $form{'udom'}) { |
my $hostintdom = &Apache::lonnet::internet_dom($lonhost);
|
my $uprim = &Apache::lonnet::domain($form{'udom'},'primary'); |
if ($hostintdom ne $suintdom) {
|
my $uintdom = &Apache::lonnet::internet_dom($uprim); |
&Apache::lonnet::logthis('Attempted switch user on a '
|
unless ($suprim eq $uprim) { |
.'server with a different "internet domain".');
|
unless ($suintdom eq $uintdom) { |
} else {
|
&Apache::lonnet::logthis('Attempted switch user ' |
|
.'to user with different "internet domain".'); |
# -------------------------------------------------------- actually switch users
|
$noprivswitch = 1; |
|
} |
&Apache::lonnet::logperm('User '.$form{'uname'}.' at '.
|
} |
$form{'udom'}.' logging in as '.$suname.':'.$sudom);
|
} |
$form{'uname'}=$suname;
|
|
if ($form{'udom'} ne $sudom) {
|
unless ($noprivswitch) { |
$form{'udom'}=$sudom;
|
# |
}
|
# server where log-in occurs must have same "internet domain" as su-user's home |
}
|
# server |
}
|
# |
}
|
my $lonhost = $r->dir_config('lonHostID'); |
}
|
my $hostintdom = &Apache::lonnet::internet_dom($lonhost); |
} else {
|
if ($hostintdom ne $suintdom) { |
&Apache::lonnet::logthis('Non-privileged user attempting switch user');
|
&Apache::lonnet::logthis('Attempted switch user on a ' |
}
|
.'server with a different "internet domain".'); |
}
|
} else { |
|
|
my ($is_balancer,$otherserver);
|
# -------------------------------------------------------- actually switch users |
|
|
unless ($hosthere) {
|
&Apache::lonnet::logperm('User '.$form{'uname'}.' at '. |
($is_balancer,$otherserver) =
|
$form{'udom'}.' logging in as '.$suname.':'.$sudom); |
&Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login');
|
$form{'uname'}=$suname; |
if ($is_balancer) {
|
if ($form{'udom'} ne $sudom) { |
# Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
|
$form{'udom'}=$sudom; |
my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r);
|
} |
if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) {
|
} |
$otherserver = $found_server;
|
} |
}
|
} |
if ($otherserver eq '') {
|
} |
my $lowest_load;
|
} else { |
($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'});
|
&Apache::lonnet::logthis('Non-privileged user attempting switch user'); |
if ($lowest_load > 100) {
|
} |
$otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$form{'udom'});
|
} |
}
|
|
}
|
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
if ($otherserver ne '') {
|
if (($form{'linkprot'}) && ($form{'linkprotuser'} ne '')) { |
my @hosts = &Apache::lonnet::current_machine_ids();
|
unless($form{'linkprotuser'} eq $form{'uname'}.':'.$form{'udom'}) { |
if (grep(/^\Q$otherserver\E$/,@hosts)) {
|
delete($form{'udom'}); |
$hosthere = $otherserver;
|
delete($form{'uname'}); |
}
|
&failed($r,'Username and/or domain are different to that expected for the link you followed from another system', |
}
|
\%form,$authhost); |
}
|
return OK; |
}
|
} |
|
} |
if (($is_balancer) && (!$hosthere)) {
|
} |
if ($otherserver) {
|
|
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
|
my ($is_balancer,$otherserver); |
\%form);
|
|
my $switchto = '/adm/switchserver?otherserver='.$otherserver;
|
unless ($hosthere) { |
if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
|
($is_balancer,$otherserver) = |
$switchto .= '&origurl='.$firsturl; #should escape
|
&Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login'); |
}
|
if ($is_balancer) { |
if ($form{'role'}) {
|
# Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer) |
$switchto .= '&role='.$form{'role'};
|
my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r); |
}
|
if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) { |
if ($form{'symb'}) {
|
$otherserver = $found_server; |
$switchto .= '&symb='.$form{'symb'};
|
} |
}
|
if ($otherserver eq '') { |
if ($form{'linkprot'}) {
|
my $lowest_load; |
$env{'request.linkprot'} = $form{'linkprot'};
|
($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'}); |
} elsif ($form{'linkkey'}) {
|
if ($lowest_load > 100) { |
$env{'request.linkkey'} = $form{'linkkey'};
|
$otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$form{'udom'}); |
}
|
} |
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
|
} |
&set_deeplink_login(%form);
|
if ($otherserver ne '') { |
}
|
my @hosts = &Apache::lonnet::current_machine_ids(); |
$r->internal_redirect($switchto);
|
if (grep(/^\Q$otherserver\E$/,@hosts)) { |
} else {
|
$hosthere = $otherserver; |
&Apache::loncommon::content_type($r,'text/html');
|
} |
$r->send_http_header;
|
} |
$r->print(&noswitch());
|
} |
}
|
} |
return OK;
|
|
} else {
|
if (($is_balancer) && (!$hosthere)) { |
if (!&check_can_host($r,\%form,$authhost)) {
|
if ($otherserver) { |
my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});
|
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef, |
if ($otherserver) {
|
\%form); |
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
|
my $switchto = '/adm/switchserver?otherserver='.$otherserver; |
\%form);
|
if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) { |
my $switchto = '/adm/switchserver?otherserver='.$otherserver;
|
$switchto .= '&origurl='.$firsturl; |
if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
|
} |
$switchto .= '&origurl='.$firsturl; #should escape
|
if ($form{'role'}) { |
}
|
$switchto .= '&role='.$form{'role'}; |
if ($form{'role'}) {
|
} |
$switchto .= '&role='.$form{'role'};
|
if ($form{'symb'}) { |
}
|
$switchto .= '&symb='.$form{'symb'}; |
if ($form{'symb'}) {
|
} |
$switchto .= '&symb='.$form{'symb'};
|
if ($form{'linkprot'}) { |
}
|
$env{'request.linkprot'} = $form{'linkprot'}; |
if ($form{'linkprot'}) {
|
foreach my $item ('linkprotuser','linkprotexit') { |
$env{'request.linkprot'} = $form{'linkprot'};
|
if ($form{$item}) { |
} elsif ($form{'linkkey'}) {
|
$env{'request.'.$item} = $form{$item}; |
$env{'request.linkkey'} = $form{'linkkey'};
|
} |
}
|
} |
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
|
} elsif ($form{'linkkey'} ne '') { |
&set_deeplink_login(%form);
|
$env{'request.linkkey'} = $form{'linkkey'}; |
}
|
} |
$r->internal_redirect($switchto);
|
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
} else {
|
&set_deeplink_login(%form); |
&Apache::loncommon::content_type($r,'text/html');
|
} |
$r->send_http_header;
|
$r->internal_redirect($switchto); |
$r->print(&noswitch());
|
} else { |
}
|
&Apache::loncommon::content_type($r,'text/html'); |
return OK;
|
$r->send_http_header; |
}
|
$r->print(&noswitch()); |
|
} |
# ------------------------------------------------------- Do the load balancing
|
return OK; |
|
} else { |
# ---------------------------------------------------------- Determine own load
|
if (!&check_can_host($r,\%form,$authhost)) { |
my $loadlim = $r->dir_config('lonLoadLim');
|
my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'}); |
my $loadavg;
|
if ($otherserver) { |
{
|
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef, |
my $loadfile=Apache::File->new('/proc/loadavg');
|
\%form); |
$loadavg=<$loadfile>;
|
my $switchto = '/adm/switchserver?otherserver='.$otherserver; |
}
|
if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) { |
$loadavg =~ s/\s.*//g;
|
$switchto .= '&origurl='.$firsturl; |
my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
|
} |
my $userloadpercent=&Apache::lonnet::userload();
|
if ($form{'role'}) { |
|
$switchto .= '&role='.$form{'role'}; |
# ---------------------------------------------------------- Are we overloaded?
|
} |
if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
|
if ($form{'symb'}) { |
my $unloaded=Apache::lonnet::spareserver($r,$loadpercent,$userloadpercent,1,$form{'udom'});
|
$switchto .= '&symb='.$form{'symb'}; |
if (!$unloaded) {
|
} |
($unloaded) = &Apache::lonnet::choose_server($form{'udom'});
|
if ($form{'linkprot'}) { |
}
|
$env{'request.linkprot'} = $form{'linkprot'}; |
if ($unloaded) {
|
foreach my $item ('linkprotuser','linkprotexit') { |
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',
|
if ($form{$item}) { |
undef,\%form);
|
$env{'request.'.$item} = $form{$item}; |
if ($form{'linkprot'}) {
|
} |
$env{'request.linkprot'} = $form{'linkprot'};
|
} |
} elsif ($form{'linkkey'}) {
|
} elsif ($form{'linkkey'} ne '') { |
$env{'request.linkkey'} = $form{'linkkey'};
|
$env{'request.linkkey'} = $form{'linkkey'}; |
}
|
} |
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
|
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
&set_deeplink_login(%form);
|
&set_deeplink_login(%form); |
}
|
} |
$r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);
|
$r->internal_redirect($switchto); |
return OK;
|
} else { |
}
|
&Apache::loncommon::content_type($r,'text/html'); |
}
|
$r->send_http_header; |
if (($is_balancer) && ($hosthere)) {
|
$r->print(&noswitch()); |
$form{'noloadbalance'} = $hosthere;
|
} |
}
|
return OK; |
my $extra_env;
|
} |
if ($form{'linkprot'}) {
|
|
my ($linkprotector,$uri) = split(/:/,$form{'linkprot'},2);
|
# ------------------------------------------------------- Do the load balancing |
if ($linkprotector) {
|
|
$extra_env = {'user.linkprotector' => $linkprotector,
|
# ---------------------------------------------------------- Determine own load |
'user.linkproturi' => $uri};
|
my $loadlim = $r->dir_config('lonLoadLim'); |
}
|
my $loadavg; |
} elsif ($form{'linkkey'}) {
|
{ |
$extra_env = {'user.deeplinkkey' => $form{'linkkey'},
|
my $loadfile=Apache::File->new('/proc/loadavg'); |
'user.keyedlinkuri' => $form{'firsturl'}};
|
$loadavg=<$loadfile>; |
}
|
} |
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
|
$loadavg =~ s/\s.*//g; |
&set_deeplink_login(%form);
|
my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim); |
if ($form{'linkprot'}) {
|
my $userloadpercent=&Apache::lonnet::userload(); |
if (ref($extra_env) eq 'HASH') {
|
|
%{$extra_env} = ( %{$extra_env}, 'request.linkprot' => $form{'linkprot'} );
|
# ---------------------------------------------------------- Are we overloaded? |
} else {
|
if ((($userloadpercent>100.0)||($loadpercent>100.0))) { |
$extra_env = {'request.linkprot' => $form{'linkprot'}};
|
my $unloaded=Apache::lonnet::spareserver($r,$loadpercent,$userloadpercent,1,$form{'udom'}); |
}
|
if (!$unloaded) { |
} elsif ($form{'linkkey'}) {
|
($unloaded) = &Apache::lonnet::choose_server($form{'udom'}); |
if (ref($extra_env) eq 'HASH') {
|
} |
%{$extra_env} = ( %{$extra_env}, 'request.linkkey' => $form{'linkkey'} );
|
if ($unloaded) { |
} else {
|
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect', |
$extra_env = {'request.linkkey' => $form{'linkkey'}};
|
undef,\%form); |
}
|
if ($form{'linkprot'}) { |
}
|
$env{'request.linkprot'} = $form{'linkprot'}; |
if ($env{'request.deeplink.login'}) {
|
} elsif ($form{'linkkey'} ne '') { |
if (ref($extra_env) eq 'HASH') {
|
$env{'request.linkkey'} = $form{'linkkey'}; |
%{$extra_env} = ( %{$extra_env}, 'request.deeplink.login' => $form{'firsturl'} );
|
} |
} else {
|
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
$extra_env = {'request.deeplink.login' => $form{'firsturl'}};
|
&set_deeplink_login(%form); |
}
|
} |
}
|
$r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl); |
}
|
return OK; |
&success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,$extra_env,
|
} |
\%form);
|
} |
return OK;
|
if (($is_balancer) && ($hosthere)) { |
}
|
$form{'noloadbalance'} = $hosthere; |
}
|
} |
|
my $extra_env; |
sub set_deeplink_login {
|
if (($hosthere) && ($sessiondata{'sessionserver'} ne '')) { |
my (%form) = @_;
|
if ($sessiondata{'origurl'} ne '') { |
if ($form{'firsturl'} =~ m{^/tiny/($match_domain)/\w+$}) {
|
$firsturl = $sessiondata{'origurl'}; |
my $cdom = $1;
|
$form{'firsturl'} = $sessiondata{'origurl'}; |
my ($cnum,$symb) = &Apache::loncommon::symb_from_tinyurl($form{'firsturl'},'',$cdom);
|
my @names = ('role','symb','linkprot','linkkey'); |
if ($symb) {
|
foreach my $item (@names) { |
if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
|
if ($sessiondata{$item} ne '') { |
my ($disallow,$deeplink);
|
$form{$item} = $sessiondata{$item}; |
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');
|
if ($form{'linkprot'}) { |
}
|
my ($linkprotector,$uri) = split(/:/,$form{'linkprot'},2); |
} else {
|
if ($linkprotector) { |
$deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
|
$extra_env = {'user.linkprotector' => $linkprotector, |
}
|
'user.linkproturi' => $uri}; |
if ($deeplink ne '') {
|
} |
my ($state,$others,$listed,$scope,$protect) = split(/,/,$deeplink);
|
} elsif ($form{'linkkey'} ne '') { |
if (($protect ne 'none') && ($protect ne '')) {
|
$extra_env = {'user.deeplinkkey' => $form{'linkkey'}, |
my ($acctype,$item) = split(/:/,$protect);
|
'user.keyedlinkuri' => $form{'firsturl'}}; |
if ($acctype =~ /lti(c|d)$/) {
|
} |
unless ($form{'linkprot'} eq $item.$1.':'.$env{'request.deeplink.login'}) {
|
if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { |
$disallow = 1;
|
&set_deeplink_login(%form); |
}
|
if ($form{'linkprot'}) { |
} elsif ($acctype eq 'key') {
|
if (ref($extra_env) eq 'HASH') { |
unless ($form{'linkkey'} eq $item) {
|
%{$extra_env} = ( %{$extra_env}, 'request.linkprot' => $form{'linkprot'} ); |
$disallow = 1;
|
} else { |
}
|
$extra_env = {'request.linkprot' => $form{'linkprot'}}; |
}
|
} |
}
|
if ($form{'linkprotexit'}) { |
}
|
$extra_env->{'request.linkprotexit'} = $form{'linkprotexit'}; |
unless ($disallow) {
|
} |
$env{'request.deeplink.login'} = $form{'firsturl'};
|
} elsif ($form{'linkkey'} ne '') { |
}
|
if (ref($extra_env) eq 'HASH') { |
} else {
|
%{$extra_env} = ( %{$extra_env}, 'request.linkkey' => $form{'linkkey'} ); |
$env{'request.deeplink.login'} = $form{'firsturl'};
|
} else { |
}
|
$extra_env = {'request.linkkey' => $form{'linkkey'}}; |
}
|
} |
}
|
} |
return;
|
if ($env{'request.deeplink.login'}) { |
}
|
if (ref($extra_env) eq 'HASH') { |
|
%{$extra_env} = ( %{$extra_env}, 'request.deeplink.login' => $form{'firsturl'} ); |
sub check_can_host {
|
} else { |
my ($r,$form,$authhost,$domdesc) = @_;
|
$extra_env = {'request.deeplink.login' => $form{'firsturl'}}; |
return unless (ref($form) eq 'HASH');
|
} |
my $canhost = 1;
|
} |
my $lonhost = $r->dir_config('lonHostID');
|
} |
my $udom = $form->{'udom'};
|
&success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,$extra_env, |
my @intdoms;
|
\%form); |
my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
|
return OK; |
if (ref($internet_names) eq 'ARRAY') {
|
} |
@intdoms = @{$internet_names};
|
} |
}
|
|
my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
|
sub get_form_items { |
my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
|
my ($r) = @_; |
unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {
|
my $buffer; |
my $machine_dom = &Apache::lonnet::host_domain($lonhost);
|
if ($r->header_in('Content-length') > 0) { |
my $hostname = &Apache::lonnet::hostname($lonhost);
|
$r->read($buffer,$r->header_in('Content-length'),0); |
my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
|
} |
my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
|
my %form; |
my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
|
foreach my $pair (split(/&/,$buffer)) { |
my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);
|
my ($name,$value) = split(/=/,$pair); |
my $loncaparev;
|
$value =~ tr/+/ /; |
if ($authhost eq 'no_account_on_host') {
|
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; |
$loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom);
|
$form{$name}=$value; |
} else {
|
} |
$loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost);
|
return %form; |
}
|
} |
$canhost = &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev,
|
|
$udomdefaults{'remotesessions'},
|
sub set_deeplink_login { |
$defdomdefaults{'hostedsessions'});
|
my (%form) = @_; |
}
|
my $disallow; |
unless ($canhost) {
|
if ($form{'firsturl'} =~ m{^/tiny/($match_domain)/\w+$}) { |
if ($authhost eq 'no_account_on_host') {
|
my $cdom = $1; |
my $checkloginvia = 1;
|
my ($cnum,$symb) = &Apache::loncommon::symb_from_tinyurl($form{'firsturl'},'',$cdom); |
my ($login_host,$hostname) =
|
if ($symb) { |
&Apache::lonnet::choose_server($udom,$checkloginvia);
|
if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { |
&Apache::loncommon::content_type($r,'text/html');
|
my $deeplink; |
$r->send_http_header;
|
if ($symb =~ /\.(page|sequence)$/) { |
if ($login_host ne '') {
|
my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($symb))[2]); |
my $protocol = $Apache::lonnet::protocol{$login_host};
|
my $navmap = Apache::lonnavmaps::navmap->new(); |
$protocol = 'http' if ($protocol ne 'https');
|
if (ref($navmap)) { |
my $alias = &Apache::lonnet::use_proxy_alias($r,$login_host);
|
$deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink'); |
$hostname = $alias if ($alias ne '');
|
} |
my $newurl = $protocol.'://'.$hostname.'/adm/createaccount';
|
} else { |
#FIXME Should preserve where user was going and linkprot by setting ltoken at $login_host
|
$deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb); |
$r->print(&Apache::loncommon::start_page('Create a user account in LON-CAPA').
|
} |
'<h3>'.&mt('Account creation').'</h3>'.
|
if ($deeplink ne '') { |
&mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.
|
my ($state,$others,$listed,$scope,$protect) = split(/,/,$deeplink); |
'<p>'.&mt('You will be able to create one by logging into a LON-CAPA server within the [_1] domain.',$domdesc).'</p>'.
|
if (($protect ne 'none') && ($protect ne '')) { |
'<p>'.&mt('[_1]Log in[_2]','<a href="'.$newurl.'">','</a>').
|
my ($acctype,$item) = split(/:/,$protect); |
&Apache::loncommon::end_page());
|
if ($acctype =~ /lti(c|d)$/) { |
} else {
|
unless ($form{'linkprot'} eq $item.$1.':'.$env{'request.deeplink.login'}) { |
$r->print(&Apache::loncommon::start_page('Access to LON-CAPA unavailable').
|
$disallow = 1; |
'<h3>'.&mt('Account creation unavailable').'</h3>'.
|
} |
&mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.
|
} elsif ($acctype eq 'key') { |
'<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>'.
|
unless ($form{'linkkey'} eq $item) { |
&Apache::loncommon::end_page());
|
$disallow = 1; |
}
|
} |
} else {
|
} |
&success($r,$form->{'uname'},$udom,$authhost,'noredirect',undef,
|
} |
$form);
|
} |
if ($form->{'linkprot'}) {
|
unless ($disallow) { |
$env{'request.linkprot'} = $form->{'linkprot'};
|
$env{'request.deeplink.login'} = $form{'firsturl'}; |
} elsif ($form->{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
|
} |
if ($form->{'linkkey'}) {
|
} else { |
$env{'request.linkkey'} = $form->{'linkkey'};
|
$env{'request.deeplink.login'} = $form{'firsturl'}; |
}
|
} |
$env{'request.deeplink.login'} = $form->{'firsturl'};
|
} |
}
|
} |
my ($otherserver) = &Apache::lonnet::choose_server($udom);
|
if ($disallow) { |
$r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);
|
return; |
}
|
} |
}
|
return 'ok'; |
return $canhost;
|
} |
}
|
|
|
sub set_retry_token { |
sub noswitch {
|
my ($form,$lonhost,$querystr) = @_; |
my $result = &Apache::loncommon::start_page('Access to LON-CAPA unavailable').
|
if (ref($form) eq 'HASH') { |
'<h3>'.&mt('Session unavailable').'</h3>'.
|
my ($firsturl,$token,$extras,@names); |
&mt('This LON-CAPA server is unable to host your session.').'<br />'.
|
@names = ('role','symb','linkprotuser','linkprotexit','linkprot','linkkey','iptoken'); |
'<p>'.&mt('Currently no other LON-CAPA server is available to host your session either.').'</p>'.
|
foreach my $name (@names) { |
&Apache::loncommon::end_page();
|
if ($form->{$name} ne '') { |
return $result;
|
$extras .= '&'.$name.'='.&escape($form->{$name}); |
}
|
last if ($name eq 'linkprot'); |
|
} |
sub loginhelpdisplay {
|
} |
my ($authdomain) = @_;
|
my $firsturl = $form->{'firsturl'}; |
my $login_help = 1;
|
if (($firsturl ne '') || ($extras ne '')) { |
my $lang = &Apache::lonlocal::current_language();
|
$extras .= ':retry'; |
if ($login_help) {
|
$token = &Apache::lonnet::reply('tmpput:'.&escape($firsturl). |
my $dom = $authdomain;
|
$extras,$lonhost); |
if ($dom eq '') {
|
if (($token eq 'con_lost') || ($token eq 'no_such_host')) { |
$dom = &Apache::lonnet::default_login_domain();
|
return 'fail'; |
}
|
} else { |
my %domconfhash = &Apache::loncommon::get_domainconf($dom);
|
if (ref($querystr)) { |
my $loginhelp_url;
|
$$querystr = 'retry='.$token; |
if ($lang) {
|
} |
$loginhelp_url = $domconfhash{$dom.'.login.helpurl_'.$lang};
|
return 'ok'; |
if ($loginhelp_url ne '') {
|
} |
return $loginhelp_url;
|
} |
}
|
} |
}
|
return; |
$loginhelp_url = $domconfhash{$dom.'.login.helpurl_nolang'};
|
} |
if ($loginhelp_url ne '') {
|
|
return $loginhelp_url;
|
sub check_can_host { |
} else {
|
my ($r,$form,$authhost,$domdesc) = @_; |
return '/adm/loginproblems.html';
|
return unless (ref($form) eq 'HASH'); |
}
|
my $canhost = 1; |
}
|
my $lonhost = $r->dir_config('lonHostID'); |
return;
|
my $udom = $form->{'udom'}; |
}
|
my @intdoms; |
|
my $internet_names = &Apache::lonnet::get_internet_names($lonhost); |
1;
|
if (ref($internet_names) eq 'ARRAY') { |
__END__
|
@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__ |
|
|
|
|
|