From: rettenbe Date: Tue, 19 Feb 2008 13:03:07 +0000 (+0000) Subject: msg out of si can be forwarded to GOsa X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c75f7bb4c890f9f999bd888a2a261e8ebed5c8a5;p=gosa.git msg out of si can be forwarded to GOsa git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8953 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/client/events/corefunctions.pm b/gosa-si/client/events/corefunctions.pm index 80589e863..ac3a66018 100644 --- a/gosa-si/client/events/corefunctions.pm +++ b/gosa-si/client/events/corefunctions.pm @@ -418,9 +418,12 @@ sub ping { my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; + my $session_id = @{$msg_hash->{'session_id'}}[0]; + # switch target and source and send msg back my $out_hash = &main::create_xml_hash("got_ping", $target, $source); + &add_content2xml_hash($out_hash, "session_id", $session_id); my $out_msg = &main::create_xml_string($out_hash); return $out_msg; diff --git a/gosa-si/debian/gosa-si-server.install b/gosa-si/debian/gosa-si-server.install index 09d25d16f..db7db1416 100644 --- a/gosa-si/debian/gosa-si-server.install +++ b/gosa-si/debian/gosa-si-server.install @@ -6,4 +6,4 @@ modules/SIPackages.pm usr/lib/gosa-si/modules modules/GosaPackages.pm usr/lib/gosa-si/modules modules/ArpHandler.pm usr/lib/gosa-si/modules modules/oui.txt usr/lib/gosa-si/modules -server/events/installation.pm usr/lib/gosa-si/server/events +server/events/gosaTriggered.pm usr/lib/gosa-si/server/events diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 570906585..590d9668e 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -879,7 +879,8 @@ sub _start { sub client_input { no strict "refs"; - my ($heap,$input,$wheel) = @_[HEAP, ARG0, ARG1]; + my ($kernel, $session, $heap,$input,$wheel) = @_[KERNEL, SESSION, HEAP, ARG0, ARG1]; + my $session_id = $session->ID; my ($msg, $msg_hash, $module); my $error = 0; my $answer_l; @@ -910,7 +911,7 @@ sub client_input { # process incoming msg if( $error == 0) { daemon_log("Processing module ".$module, 5); - $answer_l = &{ $module."::process_incoming_msg" }($msg, $msg_hash, $heap->{'remote_ip'}); + $answer_l = &{ $module."::process_incoming_msg" }($msg, $msg_hash, $session_id); if ( 0 > @{$answer_l} ) { my $answer_str = join("\n", @{$answer_l}); @@ -949,9 +950,11 @@ sub client_input { } } elsif( $answer_target eq "GOSA" ) { + $answer =~ /(\d)<\/session_id>/; + # answer is for GOSA and has to returned to connected client my $gosa_answer = &encrypt_msg($answer, $GosaPackages_key); - $client_answer = $gosa_answer; + $client_answer = $gosa_answer."session_id=$1"; } elsif( $answer_target eq "KNOWN_SERVER" ) { # answer is for all server in known_server @@ -1025,7 +1028,17 @@ sub client_input { } if( $client_answer ) { - $heap->{client}->put($client_answer); + + if( $client_answer =~ /session_id=(\d+)/ ) { + my $session_id = $1; + my $session_reference = $kernel->ID_id_to_session($1); + my $session_heap = $session_reference->get_heap(); + $session_heap->{client}->put( $client_answer ); + } + else { + $heap->{client}->put($client_answer); + } + } return; diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index bc067c337..d53227ef6 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -252,46 +252,52 @@ sub import_events { # DESCRIPTION: handels the proceeded distribution to the appropriated functions #=============================================================================== sub process_incoming_msg { - my ($msg, $msg_hash) = @_ ; + my ($msg, $msg_hash, $session_id) = @_ ; my $header = @{$msg_hash->{header}}[0]; - my $out_msg; - + my @msg_l; + my @out_msg_l; + &main::daemon_log("GosaPackages: receive '$header'", 1); if ($header =~ /^job_/) { - $out_msg = &process_job_msg($msg, $msg_hash); + @msg_l = &process_job_msg($msg, $msg_hash, $session_id); } elsif ($header =~ /^gosa_/) { - $out_msg = &process_gosa_msg($msg, $msg_hash); + @msg_l = &process_gosa_msg($msg, $msg_hash, $session_id); } else { &main::daemon_log("ERROR: $header is not a valid GosaPackage-header, need a 'job_' or a 'gosa_' prefix"); } - # keep job queue uptodate and save result and status - if (defined ($out_msg) && $out_msg =~ /(\d*?)<\/jobdb_id>/) { - my $job_id = $1; - my $sql = "UPDATE '".$main::job_queue_table_name. - "' SET status='done', result='".$out_msg. - "' WHERE id='$job_id'"; - my $res = $main::job_db->exec_statement($sql); - } + foreach my $out_msg ( @msg_l ) { - # substitute in all outgoing msg GOSA of $server_address - $out_msg =~ s/GOSA<\/source>/$server_address<\/source>/g; + # keep job queue uptodate and save result and status + if (defined ($out_msg) && $out_msg =~ /(\d*?)<\/jobdb_id>/) { + my $job_id = $1; + my $sql = "UPDATE '".$main::job_queue_table_name. + "' SET status='done', result='".$out_msg. + "' WHERE id='$job_id'"; + my $res = $main::job_db->exec_statement($sql); + } + + # substitute in all outgoing msg GOSA of $server_address + $out_msg =~ s/GOSA<\/source>/$server_address<\/source>/g; + + if (defined $out_msg){ + push(@out_msg_l, $out_msg); + } - my @out_msg_l; - if (defined $out_msg){ - push(@out_msg_l, $out_msg); } + return \@out_msg_l; } sub process_gosa_msg { - my ($msg, $msg_hash) = @_ ; + my ($msg, $msg_hash, $session_id) = @_ ; my $out_msg; - + my @out_msg_l; + my $header = @{$msg_hash->{'header'}}[0]; $header =~ s/gosa_//; @@ -318,23 +324,28 @@ sub process_gosa_msg { # a event exists with the header as name &main::daemon_log("found event '$header' at event-module '".$event_hash->{$header}."'", 5); no strict 'refs'; - $out_msg = &{$event_hash->{$header}."::$header"}($msg, $msg_hash); + @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); } } # if delivery not possible raise error and return - if (not defined $out_msg) { + if( not @out_msg_l ) { &main::daemon_log("ERROR: GosaPackages: no event handler or core function defined for $header", 1); - } elsif ($out_msg eq "") { + } elsif( 0 == @out_msg_l) { &main::daemon_log("ERROR: GosaPackages got not answer from event_handler $header", 1); + } elsif( $out_msg ) { + push(@out_msg_l, $out_msg); } - return $out_msg; + + return @out_msg_l; } sub process_job_msg { my ($msg, $msg_hash)= @_ ; + my $out_msg; + my @out_msg_l; my $header = @{$msg_hash->{header}}[0]; $header =~ s/job_//; @@ -357,9 +368,14 @@ sub process_job_msg { if (not $res == 0) { &main::daemon_log("ERROR: GosaPackages: process_job_msg: $res", 1); } + else { + &main::daemon_log("INFO: GosaPackages: $header job successfully added to job queue", 5); + } - &main::daemon_log("GosaPackages: $header job successfully added to job queue", 3); - return "
answer
$server_addressGOSA$res
"; + $out_msg = "
answer
$server_addressGOSA$res
"; + push( @out_msg_l, $out_msg ); + + return @out_msg_l; } diff --git a/gosa-si/modules/SIPackages.pm b/gosa-si/modules/SIPackages.pm index 9c5ad6086..f84e3277b 100644 --- a/gosa-si/modules/SIPackages.pm +++ b/gosa-si/modules/SIPackages.pm @@ -445,12 +445,6 @@ sub process_incoming_msg { } } -# if( $error == 0) { -# if( 0 == @out_msg_l ) { -# push(@out_msg_l, $msg); -# } -# } - return \@out_msg_l; } @@ -463,21 +457,44 @@ sub process_incoming_msg { #=============================================================================== sub got_ping { my ($msg_hash) = @_; - + my $source = @{$msg_hash->{source}}[0]; my $target = @{$msg_hash->{target}}[0]; my $header = @{$msg_hash->{header}}[0]; + my $session_id = @{$msg_hash->{'session_id'}}[0]; + my $act_time = &get_time; + my @out_msg_l; + my $out_msg; + + # check known_clients_db + my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source'"; + my $query_res = $main::known_clients_db->select_dbentry( $sql_statement ); + if( 1 == keys %{$query_res} ) { + my $sql_statement= "UPDATE known_clients ". + "SET status='$header', timestamp='$act_time' ". + "WHERE hostname='$source'"; + my $res = $main::known_clients_db->update_dbentry( $sql_statement ); + } - if(exists $main::known_daemons->{$source}) { - &main::add_content2known_daemons(hostname=>$source, status=>$header); - } else { - &main::add_content2known_clients(hostname=>$source, status=>$header); - } + # check known_server_db + $sql_statement = "SELECT * FROM known_server WHERE hostname='$source'"; + $query_res = $main::known_server_db->select_dbentry( $sql_statement ); + if( 1 == keys %{$query_res} ) { + my $sql_statement= "UPDATE known_server ". + "SET status='$header', timestamp='$act_time' ". + "WHERE hostname='$source'"; + my $res = $main::known_server_db->update_dbentry( $sql_statement ); + } + + # create out_msg + my $out_hash = &create_xml_hash($header, $source, "GOSA"); + &add_content2xml_hash($out_hash, "session_id", $session_id); + $out_msg = &create_xml_string($out_hash); + push(@out_msg_l, $out_msg); - return; + return @out_msg_l; } - #=== FUNCTION ================================================================ # NAME: new_passwd # PARAMETERS: msg_hash - ref - hash from function create_xml_hash @@ -771,12 +788,12 @@ sub new_ldap_config { @servers= sort (@servers); foreach $server (@servers){ - # Conversation for backward compatibility - if ($server !=~ /^ldap[^:]+:\/\// ) { - if ($server =~ /^([^:]+):(.*)$/ ) { - $server= "1:dummy:ldap://$1/$2"; - } - } + # Conversation for backward compatibility + if ($server !=~ /^ldap[^:]+:\/\// ) { + if ($server =~ /^([^:]+):(.*)$/ ) { + $server= "1:dummy:ldap://$1/$2"; + } + } $base= $server; $server =~ s%^[^:]+:[^:]+:(ldap.*://[^/]+)/.*$%$1%; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 98391deab..d0e189b53 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -16,7 +16,7 @@ if($sock->connected()){ /* Prepare a hunge bunch of data to be send */ # add -#$data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 19700101000001
"; +$data = "
gosa_ping
GOSA00:01:6c:9d:b9:fa
"; #$data = "
job_sayHello
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; #$data = "
job_ping
10.89.1.155:20083 10.89.1.155:2008100:1B:77:04:8A:6C 20130102133900
"; @@ -53,7 +53,7 @@ if($sock->connected()){ #$data = "
gosa_import_events
00:01:6c:9d:b9:fa 10.89.1.31:20081
"; -$data = "
gosa_trigger_action_localboot
00:01:6c:9d:b9:fa 10.89.1.31:20081 -1
"; +#$data = "
gosa_trigger_action_localboot
00:01:6c:9d:b9:fa 10.89.1.31:20081 -1
";