1# Module of TWiki Enterprise Collaboration Platform, http://TWiki.org/
2#
3# Copyright (C) 1999-2018 Peter Thoeny, peter[at]thoeny.org
4# and TWiki Contributors. All Rights Reserved. TWiki Contributors
5# are listed in the AUTHORS file in the root of this distribution.
6# NOTE: Please extend that file, not this notice.
7#
8# This program is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License
10# as published by the Free Software Foundation; either version 3
11# of the License, or (at your option) any later version. For
12# more details read LICENSE in the root of this distribution.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17#
18# As per the GPL, removal of this notice is prohibited.
19
20=pod
21
22---+!! package TWiki::LoginManager::Session
23
24Class to provide CGI::Session like infra-structure, compatible with
25TWiki Runtime Engine mechanisms other than CGI.
26
27It inherits from CGI::Session and redefine methods that uses %ENV directly,
28replacing by calls to TWiki::Request object, that is passed to constructor.
29
30It also redefines =name= method, to avoid creating CGI object.
31
32=cut
33
34package TWiki::LoginManager::Session;
35
36use strict;
37use base 'CGI::Session';
38
39*VERSION = \$CGI::Session::VERSION;
40*NAME    = \$CGI::Session::NAME;
41
42sub load {
43    my $this = shift;
44    # local %ENV; # TWikibug:Item6583 - commented out
45    $ENV{REMOTE_ADDR} = @_ == 1 ? $_[0]->remoteAddress : $_[1]->remoteAddress;
46    $this->SUPER::load(@_);
47}
48
49sub query {
50    my $self = shift;
51
52    if ( $self->{_QUERY} ) {
53        return $self->{_QUERY};
54    }
55    return $self->{_QUERY} = TWiki::Request->new();
56}
57
58sub _ip_matches {
59  return ( $_[0]->{_DATA}->{_SESSION_REMOTE_ADDR} eq $_[0]->{_QUERY}->remoteAddress );
60}
61
621;
63