Lines 23-29
use Digest::MD5 qw(md5_base64);
Link Here
|
23 |
use File::Spec; |
23 |
use File::Spec; |
24 |
use JSON qw/encode_json/; |
24 |
use JSON qw/encode_json/; |
25 |
use URI::Escape; |
25 |
use URI::Escape; |
26 |
use CGI::Session; |
26 |
use Data::Session; |
27 |
|
27 |
|
28 |
require Exporter; |
28 |
require Exporter; |
29 |
use C4::Context; |
29 |
use C4::Context; |
Lines 1088-1094
sub checkauth {
Link Here
|
1088 |
$session->param( 'branchname', $branchname ); |
1088 |
$session->param( 'branchname', $branchname ); |
1089 |
$session->param( 'flags', $userflags ); |
1089 |
$session->param( 'flags', $userflags ); |
1090 |
$session->param( 'emailaddress', $emailaddress ); |
1090 |
$session->param( 'emailaddress', $emailaddress ); |
1091 |
$session->param( 'ip', $session->remote_addr() ); |
1091 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1092 |
$session->param( 'lasttime', time() ); |
1092 |
$session->param( 'lasttime', time() ); |
1093 |
$session->param( 'shibboleth', $shibSuccess ); |
1093 |
$session->param( 'shibboleth', $shibSuccess ); |
1094 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch); |
1094 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch); |
Lines 1106-1112
sub checkauth {
Link Here
|
1106 |
$session->param( 'branchname', 'NO_LIBRARY_SET' ); |
1106 |
$session->param( 'branchname', 'NO_LIBRARY_SET' ); |
1107 |
$session->param( 'flags', 1 ); |
1107 |
$session->param( 'flags', 1 ); |
1108 |
$session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') ); |
1108 |
$session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') ); |
1109 |
$session->param( 'ip', $session->remote_addr() ); |
1109 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1110 |
$session->param( 'lasttime', time() ); |
1110 |
$session->param( 'lasttime', time() ); |
1111 |
} |
1111 |
} |
1112 |
C4::Context->set_userenv( |
1112 |
C4::Context->set_userenv( |
Lines 1128-1134
sub checkauth {
Link Here
|
1128 |
C4::Context->_unset_userenv($sessionID); |
1128 |
C4::Context->_unset_userenv($sessionID); |
1129 |
} |
1129 |
} |
1130 |
$session->param( 'lasttime', time() ); |
1130 |
$session->param( 'lasttime', time() ); |
1131 |
$session->param( 'ip', $session->remote_addr() ); |
1131 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1132 |
$session->param( 'sessiontype', 'anon' ); |
1132 |
$session->param( 'sessiontype', 'anon' ); |
1133 |
} |
1133 |
} |
1134 |
} # END if ( $userid = $query->param('userid') ) |
1134 |
} # END if ( $userid = $query->param('userid') ) |
Lines 1139-1145
sub checkauth {
Link Here
|
1139 |
$debug and warn "Initiating an anonymous session..."; |
1139 |
$debug and warn "Initiating an anonymous session..."; |
1140 |
|
1140 |
|
1141 |
# setting a couple of other session vars... |
1141 |
# setting a couple of other session vars... |
1142 |
$session->param( 'ip', $session->remote_addr() ); |
1142 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1143 |
$session->param( 'lasttime', time() ); |
1143 |
$session->param( 'lasttime', time() ); |
1144 |
$session->param( 'sessiontype', 'anon' ); |
1144 |
$session->param( 'sessiontype', 'anon' ); |
1145 |
} |
1145 |
} |
Lines 1532-1538
sub check_api_auth {
Link Here
|
1532 |
$session->param( 'branchname', $branchname ); |
1532 |
$session->param( 'branchname', $branchname ); |
1533 |
$session->param( 'flags', $userflags ); |
1533 |
$session->param( 'flags', $userflags ); |
1534 |
$session->param( 'emailaddress', $emailaddress ); |
1534 |
$session->param( 'emailaddress', $emailaddress ); |
1535 |
$session->param( 'ip', $session->remote_addr() ); |
1535 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1536 |
$session->param( 'lasttime', time() ); |
1536 |
$session->param( 'lasttime', time() ); |
1537 |
} elsif ( $return == 2 ) { |
1537 |
} elsif ( $return == 2 ) { |
1538 |
|
1538 |
|
Lines 1546-1552
sub check_api_auth {
Link Here
|
1546 |
$session->param( 'branchname', 'NO_LIBRARY_SET' ); |
1546 |
$session->param( 'branchname', 'NO_LIBRARY_SET' ); |
1547 |
$session->param( 'flags', 1 ); |
1547 |
$session->param( 'flags', 1 ); |
1548 |
$session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') ); |
1548 |
$session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') ); |
1549 |
$session->param( 'ip', $session->remote_addr() ); |
1549 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1550 |
$session->param( 'lasttime', time() ); |
1550 |
$session->param( 'lasttime', time() ); |
1551 |
} |
1551 |
} |
1552 |
C4::Context->set_userenv( |
1552 |
C4::Context->set_userenv( |
Lines 1682-1691
sub check_cookie_auth {
Link Here
|
1682 |
|
1682 |
|
1683 |
=head2 get_session |
1683 |
=head2 get_session |
1684 |
|
1684 |
|
1685 |
use CGI::Session; |
|
|
1686 |
my $session = get_session($sessionID); |
1685 |
my $session = get_session($sessionID); |
1687 |
|
1686 |
|
1688 |
Given a session ID, retrieve the CGI::Session object used to store |
1687 |
Given a session ID, retrieve the Data::Session object used to store |
1689 |
the session's state. The session object can be used to store |
1688 |
the session's state. The session object can be used to store |
1690 |
data that needs to be accessed by different scripts during a |
1689 |
data that needs to be accessed by different scripts during a |
1691 |
user's session. |
1690 |
user's session. |
Lines 1701-1720
sub get_session {
Link Here
|
1701 |
my $dbh = C4::Context->dbh; |
1700 |
my $dbh = C4::Context->dbh; |
1702 |
my $session; |
1701 |
my $session; |
1703 |
if ( $storage_method eq 'mysql' ) { |
1702 |
if ( $storage_method eq 'mysql' ) { |
1704 |
$session = new CGI::Session( "driver:MySQL;serializer:yaml;id:md5", $sessionID, { Handle => $dbh } ); |
1703 |
# Note that the doc is wrong, type is required, if not provided it default to File |
1705 |
} |
1704 |
$session = Data::Session->new( dbh => $dbh, type => 'driver:mysql;id:MD5;serialize:YAML' ) or die $Data::Session::errstr; |
1706 |
elsif ( $storage_method eq 'Pg' ) { |
1705 |
} elsif ( $storage_method eq 'Pg' ) { |
1707 |
$session = new CGI::Session( "driver:PostgreSQL;serializer:yaml;id:md5", $sessionID, { Handle => $dbh } ); |
1706 |
warn "The system preference SessionStorage is set to 'Pg' but this is not supported yet!"; |
1708 |
} |
1707 |
} elsif ( $storage_method eq 'memcached' and my $memcached = Koha::Caches->get_instance->memcached_cache ) { |
1709 |
elsif ( $storage_method eq 'memcached' && Koha::Caches->get_instance->memcached_cache ) { |
1708 |
$session = Data::Session->new( |
1710 |
my $memcached = Koha::Caches->get_instance()->memcached_cache; |
1709 |
type => 'driver:Memcached;id:SHA1;serialize:DataDumper', |
1711 |
$session = new CGI::Session( "driver:memcached;serializer:yaml;id:md5", $sessionID, { Memcached => $memcached } ); |
1710 |
cache => $memcached, |
|
|
1711 |
); |
1712 |
} elsif ( $storage_method ne 'tmp' ) { |
1713 |
warn "The system preference SessionStorage is set to an invalid value '$storage_method'"; |
1712 |
} |
1714 |
} |
1713 |
else { |
1715 |
if ( $storage_method eq 'tmp' or not $session ) { |
1714 |
# catch all defaults to tmp should work on all systems |
1716 |
if ( $storage_method ne 'tmp' ) { |
1715 |
my $dir = File::Spec->tmpdir; |
1717 |
warn "The session has not been correctly retrieved, defaulting to temporary storage: " . $Data::Session::errstr; |
1716 |
my $instance = C4::Context->config( 'database' ); #actually for packages not exactly the instance name, but generally safer to leave it as it is |
1718 |
} |
1717 |
$session = new CGI::Session( "driver:File;serializer:yaml;id:md5", $sessionID, { Directory => "$dir/cgisess_$instance" } ); |
1719 |
my $dir = '/tmp/'; #File::Spec->tmpdir; |
|
|
1720 |
my $instance = C4::Context->config('database'); #actually for packages not exactly the instance name, but generally safer to leave it as it is |
1721 |
$session = Data::Session->new( type => 'driver:File;id:MD5;serialize:YAML', directory => "$dir/cgisess_$instance" ) or die $Data::Session::errstr; |
1718 |
} |
1722 |
} |
1719 |
return $session; |
1723 |
return $session; |
1720 |
} |
1724 |
} |