Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 67 lines (51 sloc) 1.599 kb
185adfb Additions to authentication scheme. Logs to /tmp/sessionlog. Will move...
tonnesen authored
1 #!/usr/bin/perl
2
3 use CGI;
4 use C4::Database;
5
6 my $query=new CGI;
7
8 my $sessionID=$query->cookie('sessionID');
9
10 my $sessions;
11 open (S, "/tmp/sessions");
12 while (my ($sid, $u, $lasttime) = split(/:/, <S>)) {
13 chomp $lasttime;
14 (next) unless ($sid);
15 (next) if ($sid eq $sessionID);
16 $sessions->{$sid}->{'userid'}=$u;
17 $sessions->{$sid}->{'lasttime'}=$lasttime;
18 }
19 open (S, ">/tmp/sessions");
20 foreach (keys %$sessions) {
21 my $userid=$sessions->{$_}->{'userid'};
22 my $lasttime=$sessions->{$_}->{'lasttime'};
23 print S "$_:$userid:$lasttime\n";
24 }
25
26 my $dbh=C4Connect;
27
28 # Check that this is the ip that created the session before deleting it
29
30 my $sth=$dbh->prepare("select userid,ip from sessions where sessionID=?");
31 $sth->execute($sessionID);
32 my ($userid, $ip);
33 if ($sth->rows) {
34 ($userid,$ip) = $sth->fetchrow;
35 if ($ip ne $ENV{'REMOTE_ADDR'}) {
36 # attempt to logout from a different ip than cookie was created at
37 exit;
38 }
39 }
40
41 $sth=$dbh->prepare("delete from sessions where sessionID=?");
42 $sth->execute($sessionID);
43 open L, ">>/tmp/sessionlog";
a66bcaa Minor changes to authentication routines.
tonnesen authored
44 my $time=localtime(time());
45 printf L "%20s from %16s logged out at %30s (manual log out).\n", $userid, $ip, $time;
185adfb Additions to authentication scheme. Logs to /tmp/sessionlog. Will move...
tonnesen authored
46 close L;
47
48 my $cookie=$query->cookie(-name => 'sessionID',
49 -value => '',
50 -expires => '+1y');
51
a66bcaa Minor changes to authentication routines.
tonnesen authored
52 # Should redirect to intranet home page after logging out
53
54 print $query->redirect("mainpage.pl");
185adfb Additions to authentication scheme. Logs to /tmp/sessionlog. Will move...
tonnesen authored
55
56 exit;
57 if ($sessionID) {
58 print "Logged out of $sessionID<br>\n";
59 print "<a href=shelves.pl>Login</a>";
60 } else {
61 print "Not logged in.<br>\n";
62 print "<a href=shelves.pl>Login</a>";
63 }
64
65
66
Something went wrong with that request. Please try again.