HTML::Template => HTML::Template::Pro
[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::Auth qw/:DEFAULT get_session/;
21 use C4::Output;
22 use HTML::Template::Pro;
23 use CGI::Session;
24
25 my $query=new CGI;
26
27 my $sessionID=$query->cookie('sessionID');
28
29
30 if ($ENV{'REMOTE_USER'}) {
31     print $query->header();
32     print startpage();
33     print startmenu('catalogue');
34     print qq|
35 <h1>Logout Feature Not Available</h1>
36 Your Koha server is configured to use a type of authentication called "Basic
37 Authentication" instead of using a cookies-based authentication system.  With
38 Basic Authentication, the only way to logout of Koha is by exiting your
39 browser.
40 |;
41     print endmenu('catalogue');
42     print endpage();
43     exit;
44 }
45
46 my $sessions;
47 open (S, "/tmp/sessions");
48   # FIXME - Come up with a better logging mechanism
49 while (my ($sid, $u, $lasttime) = split(/:/, <S>)) {
50     chomp $lasttime;
51     (next) unless ($sid);
52     (next) if ($sid eq $sessionID);
53     $sessions->{$sid}->{'userid'}=$u;
54     $sessions->{$sid}->{'lasttime'}=$lasttime;
55 }
56 open (S, ">/tmp/sessions");
57 foreach (keys %$sessions) {
58     my $userid=$sessions->{$_}->{'userid'};
59     my $lasttime=$sessions->{$_}->{'lasttime'};
60     print S "$_:$userid:$lasttime\n";
61 }
62
63 my $dbh = C4::Context->dbh;
64 # Check that this is the ip that created the session before deleting it
65 my $session = get_session($sessionID);
66 $session->flush;
67 $session->delete;
68 my $sth=$dbh->prepare("delete from sessions where sessionID=?");
69 $sth->execute($sessionID);
70 open L, ">>/tmp/sessionlog";
71 my $time=localtime(time());
72 printf L "%20s from %16s logged out at %30s (manual log out).\n", $userid, $ip, $time;
73 close L;
74
75 my $cookie=$query->cookie(-name => 'sessionID',
76         -value => '',
77         -expires => '+1y');
78
79 # Should redirect to opac home page after logging out
80
81 print $query->redirect("/cgi-bin/koha/opac-main.pl");
82
83 exit;
84
85
86