File:
[LON-CAPA] /
loncom /
cgi /
loncgi.pm
Revision
1.8:
download - view:
text,
annotated -
select for diffs
Tue Sep 19 21:36:31 2006 UTC (18 years ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_7_X,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_X,
version_2_4_99_0,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
version_2_3_0,
version_2_2_99_1,
version_2_2_99_0,
HEAD
- change sesion env into a .db file
(simplifies the appenv/delenv process)
1: #
2: # LON-CAPA helpers for cgi-bin scripts
3: #
4: # $Id: loncgi.pm,v 1.8 2006/09/19 21:36:31 albertel 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:
56: use lib '/home/httpd/lib/perl/';
57: use CGI();
58: use CGI::Cookie();
59: use Fcntl qw(:flock);
60: use LONCAPA;
61: use LONCAPA::Configuration();
62: use GDBM_File;
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.
82: Loads the users environment into the %env hash if the cookie is correct.
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:
135: Load the users environment into the %env hash.
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)=@_;
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);
151: }
152: $Apache::lonnet::env{'user.environment'} = "$lonidsdir/$handle.id";
153: return undef;
154: }
155:
156: #############################################
157: #############################################
158:
159:
160: =pod
161:
162: =back
163:
164: =cut
165:
166: 1;
167:
168: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>