--- loncom/auth/lonauth.pm 2003/09/20 17:44:22 1.57 +++ loncom/auth/lonauth.pm 2005/02/07 20:33:04 1.64 @@ -1,7 +1,7 @@ # The LearningOnline Network # User Authentication Module # -# $Id: lonauth.pm,v 1.57 2003/09/20 17:44:22 www Exp $ +# $Id: lonauth.pm,v 1.64 2005/02/07 20:33:04 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -181,16 +181,29 @@ sub success { # -------------------------------------------------------- Menu script and info my $windowinfo=&Apache::lonmenu::open($clientos); my $startupremote=&Apache::lonmenu::startupremote($lowerurl); + my $remoteinfo=&Apache::lonmenu::load_remote_msg($lowerurl); my $setflags=&Apache::lonmenu::setflags(); my $maincall=&Apache::lonmenu::maincall(); my $bodytag=&Apache::loncommon::bodytag('Successful Login'); + my $add=&addcontent(); + my $continuelink; + if (($ENV{'browser.interface'} eq 'textual') || + ($ENV{'environment.remote'} eq 'off')) { + $continuelink="".&mt('Continue').""; + } # ------------------------------------------------- Output for successful login $r->send_cgi_header(< 'Welcome', + 'mes' => 'Welcome to the LearningOnline Network with CAPA. Please wait while your session is being set up', + 'pro' => 'Problems', + 'log' => 'loginproblems.html', + ); $r->print(< @@ -200,12 +213,12 @@ $startupremote $bodytag $setflags $windowinfo -

Welcome!

-Welcome to the LearningOnline Network with CAPA. -Please wait while your session -is being set up.

-Problems?

+

$lt{'wel'}

+$lt{'mes'}.

+$lt{'pro'}?

+$remoteinfo $maincall +$continuelink ENDSUCCESS @@ -216,8 +229,9 @@ ENDSUCCESS sub failed { my ($r,$message) = @_; my $bodytag=&Apache::loncommon::bodytag('Unsuccessful Login'); + my $add=&addcontent(); $r->send_cgi_header(<print(< Unsuccessful Login to the LearningOnline Network with CAPA - $bodytag

Sorry ...

$message

@@ -237,6 +250,17 @@ $bodytag ENDFAILED } +# --------------------------------------------------------------------- Charset + +sub addcontent { + my $encoding=&Apache::lonlocal::current_encoding; + if ($encoding) { + return '; charset='.$encoding; + } else { + return ''; + } +} + # ------------------------------------------------------------------ Rerouting! sub reroute { @@ -251,7 +275,6 @@ ENDRFHEADER Rerouting Login to the LearningOnline Network with CAPA - $bodytag

Sorry ...

Please log in again. @@ -273,6 +296,42 @@ sub handler { &Apache::lonlocal::get_language_handle($r); +# -------------------------------- Prevent users from attempting to login twice + my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); + my $lonid=$cookies{'lonID'}; + my $cookie; + if ($lonid) { + my $handle=$lonid->value; + $handle=~s/\W//g; + my $lonidsdir=$r->dir_config('lonIDsDir'); + if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) { +# Indeed, a valid token is found + $r->send_cgi_header(<print(< + +Already logged in + +$bodytag +

You are already logged in

+

Please either continue the current session or +logout.

+

+Problems?

+ + +ENDFAILED + return OK; + } + } + +# ---------------------------------------------------- No valid token, continue + + my $buffer; $r->read($buffer,$r->header_in('Content-length'),0); my @pairs=split(/&/,$buffer); @@ -290,7 +349,12 @@ sub handler { failed($r,'Username, password and domain need to be specified.'); return OK; } + +# split user logging in and "su"-user + + ($FORM{'uname'},$FORM{'suname'})=split(/\:/,$FORM{'uname'}); $FORM{'uname'} =~ s/\W//g; + $FORM{'suname'} =~ s/\W//g; $FORM{'udom'} =~ s/\W//g; my $role = $r->dir_config('lonRole'); @@ -343,11 +407,33 @@ sub handler { return OK; } - if (($firsturl eq '') || ($firsturl eq '/adm/logout')) { + if (($firsturl eq '') || + ($firsturl=~/^\/adm\/(logout|remote)/)) { $firsturl='/adm/roles'; } - - success($r,$FORM{'uname'},$FORM{'udom'},$authhost,$firsturl); +# --------------------------------- Are we attempting to login as somebody else? + if ($FORM{'suname'}) { +# ------------ see if the original user has enough privileges to pull this stunt + if (&Apache::lonnet::privileged($FORM{'uname'},$FORM{'udom'})) { +# ---------------------------------------------------- see if the su-user exists + unless (&Apache::lonnet::homeserver($FORM{'suname'},$FORM{'udom'}) + eq 'no_host') { + &Apache::lonnet::logthis(&Apache::lonnet::homeserver($FORM{'suname'},$FORM{'udom'})); +# ------------------------------ see if the su-user is not too highly privileged + unless (&Apache::lonnet::privileged($FORM{'suname'},$FORM{'udom'})) { +# -------------------------------------------------------- actually switch users + &Apache::lonnet::logperm('User '.$FORM{'uname'}.' at '.$FORM{'udom'}. + ' logging in as '.$FORM{'suname'}); + $FORM{'uname'}=$FORM{'suname'}; + } else { + &Apache::lonnet::logthis('Attempted switch user to privileged user'); + } + } + } else { + &Apache::lonnet::logthis('Non-privileged user attempting switch user'); + } + } + &success($r,$FORM{'uname'},$FORM{'udom'},$authhost,$firsturl); return OK; }