Lines 32-58
use C4::Koha;
Link Here
|
32 |
use C4::Branch; # GetBranches |
32 |
use C4::Branch; # GetBranches |
33 |
use C4::VirtualShelves; |
33 |
use C4::VirtualShelves; |
34 |
use POSIX qw/strftime/; |
34 |
use POSIX qw/strftime/; |
|
|
35 |
use List::MoreUtils qw/ any /; |
35 |
|
36 |
|
36 |
# use utf8; |
37 |
# use utf8; |
37 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout $servers $memcached); |
38 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout $servers $memcached); |
38 |
|
39 |
|
39 |
BEGIN { |
40 |
BEGIN { |
40 |
$VERSION = 3.02; # set version for version checking |
41 |
sub psgi_env { any { /^psgi\./ } keys %ENV } |
41 |
$debug = $ENV{DEBUG}; |
42 |
sub safe_exit { |
42 |
@ISA = qw(Exporter); |
43 |
if ( psgi_env ) { die 'psgi:exit' } |
43 |
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions); |
44 |
else { exit } |
44 |
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &get_all_subpermissions &get_user_subpermissions); |
45 |
} |
45 |
%EXPORT_TAGS = (EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)]); |
46 |
|
46 |
$ldap = C4::Context->config('useldapserver') || 0; |
47 |
$VERSION = 3.02; # set version for version checking |
47 |
$cas = C4::Context->preference('casAuthentication'); |
48 |
$debug = $ENV{DEBUG}; |
48 |
$caslogout = C4::Context->preference('casLogout'); |
49 |
@ISA = qw(Exporter); |
|
|
50 |
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions); |
51 |
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &get_all_subpermissions &get_user_subpermissions); |
52 |
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] ); |
53 |
$ldap = C4::Context->config('useldapserver') || 0; |
54 |
$cas = C4::Context->preference('casAuthentication'); |
55 |
$caslogout = C4::Context->preference('casLogout'); |
56 |
require C4::Auth_with_cas; # no import |
49 |
if ($ldap) { |
57 |
if ($ldap) { |
50 |
require C4::Auth_with_ldap; # no import |
58 |
require C4::Auth_with_ldap; |
51 |
import C4::Auth_with_ldap qw(checkpw_ldap); |
59 |
# no import import C4::Auth_with_ldap qw(checkpw_ldap); |
52 |
} |
60 |
} |
53 |
if ($cas) { |
61 |
if ($cas) { |
54 |
require C4::Auth_with_cas; # no import |
62 |
import C4::Auth_with_cas qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url); |
55 |
import C4::Auth_with_cas qw(checkpw_cas login_cas logout_cas login_cas_url); |
|
|
56 |
} |
63 |
} |
57 |
$servers = C4::Context->config('memcached_servers'); |
64 |
$servers = C4::Context->config('memcached_servers'); |
58 |
if ($servers) { |
65 |
if ($servers) { |
Lines 130-137
Output.pm module.
Link Here
|
130 |
=cut |
137 |
=cut |
131 |
|
138 |
|
132 |
my $SEARCH_HISTORY_INSERT_SQL =<<EOQ; |
139 |
my $SEARCH_HISTORY_INSERT_SQL =<<EOQ; |
133 |
INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time ) |
140 |
INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, time ) |
134 |
VALUES ( ?, ?, ?, ?, ?, FROM_UNIXTIME(?)) |
141 |
VALUES ( ?, ?, ?, ?, ?, ?, ?, FROM_UNIXTIME(?)) |
135 |
EOQ |
142 |
EOQ |
136 |
sub get_template_and_user { |
143 |
sub get_template_and_user { |
137 |
my $in = shift; |
144 |
my $in = shift; |
Lines 264-276
sub get_template_and_user {
Link Here
|
264 |
my @recentSearches = @{thaw($searchcookie) || []}; |
271 |
my @recentSearches = @{thaw($searchcookie) || []}; |
265 |
if (@recentSearches) { |
272 |
if (@recentSearches) { |
266 |
my $sth = $dbh->prepare($SEARCH_HISTORY_INSERT_SQL); |
273 |
my $sth = $dbh->prepare($SEARCH_HISTORY_INSERT_SQL); |
267 |
$sth->execute( $borrowernumber, |
274 |
|
268 |
$in->{'query'}->cookie("CGISESSID"), |
275 |
$sth->execute( $borrowernumber, $in->{'query'}->cookie("CGISESSID"), $_->{'query_desc'}, $_->{'query_cgi'}, $_->{'limit_desc'}, $_->{'limit_cgi'}, $_->{'total'}, $_->{'time'}, ) |
269 |
$_->{'query_desc'}, |
276 |
foreach @recentSearches; |
270 |
$_->{'query_cgi'}, |
|
|
271 |
$_->{'total'}, |
272 |
$_->{'time'}, |
273 |
) foreach @recentSearches; |
274 |
|
277 |
|
275 |
# And then, delete the cookie's content |
278 |
# And then, delete the cookie's content |
276 |
my $newsearchcookie = $in->{'query'}->cookie( |
279 |
my $newsearchcookie = $in->{'query'}->cookie( |
Lines 571-589
sub _version_check ($$) {
Link Here
|
571 |
# and so we must redirect to OPAC maintenance page or to the WebInstaller |
574 |
# and so we must redirect to OPAC maintenance page or to the WebInstaller |
572 |
# also, if OpacMaintenance is ON, OPAC should redirect to maintenance |
575 |
# also, if OpacMaintenance is ON, OPAC should redirect to maintenance |
573 |
if (C4::Context->preference('OpacMaintenance') && $type eq 'opac') { |
576 |
if (C4::Context->preference('OpacMaintenance') && $type eq 'opac') { |
574 |
warn "OPAC Install required, redirecting to maintenance"; |
|
|
575 |
print $query->redirect("/cgi-bin/koha/maintenance.pl"); |
576 |
} |
577 |
unless ($version = C4::Context->preference('Version')) { # assignment, not comparison |
578 |
if ($type ne 'opac') { |
579 |
warn "Install required, redirecting to Installer"; |
580 |
print $query->redirect("/cgi-bin/koha/installer/install.pl"); |
581 |
} |
582 |
else { |
583 |
warn "OPAC Install required, redirecting to maintenance"; |
577 |
warn "OPAC Install required, redirecting to maintenance"; |
584 |
print $query->redirect("/cgi-bin/koha/maintenance.pl"); |
578 |
print $query->redirect("/cgi-bin/koha/maintenance.pl"); |
585 |
} |
579 |
} |
586 |
exit; |
580 |
unless ( $version = C4::Context->preference('Version') ) { # assignment, not comparison |
|
|
581 |
if ( $type ne 'opac' ) { |
582 |
warn "Install required, redirecting to Installer"; |
583 |
print $query->redirect("/cgi-bin/koha/installer/install.pl"); |
584 |
} else { |
585 |
warn "OPAC Install required, redirecting to maintenance"; |
586 |
print $query->redirect("/cgi-bin/koha/maintenance.pl"); |
587 |
} |
588 |
safe_exit; |
587 |
} |
589 |
} |
588 |
|
590 |
|
589 |
# check that database and koha version are the same |
591 |
# check that database and koha version are the same |
Lines 603-609
sub _version_check ($$) {
Link Here
|
603 |
warn sprintf("OPAC: " . $warning, 'maintenance'); |
605 |
warn sprintf("OPAC: " . $warning, 'maintenance'); |
604 |
print $query->redirect("/cgi-bin/koha/maintenance.pl"); |
606 |
print $query->redirect("/cgi-bin/koha/maintenance.pl"); |
605 |
} |
607 |
} |
606 |
exit; |
608 |
safe_exit; |
607 |
} |
609 |
} |
608 |
} |
610 |
} |
609 |
|
611 |
|
Lines 638-643
sub checkauth {
Link Here
|
638 |
my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves ); |
640 |
my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves ); |
639 |
my $logout = $query->param('logout.x'); |
641 |
my $logout = $query->param('logout.x'); |
640 |
|
642 |
|
|
|
643 |
# This parameter is the name of the CAS server we want to authenticate against, |
644 |
# when using authentication against multiple CAS servers, as configured in Auth_cas_servers.yaml |
645 |
my $casparam = $query->param('cas'); |
646 |
|
641 |
if ( $userid = $ENV{'REMOTE_USER'} ) { |
647 |
if ( $userid = $ENV{'REMOTE_USER'} ) { |
642 |
# Using Basic Authentication, no cookies required |
648 |
# Using Basic Authentication, no cookies required |
643 |
$cookie = $query->cookie( |
649 |
$cookie = $query->cookie( |
Lines 985-995
sub checkauth {
Link Here
|
985 |
$template->param( OpacPublic => C4::Context->preference("OpacPublic")); |
991 |
$template->param( OpacPublic => C4::Context->preference("OpacPublic")); |
986 |
$template->param( loginprompt => 1 ) unless $info{'nopermission'}; |
992 |
$template->param( loginprompt => 1 ) unless $info{'nopermission'}; |
987 |
|
993 |
|
988 |
if ($cas) { |
994 |
if ($cas) { |
|
|
995 |
|
996 |
# Is authentication against multiple CAS servers enabled? |
997 |
if (C4::Auth_with_cas::multipleAuth && !$casparam) { |
998 |
my $casservers = C4::Auth_with_cas::getMultipleAuth(); |
999 |
my @tmplservers; |
1000 |
foreach my $key (keys %$casservers) { |
1001 |
push @tmplservers, {name => $key, value => login_cas_url($query, $key) . "?cas=$key" }; |
1002 |
} |
1003 |
#warn Data::Dumper::Dumper(\@tmplservers); |
1004 |
$template->param( |
1005 |
casServersLoop => \@tmplservers |
1006 |
); |
1007 |
} else { |
1008 |
$template->param( |
1009 |
casServerUrl => login_cas_url($query), |
1010 |
); |
1011 |
} |
1012 |
|
989 |
$template->param( |
1013 |
$template->param( |
990 |
casServerUrl => login_cas_url(), |
1014 |
invalidCasLogin => $info{'invalidCasLogin'} |
991 |
invalidCasLogin => $info{'invalidCasLogin'} |
1015 |
); |
992 |
); |
|
|
993 |
} |
1016 |
} |
994 |
|
1017 |
|
995 |
my $self_url = $query->url( -absolute => 1 ); |
1018 |
my $self_url = $query->url( -absolute => 1 ); |
Lines 1006-1012
sub checkauth {
Link Here
|
1006 |
-cookie => $cookie |
1029 |
-cookie => $cookie |
1007 |
), |
1030 |
), |
1008 |
$template->output; |
1031 |
$template->output; |
1009 |
exit; |
1032 |
safe_exit; |
1010 |
} |
1033 |
} |
1011 |
|
1034 |
|
1012 |
=head2 check_api_auth |
1035 |
=head2 check_api_auth |
Lines 1079-1085
sub check_api_auth {
Link Here
|
1079 |
unless ($query->param('userid')) { |
1102 |
unless ($query->param('userid')) { |
1080 |
$sessionID = $query->cookie("CGISESSID"); |
1103 |
$sessionID = $query->cookie("CGISESSID"); |
1081 |
} |
1104 |
} |
1082 |
if ($sessionID) { |
1105 |
if ($sessionID && not $cas) { |
1083 |
my $session = get_session($sessionID); |
1106 |
my $session = get_session($sessionID); |
1084 |
C4::Context->_new_userenv($sessionID); |
1107 |
C4::Context->_new_userenv($sessionID); |
1085 |
if ($session) { |
1108 |
if ($session) { |
Lines 1129-1146
sub check_api_auth {
Link Here
|
1129 |
# new login |
1152 |
# new login |
1130 |
my $userid = $query->param('userid'); |
1153 |
my $userid = $query->param('userid'); |
1131 |
my $password = $query->param('password'); |
1154 |
my $password = $query->param('password'); |
1132 |
unless ($userid and $password) { |
1155 |
my ($return, $cardnumber); |
1133 |
# caller did something wrong, fail the authenticateion |
1156 |
|
1134 |
return ("failed", undef, undef); |
1157 |
# Proxy CAS auth |
1135 |
} |
1158 |
if ($cas && $query->param('PT')) { |
1136 |
my ($return, $cardnumber); |
|
|
1137 |
if ($cas && $query->param('ticket')) { |
1138 |
my $retuserid; |
1159 |
my $retuserid; |
1139 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
1160 |
$debug and print STDERR "## check_api_auth - checking CAS\n"; |
1140 |
$userid = $retuserid; |
1161 |
# In case of a CAS authentication, we use the ticket instead of the password |
|
|
1162 |
my $PT = $query->param('PT'); |
1163 |
($return,$cardnumber,$userid) = check_api_auth_cas($dbh, $PT, $query); # EXTERNAL AUTH |
1141 |
} else { |
1164 |
} else { |
|
|
1165 |
# User / password auth |
1166 |
unless ($userid and $password) { |
1167 |
# caller did something wrong, fail the authenticateion |
1168 |
return ("failed", undef, undef); |
1169 |
} |
1142 |
( $return, $cardnumber ) = checkpw( $dbh, $userid, $password, $query ); |
1170 |
( $return, $cardnumber ) = checkpw( $dbh, $userid, $password, $query ); |
1143 |
} |
1171 |
} |
|
|
1172 |
|
1144 |
if ($return and haspermission( $userid, $flagsrequired)) { |
1173 |
if ($return and haspermission( $userid, $flagsrequired)) { |
1145 |
my $session = get_session(""); |
1174 |
my $session = get_session(""); |
1146 |
return ("failed", undef, undef) unless $session; |
1175 |
return ("failed", undef, undef) unless $session; |
Lines 1397-1403
sub checkpw {
Link Here
|
1397 |
($retval) and return ($retval,$retcard); |
1426 |
($retval) and return ($retval,$retcard); |
1398 |
} |
1427 |
} |
1399 |
|
1428 |
|
1400 |
if ($cas && $query->param('ticket')) { |
1429 |
if ($cas && $query && $query->param('ticket')) { |
1401 |
$debug and print STDERR "## checkpw - checking CAS\n"; |
1430 |
$debug and print STDERR "## checkpw - checking CAS\n"; |
1402 |
# In case of a CAS authentication, we use the ticket instead of the password |
1431 |
# In case of a CAS authentication, we use the ticket instead of the password |
1403 |
my $ticket = $query->param('ticket'); |
1432 |
my $ticket = $query->param('ticket'); |