From 9d042c9d8a453371a6fdd074f45b6b290c792431 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Thu, 25 Sep 2008 09:05:39 +0000 Subject: [PATCH] update: setting of gosaLastSystem and gosaLastSystemLogin implementation in clmessages.pm git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12547 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 2 +- gosa-si/server/events/clMessages.pm | 109 ++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index e82330484..57845bec8 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -3343,7 +3343,7 @@ POE::Component::Server::TCP->new( } ); -daemon_log("start socket for incoming xml messages at port '$server_port' ", 1); +daemon_log("0 INFO: start socket for incoming xml messages at port '$server_port' ", 1); # create session for repeatedly checking the job queue for jobs POE::Session->create( diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index f3c5de809..8dcde99fb 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -168,6 +168,9 @@ sub CURRENTLY_LOGGED_IN { &main::daemon_log("$session_id INFO: no logged in users reported from host '$source'", 5); return; } + + # Invoke set_last_system + my $res = &set_last_system($msg, $msg_hash, $session_id); # fetch all user currently assigned to the client at login_users_db my %currently_logged_in_user = (); @@ -226,6 +229,112 @@ sub CURRENTLY_LOGGED_IN { } +## @method set_last_system() +# @details Message set ldap attributes 'gosaLastSystemLogin' and 'gosaLastSystem' +# @param msg - STRING - xml message with tag 'last_system_login' and 'last_system' +# @param msg_hash - HASHREF - message information parsed into a hash +# @param session_id - INTEGER - POE session id of the processing of this message +sub set_last_system { + my ($msg, $msg_hash, $session_id) = @_; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + my $login = @{$msg_hash->{$header}}[0]; + + # Sanity check of needed parameter + if (not exists $msg_hash->{'timestamp'}){ + &main::daemon_log("$session_id ERROR: message does not contain needed xml tag 'timestamp', ". + "setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1); + &main::daemon_log($msg, 1); + return; + } + if (@{$msg_hash->{'timestamp'}} != 1) { + &main::daemon_log("$session_id ERROR: xml tag 'timestamp' has no content or exists more than one time, ". + "setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1); + &ymain::daemon_log($msg, 1); + return; + } + if (not exists $msg_hash->{'macaddress'}){ + &main::daemon_log("$session_id ERROR: message does not contain needed xml tag 'mac_address', ". + "setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1); + &main::daemon_log($msg, 1); + return; + } + if (@{$msg_hash->{'macaddress'}} != 1) { + &main::daemon_log("$session_id ERROR: xml tag 'macaddress' has no content or exists more than one time, ". + "setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1); + &ymain::daemon_log($msg, 1); + return; + } + + # Fetch needed parameter + my $mac = @{$msg_hash->{'macaddress'}}[0]; + my $timestamp = @{$msg_hash->{'timestamp'}}[0]; + + # Prepare login list + my @login_list = split(' ', @{$msg_hash->{$header}}[0] ); + + # Sanity check of login list + if (@login_list == 0) { + # TODO + return; + } + + # Fetch ldap handle + my $ldap_handle = &main::get_ldap_handle(); + + # Get system info + my $ldap_mesg= $ldap_handle->search( + base => $main::ldap_base, + scope => 'sub', + filter => "macAddress=$mac", + ); + if ($ldap_mesg->count == 0) { + &main::daemon_log("$session_id ERROR: no system with mac address='$mac' was found in base '". + $main::ldap_base."', setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1); + return; + } + my $ldap_entry = $ldap_mesg->pop_entry(); + my $system_dn = $ldap_entry->get_value('dn'); + + # For each logged in user set gosaLastSystem and gosaLastSystemLogin + foreach my $user (@login_list) { + # Search user + my $ldap_mesg= $ldap_handle->search( + base => $main::ldap_base, + scope => 'sub', + filter => "uid=$user", + ); + # Sanity check of user search + if ($ldap_mesg->count == 0) { + &main::daemon_log("$session_id ERROR: no user with uid='$user' was found in base '". + $main::ldap_base."', setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1); + + # Set gosaLastSystem and gosaLastSystemLogin + } else { + my $ldap_entry= $ldap_mesg->pop_entry(); + if (defined($ldap_entry->get_value('gosaLastSystem'))) { + $ldap_entry->replace ( 'gosaLastSystem' => $system_dn ); + } else { + $ldap_entry->add( 'gosaLastSystem' => $system_dn ); + } + if (defined($ldap_entry->get_value('gosaLastSystemLogin'))) { + $ldap_entry->replace ( 'gosaLastSystemLogin' => $timestamp ); + } else { + $ldap_entry->add( 'gosaLastSystemLogin' => $timestamp ); + } + my $result = $ldap_entry->update($ldap_handle); + if ($result->code() != 0) { + &main::daemon_log("$session_id ERROR: setting 'gosaLastSystem' and 'gosaLastSystemLogin' at user '$user' failed: ". + $result->{'errorMessage'}, 1); + &main::daemon_log("$session_id ERROR: $msg", 1); + } + } + } + + return; +} + + ## @method GOTOACTIVATION() # @details Client is set at job_queue_db to status 'processing' and 'modified'. # @param msg - STRING - xml message with tag 'macaddress' -- 2.30.2