Code

bugfix: user messages adapted to server-server communication
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 5 Sep 2008 08:06:42 +0000 (08:06 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 5 Sep 2008 08:06:42 +0000 (08:06 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12366 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/client/events/gosaTriggered.pm
gosa-si/gosa-si-server
gosa-si/server/events/mailqueue_com.pm
gosa-si/server/events/server_server_com.pm
gosa-si/tests/client.php

index e2585774018b11f5fa180132fde1eb56b9ef1b91..3caffff15ea00dd70a72826978e8822ff82c72b7 100644 (file)
@@ -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/<header>usr_msg<\/header>/<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);
 }
 
 
index 231fa016a91e12c6e92e76ca2a12760ca5e33696..b0b4ffbda0538ff09ae0daddd10b52694cc07919 100755 (executable)
@@ -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>/<forward_to_gosa>$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); 
index b285b96f1bad607f1f9a1b4c0bce9602dd3c9494..87642ebd0248f9d533b15c510736099e71a84051 100644 (file)
@@ -228,6 +228,7 @@ sub mailqueue_header {
     return ( $answer_msg );
 }
 
+
 =pod
 
 =head1 BUGS
index 171a4eaed6ccd0e87662aa473cd27bd7319a245e..2fd0f7459c46968c3ce77b70992b862559655a86 100644 (file)
@@ -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;
index c5e2b51a33633c2f5cd2704019c06ec29c00d75b..d4dc8edd8367b7f1f3a7df4b28f673660dbb225a 100755 (executable)
@@ -69,7 +69,6 @@ for($count = 1; $count <= $zahl; $count++)
     #$data = "<xml> <header>job_trigger_action_instant_update</header> <target>00:01:6c:9d:b9:fa</target> <source>GOSA</source> <timestamp>19700101000000</timestamp> </xml>";
     #$data = "<xml> <header>gosa_new_ping</header> <target>00:01:6c:9d:b9:fa</target> <source>GOSA</source> </xml>";
 
-
     # get_login_usr_for_client
     #$data = "<xml> <header>gosa_get_login_usr_for_client</header> <target>GOSA</target> <source>GOSA</source> <client>00:01:6c:9d:b9:fa</client></xml>";
 
@@ -79,6 +78,11 @@ for($count = 1; $count <= $zahl; $count++)
     # List all si-server providing opsi
     #$data = "<xml> <header>gosa_get_hosts_with_module</header> <source>GOSA</source> <target>10.89.1.31:20081</target> <module_name>mailqueue_com</module_name> </xml>";
 
+    # Send messages to a user and displayed message via konch
+    #$data = "<xml> <header>gosa_send_user_msg</header> <target>GOSA</target> <source>GOSA</source> <subject>".base64_encode("eine wichtige nachricht")."</subject> <from>admin</from>  <user>polle</user> <user>harald</user> <delivery_time>20130101235959</delivery_time> <message>".base64_encode("kaffeepause")."</message> </xml>"; 
+    #$data = "<xml> <header>gosa_send_user_msg</header> <target>10.89.1.30:20081</target> <source>GOSA</source> <subject>".base64_encode("eine wichtige nachricht")."</subject> <from>admin</from> <user>polle</user> <user>harald</user> <delivery_time>20130101235959</delivery_time> <message>".base64_encode("kaffeepause")."</message> </xml>";
+    #$data = "<xml> <header>gosa_send_user_msg</header> <target>10.89.1.30:20081</target> <source>GOSA</source> <subject>".base64_encode("eine wichtige nachricht")."</subject> <from>admin</from> <user>rettenbe</user> <delivery_time>20130101235959</delivery_time> <message>".base64_encode("kaffeepause")."</message> </xml>";
+
     ##################
     # recreate fai dbs
     #$data = "<xml> <header>gosa_recreate_fai_server_db</header> <target>GOSA</target> <source>GOSA</source></xml>"; 
@@ -176,21 +180,20 @@ for($count = 1; $count <= $zahl; $count++)
     #########################
     # Mailqueue communication
     
-    # writing data into a mailqueue
-    #$data = "<xml> <header>gosa_send_user_msg</header> <target>GOSA</target> <source>GOSA</source> <subject>".base64_encode("eine wichtige nachricht")."</subject> <from>admin</from>  <user>polle</user> <user>harald</user> <delivery_time>20130101235959</delivery_time> <message>".base64_encode("kaffeepause")."</message> </xml>"; 
-    #$data = "<xml> <header>gosa_send_user_msg</header> <target>10.89.1.30:20081</target> <source>GOSA</source> <subject>".base64_encode("eine wichtige nachricht")."</subject> <from>admin</from> <user>polle</user> <user>harald</user> <delivery_time>20130101235959</delivery_time> <message>".base64_encode("kaffeepause")."</message> </xml>";
-    $data = "<xml> <header>gosa_send_user_msg</header> <target>10.89.1.30:20081</target> <source>GOSA</source> <subject>".base64_encode("eine wichtige nachricht")."</subject> <from>admin</from> <user>polle</user> <user>harald</user> <delivery_time>20130101235959</delivery_time> <message>".base64_encode("kaffeepause")."</message> </xml>";
+    # Writing data into a mailqueue
+    #echo sabber | mail -s test horst@woauchimmer.de    
 
+    # Querying the mailqueue at 
     #$data = "<xml> <header>gosa_mailqueue_query</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> </xml>";
-    #$data = "<xml> <header>gosa_mailqueue_query</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> </xml>";
+    $data = "<xml> <header>gosa_mailqueue_query</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> </xml>";
 
-    # multiple xml tags msg_id are allowed
+    # Multiple xml tags msg_id are allowed
     #$data = "<xml> <header>gosa_mailqueue_hold</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <msg_id>99C8ABEF23</msg_id> </xml>";
     #$data = "<xml> <header>gosa_mailqueue_unhold</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <msg_id>5657EBEEF7</msg_id> </xml>";
     #$data = "<xml> <header>gosa_mailqueue_requeue</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <msg_id>11A09BEF04</msg_id> </xml>";
-    #$data = "<xml> <header>gosa_mailqueue_del</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> <msg_id></msg_id> </xml>";
+    #$data = "<xml> <header>gosa_mailqueue_del</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <msg_id>CEAFDBEF45</msg_id> </xml>";
 
-    # only one xml tag msg_id is allowed
+    # Only one xml tag msg_id is allowed
     #$data = "<xml> <header>gosa_mailqueue_header</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <msg_id>99E92BEF2B</msg_id> </xml>";
      
     ########################