4 use Digest::MD5 qw(md5_base64);
10 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
12 # set the version for version checking
24 # $authnotrequired will be set for scripts which will run without authentication
25 my $authnotrequired=shift;
26 if (my $userid=$ENV{'REMOTE_USERNAME'}) {
27 # Using Basic Authentication, no cookies required
28 my $cookie=$query->cookie(-name => 'sessionID',
31 return ($userid, $cookie, '');
33 my $sessionID=$query->cookie('sessionID');
37 my $sth=$dbh->prepare("select userid,ip,lasttime from sessions where sessionid=?");
38 $sth->execute($sessionID);
40 my ($userid, $ip, $lasttime) = $sth->fetchrow;
41 if ($lasttime<time()-45 && $userid ne 'tonnesen') {
43 $message="You have been logged out due to inactivity.";
44 my $sti=$dbh->prepare("delete from sessions where sessionID=?");
45 $sti->execute($sessionID);
46 my $scriptname=$ENV{'SCRIPT_NAME'};
47 my $selfurl=$query->self_url();
48 $sti=$dbh->prepare("insert into sessionqueries (sessionID, userid, value) values (?, ?, ?)");
49 $sti->execute($sessionID, $userid, $selfurl);
50 open L, ">>/tmp/sessionlog";
51 my $time=localtime(time());
52 printf L "%20s from %16s logged out at %30s (inactivity).\n", $userid, $ip, $time;
54 } elsif ($ip ne $ENV{'REMOTE_ADDR'}) {
55 # Different ip than originally logged in from
56 my $newip=$ENV{'REMOTE_ADDR'};
58 $message="ERROR ERROR ERROR ERROR<br>Attempt to re-use a cookie from a different ip address.<br>(authenticated from $ip, this request from $newip)";
60 my $cookie=$query->cookie(-name => 'sessionID',
63 my $sti=$dbh->prepare("update sessions set lasttime=? where sessionID=?");
64 $sti->execute(time(), $sessionID);
65 return ($userid, $cookie, $sessionID);
71 if ($authnotrequired) {
72 my $cookie=$query->cookie(-name => 'sessionID',
75 return('', $cookie, '');
77 ($sessionID) || ($sessionID=int(rand()*100000).'-'.time());
78 my $userid=$query->param('userid');
79 my $password=$query->param('password');
80 if (checkpw($dbh, $userid, $password)) {
81 my $sti=$dbh->prepare("delete from sessions where sessionID=? and userid=?");
82 $sti->execute($sessionID, $userid);
83 $sti=$dbh->prepare("insert into sessions (sessionID, userid, ip,lasttime) values (?, ?, ?, ?)");
84 $sti->execute($sessionID, $userid, $ENV{'REMOTE_ADDR'}, time());
85 $sti=$dbh->prepare("select value from sessionqueries where sessionID=? and userid=?");
86 $sti->execute($sessionID, $userid);
88 my $stj=$dbh->prepare("delete from sessionqueries where sessionID=?");
89 $stj->execute($sessionID);
90 my ($selfurl) = $sti->fetchrow;
91 print $query->redirect($selfurl);
94 open L, ">>/tmp/sessionlog";
95 my $time=localtime(time());
96 printf L "%20s from %16s logged in at %30s.\n", $userid, $ENV{'REMOTE_ADDR'}, $time;
98 my $cookie=$query->cookie(-name => 'sessionID',
101 return ($userid, $cookie, $sessionID);
104 $message="Invalid userid or password entered.";
107 foreach (param $query) {
108 $parameters->{$_}=$query->{$_};
110 my $cookie=$query->cookie(-name => 'sessionID',
111 -value => $sessionID,
113 print $query->header(-cookie=>$cookie);
116 <body background=/images/kohaback.jpg>
121 <table border=0 cellpadding=10 cellspacing=0 width=60%>
122 <tr><td align=center valign=top>
124 <table border=0 bgcolor=#dddddd cellpadding=10 cellspacing=0>
125 <tr><th colspan=2 background=/images/background-mem.gif><font size=+2>Koha Login</font></th></tr>
126 <tr><td>Name:</td><td><input name=userid></td></tr>
127 <tr><td>Password:</td><td><input type=password name=password></td></tr>
128 <tr><td colspan=2 align=center><input type=submit value=login></td></tr>
131 </td><td align=center valign=top>
133 <table border=0 bgcolor=#dddddd cellpadding=10 cellspacing=0>
134 <tr><th background=/images/background-mem.gif><font size=+2>Demo Information</font></th></tr>
136 Log in as librarian/koha or patron/koha. The timeout is set to 40 seconds of
137 inactivity for the purposes of this demo. You can navigate to the Circulation
138 or Acquisitions modules and you should see an indicator in the upper left of
139 the screen saying who you are logged in as. If you want to try it out with
140 a longer timout period, log in as tonnesen/koha and there will be no
143 You can also log in using a patron cardnumber. Try V10000008 and
144 V1000002X with password koha.
162 # This should be modified to allow a select of authentication schemes (ie LDAP)
163 # as well as local authentication through the borrowers tables passwd field
165 my ($dbh, $userid, $password) = @_;
166 my $sth=$dbh->prepare("select password from borrowers where userid=?");
167 $sth->execute($userid);
169 my ($md5password) = $sth->fetchrow;
170 if (md5_base64($password) eq $md5password) {
174 my $sth=$dbh->prepare("select password from borrowers where cardnumber=?");
175 $sth->execute($userid);
177 my ($md5password) = $sth->fetchrow;
178 if (md5_base64($password) eq $md5password) {
186 END { } # module clean-up code here (global destructor)