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 1111-1117
sub checkauth {
Link Here
|
1111 |
$session->param( 'branchname', $branchname ); |
1111 |
$session->param( 'branchname', $branchname ); |
1112 |
$session->param( 'flags', $userflags ); |
1112 |
$session->param( 'flags', $userflags ); |
1113 |
$session->param( 'emailaddress', $emailaddress ); |
1113 |
$session->param( 'emailaddress', $emailaddress ); |
1114 |
$session->param( 'ip', $session->remote_addr() ); |
1114 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1115 |
$session->param( 'lasttime', time() ); |
1115 |
$session->param( 'lasttime', time() ); |
1116 |
$session->param( 'shibboleth', $shibSuccess ); |
1116 |
$session->param( 'shibboleth', $shibSuccess ); |
1117 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch); |
1117 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch); |
Lines 1129-1135
sub checkauth {
Link Here
|
1129 |
$session->param( 'branchname', 'NO_LIBRARY_SET' ); |
1129 |
$session->param( 'branchname', 'NO_LIBRARY_SET' ); |
1130 |
$session->param( 'flags', 1 ); |
1130 |
$session->param( 'flags', 1 ); |
1131 |
$session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') ); |
1131 |
$session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') ); |
1132 |
$session->param( 'ip', $session->remote_addr() ); |
1132 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1133 |
$session->param( 'lasttime', time() ); |
1133 |
$session->param( 'lasttime', time() ); |
1134 |
} |
1134 |
} |
1135 |
if ($persona) { |
1135 |
if ($persona) { |
Lines 1154-1160
sub checkauth {
Link Here
|
1154 |
C4::Context->_unset_userenv($sessionID); |
1154 |
C4::Context->_unset_userenv($sessionID); |
1155 |
} |
1155 |
} |
1156 |
$session->param( 'lasttime', time() ); |
1156 |
$session->param( 'lasttime', time() ); |
1157 |
$session->param( 'ip', $session->remote_addr() ); |
1157 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1158 |
$session->param( 'sessiontype', 'anon' ); |
1158 |
$session->param( 'sessiontype', 'anon' ); |
1159 |
} |
1159 |
} |
1160 |
} # END if ( $userid = $query->param('userid') ) |
1160 |
} # END if ( $userid = $query->param('userid') ) |
Lines 1165-1171
sub checkauth {
Link Here
|
1165 |
$debug and warn "Initiating an anonymous session..."; |
1165 |
$debug and warn "Initiating an anonymous session..."; |
1166 |
|
1166 |
|
1167 |
# setting a couple of other session vars... |
1167 |
# setting a couple of other session vars... |
1168 |
$session->param( 'ip', $session->remote_addr() ); |
1168 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1169 |
$session->param( 'lasttime', time() ); |
1169 |
$session->param( 'lasttime', time() ); |
1170 |
$session->param( 'sessiontype', 'anon' ); |
1170 |
$session->param( 'sessiontype', 'anon' ); |
1171 |
} |
1171 |
} |
Lines 1559-1565
sub check_api_auth {
Link Here
|
1559 |
$session->param( 'branchname', $branchname ); |
1559 |
$session->param( 'branchname', $branchname ); |
1560 |
$session->param( 'flags', $userflags ); |
1560 |
$session->param( 'flags', $userflags ); |
1561 |
$session->param( 'emailaddress', $emailaddress ); |
1561 |
$session->param( 'emailaddress', $emailaddress ); |
1562 |
$session->param( 'ip', $session->remote_addr() ); |
1562 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1563 |
$session->param( 'lasttime', time() ); |
1563 |
$session->param( 'lasttime', time() ); |
1564 |
} elsif ( $return == 2 ) { |
1564 |
} elsif ( $return == 2 ) { |
1565 |
|
1565 |
|
Lines 1573-1579
sub check_api_auth {
Link Here
|
1573 |
$session->param( 'branchname', 'NO_LIBRARY_SET' ); |
1573 |
$session->param( 'branchname', 'NO_LIBRARY_SET' ); |
1574 |
$session->param( 'flags', 1 ); |
1574 |
$session->param( 'flags', 1 ); |
1575 |
$session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') ); |
1575 |
$session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') ); |
1576 |
$session->param( 'ip', $session->remote_addr() ); |
1576 |
$session->param( 'ip', $ENV{REMOTE_ADDR} ); |
1577 |
$session->param( 'lasttime', time() ); |
1577 |
$session->param( 'lasttime', time() ); |
1578 |
} |
1578 |
} |
1579 |
C4::Context->set_userenv( |
1579 |
C4::Context->set_userenv( |
Lines 1709-1718
sub check_cookie_auth {
Link Here
|
1709 |
|
1709 |
|
1710 |
=head2 get_session |
1710 |
=head2 get_session |
1711 |
|
1711 |
|
1712 |
use CGI::Session; |
|
|
1713 |
my $session = get_session($sessionID); |
1712 |
my $session = get_session($sessionID); |
1714 |
|
1713 |
|
1715 |
Given a session ID, retrieve the CGI::Session object used to store |
1714 |
Given a session ID, retrieve the Data::Session object used to store |
1716 |
the session's state. The session object can be used to store |
1715 |
the session's state. The session object can be used to store |
1717 |
data that needs to be accessed by different scripts during a |
1716 |
data that needs to be accessed by different scripts during a |
1718 |
user's session. |
1717 |
user's session. |
Lines 1728-1747
sub get_session {
Link Here
|
1728 |
my $dbh = C4::Context->dbh; |
1727 |
my $dbh = C4::Context->dbh; |
1729 |
my $session; |
1728 |
my $session; |
1730 |
if ( $storage_method eq 'mysql' ) { |
1729 |
if ( $storage_method eq 'mysql' ) { |
1731 |
$session = new CGI::Session( "driver:MySQL;serializer:yaml;id:md5", $sessionID, { Handle => $dbh } ); |
1730 |
# Note that the doc is wrong, type is required, if not provided it default to File |
1732 |
} |
1731 |
$session = Data::Session->new( dbh => $dbh, type => 'driver:mysql;id:MD5;serialize:YAML' ) or die $Data::Session::errstr; |
1733 |
elsif ( $storage_method eq 'Pg' ) { |
1732 |
} elsif ( $storage_method eq 'Pg' ) { |
1734 |
$session = new CGI::Session( "driver:PostgreSQL;serializer:yaml;id:md5", $sessionID, { Handle => $dbh } ); |
1733 |
warn "The system preference SessionStorage is set to 'Pg' but this is not supported yet!"; |
1735 |
} |
1734 |
} elsif ( $storage_method eq 'memcached' and my $memcached = Koha::Caches->get_instance->memcached_cache ) { |
1736 |
elsif ( $storage_method eq 'memcached' && Koha::Caches->get_instance->memcached_cache ) { |
1735 |
$session = Data::Session->new( |
1737 |
my $memcached = Koha::Caches->get_instance()->memcached_cache; |
1736 |
type => 'driver:Memcached;id:SHA1;serialize:DataDumper', |
1738 |
$session = new CGI::Session( "driver:memcached;serializer:yaml;id:md5", $sessionID, { Memcached => $memcached } ); |
1737 |
cache => $memcached, |
|
|
1738 |
); |
1739 |
} elsif ( $storage_method ne 'tmp' ) { |
1740 |
warn "The system preference SessionStorage is set to an invalid value '$storage_method'"; |
1739 |
} |
1741 |
} |
1740 |
else { |
1742 |
if ( $storage_method eq 'tmp' or not $session ) { |
1741 |
# catch all defaults to tmp should work on all systems |
1743 |
if ( $storage_method ne 'tmp' ) { |
1742 |
my $dir = File::Spec->tmpdir; |
1744 |
warn "The session has not been correctly retrieved, defaulting to temporary storage: " . $Data::Session::errstr; |
1743 |
my $instance = C4::Context->config( 'database' ); #actually for packages not exactly the instance name, but generally safer to leave it as it is |
1745 |
} |
1744 |
$session = new CGI::Session( "driver:File;serializer:yaml;id:md5", $sessionID, { Directory => "$dir/cgisess_$instance" } ); |
1746 |
my $dir = '/tmp/'; #File::Spec->tmpdir; |
|
|
1747 |
my $instance = C4::Context->config('database'); #actually for packages not exactly the instance name, but generally safer to leave it as it is |
1748 |
$session = Data::Session->new( type => 'driver:File;id:MD5;serialize:YAML', directory => "$dir/cgisess_$instance" ) or die $Data::Session::errstr; |
1745 |
} |
1749 |
} |
1746 |
return $session; |
1750 |
return $session; |
1747 |
} |
1751 |
} |