From: rettenbe Date: Fri, 5 Sep 2008 09:40:36 +0000 (+0000) Subject: update: outdated logged in user are deleted from login_users_db X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7fe1e4f05bcacd2a17567f8526844d9e64ebb1bc;p=gosa.git update: outdated logged in user are deleted from login_users_db git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12368 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index b0b4ffbda..8bc1100fd 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -54,7 +54,6 @@ use POE qw(Component::Server::TCP Wheel::Run Filter::Reference); use Net::LDAP; use Net::LDAP::Util qw(:escape); use Time::HiRes qw( usleep); -use DateTime; my $modules_path = "/usr/lib/gosa-si/modules"; use lib "/usr/lib/gosa-si/modules"; @@ -210,6 +209,10 @@ my $job_queue_opsi_delay = 10; our $opsi_client; our $opsi_url; +# Lifetime of logged in user information. If no update information comes after n seconds, +# the user is expeceted to be no longer logged in or the host is no longer running. Because +# of this, the user is deleted from login_users_db +our $logged_in_user_date_of_expiry = 600; %cfg_defaults = ( @@ -247,6 +250,7 @@ our $opsi_url; }, "ClientPackages" => { "key" => [\$ClientPackages_key, "none"], + "user-date-of-expiry" => [\$logged_in_user_date_of_expiry, 600], }, "ServerPackages"=> { "address" => [\$foreign_server_string, ""], diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index ff9da894e..47a077b7e 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -33,6 +33,7 @@ my @functions = ( "inform_all_other_si_server", "read_configfile", "check_opsi_res", + "calc_timestamp", ); @EXPORT = @functions; use strict; @@ -44,6 +45,7 @@ use MIME::Base64; use XML::Simple; use Data::Dumper; use Net::DNS; +use DateTime; my $op_hash = { @@ -824,5 +826,33 @@ sub check_opsi_res { return 0; } +sub calc_timestamp { + my ($timestamp, $operation, $value) = @_ ; + my $res_timestamp = 0; + + $value = int($value); + $timestamp = int($timestamp); + $timestamp =~ /(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/; + my $dt = DateTime->new( year => $1, + month => $2, + day => $3, + hour => $4, + minute => $5, + second => $6, + ); + + if ($operation eq "plus" || $operation eq "+") { + $dt->add( seconds => $value); + $res_timestamp = $dt->ymd('').$dt->hms(''); + } + + if ($operation eq "minus" || $operation eq "-") { + $dt->subtract(seconds => $value); + $res_timestamp = $dt->ymd('').$dt->hms(''); + } + + return $res_timestamp; +} + 1; diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index fde8b36b4..56925c9de 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -208,6 +208,20 @@ sub CURRENTLY_LOGGED_IN { &main::daemon_log("$session_id WARNING: delete user '$obsolete_user' at client '$source' from login_user_db", 3); } + # Delete all users which logged in information is older than their logged_in_user_date_of_expiry + my $act_time = &get_time(); + my $expiry_date = &calc_timestamp($act_time, "minus", $main::logged_in_user_date_of_expiry); + + $sql_statement = "SELECT * FROM $main::login_users_tn WHERE CAST(timestamp as INTEGER)<$expiry_date"; + $db_res = $main::login_users_db->select_dbentry($sql_statement); + + while( my($hit_id, $hit) = each(%{$db_res}) ) { + &main::daemon_log("$session_id INFO: user '".$hit->{'user'}."' is no longer reported to be logged in at host '".$hit->{'client'}."'", 5); + my $sql = "DELETE FROM $main::login_users_tn WHERE (client='".$hit->{'client'}."' AND user='".$hit->{'user'}."')"; + my $res = $main::login_users_db->del_dbentry($sql); + &main::daemon_log("$session_id INFO: delete user '".$hit->{'user'}."' at client '".$hit->{'client'}."' from login_user_db", 5); + } + return; }