From: rettenbe Date: Fri, 7 Nov 2008 09:01:20 +0000 (+0000) Subject: user messages handling switched to server-server communication X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2c087c322238646a437c4f920cdbb8b9bb1830a6;p=gosa.git user messages handling switched to server-server communication git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@12959 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/client/events/gosaTriggered.pm b/gosa-si/client/events/gosaTriggered.pm index 3caffff15..6edc2758f 100644 --- a/gosa-si/client/events/gosaTriggered.pm +++ b/gosa-si/client/events/gosaTriggered.pm @@ -41,6 +41,7 @@ my @events = ( "trigger_action_reinstall", "trigger_action_update", "trigger_action_instant_update", + "trigger_goto_settings_reload", ); @EXPORT = @events; @@ -49,6 +50,7 @@ use warnings; use GOSA::GosaSupportDaemon; use Data::Dumper; use MIME::Base64; +use Data::Random qw(:all); BEGIN {} @@ -124,17 +126,14 @@ 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; - # 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]); + my $feedback = system("/usr/bin/goto-notify user-message '$to' '$subject' '$message' '$rand_file' &" ); - - return &create_xml_string($out_hash); + return } @@ -495,5 +494,20 @@ sub trigger_action_instant_update { return; } +sub trigger_goto_settings_reload { + my ($msg, $msg_hash) = @_; + + # Execute goto settings reload + my $cmd = "/etc/init.d/goto-agents"; + my $pram = "start"; + if (-f $cmd){ + my $feedback = system("$cmd $pram") or &main::daemon_log("ERROR: $@"); + } else { + &main::daemon_log("ERROR: cannot exec $cmd, file not found!"); + } + + return; +} + 1; diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index ab3fb734a..933b2fa4a 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"; @@ -551,14 +554,15 @@ sub register_at_gosa_si_server { # Check if our ip is resolvable - if not: don't try to register my $ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); my $dnsname= gethostbyaddr(inet_aton($ip), AF_INET); - if(!defined($dnsname)) { - if( defined($client_force_hostname) && $client_force_hostname eq "true") { - $dnsname = `hostname`; - } else { - &write_to_file("goto-error-dns:$ip", $fai_logpath); - exit(1); - } - } + if(!defined($dnsname)) { + if( defined($client_force_hostname) && $client_force_hostname eq "true") { + $dnsname = `hostname`; + } else { + &write_to_file("goto-error-dns:$ip", $fai_logpath); + &main::daemon_log("ERROR: ip is not resolvable, no registration possible. Write 'goto-error-dns:$ip' to $fai_logpath", 1); + exit(1); + } + } # create registration msg my $local_ip = &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); @@ -772,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 ]; @@ -805,6 +871,8 @@ sub fifo_got_record { my $clmsg_hash = &create_xml_hash("CLMSG_$header", $client_address, $server_address, $content); &add_content2xml_hash($clmsg_hash, "macaddress", $client_mac_address); + my $utc_ts = &main::get_utc_time(); + &add_content2xml_hash($clmsg_hash, "timestamp", $utc_ts); my $clmsg = &create_xml_string($clmsg_hash); &send_msg_to_target($clmsg, $server_address, $server_key, "CLMSG_$header"); @@ -890,6 +958,7 @@ sub _start { $heap->{watchers}->{ $watcher->ID } = $watcher; } $kernel->yield('trigger_logged_in_users_report'); + $kernel->yield('trigger_seen_messages'); } @@ -1163,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, diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index b09f02411..84de9b733 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -172,7 +172,7 @@ my @foreign_clients_col_names = ("hostname", "macaddress", "regserver", "timesta our $login_users_db; our $login_users_tn = "login_users"; my $login_users_file_name; -my @login_users_col_names = ("client", "user", "timestamp"); +my @login_users_col_names = ("client", "user", "timestamp", "regserver"); # holds all fai server, the debian release and tag our $fai_server_db; diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 6d65168db..b0497ec59 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -117,11 +117,13 @@ sub LOGIN { my $source = @{$msg_hash->{'source'}}[0]; my $login = @{$msg_hash->{$header}}[0]; + # Add user to login_users_db my %add_hash = ( table=>$main::login_users_tn, primkey=> ['client', 'user'], client=>$source, user=>$login, timestamp=>&get_time, + regserver=>'localhost', ); my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash ); if ($res != 0) { @@ -129,7 +131,11 @@ sub LOGIN { return; } - return; + # Share login information with all other si-server + my %data = ( 'new_user' => "$source;$login" ); + my $info_msg = &build_msg("information_sharing", $main::server_address, "KNOWN_SERVER", \%data); + + return ($info_msg); } @@ -187,6 +193,7 @@ sub CURRENTLY_LOGGED_IN { client=>$source, user=>$user, timestamp=>&get_time, + regserver=>'localhost', ); my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash ); if ($res != 0) { @@ -222,7 +229,16 @@ sub CURRENTLY_LOGGED_IN { &main::daemon_log("$session_id INFO: delete user '".$hit->{'user'}."' at client '".$hit->{'client'}."' from login_user_db", 5); } - return; + # Inform all other server which users are logged in at clients registered at local server + my $info_sql = "SELECT * FROM $main::login_users_tn"; + my $info_res = $main::login_users_db->select_dbentry($info_sql); + my $info_msg_hash = &create_xml_hash("information_sharing", $main::server_address, "KNOWN_SERVER"); + while (my ($hit_id, $hit) = each(%$info_res)) { + &add_content2xml_hash($info_msg_hash, 'user_db', $hit->{'client'}.";".$hit->{'user'}); + } + my $info_msg = &create_xml_string($info_msg_hash); + + return ($info_msg); }