From a75886104b2ccb1b2295315b95c0a7cc1a548ede Mon Sep 17 00:00:00 2001 From: rettenbe Date: Thu, 6 Nov 2008 13:48:51 +0000 Subject: [PATCH] * change of client/event/gosaTriggered.pm to trigger the 'seen'-feedback * si-client wachtes /tmp/goto_notify_* pattern and send confirm msg of seen user messages back to server * goto2/konch/src/goto-notify was changed under this circumstance git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12940 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/client/events/gosaTriggered.pm | 21 +++++--- gosa-si/gosa-si-client | 69 +++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/gosa-si/client/events/gosaTriggered.pm b/gosa-si/client/events/gosaTriggered.pm index 412587ebe..2f6517e2c 100644 --- a/gosa-si/client/events/gosaTriggered.pm +++ b/gosa-si/client/events/gosaTriggered.pm @@ -50,6 +50,7 @@ use warnings; use GOSA::GosaSupportDaemon; use Data::Dumper; use MIME::Base64; +use Data::Random qw(:all); BEGIN {} @@ -125,17 +126,23 @@ sub usr_msg { 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'" ); + my $rand_file = "/tmp/goto_notify_".join("",rand_chars(set=>'alphanumeric', min=>16, max=>16)); + open(DATEI, ">$rand_file"); + print DATEI "source:$source\ntarget:$target\nusr:$to\nsubject:".@{$msg_hash->{'subject'}}[0]."\nmessage:".@{$msg_hash->{'message'}}[0]."\n"; + close DATEI; + + my $feedback = system("/usr/bin/goto-notify user-message '$to' '$subject' '$message' '$rand_file' &" ); # give gosa-si-server feedback, that msg was received - $msg =~ s/
usr_msg<\/header>/
confirm_usr_msg<\/header>/g; - 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]); +# $msg =~ s/
usr_msg<\/header>/
confirm_usr_msg<\/header>/g; +# 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); +# return &create_xml_string($out_hash); + return } diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index a3987e70e..962102fe6 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -83,9 +83,12 @@ $gosa_si_client_fifo = "/var/run/gosa-si-client.socket"; my $delay_set_time = 10; our $prg= basename($0); -# all x seconds the client reports logged_in users to gosa-si-server +# all n seconds the client reports logged_in users to gosa-si-server my $trigger_logged_in_users_report_delay = 600; +# all n seconds the client reports messages seen by user +my $trigger_seen_messages_delay = 30; + # directory where all log files from installation are stored my $fai_log_dir = "/var/log/fai"; @@ -773,6 +776,68 @@ sub trigger_logged_in_users_report { } +sub trigger_seen_messages { + my ($kernel) = $_[KERNEL] ; + + # Select all files under /tmp with prefix 'goto_notify' + my $goto_dir = "/tmp"; + opendir(DIR, $goto_dir); + my @goto_files = grep { /^goto_notify_/ && -f "$goto_dir/$_" } readdir(DIR); + closedir DIR; + + # Check if file has 'seen' tag + foreach my $goto_file (@goto_files) { + open(FILE, "$goto_dir/$goto_file"); + my @lines = ; + close FILE; + + my $source; + my $target; + my $usr; + my $subject; + my $message; + my $seen = 0; + chomp(@lines); + foreach my $line (@lines) { + if ($line =~ /^source:([\S\s]*)$/) { + $source = $1 + } + if ($line =~ /^target:([\S\s]*)$/) { + $target = $1; + } + if ($line =~ /^usr:([\S\s]*)$/) { + $usr = $1; + } + if ($line =~ /^subject:([\S\s]*)$/) { + $subject = $1; + } + if ($line =~ /^message:([\S\s]*)$/) { + $message = $1; + } + if ($line =~ /^seen$/) { + $seen++; + } + } + + # Send 'confirm_usr_msg' back to msg-hosting server + if ($seen) { + my %data = ('usr'=>$usr, 'subject'=>$subject, 'message'=>$message); + my $confirm_msg = &build_msg("confirm_usr_msg", $target, $source, \%data); + my $send_error = &send_msg_to_target($confirm_msg, $server_address, $server_key); + + # Delete file + if (not $send_error) { + system("rm $goto_dir/$goto_file"); + } + } + } + + $kernel->delay_set('trigger_seen_messages', $trigger_seen_messages_delay); + + return; +} + + sub generic_file_error { my ( $heap, $operation, $errno, $error_string, $wheel_id ) = @_[ HEAP, ARG0, ARG1, ARG2, ARG3 ]; @@ -893,6 +958,7 @@ sub _start { $heap->{watchers}->{ $watcher->ID } = $watcher; } $kernel->yield('trigger_logged_in_users_report'); + $kernel->yield('trigger_seen_messages'); } @@ -1166,6 +1232,7 @@ POE::Session->create( # trigger periodical tasks trigger_new_key => \&trigger_new_key, trigger_logged_in_users_report => \&trigger_logged_in_users_report, + trigger_seen_messages => \&trigger_seen_messages, # handle records from each defined file differently fifo_record => \&fifo_got_record, -- 2.30.2