--- loncom/auth/lonauth.pm 1999/10/13 17:48:52 1.1
+++ loncom/auth/lonauth.pm 2022/02/27 02:06:20 1.121.2.25
@@ -1,120 +1,855 @@
# The LearningOnline Network
# User Authentication Module
-# 5/21/99,5/22,5/25,5/26,5/27,5/29,6/2,6/11,6/14,6/15 Gerd Kortemeyer
+#
+# $Id: lonauth.pm,v 1.121.2.25 2022/02/27 02:06:20 raeburn Exp $
+#
+# Copyright Michigan State University Board of Trustees
+#
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
+#
+# 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
package Apache::lonauth;
+use strict;
+use LONCAPA;
use Apache::Constants qw(:common);
-use Apache::File;
use CGI qw(:standard);
+use Apache::loncommon();
+use Apache::lonnet;
+use Apache::lonmenu();
+use Apache::createaccount;
+use Fcntl qw(:flock);
+use Apache::lonlocal;
+use Apache::File();
+use HTML::Entities;
+use Digest::MD5;
use CGI::Cookie();
-use Apache::lonnet();
-
+
# ------------------------------------------------------------ Successful login
-
sub success {
- my ($r, $lowerurl, $username, $domain, $authhost) = @_;
- my $lonids=$r->dir_config('lonIDsDir');
-# See if old ID present, but overlooked
- my $cookie;
- if ($cookie=<$lonids/$username\_*\_$domain\_$authhost.id>) {
- $cookie=~s/\.id//;
- $cookie=~s/$lonids\///;
+ my ($r, $username, $domain, $authhost, $lowerurl, $extra_env,
+ $form,$cid,$expirepub) = @_;
+
+# ------------------------------------------------------------ Get cookie ready
+ my $cookie =
+ &Apache::loncommon::init_user_environment($r, $username, $domain,
+ $authhost, $form,
+ {'extra_env' => $extra_env,});
+
+ my $public=($username eq 'public' && $domain eq 'public');
+
+ if ($public or $lowerurl eq 'noredirect') { return $cookie; }
+
+# -------------------------------------------------------------------- Log this
+
+ my $ip = &Apache::lonnet::get_requestor_ip();
+ &Apache::lonnet::log($domain,$username,$authhost,
+ "Login $ip");
+
+# ------------------------------------------------- Check for critical messages
+
+ my @what=&Apache::lonnet::dump('critical',$domain,$username);
+ if ($what[0]) {
+ 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');
+ if ($ssl) {
+ $securecookie="lonSID=$cookie; path=/; HttpOnly; secure";
+ my $lonidsdir=$r->dir_config('lonIDsDir');
+ if (($lonidsdir) && (-e "$lonidsdir/$cookie.id")) {
+ my $linkname=substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 32).'_linked';
+ if (-e "$lonidsdir/$linkname.id") {
+ unlink("$lonidsdir/$linkname.id");
+ }
+ my $made_symlink = eval { symlink("$lonidsdir/$cookie.id",
+ "$lonidsdir/$linkname.id"); 1 };
+ if ($made_symlink) {
+ $defaultcookie = "lonLinkID=$linkname; path=/; HttpOnly;";
+ &Apache::lonnet::appenv({'user.linkedenv' => $linkname});
+ }
+ }
} else {
+ $defaultcookie = "lonID=$cookie; path=/; HttpOnly;";
+ }
+# -------------------------------------------------------- Menu script and info
+ my $destination = $lowerurl;
+
+ if (defined($form->{role})) {
+ my $envkey = 'user.role.'.$form->{role};
my $now=time;
- $cookie="$username\_$now\_$domain\_$authhost";
- {
- my $idf=Apache::File->new(">$lonids/$cookie.id");
- print $idf "Name: $username\n";
+ my $then=$env{'user.login.time'};
+ my $refresh=$env{'user.refresh.time'};
+ my $update=$env{'user.update.time'};
+ if (!$update) {
+ $update = $then;
+ }
+ if (exists($env{$envkey})) {
+ my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus);
+ &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
+ \$trolecode,\$tstatus,\$tstart,\$tend);
+ if ($tstatus eq 'is') {
+ $destination .= ($destination =~ /\?/) ? '&' : '?';
+ my $newrole = &HTML::Entities::encode($form->{role},'"<>&');
+ $destination .= 'selectrole=1&'.$newrole.'=1';
+ }
+ }
+ }
+ if (defined($form->{symb})) {
+ my $destsymb = $form->{symb};
+ my $encrypted;
+ if ($destsymb =~ m{^/enc/}) {
+ $encrypted = 1;
+ if ($cid) {
+ $destsymb = &Apache::lonenc::unencrypted($destsymb,$cid);
+ }
}
+ $destination .= ($destination =~ /\?/) ? '&' : '?';
+ if ($destsymb =~ /___/) {
+ my ($map,$resid,$desturl)=split(/___/,$destsymb);
+ $desturl = &Apache::lonnet::clutter($desturl);
+ if ($encrypted) {
+ $desturl = &Apache::lonenc::encrypted($desturl,1,$cid);
+ $destsymb = $form->{symb};
+ }
+ $desturl = &HTML::Entities::encode($desturl,'"<>&');
+ $destsymb = &HTML::Entities::encode($destsymb,'"<>&');
+ $destination .= 'destinationurl='.$desturl.
+ '&destsymb='.$destsymb;
+ } elsif (!$encrypted) {
+ $destsymb = &HTML::Entities::encode($destsymb,'"<>&');
+ $destination .= 'destinationurl='.$destsymb;
+ }
+ }
+ if ($destination =~ m{^/adm/roles}) {
+ $destination .= ($destination =~ /\?/) ? '&' : '?';
+ $destination .= 'source=login';
+ }
+
+ my $windowinfo=&Apache::lonmenu::open($env{'browser.os'});
+ my $startupremote=&Apache::lonmenu::startupremote($destination);
+ my $remoteinfo=&Apache::lonmenu::load_remote_msg($lowerurl);
+ my $setflags=&Apache::lonmenu::setflags();
+ my $maincall=&Apache::lonmenu::maincall();
+ my $brcrum = [{'href' => '',
+ 'text' => 'Successful Login'},];
+ my $start_page=&Apache::loncommon::start_page('Successful Login',
+ $startupremote,
+ {'no_inline_link' => 1,
+ 'bread_crumbs' => $brcrum,});
+ my $end_page =&Apache::loncommon::end_page();
+
+ my $continuelink;
+ if ($env{'environment.remote'} eq 'off') {
+ $continuelink=''.&mt('Continue').'';
}
- $cookie="lonID=$cookie; path=/";
- $r->send_cgi_header(<headers_out->add('Set-cookie' => $securecookie);
+ }
+ if ($defaultcookie) {
+ $r->headers_out->add('Set-cookie' => $defaultcookie);
+ }
+ if ($expirepub) {
+ my $c = new CGI::Cookie(-name => 'lonPubID',
+ -value => '',
+ -expires => '-10y',);
+ $r->headers_out->add('Set-cookie' => $c);
+ }
+ $r->send_http_header;
+
+ my %lt=&Apache::lonlocal::texthash(
+ 'wel' => 'Welcome',
+ 'pro' => 'Login problems?',
+ );
+ my $loginhelp = &loginhelpdisplay($domain);
+ if ($loginhelp) {
+ $loginhelp = ''.$lt{'pro'}.'
';
+ }
+
+ my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','','');
$r->print(<
-
-Successful Login to the LearningOnline Network
-
-
-