View | Details | Raw Unified | Return to bug 7167
Collapse All | Expand All

(-)a/C4/Auth.pm (-14 / +46 lines)
Lines 28-33 require Exporter; Link Here
28
use C4::Context;
28
use C4::Context;
29
use C4::Templates;    # to get the template
29
use C4::Templates;    # to get the template
30
use C4::Branch; # GetBranches
30
use C4::Branch; # GetBranches
31
use C4::Update::Database;
31
use C4::VirtualShelves;
32
use C4::VirtualShelves;
32
use POSIX qw/strftime/;
33
use POSIX qw/strftime/;
33
use List::MoreUtils qw/ any /;
34
use List::MoreUtils qw/ any /;
Lines 134-142 sub get_template_and_user { Link Here
134
    my $in       = shift;
135
    my $in       = shift;
135
    my $template =
136
    my $template =
136
      C4::Templates::gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} );
137
      C4::Templates::gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} );
137
    my ( $user, $cookie, $sessionID, $flags );
138
    my ( $user, $cookie, $sessionID, $flags, $new_session );
138
    if ( $in->{'template_name'} !~m/maintenance/ ) {
139
    if ( $in->{'template_name'} !~m/maintenance/ ) {
139
        ( $user, $cookie, $sessionID, $flags ) = checkauth(
140
        ( $user, $cookie, $sessionID, $flags, $new_session ) = checkauth(
140
            $in->{'query'},
141
            $in->{'query'},
141
            $in->{'authnotrequired'},
142
            $in->{'authnotrequired'},
142
            $in->{'flagsrequired'},
143
            $in->{'flagsrequired'},
Lines 466-471 sub get_template_and_user { Link Here
466
467
467
        $template->param(OpacPublic => '1') if ($user || C4::Context->preference("OpacPublic"));
468
        $template->param(OpacPublic => '1') if ($user || C4::Context->preference("OpacPublic"));
468
    }
469
    }
470
471
    if ( $new_session ) {
472
        # Check the version and redirect if DB is not up-to-date
473
        version_check($in->{query}, $in->{'type'}, $cookie);
474
    }
475
469
    return ( $template, $borrowernumber, $cookie, $flags);
476
    return ( $template, $borrowernumber, $cookie, $flags);
470
}
477
}
471
478
Lines 563-568 sub _timeout_syspref { Link Here
563
    return $timeout;
570
    return $timeout;
564
}
571
}
565
572
573
sub version_check {
574
    my ( $query, $type, $cookie ) = @_;
575
    # check we have a Version. Otherwise => go to installer
576
    unless ( C4::Context->preference('Version') ) {
577
        if ( $type ne 'opac' ) {
578
            $debug && warn "Install required, redirecting to Installer";
579
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
580
        } else {
581
            $debug && warn "OPAC Install required, redirecting to maintenance";
582
            print $query->redirect("/cgi-bin/koha/maintenance.pl");
583
        }
584
        safe_exit;
585
    }
586
587
    # check if you're uptodate, and if you're not, head to updater
588
    my $koha39 =~ "3.0900000";
589
590
    # Old updatedatabase method
591
    if (C4::Context->preference('Version') < $koha39) {
592
        print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3");
593
        safe_exit;
594
    }
595
596
    # New updatedatabase method
597
    unless ( C4::Update::Database::is_uptodate() ) {
598
        # not up-to-date, redirect to updatedatabase page
599
        warn "redirect to updatedatabase";
600
        print $query->redirect(-location => "/cgi-bin/koha/admin/updatedatabase.pl", -cookie => $cookie);
601
        safe_exit;
602
    }
603
}
604
566
sub checkauth {
605
sub checkauth {
567
    my $query = shift;
606
    my $query = shift;
568
	$debug and warn "Checking Auth";
607
	$debug and warn "Checking Auth";
Lines 571-576 sub checkauth { Link Here
571
    my $flagsrequired   = shift;
610
    my $flagsrequired   = shift;
572
    my $type            = shift;
611
    my $type            = shift;
573
    $type = 'opac' unless $type;
612
    $type = 'opac' unless $type;
613
    my $new_session = 0;
574
614
575
    my $dbh     = C4::Context->dbh;
615
    my $dbh     = C4::Context->dbh;
576
    my $timeout = _timeout_syspref();
616
    my $timeout = _timeout_syspref();
Lines 579-595 sub checkauth { Link Here
579
        $timeout = $1 * 86400;
619
        $timeout = $1 * 86400;
580
    };
620
    };
581
    $timeout = 600 unless $timeout;
621
    $timeout = 600 unless $timeout;
582
    # check we have a Version. Otherwise => go to installer
583
    unless ( C4::Context->preference('Version') ) {    # assignment, not comparison
584
        if ( $type ne 'opac' ) {
585
            $debug && warn "Install required, redirecting to Installer";
586
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
587
        } else {
588
            $debug && warn "OPAC Install required, redirecting to maintenance";
589
            print $query->redirect("/cgi-bin/koha/maintenance.pl");
590
        }
591
        safe_exit;
592
    }
593
622
594
    # state variables
623
    # state variables
595
    my $loggedin = 0;
624
    my $loggedin = 0;
Lines 694-699 sub checkauth { Link Here
694
        my $sessionID = $session->id;
723
        my $sessionID = $session->id;
695
        C4::Context->_new_userenv($sessionID);
724
        C4::Context->_new_userenv($sessionID);
696
        $cookie = $query->cookie( CGISESSID => $sessionID );
725
        $cookie = $query->cookie( CGISESSID => $sessionID );
726
697
        $userid = $query->param('userid');
727
        $userid = $query->param('userid');
698
        if (   ( $cas && $query->param('ticket') )
728
        if (   ( $cas && $query->param('ticket') )
699
            || $userid
729
            || $userid
Lines 708-713 sub checkauth { Link Here
708
                  checkpw( $dbh, $userid, $password, $query );
738
                  checkpw( $dbh, $userid, $password, $query );
709
                $userid = $retuserid;
739
                $userid = $retuserid;
710
                $info{'invalidCasLogin'} = 1 unless ($return);
740
                $info{'invalidCasLogin'} = 1 unless ($return);
741
                $new_session = 1;
711
            }
742
            }
712
            elsif (
743
            elsif (
713
                ( $pki_field eq 'Common Name' && $ENV{'SSL_CLIENT_S_DN_CN'} )
744
                ( $pki_field eq 'Common Name' && $ENV{'SSL_CLIENT_S_DN_CN'} )
Lines 746-751 sub checkauth { Link Here
746
                ( $return, $cardnumber, $retuserid ) =
777
                ( $return, $cardnumber, $retuserid ) =
747
                  checkpw( $dbh, $userid, $password, $query );
778
                  checkpw( $dbh, $userid, $password, $query );
748
                $userid = $retuserid if ( $retuserid ne '' );
779
                $userid = $retuserid if ( $retuserid ne '' );
780
                $new_session = 1;
749
            }
781
            }
750
		if ($return) {
782
		if ($return) {
751
               #_session_log(sprintf "%20s from %16s logged in  at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime));
783
               #_session_log(sprintf "%20s from %16s logged in  at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime));
Lines 887-893 sub checkauth { Link Here
887
        unless ($cookie) {
919
        unless ($cookie) {
888
            $cookie = $query->cookie( CGISESSID => '' );
920
            $cookie = $query->cookie( CGISESSID => '' );
889
        }
921
        }
890
        return ( $userid, $cookie, $sessionID, $flags );
922
        return ( $userid, $cookie, $sessionID, $flags, $new_session );
891
    }
923
    }
892
924
893
#
925
#
(-)a/mainpage.pl (-17 / +1 lines)
Lines 28-34 use C4::NewsChannels; Link Here
28
use C4::Review qw/numberofreviews/;
28
use C4::Review qw/numberofreviews/;
29
use C4::Suggestions qw/CountSuggestion/;
29
use C4::Suggestions qw/CountSuggestion/;
30
use C4::Tags qw/get_count_by_tag_status/;
30
use C4::Tags qw/get_count_by_tag_status/;
31
use C4::Update::Database;
32
31
33
my $query     = new CGI;
32
my $query     = new CGI;
34
33
Lines 44-64 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
44
    }
43
    }
45
);
44
);
46
45
47
#
46
C4::Auth::version_check($query, 'intranet', $cookie);
48
# check if you're uptodate, and if you're not, head to updater
49
#
50
my $koha36= C4::Context::KOHAVERSION;
51
$koha36 =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
52
53
if (C4::Context->preference('Version') < $koha36) {
54
    print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3");
55
    exit;
56
}
57
unless ( C4::Update::Database::is_uptodate() ) {
58
    # not uptodate, redirect to updatedatabase page
59
    print $query->redirect("/cgi-bin/koha/admin/updatedatabase.pl");
60
    exit;
61
}
62
47
63
my $all_koha_news   = &GetNewsToDisplay("koha");
48
my $all_koha_news   = &GetNewsToDisplay("koha");
64
my $koha_news_count = scalar @$all_koha_news;
49
my $koha_news_count = scalar @$all_koha_news;
65
- 

Return to bug 7167