Annotation of loncom/cgi/loncgi.pm, revision 1.8
1.1 matthew 1: #
2: # LON-CAPA helpers for cgi-bin scripts
3: #
1.8 ! albertel 4: # $Id: loncgi.pm,v 1.7 2006/05/18 14:24:06 albertel Exp $
1.1 matthew 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';
1.2 albertel 55:
1.7 albertel 56: use lib '/home/httpd/lib/perl/';
1.1 matthew 57: use CGI();
58: use CGI::Cookie();
59: use Fcntl qw(:flock);
1.7 albertel 60: use LONCAPA;
1.1 matthew 61: use LONCAPA::Configuration();
1.8 ! albertel 62: use GDBM_File;
1.1 matthew 63:
64: my $lonidsdir;
65:
66: BEGIN {
67: my $perlvar=LONCAPA::Configuration::read_conf('loncapa.conf');
68: delete $perlvar->{'lonReceipt'};
69: $lonidsdir = $perlvar->{'lonIDsDir'};
70: }
71:
72: #############################################
73: #############################################
74:
75: =pod
76:
77: =item check_cookie_and_load_env
78:
79: Inputs: none
80:
81: Returns: 1 if the user has a LON-CAPA cookie 0 if not.
1.3 albertel 82: Loads the users environment into the %env hash if the cookie is correct.
1.1 matthew 83:
84: =cut
85:
86: #############################################
87: #############################################
88: sub check_cookie_and_load_env {
89: my %cookies=fetch CGI::Cookie;
90: if (exists($cookies{'lonID'}) &&
91: -e "$lonidsdir/".$cookies{'lonID'}->value.".id") {
92: # cookie found
93: &transfer_profile_to_env($cookies{'lonID'}->value);
94: return 1;
95: } else {
96: # No cookie found
97: return 0;
98: }
99: }
100:
101: #############################################
102: #############################################
103:
104: =pod
105:
106: =item check_cookie
107:
108: Inputs: none
109:
110: Returns: 1 if the user has a LON-CAPA cookie and 0 if not.
111:
112: =cut
113:
114: #############################################
115: #############################################
116: sub check_cookie {
117: my %cookies=fetch CGI::Cookie;
118: if (exists($cookies{'lonID'}) &&
119: -e "$lonidsdir/".$cookies{'lonID'}->value.".id") {
120: # cookie found
121: return 1;
122: } else {
123: # No cookie found
124: return 0;
125: }
126: }
127:
128: #############################################
129: #############################################
130:
131: =pod
132:
133: =item transfer_profile_to_env
134:
1.3 albertel 135: Load the users environment into the %env hash.
1.1 matthew 136:
137: Inputs: $handle, the name of the users LON-CAPA cookie.
138:
139: Returns: undef
140:
141: =cut
142:
143: #############################################
144: #############################################
145: sub transfer_profile_to_env {
146: my ($handle)=@_;
1.8 ! albertel 147: if (tie(my %disk_env,'GDBM_File',"$lonidsdir/$handle.id",&GDBM_READER(),
! 148: 0640)) {
! 149: %Apache::lonnet::env = %disk_env;
! 150: untie(%disk_env);
1.1 matthew 151: }
1.4 albertel 152: $Apache::lonnet::env{'user.environment'} = "$lonidsdir/$handle.id";
1.1 matthew 153: return undef;
154: }
155:
156: #############################################
157: #############################################
158:
1.6 albertel 159:
1.1 matthew 160: =pod
161:
162: =back
163:
164: =cut
165:
166: 1;
167:
168: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>