From 51e287c0092efd49ce45f974cf3d1a8948ba6ab1 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Fri, 5 Sep 2008 08:06:42 +0000 Subject: [PATCH] bugfix: user messages adapted to server-server communication git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12366 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/client/events/gosaTriggered.pm | 13 +++- gosa-si/gosa-si-server | 78 +++++++++++++++++----- gosa-si/server/events/mailqueue_com.pm | 1 + gosa-si/server/events/server_server_com.pm | 8 +++ gosa-si/tests/client.php | 21 +++--- 5 files changed, 93 insertions(+), 28 deletions(-) diff --git a/gosa-si/client/events/gosaTriggered.pm b/gosa-si/client/events/gosaTriggered.pm index e25857740..3caffff15 100644 --- a/gosa-si/client/events/gosaTriggered.pm +++ b/gosa-si/client/events/gosaTriggered.pm @@ -116,16 +116,25 @@ sub get_events { return \@events; } ############################################################################### sub usr_msg { my ($msg, $msg_hash) = @_; - + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + my $target = @{$msg_hash->{'target'}}[0]; my $to = @{$msg_hash->{'usr'}}[0]; my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]); my $message = &decode_base64(@{$msg_hash->{'message'}}[0]); + system( "/usr/bin/goto-notify user-message '$to' '$subject' '$message'" ); # give gosa-si-server feedback, that msg was received $msg =~ s/
usr_msg<\/header>/
confirm_usr_msg<\/header>/g; - return $msg; + my $out_hash = &create_xml_hash("confirm_usr_msg", $target, $source); + &add_content2xml_hash($out_hash, 'usr', $to); + &add_content2xml_hash($out_hash, 'subject', @{$msg_hash->{'subject'}}[0]); + &add_content2xml_hash($out_hash, 'message', @{$msg_hash->{'message'}}[0]); + + + return &create_xml_string($out_hash); } diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 231fa016a..b0b4ffbda 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -1085,7 +1085,8 @@ sub msg_to_decrypt { # target is own address without forward_to_gosa-tag -> process here if (not $done) { - if ((($target eq $local_address) || ($target eq $local_mac) ) && (not exists $msg_hash->{'forward_to_gosa'})) { + #if ((($target eq $local_address) || ($target eq $local_mac) ) && (not exists $msg_hash->{'forward_to_gosa'})) { + if (($target eq $local_address) && (not exists $msg_hash->{'forward_to_gosa'})) { $done = 1; if ($source eq "GOSA") { $msg =~ s/<\/xml>/$local_address,$session_id<\/forward_to_gosa><\/xml>/; @@ -1118,7 +1119,7 @@ sub msg_to_decrypt { my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; my $gosa_at; my $gosa_session_id; - if ((($target eq $local_address) || ($target eq $local_mac) ) && (defined $forward_to_gosa)){ + if (($target eq $local_address) && (defined $forward_to_gosa)){ my ($gosa_at, $gosa_session_id) = split(/,/, $forward_to_gosa); if ($gosa_at ne $local_address) { $done = 1; @@ -1151,7 +1152,7 @@ sub msg_to_decrypt { my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; my $gosa_at; my $gosa_session_id; - if ((($target eq $local_address) || ($target eq $local_mac) ) && (defined $forward_to_gosa)){ + if (($target eq $local_address) && (defined $forward_to_gosa)){ my ($gosa_at, $gosa_session_id) = split(/,/, $forward_to_gosa); if ($gosa_at eq $local_address) { my $session_reference = $kernel->ID_id_to_session($gosa_session_id); @@ -1865,32 +1866,75 @@ sub watch_for_delivery_messages { my $send_succeed = 0; foreach my $hit (@$res) { my $receiver_host = @$hit[0]; + my $delivered2host = 0; &daemon_log("M DEBUG: user '$receiver' is logged in at host '$receiver_host'", 7); - # fetch key to encrypt msg propperly for usr/host + # Looking for host in know_clients_db my $sql = "SELECT * FROM $known_clients_tn WHERE (hostname='$receiver_host')"; - &daemon_log("0 DEBUG: $sql", 7); my $res = $known_clients_db->exec_statement($sql); - # host is already down - if (not ref(@$res[0]) eq "ARRAY") { next; } + # Host is known in known_clients_db + if (ref(@$res[0]) eq "ARRAY") { + my $receiver_key = @{@{$res}[0]}[2]; + my %data = ('subject' => $subject, 'message' => $message, 'usr' => $receiver); + my $out_msg = &build_msg("usr_msg", $server_address, $receiver_host, \%data ); + my $error = &send_msg_to_target($out_msg, $receiver_host, $receiver_key, "usr_msg", 0); + if ($error == 0 ) { + $send_succeed++ ; + $delivered2host++ ; + &daemon_log("M DEBUG: send message for user '$receiver' to host '$receiver_host'", 7); + } else { + &daemon_log("M DEBUG: cannot send message for user '$receiver' to host '$receiver_host'", 7); + } + } + + # Message already send, do not need to do anything more, otherwise ... + if ($delivered2host) { next;} + + # ...looking for host in foreign_clients_db + $sql = "SELECT * FROM $foreign_clients_tn WHERE (hostname='$receiver_host')"; + $res = $foreign_clients_db->exec_statement($sql); + + # Host is known in foreign_clients_db + if (ref(@$res[0]) eq "ARRAY") { + my $registration_server = @{@{$res}[0]}[2]; + + # Fetch encryption key for registration server + my $sql = "SELECT * FROM $known_server_tn WHERE (hostname='$registration_server')"; + my $res = $known_server_db->exec_statement($sql); + if (ref(@$res[0]) eq "ARRAY") { + my $registration_server_key = @{@{$res}[0]}[3]; + my %data = ('subject' => $subject, 'message' => $message, 'usr' => $receiver); + my $out_msg = &build_msg("usr_msg", $server_address, $receiver_host, \%data ); + my $error = &send_msg_to_target($out_msg, $registration_server, $registration_server_key, "usr_msg", 0); + if ($error == 0 ) { + $send_succeed++ ; + $delivered2host++ ; + &daemon_log("M DEBUG: send message for user '$receiver' to server '$registration_server'", 7); + } else { + &daemon_log("M ERROR: cannot send message for user '$receiver' to server '$registration_server'", 1); + } - # host is on - my $receiver_key = @{@{$res}[0]}[2]; - my %data = ('subject' => $subject, 'message' => $message, 'usr' => $receiver); - my $out_msg = &build_msg("usr_msg", $server_address, $receiver_host, \%data ); - my $error = &send_msg_to_target($out_msg, $receiver_host, $receiver_key, "usr_msg", 0); - if ($error == 0 ) { - $send_succeed++ ; - } + } else { + &daemon_log("M ERROR: host '$receiver_host' is reported to be ". + "registrated at server '$registration_server', ". + "but no data available in known_server_db ", 1); + } + } + + if (not $delivered2host) { + &daemon_log("M ERROR: unable to send user message to host '$receiver_host'", 1); + } } if ($send_succeed) { # set outgoing msg at db to deliverd my $sql = "UPDATE $messaging_tn SET flag='d' WHERE (id='$msg_id' AND direction='out' AND message_to='$receiver')"; - &daemon_log("0 DEBUG: $sql", 7); my $res = $messaging_db->exec_statement($sql); - } + &daemon_log("M INFO: send message for user '$receiver' to logged in hosts", 5); + } else { + &daemon_log("M WARNING: failed to deliver message for user '$receiver'", 3); + } } $kernel->delay_set('watch_for_delivery_messages', $messaging_db_loop_delay); diff --git a/gosa-si/server/events/mailqueue_com.pm b/gosa-si/server/events/mailqueue_com.pm index b285b96f1..87642ebd0 100644 --- a/gosa-si/server/events/mailqueue_com.pm +++ b/gosa-si/server/events/mailqueue_com.pm @@ -228,6 +228,7 @@ sub mailqueue_header { return ( $answer_msg ); } + =pod =head1 BUGS diff --git a/gosa-si/server/events/server_server_com.pm b/gosa-si/server/events/server_server_com.pm index 171a4eaed..2fd0f7459 100644 --- a/gosa-si/server/events/server_server_com.pm +++ b/gosa-si/server/events/server_server_com.pm @@ -7,6 +7,7 @@ my @events = ( 'new_foreign_client', 'trigger_wake', 'foreign_job_updates', + 'confirm_usr_msg', ); @EXPORT = @events; @@ -325,4 +326,11 @@ sub trigger_wake { } +sub confirm_usr_msg { + my ($msg, $msg_hash, $session_id) = @_ ; + &clMessages::confirm_usr_msg($msg, $msg_hash, $session_id); + return; +} + + 1; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index c5e2b51a3..d4dc8edd8 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -69,7 +69,6 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
job_trigger_action_instant_update
00:01:6c:9d:b9:fa GOSA 19700101000000
"; #$data = "
gosa_new_ping
00:01:6c:9d:b9:fa GOSA
"; - # get_login_usr_for_client #$data = "
gosa_get_login_usr_for_client
GOSA GOSA 00:01:6c:9d:b9:fa
"; @@ -79,6 +78,11 @@ for($count = 1; $count <= $zahl; $count++) # List all si-server providing opsi #$data = "
gosa_get_hosts_with_module
GOSA 10.89.1.31:20081 mailqueue_com
"; + # Send messages to a user and displayed message via konch + #$data = "
gosa_send_user_msg
GOSA GOSA ".base64_encode("eine wichtige nachricht")." admin polle harald 20130101235959 ".base64_encode("kaffeepause")."
"; + #$data = "
gosa_send_user_msg
10.89.1.30:20081 GOSA ".base64_encode("eine wichtige nachricht")." admin polle harald 20130101235959 ".base64_encode("kaffeepause")."
"; + #$data = "
gosa_send_user_msg
10.89.1.30:20081 GOSA ".base64_encode("eine wichtige nachricht")." admin rettenbe 20130101235959 ".base64_encode("kaffeepause")."
"; + ################## # recreate fai dbs #$data = "
gosa_recreate_fai_server_db
GOSA GOSA
"; @@ -176,21 +180,20 @@ for($count = 1; $count <= $zahl; $count++) ######################### # Mailqueue communication - # writing data into a mailqueue - #$data = "
gosa_send_user_msg
GOSA GOSA ".base64_encode("eine wichtige nachricht")." admin polle harald 20130101235959 ".base64_encode("kaffeepause")."
"; - #$data = "
gosa_send_user_msg
10.89.1.30:20081 GOSA ".base64_encode("eine wichtige nachricht")." admin polle harald 20130101235959 ".base64_encode("kaffeepause")."
"; - $data = "
gosa_send_user_msg
10.89.1.30:20081 GOSA ".base64_encode("eine wichtige nachricht")." admin polle harald 20130101235959 ".base64_encode("kaffeepause")."
"; + # Writing data into a mailqueue + #echo sabber | mail -s test horst@woauchimmer.de + # Querying the mailqueue at #$data = "
gosa_mailqueue_query
GOSA 00:01:6c:9d:aa:16
"; - #$data = "
gosa_mailqueue_query
GOSA 00:01:6c:9d:b9:fa
"; + $data = "
gosa_mailqueue_query
GOSA 00:01:6c:9d:b9:fa
"; - # multiple xml tags msg_id are allowed + # Multiple xml tags msg_id are allowed #$data = "
gosa_mailqueue_hold
GOSA 00:01:6c:9d:b9:fa 99C8ABEF23
"; #$data = "
gosa_mailqueue_unhold
GOSA 00:01:6c:9d:b9:fa 5657EBEEF7
"; #$data = "
gosa_mailqueue_requeue
GOSA 00:01:6c:9d:b9:fa 11A09BEF04
"; - #$data = "
gosa_mailqueue_del
GOSA 00:01:6c:9d:aa:16
"; + #$data = "
gosa_mailqueue_del
GOSA 00:01:6c:9d:b9:fa CEAFDBEF45
"; - # only one xml tag msg_id is allowed + # Only one xml tag msg_id is allowed #$data = "
gosa_mailqueue_header
GOSA 00:01:6c:9d:b9:fa 99E92BEF2B
"; ######################## -- 2.30.2