2000-12-18 21:09:56 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# /**************************************************************************\
|
|
|
|
# * phpGroupWare *
|
|
|
|
# * http://www.phpgroupware.org *
|
|
|
|
# * Written by Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
# * -------------------------------------------- *
|
|
|
|
# * This program is free software; you can redistribute it and/or modify it *
|
|
|
|
# * under the terms of the GNU General Public License as published by the *
|
|
|
|
# * Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
# * option) any later version. *
|
|
|
|
# \**************************************************************************/
|
2001-01-10 13:06:48 +01:00
|
|
|
# $Id$
|
2000-12-18 21:09:56 +01:00
|
|
|
|
|
|
|
use DBI;
|
|
|
|
|
|
|
|
# Config section
|
|
|
|
|
|
|
|
$db_host = 'localhost';
|
|
|
|
$db_name = 'phpGroupWare';
|
|
|
|
$db_user = 'phpgroupware';
|
2001-01-10 13:06:48 +01:00
|
|
|
$db_pass = 'my_password';
|
2000-12-18 21:09:56 +01:00
|
|
|
|
|
|
|
# Email users when they don't log out ?
|
|
|
|
# If you are selecting this option. You might want to customize the message
|
|
|
|
# below.
|
|
|
|
|
|
|
|
# Note: This takes much longer to clean out the database each time. Since it
|
|
|
|
# must go select each user and then email them.
|
|
|
|
|
|
|
|
$email_user = 'Y';
|
|
|
|
$sendmail_location = '/usr/sbin/sendmail';
|
|
|
|
|
|
|
|
# Where should the message be comming from ?
|
2001-01-10 13:06:48 +01:00
|
|
|
$message_from = "webmaster\@mydomain.com";
|
2000-12-18 21:09:56 +01:00
|
|
|
|
|
|
|
# This is how long a user can be at idle before being deleted. Look at the
|
|
|
|
# SECURITY file for more information.
|
|
|
|
# The default is set to 2 hours.
|
|
|
|
|
|
|
|
$secs_to_stale = '3600';
|
|
|
|
|
|
|
|
|
|
|
|
# uncomment the line for your database.
|
|
|
|
# mysql
|
|
|
|
$dbase = DBI->connect("DBI:mysql:$db_name;$db_host",$db_user,$db_pass);
|
|
|
|
# postgresql
|
|
|
|
#$dbase = DBI->connect("DBI:Pg:dbname=$db_name;host=$db_host",$db_user,$db_pass);
|
|
|
|
|
|
|
|
# End of config section
|
|
|
|
|
|
|
|
$staletime = time() - $secs_to_stale;
|
|
|
|
|
|
|
|
if ($email_user eq 'Y') {
|
2001-01-10 13:06:48 +01:00
|
|
|
$command = $dbase->prepare("select session_lid,session_logintime,session_ip,session_id from "
|
|
|
|
. "phpgw_sessions where session_dla <= '$staletime'");
|
2000-12-18 21:09:56 +01:00
|
|
|
$command->execute();
|
|
|
|
|
|
|
|
while (@session_data = $command->fetchrow_array()) {
|
|
|
|
send_message($session_data[0],$session_data[1],$session_data[2]);
|
2001-01-10 13:06:48 +01:00
|
|
|
$command2 = $dbase->do("delete from phpgw_sessions where session_id='$session_data[3]'");
|
2000-12-18 21:09:56 +01:00
|
|
|
}
|
|
|
|
} else {
|
2001-01-10 13:06:48 +01:00
|
|
|
$command = $dbase->do("delete from phpgw_sessions where session_dla <= '$staletime'");
|
2000-12-18 21:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#$command->finish();
|
|
|
|
$dbase->disconnect();
|
|
|
|
|
|
|
|
sub send_message($$$)
|
|
|
|
{
|
|
|
|
my($loginid, $logintime,$IP)=@_;
|
|
|
|
open ( SENDMAIL, "|$sendmail_location -t" ) || warn "Can't open sendmail";
|
|
|
|
print SENDMAIL "To: $loginid\@localhost\n";
|
|
|
|
print SENDMAIL "Subject: Important account information\n";
|
|
|
|
print SENDMAIL "From: $message_from\n\n";
|
|
|
|
print SENDMAIL "According to our records, you have not logged out during ";
|
|
|
|
print SENDMAIL "your recent session. It is important to that you click ";
|
|
|
|
print SENDMAIL "on the logout icons when done with your session. ";
|
|
|
|
print SENDMAIL "\nFor more information, contact your system admin.\n\n";
|
|
|
|
print SENDMAIL "Session information:\n";
|
|
|
|
print SENDMAIL "logintime: " . localtime( $logintime ) . "\n";
|
|
|
|
print SENDMAIL "IP Address: " . $IP . "\n.\n";
|
|
|
|
close ( SENDMAIL );
|
|
|
|
}
|