use strict;
use warnings;
use Digest::MD5 qw(md5_base64);
+use File::Spec;
use JSON qw/encode_json/;
use URI::Escape;
use CGI::Session;
use C4::Search::History;
use Koha;
use Koha::AuthUtils qw(hash_password);
+use Koha::LibraryCategories;
+use Koha::Libraries;
use POSIX qw/strftime/;
use List::MoreUtils qw/ any /;
use Encode qw( encode is_utf8);
# use utf8;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout $shib $shib_login);
+use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout $shib $shib_login);
BEGIN {
sub psgi_env { any { /^psgi\./ } keys %ENV }
if (psgi_env) { die 'psgi:exit' }
else { exit }
}
- $VERSION = 3.07.00.049; # set version for version checking
$debug = $ENV{DEBUG};
@ISA = qw(Exporter);
-HttpOnly => 1,
);
- $template->param( loginprompt => 1 );
+ $template->param(
+ loginprompt => 1,
+ script_name => _get_script_name(),
+ );
print $in->{query}->header(
- -type => 'text/html',
- -charset => 'utf-8',
- -cookie => $cookie,
+ { type => 'text/html',
+ charset => 'utf-8',
+ cookie => $cookie,
+ 'X-Frame-Options' => 'SAMEORIGIN'
+ }
),
$template->output;
safe_exit;
$template->param( dateformat => C4::Context->preference('dateformat') );
}
- $template->param(auth_forwarded_hash => $in->{'query'}->param('auth_forwarded_hash'));
+ $template->param(auth_forwarded_hash => scalar $in->{'query'}->param('auth_forwarded_hash'));
# these template parameters are set the same regardless of $in->{'type'}
hide_marc => C4::Context->preference("hide_marc"),
item_level_itypes => C4::Context->preference('item-level_itypes'),
patronimages => C4::Context->preference("patronimages"),
- singleBranchMode => C4::Context->preference("singleBranchMode"),
+ singleBranchMode => ( Koha::Libraries->search->count == 1 ),
XSLTDetailsDisplay => C4::Context->preference("XSLTDetailsDisplay"),
XSLTResultsDisplay => C4::Context->preference("XSLTResultsDisplay"),
using_https => $using_https,
$opac_name = C4::Context->userenv->{'branch'};
}
+ my $library_categories = Koha::LibraryCategories->search({categorytype => 'searchdomain', show_in_pulldown => 1}, { order_by => ['categorytype', 'categorycode']});
$template->param(
OpacAdditionalStylesheet => C4::Context->preference("OpacAdditionalStylesheet"),
AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"),
- AuthorisedValueImages => C4::Context->preference("AuthorisedValueImages"),
BranchesLoop => GetBranchesLoop($opac_name),
- BranchCategoriesLoop => GetBranchCategories( 'searchdomain', 1, $opac_name ),
+ BranchCategoriesLoop => $library_categories,
+ opac_name => $opac_name,
LibraryName => "" . C4::Context->preference("LibraryName"),
LibraryNameTitle => "" . $LibraryNameTitle,
LoginBranchname => C4::Context->userenv ? C4::Context->userenv->{"branchname"} : "",
opacreadinghistory => C4::Context->preference("opacreadinghistory"),
OPACUserJS => C4::Context->preference("OPACUserJS"),
opacuserlogin => "" . C4::Context->preference("opacuserlogin"),
+ OpenLibrarySearch => C4::Context->preference("OpenLibrarySearch"),
ShowReviewer => C4::Context->preference("ShowReviewer"),
ShowReviewerPhoto => C4::Context->preference("ShowReviewerPhoto"),
suggestion => "" . C4::Context->preference("suggestion"),
opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
login => 1,
INPUTS => \@inputs,
+ script_name => _get_script_name(),
casAuthentication => C4::Context->preference("casAuthentication"),
shibbolethAuthentication => $shib,
SessionRestrictionByIP => C4::Context->preference("SessionRestrictionByIP"),
opac_css_override => $ENV{'OPAC_CSS_OVERRIDE'},
);
+ $template->param( SCO_login => 1 ) if ( $query->param('sco_user_login') );
$template->param( OpacPublic => C4::Context->preference("OpacPublic") );
$template->param( loginprompt => 1 ) unless $info{'nopermission'};
);
}
+ if (C4::Context->preference('GoogleOpenIDConnect')) {
+ if ($query->param("OpenIDConnectFailed")) {
+ my $reason = $query->param('OpenIDConnectFailed');
+ $template->param(invalidGoogleOpenIDConnectLogin => $reason);
+ }
+ }
+
$template->param(
LibraryName => C4::Context->preference("LibraryName"),
);
# $cookie = $query->cookie(CGISESSID => $session->id
# );
print $query->header(
- -type => 'text/html',
- -charset => 'utf-8',
- -cookie => $cookie
+ { type => 'text/html',
+ charset => 'utf-8',
+ cookie => $cookie,
+ 'X-Frame-Options' => 'SAMEORIGIN'
+ }
),
$template->output;
safe_exit;
}
else {
# catch all defaults to tmp should work on all systems
- $session = new CGI::Session( "driver:File;serializer:yaml;id:md5", $sessionID, { Directory => '/tmp' } );
+ my $dir = File::Spec->tmpdir;
+ my $instance = C4::Context->config( 'database' ); #actually for packages not exactly the instance name, but generally safer to leave it as it is
+ $session = new CGI::Session( "driver:File;serializer:yaml;id:md5", $sessionID, { Directory => "$dir/cgisess_$instance" } );
}
return $session;
}
sub checkpw {
- my ( $dbh, $userid, $password, $query, $type ) = @_;
+ my ( $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_;
$type = 'opac' unless $type;
if ($ldap) {
$debug and print STDERR "## checkpw - checking LDAP\n";
}
# INTERNAL AUTH
- return checkpw_internal(@_)
+ return checkpw_internal( $dbh, $userid, $password, $no_set_userenv);
}
sub checkpw_internal {
- my ( $dbh, $userid, $password ) = @_;
+ my ( $dbh, $userid, $password, $no_set_userenv ) = @_;
$password = Encode::encode( 'UTF-8', $password )
if Encode::is_utf8($password);
if ( checkpw_hash( $password, $stored_hash ) ) {
C4::Context->set_userenv( "$borrowernumber", $userid, $cardnumber,
- $firstname, $surname, $branchcode, $branchname, $flags );
+ $firstname, $surname, $branchcode, $branchname, $flags ) unless $no_set_userenv;
return 1, $cardnumber, $userid;
}
}
if ( checkpw_hash( $password, $stored_hash ) ) {
C4::Context->set_userenv( $borrowernumber, $userid, $cardnumber,
- $firstname, $surname, $branchcode, $branchname, $flags );
+ $firstname, $surname, $branchcode, $branchname, $flags ) unless $no_set_userenv;
return 1, $cardnumber, $userid;
}
}
return 0;
}
+=head2 _get_script_name
+
+This returns the correct script name, for use in redirecting back to the correct page after showing
+the login screen. It depends on details of the package Plack configuration, and should not be used
+outside this context.
+
+=cut
+
+sub _get_script_name {
+ # This is the method about.pl uses to detect Plack; now that two places use it, it MUST be
+ # right.
+ if ( ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) && $ENV{SCRIPT_NAME} =~ m,^/(intranet|opac)(.*), ) {
+ return '/cgi-bin/koha' . $2;
+ } else {
+ return $ENV{SCRIPT_NAME};
+ }
+}
+
END { } # module clean-up code here (global destructor)
1;
__END__