File:  [LON-CAPA] / loncom / auth / lonlogout.pm
Revision 1.7: download - view: text, annotated - select for diffs
Sun Mar 2 04:08:41 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
Looks prettier and allows easier re-logging in.

    1: # The LearningOnline Network
    2: # Logout Handler
    3: #
    4: # $Id: lonlogout.pm,v 1.7 2003/03/02 04:08:41 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (Cookie Based Access Handler
   29: # 5/21/99,5/22,5/29,5/31,6/15,16/11,22/11,
   30: # 01/06,01/13 Gerd Kortemeyer)
   31: # 05/31,11/29,12/29 Gerd Kortemeyer
   32: 
   33: package Apache::lonlogout;
   34: 
   35: use strict;
   36: use Apache::Constants qw(:common);
   37: use Apache::File;
   38: use Apache::lonnet;
   39: use Apache::lonmenu;
   40: use CGI::Cookie();
   41: 
   42: sub handler {
   43:     my $r = shift;
   44: 
   45:     my $requrl=$r->uri;
   46:     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
   47:     my $lonid=$cookies{'lonID'};
   48:     my $cookie;
   49:     if ($lonid) {
   50: 	my $handle=$lonid->value;
   51:         $handle=~s/\W//g;
   52:         my $lonidsdir=$r->dir_config('lonIDsDir');
   53:         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
   54:            my @profile;
   55:            my %sessionhash;
   56: 	    {
   57:              my $idf=Apache::File->new("$lonidsdir/$handle.id");
   58:              @profile=<$idf>;
   59: 	    }
   60:             my $envi;
   61:             for ($envi=0;$envi<=$#profile;$envi++) {
   62: 		chomp($profile[$envi]);
   63: 		my ($envname,$envvalue)=split(/=/,$profile[$envi]);
   64:                 $sessionhash{$envname}=$envvalue;
   65:             }
   66:             unlink("$lonidsdir/$handle.id");
   67: 	    my %temp=('logout' => time);
   68: 	    &Apache::lonnet::put('email_status',\%temp);
   69: 	    &Apache::lonnet::log($sessionhash{'user.domain'},
   70:                                  $sessionhash{'user.name'},
   71:                                  $sessionhash{'user.home'},
   72:                                  "Logout $ENV{'REMOTE_ADDR'}");
   73:             $r->content_type('text/html');
   74:             $r->send_http_header;
   75:             return OK if $r->header_only;
   76: # -------------------------------------------------------- Menu script and info
   77: 
   78:     my $windowinfo=&Apache::lonmenu::close();
   79: # ---------------------------------------------------------------- Get handover
   80:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['handover']);
   81:     my $switch='';
   82:     my $bodytag='';
   83:     my $relogmessage='';
   84:     if ($ENV{'form.handover'}) {
   85:        $switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.
   86: 	   $ENV{'form.handover'}.'">';
   87:        $bodytag=&Apache::loncommon::bodytag('Switching Server ...');
   88:    } else {
   89:        $bodytag=&Apache::loncommon::bodytag('Logged Out');
   90:        $relogmessage=(<<ENDRELOG);
   91: <h1>Goodbye!</h1>
   92: Please either <a href="javascript:self.close();">close this window</a> or
   93: <a href="/adm/login">login again</a>.
   94: ENDRELOG
   95:    }
   96: # --------------------------------------------------------------- Screen Output
   97:             $r->print(<<ENDDOCUMENT);
   98: <html>
   99: <head><title>The LearningOnline Network with CAPA Logout</title>
  100: $switch
  101: </head>
  102: $bodytag
  103: $windowinfo
  104: $relogmessage
  105: </body>
  106: </html>
  107: ENDDOCUMENT
  108:             &Apache::lonnet::flushcourselogs();
  109:             return OK; 
  110:         } else { 
  111:             $r->log_reason("Cookie $handle not valid", $r->filename); 
  112:         }
  113:     }
  114:     return FORBIDDEN;
  115: }
  116: 
  117: 1;
  118: __END__
  119: 
  120: 
  121: 
  122: 
  123: 
  124: 
  125: 
  126: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>