| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Gantry::Plugins::CookieCheck; |
|
2
|
1
|
|
|
1
|
|
767
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
693
|
use Gantry::Utils::Crypt (); |
|
|
1
|
|
|
|
|
8517
|
|
|
|
1
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use base 'Exporter'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
630
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
9
|
|
|
|
|
|
|
do_cookiecheck |
|
10
|
|
|
|
|
|
|
); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %registered_callbacks; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
17
|
|
|
|
|
|
|
# $class->get_callbacks( $namespace ) |
|
18
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
19
|
|
|
|
|
|
|
sub get_callbacks { |
|
20
|
0
|
|
|
0
|
1
|
|
my ( $class, $namespace ) = @_; |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
return if ( $registered_callbacks{ $namespace }++ ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return ( |
|
25
|
0
|
|
|
|
|
|
{ phase => 'pre_init', callback => \&set_test_cookie }, |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
30
|
|
|
|
|
|
|
# set_test_cookie |
|
31
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
32
|
|
|
|
|
|
|
sub set_test_cookie { |
|
33
|
0
|
|
|
0
|
1
|
|
my ( $gobj ) = @_; |
|
34
|
0
|
|
|
|
|
|
my $uri = $gobj->fish_uri(); |
|
35
|
0
|
|
|
|
|
|
my $loc = $gobj->fish_location(); |
|
36
|
0
|
|
|
|
|
|
my $cc_exclude = $gobj->fish_config('cc_exclude'); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Set a test cookie under the following circumstances. |
|
39
|
|
|
|
|
|
|
# The test cookie (acceptcookies) is not already set. |
|
40
|
|
|
|
|
|
|
# The current uri does not match cookiecheck. |
|
41
|
|
|
|
|
|
|
# There is no cookie check exclude path provided or |
|
42
|
|
|
|
|
|
|
# there is an exclusion and it doesn't match the current location. |
|
43
|
0
|
0
|
0
|
|
|
|
if ( |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
44
|
|
|
|
|
|
|
( ! $gobj->get_cookies( 'acceptcookies' ) ) and |
|
45
|
|
|
|
|
|
|
( $uri !~ /cookiecheck\/?$/o ) and |
|
46
|
|
|
|
|
|
|
( |
|
47
|
|
|
|
|
|
|
( ! $cc_exclude ) or ( $cc_exclude and ( $uri !~ /$cc_exclude/ ) ) |
|
48
|
|
|
|
|
|
|
) |
|
49
|
|
|
|
|
|
|
) { |
|
50
|
0
|
|
|
|
|
|
my $req = $gobj->apache_request(); |
|
51
|
0
|
|
0
|
|
|
|
my $secret = $gobj->fish_config( 'cc_secret' ) |
|
52
|
|
|
|
|
|
|
|| $gobj->gantry_secret(); |
|
53
|
0
|
|
|
|
|
|
my $crypt = Gantry::Utils::Crypt->new( { 'secret' => $secret } ); |
|
54
|
0
|
|
|
|
|
|
my $qstring = ''; |
|
55
|
0
|
|
|
|
|
|
my $goto; |
|
56
|
|
|
|
|
|
|
my $cookie; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$cookie = { |
|
59
|
|
|
|
|
|
|
name => 'acceptcookies', |
|
60
|
|
|
|
|
|
|
value => '1', |
|
61
|
|
|
|
|
|
|
path => '/', |
|
62
|
|
|
|
|
|
|
}; |
|
63
|
0
|
0
|
|
|
|
|
$cookie->{domain} = $gobj->fish_config('cc_domain') |
|
64
|
|
|
|
|
|
|
if $gobj->fish_config('cc_domain'); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Set a test cookie and then redirect. |
|
67
|
0
|
|
|
|
|
|
$gobj->set_cookie($cookie); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Determine where to redirect the user for the cookie check. |
|
70
|
0
|
|
|
|
|
|
$uri =~ s/^$loc//; |
|
71
|
0
|
|
0
|
|
|
|
$goto = $uri || '/' ; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Add parameters. |
|
74
|
0
|
|
|
|
|
|
foreach my $param ( $req->param() ) { |
|
75
|
0
|
|
|
|
|
|
$qstring .= sprintf( '&%s=%s', $param, $req->param( $param ) ); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if ( $qstring ) { |
|
79
|
|
|
|
|
|
|
# Change the first & to a ? and add query string to goto. |
|
80
|
0
|
|
|
|
|
|
$qstring =~ s/^&/?/o; |
|
81
|
0
|
|
|
|
|
|
$goto .= $qstring; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Encrypt goto |
|
85
|
0
|
|
|
|
|
|
$goto = $gobj->url_encode( $crypt->encrypt( $goto ) ); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Redirect the user. |
|
88
|
0
|
|
|
|
|
|
$gobj->relocate( $loc . "/cookiecheck?url=${goto}" ); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
93
|
|
|
|
|
|
|
# do_cookiecheck() |
|
94
|
|
|
|
|
|
|
#----------------------------------------------------------- |
|
95
|
|
|
|
|
|
|
sub do_cookiecheck { |
|
96
|
0
|
|
|
0
|
1
|
|
my $gobj = shift; |
|
97
|
0
|
|
|
|
|
|
my $params = $gobj->params(); |
|
98
|
0
|
|
0
|
|
|
|
my $secret = $gobj->fish_config( 'cc_secret' ) |
|
99
|
|
|
|
|
|
|
|| $gobj->gantry_secret(); |
|
100
|
0
|
|
|
|
|
|
my $crypt = Gantry::Utils::Crypt->new( { 'secret' => $secret } ); |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Decrypt url parameter. |
|
103
|
0
|
|
|
|
|
|
$params->{url} = $crypt->decrypt( $params->{url} ); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# If acceptcookies is set then send the user to the original |
|
106
|
|
|
|
|
|
|
# url they requested. |
|
107
|
0
|
0
|
|
|
|
|
if( $gobj->get_cookies( 'acceptcookies' ) ) { |
|
108
|
0
|
|
|
|
|
|
$gobj->relocate( $gobj->location() . $params->{url} ); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
else { |
|
111
|
|
|
|
|
|
|
# Cookies aren't enabled. Display an error page. |
|
112
|
0
|
|
0
|
|
|
|
my $cc_title = $gobj->fish_config( 'cc_title' ) || 'Missing Cookies'; |
|
113
|
0
|
|
0
|
|
|
|
my $cc_wrapper = $gobj->fish_config( 'cc_wrapper' ) || |
|
114
|
|
|
|
|
|
|
$gobj->fish_config( 'template_wrapper' ) || 'default.tt'; |
|
115
|
0
|
|
0
|
|
|
|
my $cc_template = $gobj->fish_config( 'cc_template' ) || 'cc.tt'; |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$gobj->template_wrapper( $cc_wrapper ); |
|
118
|
0
|
|
|
|
|
|
$gobj->stash->view->title( $cc_title ); |
|
119
|
0
|
|
|
|
|
|
$gobj->stash->view->template( $cc_template ); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |