fixing syntax error in sysprefs.sql
[koha.git] / opac / opac-logout.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 use CGI;
19 use C4::Context;
20 use C4::Output;
21 use HTML::Template;
22 use CGI::Session;
23
24 my $query=new CGI;
25
26 my $sessionID=$query->cookie('sessionID');
27
28
29 if ($ENV{'REMOTE_USER'}) {
30     print $query->header();
31     print startpage();
32     print startmenu('catalogue');
33     print qq|
34 <h1>Logout Feature Not Available</h1>
35 Your Koha server is configured to use a type of authentication called "Basic
36 Authentication" instead of using a cookies-based authentication system.  With
37 Basic Authentication, the only way to logout of Koha is by exiting your
38 browser.
39 |;
40     print endmenu('catalogue');
41     print endpage();
42     exit;
43 }
44
45 my $sessions;
46 open (S, "/tmp/sessions");
47   # FIXME - Come up with a better logging mechanism
48 while (my ($sid, $u, $lasttime) = split(/:/, <S>)) {
49     chomp $lasttime;
50     (next) unless ($sid);
51     (next) if ($sid eq $sessionID);
52     $sessions->{$sid}->{'userid'}=$u;
53     $sessions->{$sid}->{'lasttime'}=$lasttime;
54 }
55 open (S, ">/tmp/sessions");
56 foreach (keys %$sessions) {
57     my $userid=$sessions->{$_}->{'userid'};
58     my $lasttime=$sessions->{$_}->{'lasttime'};
59     print S "$_:$userid:$lasttime\n";
60 }
61
62 my $dbh = C4::Context->dbh;
63
64 # Check that this is the ip that created the session before deleting it
65
66     if ($storage_method eq 'mysql'){
67         $session = new CGI::Session("driver:MySQL", $sessionID, {Handle=>$dbh});
68     }
69     else {
70       # catch all defaults to tmp should work on all systems
71       $session = new CGI::Session("driver:File", $sessionID, {Directory=>'/tmp'});      
72     }
73
74 $session->flush;
75 $session->delete;
76 my $sth=$dbh->prepare("delete from sessions where sessionID=?");
77 $sth->execute($sessionID);
78 open L, ">>/tmp/sessionlog";
79 my $time=localtime(time());
80 printf L "%20s from %16s logged out at %30s (manual log out).\n", $userid, $ip, $time;
81 close L;
82
83 my $cookie=$query->cookie(-name => 'sessionID',
84         -value => '',
85         -expires => '+1y');
86
87 # Should redirect to opac home page after logging out
88
89 print $query->redirect("/cgi-bin/koha/opac-main.pl");
90
91 exit;
92
93
94