|
Lines 145-151
sub get_template_and_user {
Link Here
|
| 145 |
|
145 |
|
| 146 |
my $borrowernumber; |
146 |
my $borrowernumber; |
| 147 |
my $insecure = C4::Context->preference('insecure'); |
147 |
my $insecure = C4::Context->preference('insecure'); |
| 148 |
if ($user or $insecure) { |
148 |
if ( $user or $insecure ) { |
|
|
149 |
|
| 150 |
# It's possible for $user to be the borrowernumber if they don't have a |
| 151 |
# userid defined (and are logging in through some other method, such as |
| 152 |
# SSL certs against an email address) |
| 153 |
$borrowernumber = getborrowernumber($user) if defined($user); |
| 154 |
if ( !defined($borrowernumber) && defined($user) ) { |
| 155 |
my $borrower = GetMember( borrowernumber => $user ); |
| 156 |
if ($borrower) { |
| 157 |
$borrowernumber = $user; |
| 158 |
|
| 159 |
# A bit of a hack, but I don't know there's a nicer way to do |
| 160 |
# it. |
| 161 |
$user = $borrower->{firstname} . ' ' . $borrower->{surname}; |
| 162 |
} |
| 163 |
} |
| 149 |
|
164 |
|
| 150 |
# user info |
165 |
# user info |
| 151 |
$template->param( loggedinusername => $user ); |
166 |
$template->param( loggedinusername => $user ); |
|
Lines 717-725
sub checkauth {
Link Here
|
| 717 |
} |
732 |
} |
| 718 |
unless ($userid || $sessionID) { |
733 |
unless ($userid || $sessionID) { |
| 719 |
#we initiate a session prior to checking for a username to allow for anonymous sessions... |
734 |
#we initiate a session prior to checking for a username to allow for anonymous sessions... |
| 720 |
my $session = get_session("") or die "Auth ERROR: Cannot get_session()"; |
735 |
my $session = get_session("") or die "Auth ERROR: Cannot get_session()"; |
| 721 |
my $sessionID = $session->id; |
736 |
my $sessionID = $session->id; |
| 722 |
C4::Context->_new_userenv($sessionID); |
737 |
C4::Context->_new_userenv($sessionID); |
| 723 |
$cookie = $query->cookie(CGISESSID => $sessionID); |
738 |
$cookie = $query->cookie(CGISESSID => $sessionID); |
| 724 |
$userid = $query->param('userid'); |
739 |
$userid = $query->param('userid'); |
| 725 |
if (($cas && $query->param('ticket')) || $userid) { |
740 |
if (($cas && $query->param('ticket')) || $userid) { |
|
Lines 730-736
sub checkauth {
Link Here
|
| 730 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
745 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
| 731 |
$userid = $retuserid; |
746 |
$userid = $retuserid; |
| 732 |
$info{'invalidCasLogin'} = 1 unless ($return); |
747 |
$info{'invalidCasLogin'} = 1 unless ($return); |
| 733 |
} else { |
748 |
} elsif (($pki_field eq 'Common Name' && $ENV{'SSL_CLIENT_S_DN_CN'}) || |
|
|
749 |
($pki_field eq 'emailAddress' && $ENV{'SSL_CLIENT_S_DN_Email'})) { |
| 750 |
my $value; |
| 751 |
if ($pki_field eq 'Common Name') { |
| 752 |
$value = $ENV{'SSL_CLIENT_S_DN_CN'}; |
| 753 |
} elsif ($pki_field eq 'emailAddress') { |
| 754 |
$value = $ENV{'SSL_CLIENT_S_DN_Email'}; |
| 755 |
# If we're looking up the email, there's a chance that the person |
| 756 |
# doesn't have a userid. So if there is none, we pass along the |
| 757 |
# borrower number, and the bits of code that need to know the user |
| 758 |
# ID will have to be smart enough to handle that. |
| 759 |
my @users_info = GetBorrowersWithEmail($value); |
| 760 |
if (@users_info) { |
| 761 |
# First the userid, then the borrowernum |
| 762 |
$value = $users_info[0][1] || $users_info[0][0]; |
| 763 |
} else { |
| 764 |
undef $value; |
| 765 |
} |
| 766 |
} |
| 767 |
# 0 for no user, 1 for normal, 2 for demo user. |
| 768 |
$return = $value ? 1 : 0; |
| 769 |
$userid = $value; |
| 770 |
} else { |
| 734 |
my $retuserid; |
771 |
my $retuserid; |
| 735 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
772 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
| 736 |
$userid = $retuserid if ($retuserid ne ''); |
773 |
$userid = $retuserid if ($retuserid ne ''); |
|
Lines 745-870
sub checkauth {
Link Here
|
| 745 |
C4::Context->_unset_userenv($sessionID); |
782 |
C4::Context->_unset_userenv($sessionID); |
| 746 |
} |
783 |
} |
| 747 |
|
784 |
|
| 748 |
my ($borrowernumber, $firstname, $surname, $userflags, |
785 |
my ($borrowernumber, $firstname, $surname, $userflags, |
| 749 |
$branchcode, $branchname, $branchprinter, $emailaddress); |
786 |
$branchcode, $branchname, $branchprinter, $emailaddress); |
| 750 |
|
787 |
|
| 751 |
if ( $return == 1 ) { |
788 |
if ( $return == 1 ) { |
| 752 |
my $select = " |
789 |
my $select = " |
| 753 |
SELECT borrowernumber, firstname, surname, flags, borrowers.branchcode, |
790 |
SELECT borrowernumber, firstname, surname, flags, borrowers.branchcode, |
| 754 |
branches.branchname as branchname, |
791 |
branches.branchname as branchname, |
| 755 |
branches.branchprinter as branchprinter, |
792 |
branches.branchprinter as branchprinter, |
| 756 |
email |
793 |
email |
| 757 |
FROM borrowers |
794 |
FROM borrowers |
| 758 |
LEFT JOIN branches on borrowers.branchcode=branches.branchcode |
795 |
LEFT JOIN branches on borrowers.branchcode=branches.branchcode |
| 759 |
"; |
796 |
"; |
| 760 |
my $sth = $dbh->prepare("$select where userid=?"); |
797 |
my $sth = $dbh->prepare("$select where userid=?"); |
| 761 |
$sth->execute($userid); |
798 |
$sth->execute($userid); |
| 762 |
unless ($sth->rows) { |
799 |
unless ( $sth->rows ) { |
| 763 |
$debug and print STDERR "AUTH_1: no rows for userid='$userid'\n"; |
800 |
$debug |
| 764 |
$sth = $dbh->prepare("$select where cardnumber=?"); |
801 |
and print STDERR |
| 765 |
$sth->execute($cardnumber); |
802 |
"AUTH_1: no rows for userid='$userid'\n"; |
| 766 |
|
803 |
$sth = $dbh->prepare("$select where cardnumber=?"); |
| 767 |
unless ($sth->rows) { |
804 |
$sth->execute($cardnumber); |
| 768 |
$debug and print STDERR "AUTH_2a: no rows for cardnumber='$cardnumber'\n"; |
805 |
|
| 769 |
$sth->execute($userid); |
806 |
unless ( $sth->rows ) { |
| 770 |
unless ($sth->rows) { |
807 |
$debug |
| 771 |
$debug and print STDERR "AUTH_2b: no rows for userid='$userid' AS cardnumber\n"; |
808 |
and print STDERR |
| 772 |
} |
809 |
"AUTH_2a: no rows for cardnumber='$cardnumber'\n"; |
| 773 |
} |
810 |
$sth->execute($userid); |
| 774 |
} |
811 |
unless ( $sth->rows ) { |
| 775 |
if ($sth->rows) { |
812 |
$debug |
| 776 |
($borrowernumber, $firstname, $surname, $userflags, |
813 |
and print STDERR |
| 777 |
$branchcode, $branchname, $branchprinter, $emailaddress) = $sth->fetchrow; |
814 |
"AUTH_2b: no rows for userid='$userid' AS cardnumber\n"; |
| 778 |
$debug and print STDERR "AUTH_3 results: " . |
815 |
} |
| 779 |
"$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress\n"; |
816 |
} |
| 780 |
} else { |
817 |
} |
| 781 |
print STDERR "AUTH_3: no results for userid='$userid', cardnumber='$cardnumber'.\n"; |
818 |
if ($sth->rows) { |
| 782 |
} |
819 |
($borrowernumber, $firstname, $surname, $userflags, |
|
|
820 |
$branchcode, $branchname, $branchprinter, $emailaddress) = $sth->fetchrow; |
| 821 |
$debug and print STDERR "AUTH_3 results: " . |
| 822 |
"$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress\n"; |
| 823 |
} else { |
| 824 |
print STDERR "AUTH_3: no results for userid='$userid', cardnumber='$cardnumber'.\n"; |
| 825 |
} |
| 783 |
|
826 |
|
| 784 |
# launch a sequence to check if we have a ip for the branch, i |
827 |
# launch a sequence to check if we have a ip for the branch, i |
| 785 |
# if we have one we replace the branchcode of the userenv by the branch bound in the ip. |
828 |
# if we have one we replace the branchcode of the userenv by the branch bound in the ip. |
| 786 |
|
829 |
|
| 787 |
my $ip = $ENV{'REMOTE_ADDR'}; |
830 |
my $ip = $ENV{'REMOTE_ADDR'}; |
| 788 |
# if they specify at login, use that |
831 |
# if they specify at login, use that |
| 789 |
if ($query->param('branch')) { |
832 |
if ($query->param('branch')) { |
| 790 |
$branchcode = $query->param('branch'); |
833 |
$branchcode = $query->param('branch'); |
| 791 |
$branchname = GetBranchName($branchcode); |
834 |
$branchname = GetBranchName($branchcode); |
| 792 |
} |
835 |
} |
| 793 |
my $branches = GetBranches(); |
836 |
my $branches = GetBranches(); |
| 794 |
if (C4::Context->boolean_preference('IndependantBranches') && C4::Context->boolean_preference('Autolocation')){ |
837 |
if (C4::Context->boolean_preference('IndependantBranches') && C4::Context->boolean_preference('Autolocation')){ |
| 795 |
# we have to check they are coming from the right ip range |
838 |
# we have to check they are coming from the right ip range |
| 796 |
my $domain = $branches->{$branchcode}->{'branchip'}; |
839 |
my $domain = $branches->{$branchcode}->{'branchip'}; |
| 797 |
if ($ip !~ /^$domain/){ |
840 |
if ($ip !~ /^$domain/){ |
| 798 |
$loggedin=0; |
841 |
$loggedin=0; |
| 799 |
$info{'wrongip'} = 1; |
842 |
$info{'wrongip'} = 1; |
| 800 |
} |
843 |
} |
| 801 |
} |
844 |
} |
| 802 |
|
845 |
|
| 803 |
my @branchesloop; |
846 |
my @branchesloop; |
| 804 |
foreach my $br ( keys %$branches ) { |
847 |
foreach my $br ( keys %$branches ) { |
| 805 |
# now we work with the treatment of ip |
848 |
# now we work with the treatment of ip |
| 806 |
my $domain = $branches->{$br}->{'branchip'}; |
849 |
my $domain = $branches->{$br}->{'branchip'}; |
| 807 |
if ( $domain && $ip =~ /^$domain/ ) { |
850 |
if ( $domain && $ip =~ /^$domain/ ) { |
| 808 |
$branchcode = $branches->{$br}->{'branchcode'}; |
851 |
$branchcode = $branches->{$br}->{'branchcode'}; |
| 809 |
|
852 |
|
| 810 |
# new op dev : add the branchprinter and branchname in the cookie |
853 |
# new op dev : add the branchprinter and branchname in the cookie |
| 811 |
$branchprinter = $branches->{$br}->{'branchprinter'}; |
854 |
$branchprinter = $branches->{$br}->{'branchprinter'}; |
| 812 |
$branchname = $branches->{$br}->{'branchname'}; |
855 |
$branchname = $branches->{$br}->{'branchname'}; |
| 813 |
} |
856 |
} |
| 814 |
} |
857 |
} |
| 815 |
$session->param('number',$borrowernumber); |
858 |
$session->param('number',$borrowernumber); |
| 816 |
$session->param('id',$userid); |
859 |
$session->param('id',$userid); |
| 817 |
$session->param('cardnumber',$cardnumber); |
860 |
$session->param('cardnumber',$cardnumber); |
| 818 |
$session->param('firstname',$firstname); |
861 |
$session->param('firstname',$firstname); |
| 819 |
$session->param('surname',$surname); |
862 |
$session->param('surname',$surname); |
| 820 |
$session->param('branch',$branchcode); |
863 |
$session->param('branch',$branchcode); |
| 821 |
$session->param('branchname',$branchname); |
864 |
$session->param('branchname',$branchname); |
| 822 |
$session->param('flags',$userflags); |
865 |
$session->param('flags',$userflags); |
| 823 |
$session->param('emailaddress',$emailaddress); |
866 |
$session->param('emailaddress',$emailaddress); |
| 824 |
$session->param('ip',$session->remote_addr()); |
867 |
$session->param('ip',$session->remote_addr()); |
| 825 |
$session->param('lasttime',time()); |
868 |
$session->param('lasttime',time()); |
| 826 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map {$session->param($_)} qw(cardnumber firstname surname branch) ; |
869 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map {$session->param($_)} qw(cardnumber firstname surname branch) ; |
| 827 |
} |
870 |
} |
| 828 |
elsif ( $return == 2 ) { |
871 |
elsif ( $return == 2 ) { |
| 829 |
#We suppose the user is the superlibrarian |
872 |
#We suppose the user is the superlibrarian |
| 830 |
$borrowernumber = 0; |
873 |
$borrowernumber = 0; |
| 831 |
$session->param('number',0); |
874 |
$session->param('number',0); |
| 832 |
$session->param('id',C4::Context->config('user')); |
875 |
$session->param('id',C4::Context->config('user')); |
| 833 |
$session->param('cardnumber',C4::Context->config('user')); |
876 |
$session->param('cardnumber',C4::Context->config('user')); |
| 834 |
$session->param('firstname',C4::Context->config('user')); |
877 |
$session->param('firstname',C4::Context->config('user')); |
| 835 |
$session->param('surname',C4::Context->config('user')); |
878 |
$session->param('surname',C4::Context->config('user')); |
| 836 |
$session->param('branch','NO_LIBRARY_SET'); |
879 |
$session->param('branch','NO_LIBRARY_SET'); |
| 837 |
$session->param('branchname','NO_LIBRARY_SET'); |
880 |
$session->param('branchname','NO_LIBRARY_SET'); |
| 838 |
$session->param('flags',1); |
881 |
$session->param('flags',1); |
| 839 |
$session->param('emailaddress', C4::Context->preference('KohaAdminEmailAddress')); |
882 |
$session->param('emailaddress', C4::Context->preference('KohaAdminEmailAddress')); |
| 840 |
$session->param('ip',$session->remote_addr()); |
883 |
$session->param('ip',$session->remote_addr()); |
| 841 |
$session->param('lasttime',time()); |
884 |
$session->param('lasttime',time()); |
| 842 |
} |
885 |
} |
| 843 |
C4::Context::set_userenv( |
886 |
C4::Context::set_userenv( |
| 844 |
$session->param('number'), $session->param('id'), |
887 |
$session->param('number'), $session->param('id'), |
| 845 |
$session->param('cardnumber'), $session->param('firstname'), |
888 |
$session->param('cardnumber'), $session->param('firstname'), |
| 846 |
$session->param('surname'), $session->param('branch'), |
889 |
$session->param('surname'), $session->param('branch'), |
| 847 |
$session->param('branchname'), $session->param('flags'), |
890 |
$session->param('branchname'), $session->param('flags'), |
| 848 |
$session->param('emailaddress'), $session->param('branchprinter') |
891 |
$session->param('emailaddress'), $session->param('branchprinter') |
| 849 |
); |
892 |
); |
| 850 |
|
893 |
|
| 851 |
# Grab borrower's shelves and public shelves and add them to the session |
894 |
# Grab borrower's shelves and public shelves and add them to the session |
| 852 |
# $row_count determines how many records are returned from the db query |
895 |
# $row_count determines how many records are returned from the db query |
| 853 |
# and the number of lists to be displayed of each type in the 'Lists' button drop down |
896 |
# and the number of lists to be displayed of each type in the 'Lists' button drop down |
| 854 |
my $row_count = 10; # FIXME:This probably should be a syspref |
897 |
my $row_count = 10; # FIXME:This probably should be a syspref |
| 855 |
my ($total, $totshelves, $barshelves, $pubshelves); |
898 |
my ($total, $totshelves, $barshelves, $pubshelves); |
| 856 |
($barshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(1, $row_count, $borrowernumber); |
899 |
($barshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(1, $row_count, $borrowernumber); |
| 857 |
$total->{'bartotal'} = $totshelves; |
900 |
$total->{'bartotal'} = $totshelves; |
| 858 |
($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef); |
901 |
($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef); |
| 859 |
$total->{'pubtotal'} = $totshelves; |
902 |
$total->{'pubtotal'} = $totshelves; |
| 860 |
$session->param('barshelves', $barshelves); |
903 |
$session->param('barshelves', $barshelves); |
| 861 |
$session->param('pubshelves', $pubshelves); |
904 |
$session->param('pubshelves', $pubshelves); |
| 862 |
$session->param('totshelves', $total); |
905 |
$session->param('totshelves', $total); |
| 863 |
|
906 |
|
| 864 |
C4::Context::set_shelves_userenv('bar',$barshelves); |
907 |
C4::Context::set_shelves_userenv('bar',$barshelves); |
| 865 |
C4::Context::set_shelves_userenv('pub',$pubshelves); |
908 |
C4::Context::set_shelves_userenv('pub',$pubshelves); |
| 866 |
C4::Context::set_shelves_userenv('tot',$total); |
909 |
C4::Context::set_shelves_userenv('tot',$total); |
| 867 |
} |
910 |
} |
| 868 |
else { |
911 |
else { |
| 869 |
if ($userid) { |
912 |
if ($userid) { |
| 870 |
$info{'invalid_username_or_password'} = 1; |
913 |
$info{'invalid_username_or_password'} = 1; |