Annotation of loncom/cgi/loncgi.pm, revision 1.1

1.1     ! matthew     1: #
        !             2: # LON-CAPA helpers for cgi-bin scripts
        !             3: #
        !             4: # $Id: lonacc.pm,v 1.48 2003/09/20 17:44:22 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: #############################################
        !            29: #############################################
        !            30: 
        !            31: =pod
        !            32: 
        !            33: =head1 NAME
        !            34: 
        !            35: loncgi
        !            36: 
        !            37: =head1 SYNOPSIS
        !            38: 
        !            39: Provides subroutines for checking a LON-CAPA cookie and loading the users
        !            40: environment.
        !            41: 
        !            42: =head1 Subroutines
        !            43: 
        !            44: =over 4 
        !            45: 
        !            46: =cut
        !            47: 
        !            48: #############################################
        !            49: #############################################
        !            50: package LONCAPA::loncgi;
        !            51: 
        !            52: use strict;
        !            53: use warnings FATAL=>'all';
        !            54: no warnings 'uninitialized';
        !            55: use CGI();
        !            56: use CGI::Cookie();
        !            57: use Fcntl qw(:flock);
        !            58: use LONCAPA::Configuration();
        !            59: 
        !            60: my $lonidsdir;
        !            61: 
        !            62: BEGIN {
        !            63:     my $perlvar=LONCAPA::Configuration::read_conf('loncapa.conf');
        !            64:     delete $perlvar->{'lonReceipt'};
        !            65:     $lonidsdir = $perlvar->{'lonIDsDir'};
        !            66: }
        !            67: 
        !            68: #############################################
        !            69: #############################################
        !            70: 
        !            71: =pod
        !            72: 
        !            73: =item check_cookie_and_load_env
        !            74: 
        !            75: Inputs: none
        !            76: 
        !            77: Returns: 1 if the user has a LON-CAPA cookie 0 if not.
        !            78: Loads the users environment into the %ENV hash if the cookie is correct.
        !            79: 
        !            80: =cut
        !            81: 
        !            82: #############################################
        !            83: #############################################
        !            84: sub check_cookie_and_load_env {
        !            85:     my %cookies=fetch CGI::Cookie;
        !            86:     if (exists($cookies{'lonID'}) && 
        !            87:         -e "$lonidsdir/".$cookies{'lonID'}->value.".id") {
        !            88:         # cookie found
        !            89:         &transfer_profile_to_env($cookies{'lonID'}->value);
        !            90:         return 1;
        !            91:     } else {
        !            92:         # No cookie found
        !            93:         return 0;
        !            94:     }
        !            95: }
        !            96: 
        !            97: #############################################
        !            98: #############################################
        !            99: 
        !           100: =pod
        !           101: 
        !           102: =item check_cookie
        !           103: 
        !           104: Inputs: none
        !           105: 
        !           106: Returns: 1 if the user has a LON-CAPA cookie and 0 if not.
        !           107: 
        !           108: =cut
        !           109: 
        !           110: #############################################
        !           111: #############################################
        !           112: sub check_cookie {
        !           113:     my %cookies=fetch CGI::Cookie;
        !           114:     if (exists($cookies{'lonID'}) && 
        !           115:         -e "$lonidsdir/".$cookies{'lonID'}->value.".id") {
        !           116:         # cookie found
        !           117:         return 1;
        !           118:     } else {
        !           119:         # No cookie found
        !           120:         return 0;
        !           121:     }
        !           122: }
        !           123: 
        !           124: #############################################
        !           125: #############################################
        !           126: 
        !           127: =pod
        !           128: 
        !           129: =item transfer_profile_to_env
        !           130: 
        !           131: Load the users environment into the %ENV hash.
        !           132: 
        !           133: Inputs: $handle, the name of the users LON-CAPA cookie.
        !           134: 
        !           135: Returns: undef
        !           136: 
        !           137: =cut
        !           138: 
        !           139: #############################################
        !           140: #############################################
        !           141: sub transfer_profile_to_env {
        !           142:     my ($handle)=@_;
        !           143:     my @profile;
        !           144:     {
        !           145:         open(IDFILE, "<$lonidsdir/$handle.id");
        !           146:         flock(IDFILE,LOCK_SH);
        !           147:         @profile=<IDFILE>;
        !           148:         close(IDFILE);
        !           149:     }
        !           150:     foreach my $envrow (@profile) {
        !           151:         chomp($envrow);
        !           152:         my ($envname,$envvalue)=split(/=/,$envrow);
        !           153:         $ENV{$envname} = $envvalue;
        !           154:     }
        !           155:     $ENV{'user.environment'} = "$lonidsdir/$handle.id";
        !           156:     return undef;
        !           157: }
        !           158: 
        !           159: #############################################
        !           160: #############################################
        !           161: 
        !           162: =pod
        !           163: 
        !           164: =back
        !           165: 
        !           166: =cut
        !           167: 
        !           168: 1;
        !           169: 
        !           170: __END__

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