Annotation of loncom/lti/ltilogout.pm, revision 1.1

1.1     ! raeburn     1: # The LearningOnline Network with CAPA
        !             2: # LTI Provider Module to respond to a user session logout request.
        !             3: #
        !             4: # $Id: ltilogout.pm,v 1.1 2019/07/18 20:50:20 raeburn 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: 
        !            29: package Apache::ltilogout;
        !            30: 
        !            31: use strict;
        !            32: use Apache::Constants qw(:common :http);
        !            33: use Apache::lonnet;
        !            34: use Apache::loncommon;
        !            35: 
        !            36: sub handler {
        !            37:     my $r = shift;
        !            38:     my ($id) = ($r->uri =~ m{^/adm/service/logout/(\w+)$});
        !            39:     if ($id) {
        !            40:         my $dir = $r->dir_config('ltiIDsDir');
        !            41:         my $lonhost = $r->dir_config('lonHostID');
        !            42:         if (($dir ne '') && (-d $dir)) {
        !            43:             if (-e "$dir/$id") {
        !            44:                 if (open(my $fh,'<',"$dir/$id")) {
        !            45:                     my $contents = <$fh>;
        !            46:                     chomp($contents);
        !            47:                     close($fh);
        !            48:                     my ($uname,$udom,$hostid) = split(/,/,$contents);
        !            49:                     if (($uname ne '') && ($udom ne '')) {
        !            50:                         my $uhome = &Apache::lonnet::homeserver($uname,$udom);
        !            51:                         if ($uhome ne 'no_host') {
        !            52:                             my $lonhost = $r->dir_config('lonHostID');
        !            53:                             if ($hostid eq $lonhost) {
        !            54:                                 &delete_session($udom,$uname);
        !            55:                             } else {
        !            56:                                 my ($is_balancer,$posshost,$setcookie) =
        !            57:                                     &Apache::lonnet::check_loadbalancing($uname,$udom,'login');
        !            58:                                 if ($is_balancer) {
        !            59:                                     if ($setcookie) {
        !            60:                                         my $balancedir=$r->dir_config('lonBalanceDir');
        !            61:                                         if (opendir(my $dirh,$balancedir)) {
        !            62:                                             while (my $filename=readdir($dirh)) {
        !            63:                                                 if ($filename =~/^\Q$udom\E_\Q$uname\E_/) {
        !            64:                                                     if (open(my $fh,'<',"$balancedir/$filename")) {
        !            65:                                                         my $lonid = <$fh>;
        !            66:                                                         close($fh);
        !            67:                                                         if ($lonid eq $lonhost) {
        !            68:                                                             &delete_session($r,$udom,$uname);
        !            69:                                                         } elsif (&Apache::lonnet::hostname($lonid) ne '') {
        !            70:                                                             &Apache::lonnet::delusersession($lonid,$udom,$uname);
        !            71:                                                         }
        !            72:                                                     }
        !            73:                                                     last;
        !            74:                                                 }
        !            75:                                             }
        !            76:                                             closedir($dirh);
        !            77:                                         }
        !            78:                                     } else {
        !            79:                                         my $lonid = &Apache::lonnet::find_existing_session($udom,$uname);
        !            80:                                         if ($lonid eq $lonhost) {
        !            81:                                             &delete_session($r,$udom,$uname);
        !            82:                                         } elsif (&Apache::lonnet::hostname($lonid) ne '') {
        !            83:                                             &Apache::lonnet::delusersession($lonid,$udom,$uname);
        !            84:                                         }
        !            85:                                     }
        !            86:                                 } else {
        !            87:                                     &delete_session($r,$udom,$uname);
        !            88:                                 }
        !            89:                             }
        !            90:                         }
        !            91:                     }
        !            92:                 }
        !            93:             }
        !            94:         }
        !            95:     }
        !            96:     return OK;
        !            97: }
        !            98: 
        !            99: sub delete_session {
        !           100:     my ($r,$udom,$uname) = @_;
        !           101:     my $lonidsdir = $r->dir_config('lonIDsDir');
        !           102:     if (-d $lonidsdir) {
        !           103:         if (opendir(my $dir,$lonidsdir)) {
        !           104:             while (my $filename=readdir($dir)) {
        !           105:                 if ($filename=~/^\Q$uname\E_\d+_\Q$udom\E_/) {
        !           106:                     unlink("$dir/$filename");
        !           107:                     last;
        !           108:                 }
        !           109:             }
        !           110:         }
        !           111:     }
        !           112: }
        !           113: 
        !           114: 1;

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