line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenPlugin::Session::ApacheSession; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: ApacheSession.pm,v 1.5 2003/06/10 00:30:23 andreychek Exp $ |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
3259
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
86
|
|
6
|
2
|
|
|
2
|
|
1246
|
use OpenPlugin::Session(); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
54
|
|
7
|
2
|
|
|
2
|
|
18
|
use base qw( OpenPlugin::Session ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
167
|
|
8
|
2
|
|
|
2
|
|
1041
|
use Apache::Session::Flex(); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$OpenPlugin::Session::ApacheSession::VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub init { |
14
|
|
|
|
|
|
|
my ( $self, $args ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $params = $self->_init_params; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# FIXME -- I'm not sure this belongs here. Could we somehow add "File" as |
19
|
|
|
|
|
|
|
# a datasource type, and upon a 'connect', do a permissions check? |
20
|
|
|
|
|
|
|
if ($params->{Store} eq "File") { |
21
|
|
|
|
|
|
|
# Can we write to the session dir, and is it really a directory? |
22
|
|
|
|
|
|
|
unless (-w $params->{Directory} and -d $params->{Directory}) { |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# We only do this is it's really a dir, and it's writable |
25
|
|
|
|
|
|
|
$params->{Directory} =~ /^(.*)$/; |
26
|
|
|
|
|
|
|
$params->{Directory} = $1; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
unless (mkdir $params->{Directory}, 0760) { |
29
|
|
|
|
|
|
|
$self->OP->exception->throw( |
30
|
|
|
|
|
|
|
"The session dir ($params->{Directory}) is not writable " . |
31
|
|
|
|
|
|
|
"by the Apache's httpd process! Please change the owner " . |
32
|
|
|
|
|
|
|
"of that directory to the user ID your webserver is " . |
33
|
|
|
|
|
|
|
"running as." |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
# Can we write to the lockfile dir, and is it really a directory? |
38
|
|
|
|
|
|
|
unless (-w $params->{LockDirectory} and -d $params->{LockDirectory}) { |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# We only do this is it's really a dir, and it's writable |
41
|
|
|
|
|
|
|
$params->{LockDirectory} =~ /^(.*)$/; |
42
|
|
|
|
|
|
|
$params->{LockDirectory} = $1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
unless (mkdir $params->{LockDirectory}, 0760) { |
45
|
|
|
|
|
|
|
$self->OP->exception->throw( |
46
|
|
|
|
|
|
|
"The lock dir ($params->{LockDirectory}) is not writable ". |
47
|
|
|
|
|
|
|
"by the Apache's httpd process! Please change the owner " . |
48
|
|
|
|
|
|
|
"of that directory to the user ID your webserver is " . |
49
|
|
|
|
|
|
|
"running as." |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# This session connects to the session, and returns data in it as a hashref |
59
|
|
|
|
|
|
|
sub get_session_data { |
60
|
|
|
|
|
|
|
my ( $self, $session_id ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $params = $self->_init_params; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my %session = (); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
eval { tie %session, 'Apache::Session::Flex', $session_id, { %$params }; }; |
67
|
|
|
|
|
|
|
if ( $@ ) { |
68
|
|
|
|
|
|
|
$self->OP->log->warn( "Failed to initiate session: $@" ); |
69
|
|
|
|
|
|
|
return undef; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return ( \%session ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _init_params { |
77
|
|
|
|
|
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $params = |
80
|
|
|
|
|
|
|
$self->OP->config->{'plugin'}{'session'}{'driver'}{'ApacheSession'}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Some reasonable (IMHO) defaults if we haven't been told certain parameters |
83
|
|
|
|
|
|
|
$params->{Store} ||= "File"; |
84
|
|
|
|
|
|
|
$params->{Lock} ||= "Null"; |
85
|
|
|
|
|
|
|
$params->{Generate} ||= "MD5"; |
86
|
|
|
|
|
|
|
$params->{Serialize} ||= "Storable"; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Untaint values Apache::Session uses as module names |
89
|
|
|
|
|
|
|
foreach my $key ( qw( Store Serialize Lock Generate ) ) { |
90
|
|
|
|
|
|
|
$params->{ $key } =~ m/^([-\w]+)$/; |
91
|
|
|
|
|
|
|
$params->{ $key } = $1; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
if ( $params->{Store} eq "File" ) { |
95
|
|
|
|
|
|
|
$params->{Directory} ||= "/tmp"; |
96
|
|
|
|
|
|
|
$params->{LockDirectory} ||= "/tmp"; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
if ( -d $params->{Directory} ) { |
99
|
|
|
|
|
|
|
$params->{Directory} =~ m/^(.*)$/; |
100
|
|
|
|
|
|
|
$params->{Directory} = $1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
if ( -d $params->{LockDirectory} ) { |
104
|
|
|
|
|
|
|
$params->{LockDirectory} =~ m/^(.*)$/; |
105
|
|
|
|
|
|
|
$params->{LockDirectory} = $1; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
if ( $self->OP->config->{'plugin'}{'session'}{'datasource'} ) { |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$params->{'Handle'} = |
113
|
|
|
|
|
|
|
$self->OP->datasource->connect( $self->OP->config->{'plugin'}{'session'}{'datasource'} ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
return $params; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |