Lines 32-37
use C4::Templates; # to get the template
Link Here
|
32 |
use C4::Languages; |
32 |
use C4::Languages; |
33 |
use C4::Search::History; |
33 |
use C4::Search::History; |
34 |
use Koha; |
34 |
use Koha; |
|
|
35 |
use Koha::Logger; |
35 |
use Koha::Caches; |
36 |
use Koha::Caches; |
36 |
use Koha::AuthUtils qw(get_script_name hash_password); |
37 |
use Koha::AuthUtils qw(get_script_name hash_password); |
37 |
use Koha::Checkouts; |
38 |
use Koha::Checkouts; |
Lines 50-56
use Net::CIDR;
Link Here
|
50 |
use C4::Log qw/logaction/; |
51 |
use C4::Log qw/logaction/; |
51 |
|
52 |
|
52 |
# use utf8; |
53 |
# use utf8; |
53 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout); |
54 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $ldap $cas $caslogout); |
54 |
|
55 |
|
55 |
BEGIN { |
56 |
BEGIN { |
56 |
sub psgi_env { any { /^psgi\./ } keys %ENV } |
57 |
sub psgi_env { any { /^psgi\./ } keys %ENV } |
Lines 62-68
BEGIN {
Link Here
|
62 |
|
63 |
|
63 |
C4::Context->set_remote_address; |
64 |
C4::Context->set_remote_address; |
64 |
|
65 |
|
65 |
$debug = $ENV{DEBUG}; |
|
|
66 |
@ISA = qw(Exporter); |
66 |
@ISA = qw(Exporter); |
67 |
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions); |
67 |
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions); |
68 |
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &checkpw_internal &checkpw_hash |
68 |
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &checkpw_internal &checkpw_hash |
Lines 763-769
sub _version_check {
Link Here
|
763 |
|
763 |
|
764 |
# remove the 3 last . to have a Perl number |
764 |
# remove the 3 last . to have a Perl number |
765 |
$kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; |
765 |
$kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; |
766 |
$debug and print STDERR "kohaversion : $kohaversion\n"; |
766 |
Koha::Logger->get->debug("kohaversion : $kohaversion"); |
767 |
if ( $version < $kohaversion ) { |
767 |
if ( $version < $kohaversion ) { |
768 |
my $warning = "Database update needed, redirecting to %s. Database is $version and Koha is $kohaversion"; |
768 |
my $warning = "Database update needed, redirecting to %s. Database is $version and Koha is $kohaversion"; |
769 |
if ( $type ne 'opac' ) { |
769 |
if ( $type ne 'opac' ) { |
Lines 806-812
sub _timeout_syspref {
Link Here
|
806 |
|
806 |
|
807 |
sub checkauth { |
807 |
sub checkauth { |
808 |
my $query = shift; |
808 |
my $query = shift; |
809 |
$debug and warn "Checking Auth"; |
|
|
810 |
|
809 |
|
811 |
# Get shibboleth login attribute |
810 |
# Get shibboleth login attribute |
812 |
my $shib = C4::Context->config('useshibboleth') && shib_ok(); |
811 |
my $shib = C4::Context->config('useshibboleth') && shib_ok(); |
Lines 893-899
sub checkauth {
Link Here
|
893 |
$session->param('desk_id'), $session->param('desk_name'), |
892 |
$session->param('desk_id'), $session->param('desk_name'), |
894 |
$session->param('register_id'), $session->param('register_name') |
893 |
$session->param('register_id'), $session->param('register_name') |
895 |
); |
894 |
); |
896 |
$debug and printf STDERR "AUTH_SESSION: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch); |
895 |
Koha::Logger->get->debug(sprintf "AUTH_SESSION: (%s)\t%s %s - %s", map { $session->param($_) } qw(cardnumber firstname surname branch)); |
897 |
$ip = $session->param('ip'); |
896 |
$ip = $session->param('ip'); |
898 |
$lasttime = $session->param('lasttime'); |
897 |
$lasttime = $session->param('lasttime'); |
899 |
$userid = $s_userid; |
898 |
$userid = $s_userid; |
Lines 906-912
sub checkauth {
Link Here
|
906 |
|
905 |
|
907 |
#if a user enters an id ne to the id in the current session, we need to log them in... |
906 |
#if a user enters an id ne to the id in the current session, we need to log them in... |
908 |
#first we need to clear the anonymous session... |
907 |
#first we need to clear the anonymous session... |
909 |
$debug and warn "query id = $q_userid but session id = $s_userid"; |
|
|
910 |
$anon_search_history = $session->param('search_history'); |
908 |
$anon_search_history = $session->param('search_history'); |
911 |
$session->delete(); |
909 |
$session->delete(); |
912 |
$session->flush; |
910 |
$session->flush; |
Lines 1143-1167
sub checkauth {
Link Here
|
1143 |
my $sth = $dbh->prepare("$select where userid=?"); |
1141 |
my $sth = $dbh->prepare("$select where userid=?"); |
1144 |
$sth->execute($userid); |
1142 |
$sth->execute($userid); |
1145 |
unless ( $sth->rows ) { |
1143 |
unless ( $sth->rows ) { |
1146 |
$debug and print STDERR "AUTH_1: no rows for userid='$userid'\n"; |
|
|
1147 |
$sth = $dbh->prepare("$select where cardnumber=?"); |
1144 |
$sth = $dbh->prepare("$select where cardnumber=?"); |
1148 |
$sth->execute($cardnumber); |
1145 |
$sth->execute($cardnumber); |
1149 |
|
1146 |
|
1150 |
unless ( $sth->rows ) { |
1147 |
unless ( $sth->rows ) { |
1151 |
$debug and print STDERR "AUTH_2a: no rows for cardnumber='$cardnumber'\n"; |
|
|
1152 |
$sth->execute($userid); |
1148 |
$sth->execute($userid); |
1153 |
unless ( $sth->rows ) { |
|
|
1154 |
$debug and print STDERR "AUTH_2b: no rows for userid='$userid' AS cardnumber\n"; |
1155 |
} |
1156 |
} |
1149 |
} |
1157 |
} |
1150 |
} |
1158 |
if ( $sth->rows ) { |
1151 |
if ( $sth->rows ) { |
1159 |
( $borrowernumber, $firstname, $surname, $userflags, |
1152 |
( $borrowernumber, $firstname, $surname, $userflags, |
1160 |
$branchcode, $branchname, $emailaddress ) = $sth->fetchrow; |
1153 |
$branchcode, $branchname, $emailaddress ) = $sth->fetchrow; |
1161 |
$debug and print STDERR "AUTH_3 results: " . |
|
|
1162 |
"$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress\n"; |
1163 |
} else { |
1164 |
print STDERR "AUTH_3: no results for userid='$userid', cardnumber='$cardnumber'.\n"; |
1165 |
} |
1154 |
} |
1166 |
|
1155 |
|
1167 |
# launch a sequence to check if we have a ip for the branch, i |
1156 |
# launch a sequence to check if we have a ip for the branch, i |
Lines 1236-1242
sub checkauth {
Link Here
|
1236 |
$session->param( 'shibboleth', $shibSuccess ); |
1225 |
$session->param( 'shibboleth', $shibSuccess ); |
1237 |
$session->param( 'register_id', $register_id ); |
1226 |
$session->param( 'register_id', $register_id ); |
1238 |
$session->param( 'register_name', $register_name ); |
1227 |
$session->param( 'register_name', $register_name ); |
1239 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch); |
|
|
1240 |
} |
1228 |
} |
1241 |
$session->param('cas_ticket', $cas_ticket) if $cas_ticket; |
1229 |
$session->param('cas_ticket', $cas_ticket) if $cas_ticket; |
1242 |
C4::Context->set_userenv( |
1230 |
C4::Context->set_userenv( |
Lines 1253-1259
sub checkauth {
Link Here
|
1253 |
# $return: 0 = invalid user |
1241 |
# $return: 0 = invalid user |
1254 |
# reset to anonymous session |
1242 |
# reset to anonymous session |
1255 |
else { |
1243 |
else { |
1256 |
$debug and warn "Login failed, resetting anonymous session..."; |
|
|
1257 |
if ($userid) { |
1244 |
if ($userid) { |
1258 |
$info{'invalid_username_or_password'} = 1; |
1245 |
$info{'invalid_username_or_password'} = 1; |
1259 |
C4::Context->_unset_userenv($sessionID); |
1246 |
C4::Context->_unset_userenv($sessionID); |
Lines 1266-1274
sub checkauth {
Link Here
|
1266 |
} # END if ( $q_userid |
1253 |
} # END if ( $q_userid |
1267 |
elsif ( $type eq "opac" ) { |
1254 |
elsif ( $type eq "opac" ) { |
1268 |
|
1255 |
|
1269 |
# if we are here this is an anonymous session; add public lists to it and a few other items... |
|
|
1270 |
# anonymous sessions are created only for the OPAC |
1256 |
# anonymous sessions are created only for the OPAC |
1271 |
$debug and warn "Initiating an anonymous session..."; |
|
|
1272 |
|
1257 |
|
1273 |
# setting a couple of other session vars... |
1258 |
# setting a couple of other session vars... |
1274 |
$session->param( 'ip', $session->remote_addr() ); |
1259 |
$session->param( 'ip', $session->remote_addr() ); |
Lines 1589-1595
sub check_api_auth {
Link Here
|
1589 |
# Proxy CAS auth |
1574 |
# Proxy CAS auth |
1590 |
if ( $cas && $query->param('PT') ) { |
1575 |
if ( $cas && $query->param('PT') ) { |
1591 |
my $retuserid; |
1576 |
my $retuserid; |
1592 |
$debug and print STDERR "## check_api_auth - checking CAS\n"; |
|
|
1593 |
|
1577 |
|
1594 |
# In case of a CAS authentication, we use the ticket instead of the password |
1578 |
# In case of a CAS authentication, we use the ticket instead of the password |
1595 |
my $PT = $query->param('PT'); |
1579 |
my $PT = $query->param('PT'); |
Lines 1905-1911
sub checkpw {
Link Here
|
1905 |
if ( $patron and $patron->account_locked ) { |
1889 |
if ( $patron and $patron->account_locked ) { |
1906 |
# Nothing to check, account is locked |
1890 |
# Nothing to check, account is locked |
1907 |
} elsif ($ldap && defined($password)) { |
1891 |
} elsif ($ldap && defined($password)) { |
1908 |
$debug and print STDERR "## checkpw - checking LDAP\n"; |
|
|
1909 |
my ( $retval, $retcard, $retuserid ) = checkpw_ldap(@_); # EXTERNAL AUTH |
1892 |
my ( $retval, $retcard, $retuserid ) = checkpw_ldap(@_); # EXTERNAL AUTH |
1910 |
if ( $retval == 1 ) { |
1893 |
if ( $retval == 1 ) { |
1911 |
@return = ( $retval, $retcard, $retuserid ); |
1894 |
@return = ( $retval, $retcard, $retuserid ); |
Lines 1914-1920
sub checkpw {
Link Here
|
1914 |
$check_internal_as_fallback = 1 if $retval == 0; |
1897 |
$check_internal_as_fallback = 1 if $retval == 0; |
1915 |
|
1898 |
|
1916 |
} elsif ( $cas && $query && $query->param('ticket') ) { |
1899 |
} elsif ( $cas && $query && $query->param('ticket') ) { |
1917 |
$debug and print STDERR "## checkpw - checking CAS\n"; |
|
|
1918 |
|
1900 |
|
1919 |
# In case of a CAS authentication, we use the ticket instead of the password |
1901 |
# In case of a CAS authentication, we use the ticket instead of the password |
1920 |
my $ticket = $query->param('ticket'); |
1902 |
my $ticket = $query->param('ticket'); |
Lines 1933-1940
sub checkpw {
Link Here
|
1933 |
# time around. |
1915 |
# time around. |
1934 |
elsif ( $shib && $shib_login && !$password ) { |
1916 |
elsif ( $shib && $shib_login && !$password ) { |
1935 |
|
1917 |
|
1936 |
$debug and print STDERR "## checkpw - checking Shibboleth\n"; |
|
|
1937 |
|
1938 |
# In case of a Shibboleth authentication, we expect a shibboleth user attribute |
1918 |
# In case of a Shibboleth authentication, we expect a shibboleth user attribute |
1939 |
# (defined under shibboleth mapping in koha-conf.xml) to contain the login of the |
1919 |
# (defined under shibboleth mapping in koha-conf.xml) to contain the login of the |
1940 |
# shibboleth-authenticated user |
1920 |
# shibboleth-authenticated user |
Lines 2240-2246
sub in_iprange {
Link Here
|
2240 |
if (scalar @allowedipranges > 0) { |
2220 |
if (scalar @allowedipranges > 0) { |
2241 |
my @rangelist; |
2221 |
my @rangelist; |
2242 |
eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@; |
2222 |
eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@; |
2243 |
eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || ( $ENV{DEBUG} && warn 'cidrlookup failed for ' . join(' ',@rangelist) ); |
2223 |
eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || Koha::Logger->get->warn('cidrlookup failed for ' . join(' ',@rangelist) ); |
2244 |
} |
2224 |
} |
2245 |
return $result ? 1 : 0; |
2225 |
return $result ? 1 : 0; |
2246 |
} |
2226 |
} |