From a29046db4f440e60ee3ff6da3725ba7f3d0a53b1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 6 Jul 2012 11:29:06 +0200 Subject: [PATCH 1/3] Bug 7167: Now, we check versions on mainpage.pl and after login --- C4/Auth.pm | 60 +++++++++++++++++++++++++++++++++++++++++++++------------- mainpage.pl | 17 +--------------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 6f88915..c23e87c 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -28,6 +28,7 @@ require Exporter; use C4::Context; use C4::Templates; # to get the template use C4::Branch; # GetBranches +use C4::Update::Database; use C4::VirtualShelves; use POSIX qw/strftime/; use List::MoreUtils qw/ any /; @@ -133,9 +134,9 @@ sub get_template_and_user { my $in = shift; my $template = C4::Templates::gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} ); - my ( $user, $cookie, $sessionID, $flags ); + my ( $user, $cookie, $sessionID, $flags, $new_session ); if ( $in->{'template_name'} !~m/maintenance/ ) { - ( $user, $cookie, $sessionID, $flags ) = checkauth( + ( $user, $cookie, $sessionID, $flags, $new_session ) = checkauth( $in->{'query'}, $in->{'authnotrequired'}, $in->{'flagsrequired'}, @@ -477,6 +478,12 @@ sub get_template_and_user { $template->param(OpacPublic => '1') if ($user || C4::Context->preference("OpacPublic")); } + + if ( $new_session ) { + # Check the version and redirect if DB is not up-to-date + version_check($in->{query}, $in->{'type'}, $cookie); + } + return ( $template, $borrowernumber, $cookie, $flags); } @@ -565,6 +572,38 @@ sub _session_log { close L; } +sub version_check { + my ( $query, $type, $cookie ) = @_; + # check we have a Version. Otherwise => go to installer + unless ( C4::Context->preference('Version') ) { + if ( $type ne 'opac' ) { + $debug && warn "Install required, redirecting to Installer"; + print $query->redirect("/cgi-bin/koha/installer/install.pl"); + } else { + $debug && warn "OPAC Install required, redirecting to maintenance"; + print $query->redirect("/cgi-bin/koha/maintenance.pl"); + } + safe_exit; + } + + # check if you're uptodate, and if you're not, head to updater + my $koha39 =~ "3.0900000"; + + # Old updatedatabase method + if (C4::Context->preference('Version') < $koha39) { + print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3"); + safe_exit; + } + + # New updatedatabase method + unless ( C4::Update::Database::is_uptodate() ) { + # not up-to-date, redirect to updatedatabase page + warn "redirect to updatedatabase"; + print $query->redirect(-location => "/cgi-bin/koha/admin/updatedatabase.pl", -cookie => $cookie); + safe_exit; + } +} + sub checkauth { my $query = shift; $debug and warn "Checking Auth"; @@ -573,6 +612,7 @@ sub checkauth { my $flagsrequired = shift; my $type = shift; $type = 'opac' unless $type; + my $new_session = 0; my $dbh = C4::Context->dbh; my $timeout = C4::Context->preference('timeout'); @@ -581,17 +621,6 @@ sub checkauth { $timeout = $1 * 86400; }; $timeout = 600 unless $timeout; - # check we have a Version. Otherwise => go to installer - unless ( C4::Context->preference('Version') ) { # assignment, not comparison - if ( $type ne 'opac' ) { - $debug && warn "Install required, redirecting to Installer"; - print $query->redirect("/cgi-bin/koha/installer/install.pl"); - } else { - $debug && warn "OPAC Install required, redirecting to maintenance"; - print $query->redirect("/cgi-bin/koha/maintenance.pl"); - } - safe_exit; - } # state variables my $loggedin = 0; @@ -696,6 +725,7 @@ sub checkauth { my $sessionID = $session->id; C4::Context->_new_userenv($sessionID); $cookie = $query->cookie( CGISESSID => $sessionID ); + $userid = $query->param('userid'); if ( ( $cas && $query->param('ticket') ) || $userid @@ -710,6 +740,7 @@ sub checkauth { checkpw( $dbh, $userid, $password, $query ); $userid = $retuserid; $info{'invalidCasLogin'} = 1 unless ($return); + $new_session = 1; } elsif ( ( $pki_field eq 'Common Name' && $ENV{'SSL_CLIENT_S_DN_CN'} ) @@ -748,6 +779,7 @@ sub checkauth { ( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); $userid = $retuserid if ( $retuserid ne '' ); + $new_session = 1; } if ($return) { #_session_log(sprintf "%20s from %16s logged in at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime)); @@ -889,7 +921,7 @@ sub checkauth { unless ($cookie) { $cookie = $query->cookie( CGISESSID => '' ); } - return ( $userid, $cookie, $sessionID, $flags ); + return ( $userid, $cookie, $sessionID, $flags, $new_session ); } # diff --git a/mainpage.pl b/mainpage.pl index 3e7dd3a..505c166 100755 --- a/mainpage.pl +++ b/mainpage.pl @@ -28,7 +28,6 @@ use C4::NewsChannels; use C4::Review qw/numberofreviews/; use C4::Suggestions qw/CountSuggestion/; use C4::Tags qw/get_count_by_tag_status/; -use C4::Update::Database; my $query = new CGI; @@ -44,21 +43,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -# -# check if you're uptodate, and if you're not, head to updater -# -my $koha36= C4::Context::KOHAVERSION; -$koha36 =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; - -if (C4::Context->preference('Version') < $koha36) { - print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3"); - exit; -} -unless ( C4::Update::Database::is_uptodate() ) { - # not uptodate, redirect to updatedatabase page - print $query->redirect("/cgi-bin/koha/admin/updatedatabase.pl"); - exit; -} +C4::Auth::version_check($query, 'intranet', $cookie); my $all_koha_news = &GetNewsToDisplay("koha"); my $koha_news_count = scalar @$all_koha_news; -- 1.7.7.3