From 3b976ba01cdc0b3b144623f2efeb81931d6d2cd0 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Thu, 24 Apr 2008 14:30:33 +0000 Subject: [PATCH] new messaging system git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10676 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/client/events/gosaTriggered.pm | 28 ++++++++ gosa-si/gosa-si-server | 92 ++++++++++++++++++++------ gosa-si/server/events/clMessages.pm | 18 +++++ gosa-si/server/events/gosaTriggered.pm | 4 +- gosa-si/tests/client.php | 13 ++-- 5 files changed, 126 insertions(+), 29 deletions(-) diff --git a/gosa-si/client/events/gosaTriggered.pm b/gosa-si/client/events/gosaTriggered.pm index 9de869af8..b63aa8fc6 100644 --- a/gosa-si/client/events/gosaTriggered.pm +++ b/gosa-si/client/events/gosaTriggered.pm @@ -3,6 +3,7 @@ use Exporter; @ISA = qw(Exporter); my @events = ( "get_events", + "usr_msg", "trigger_action_localboot", "trigger_action_halt", "trigger_action_faireboot", @@ -18,6 +19,8 @@ my @events = ( use strict; use warnings; use GOSA::GosaSupportDaemon; +use Data::Dumper; +use MIME::Base64; BEGIN {} @@ -26,6 +29,31 @@ END {} sub get_events { return \@events; } +sub usr_msg { + my ($msg, $msg_hash) = @_; + + + my $to = @{$msg_hash->{'usr'}}[0]; + my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]); + my $message = &decode_base64(@{$msg_hash->{'message'}}[0]); + +print STDERR "\n\n\n##############################\n"; +print STDERR "message to: $to\n"; +print STDERR "subject: $subject\n"; +print STDERR "message: $message\n"; +print STDERR "##############################\n\n\n"; +# do, what ever you want +# konch +# kdialog +# ... + + + + # give gosa-si-server feedback, that msg was received + $msg =~ s/
usr_msg<\/header>/
confirm_usr_msg<\/header>/g; + return $msg; +} + sub trigger_action_localboot { my ($msg, $msg_hash) = @_; diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 067bce56e..9fcbf6aff 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -1250,6 +1250,7 @@ sub trigger_db_loop { $kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay); $kernel->delay_set('watch_for_done_jobs', $job_queue_loop_delay); $kernel->delay_set('watch_for_new_messages', $messaging_db_loop_delay); + $kernel->delay_set('watch_for_delivery_messages', $messaging_db_loop_delay); $kernel->delay_set('watch_for_done_messages', $messaging_db_loop_delay); } @@ -1382,7 +1383,7 @@ sub watch_for_new_messages { # translate message_to to plain login name # TODO implement reciever translation - my @reciever_l = ($message_to); + my @reciever_l = split(/,/, $message_to); my $message_id = @{$hit}[0]; #add each outgoing msg to messaging_db @@ -1405,36 +1406,62 @@ sub watch_for_new_messages { &daemon_log("M INFO: message '".@{$hit}[0]."' is prepared for delivery to reciever '$reciever'", 5); } - # send outgoing messages - my $sql_statement = "SELECT * FROM $messaging_tn WHERE ( flag='p' AND direction='out' )"; - my $res = $messaging_db->exec_statement( $sql_statement ); - foreach my $hit (@{$res}) { - # add subject, from, to and message to list coll_user_msg - my @user_msg = [@{$hit}[1], @{$hit}[2], $reciever, @{$hit}[7]]; - push( @coll_user_msg, \@user_msg); - } - - # send outgoing list to myself (gosa-si-server) to deliver each message to user - # reason for this workaround: if to much messages have to be delivered, it can come to - # denial of service problems of the server. so, the incoming message list can be processed - # by a forked child and gosa-si-server is always ready to work. - my $collection_out_msg = &create_xml_hash("collection_user_messages", $server_address, $server_address); - # add to hash 'msg1' => [subject, from, to, message] - # hash to string - # send msg to myself -# TODO - # set incoming message to flag d=deliverd $sql_statement = "UPDATE $messaging_tn SET flag='p' WHERE id='$message_id'"; &daemon_log("M DEBUG: $sql_statement", 7); $res = $messaging_db->update_dbentry($sql_statement); &daemon_log("M INFO: message '$message_id' is set to flag 'p' (processed)", 5); - } - + $kernel->delay_set('watch_for_new_messages', $messaging_db_loop_delay); + return; +} +sub watch_for_delivery_messages { + my ($kernel, $heap) = @_[KERNEL, HEAP]; + + # select outgoing messages + my $sql_statement = "SELECT * FROM $messaging_tn WHERE ( flag='p' AND direction='out' )"; + #&daemon_log("0 DEBUG: $sql", 7); + my $res = $messaging_db->exec_statement( $sql_statement ); + + # build out msg for each usr + foreach my $hit (@{$res}) { + my $receiver = @{$hit}[3]; + my $msg_id = @{$hit}[0]; + my $subject = @{$hit}[1]; + my $message = @{$hit}[7]; + + # resolve usr -> host where usr is logged in + my $sql = "SELECT * FROM $login_users_tn WHERE (user='$receiver')"; + #&daemon_log("0 DEBUG: $sql", 7); + my $res = $login_users_db->exec_statement($sql); + + # reciver is logged in nowhere + if (not ref(@$res[0]) eq "ARRAY") { next; } + + # receiver is logged in at host + my $receiver_host = @{@{$res}[0]}[0]; + + # fetch key to encrypt msg propperly for usr/host + $sql = "SELECT * FROM $known_clients_tn WHERE (hostname='$receiver_host')"; + &daemon_log("0 DEBUG: $sql", 7); + $res = $known_clients_db->exec_statement($sql); + 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_state = &send_msg_to_target($out_msg, $receiver_host, $receiver_key, "usr_msg", 0); + + if ($error_state == 0) { + # 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); + } + } + $kernel->delay_set('watch_for_delivery_messages', $messaging_db_loop_delay); return; } @@ -1442,6 +1469,26 @@ sub watch_for_new_messages { sub watch_for_done_messages { my ($kernel,$heap) = @_[KERNEL, HEAP]; + my $sql = "SELECT * FROM $messaging_tn WHERE (flag='p' AND direction='in')"; + #&daemon_log("0 DEBUG: $sql", 7); + my $res = $messaging_db->exec_statement($sql); + + foreach my $hit (@{$res}) { + my $msg_id = @{$hit}[0]; + + my $sql = "SELECT * FROM $messaging_tn WHERE (id='$msg_id' AND direction='out' AND (NOT flag='s'))"; + #&daemon_log("0 DEBUG: $sql", 7); + my $res = $messaging_db->exec_statement($sql); + + # not all usr msgs have been seen till now + if ( ref(@$res[0]) eq "ARRAY") { next; } + + $sql = "DELETE FROM $messaging_tn WHERE (id='$msg_id')"; + #&daemon_log("0 DEBUG: $sql", 7); + $res = $messaging_db->exec_statement($sql); + + } + $kernel->delay_set('watch_for_done_messages', $messaging_db_loop_delay); return; } @@ -2423,6 +2470,7 @@ POE::Session->create( _start => \&_start, sig_handler => \&sig_handler, watch_for_new_messages => \&watch_for_new_messages, + watch_for_delivery_messages => \&watch_for_delivery_messages, watch_for_done_messages => \&watch_for_done_messages, watch_for_new_jobs => \&watch_for_new_jobs, watch_for_done_jobs => \&watch_for_done_jobs, diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 576fca207..b56668762 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -2,6 +2,7 @@ package clMessages; use Exporter; @ISA = qw(Exporter); my @events = ( + "confirm_usr_msg", "PROGRESS", "FAIREBOOT", "TASKSKIP", @@ -51,6 +52,23 @@ sub get_events { } +sub confirm_usr_msg { + my ($msg, $msg_hash, $session_id) = @_; + my $message = @{$msg_hash->{'message'}}[0]; + my $subject = @{$msg_hash->{'subject'}}[0]; + my $usr = @{$msg_hash->{'usr'}}[0]; + + # set update for this message + my $sql = "UPDATE $main::messaging_tn SET flag='s' WHERE (message='$message' AND subject='$subject' AND message_to='$usr')"; + &main::daemon_log("$session_id DEBUG: $sql", 7); + my $res = $main::messaging_db->exec_statement($sql); + + + return; +} + + + sub read_configfile { my ($cfg_file, %cfg_defaults) = @_; my $cfg; diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 4fba9bec6..c788754e2 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -65,7 +65,7 @@ sub send_user_msg { #my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]); my $subject = @{$msg_hash->{'subject'}}[0]; my $from = @{$msg_hash->{'from'}}[0]; - my $to = @{$msg_hash->{'to'}}[0]; + my @to = @{$msg_hash->{'to'}}; my $delivery_time = @{$msg_hash->{'delivery_time'}}[0]; #my $message = &decode_base64(@{$msg_hash->{'message'}}[0]); my $message = @{$msg_hash->{'message'}}[0]; @@ -99,7 +99,7 @@ sub send_user_msg { id=>$new_msg_id, subject=>$subject, message_from=>$from, - message_to=>$to, + message_to=>join(",",@to), flag=>"n", direction=>"in", delivery_time=>$delivery_time, diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 52ff3c9cd..20af16b99 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -9,8 +9,10 @@ $zahl= 1; for($count = 1; $count <= $zahl; $count++) { - $sock = new Socket_Client("10.3.67.111","20081",TRUE,5); - $sock->setEncryptionKey("UldOjon9gra"); + $sock = new Socket_Client("127.0.0.1","20081",TRUE,5); + $sock->setEncryptionKey("secret-gosa-password"); + #$sock = new Socket_Client("10.3.67.111","20081",TRUE,5); + #$sock->setEncryptionKey("UldOjon9gra"); if($sock->connected()){ @@ -21,7 +23,7 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
job_ping
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa19700101000000
"; # jobdb delete - $data = "
gosa_delete_jobdb_entry
GOSA GOSA 3
"; + #$data = "
gosa_delete_jobdb_entry
GOSA GOSA 3
"; # smbhash #$data = "
gosa_gen_smb_hash
GOSAGOSAtester
"; @@ -81,7 +83,8 @@ for($count = 1; $count <= $zahl; $count++) ########### # messaging - #$data = "
gosa_send_user_msg
GOSA GOSA eine wichtige nachricht admin rettenbe 20130101235959 kaffeepause
"; + + $data = "
gosa_send_user_msg
GOSA GOSA ".base64_encode("eine wichtige nachricht")." admin polle rettenbe 20130101235959 ".base64_encode("kaffeepause")."
"; ################ # logHandling.pm @@ -99,7 +102,7 @@ for($count = 1; $count <= $zahl; $count++) ######### # Kerberos test query - $data = "
gosa_krb5_get_principal
00:01:6c:9d:aa:16 cajus@WIRECARD.SYSGOSA
"; + #$data = "
gosa_krb5_get_principal
00:01:6c:9d:aa:16 cajus@WIRECARD.SYSGOSA
"; $sock->write($data); $answer = "nothing"; -- 2.30.2