From: rettenbe Date: Fri, 9 May 2008 08:44:13 +0000 (+0000) Subject: events which have no local server implementation are forwarded to client if the clien... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a37390c1370f26a09d79d9e325cd33ca954144f6;p=gosa.git events which have no local server implementation are forwarded to client if the client is registered with this event git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10856 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index f03074b18..0202e824f 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -293,25 +293,59 @@ sub process_gosa_msg { my ($msg, $msg_hash, $session_id) = @_ ; my $out_msg; my @out_msg_l = ('nohandler'); - + my $sql_events; + my $header = @{$msg_hash->{'header'}}[0]; + my $target = @{$msg_hash->{'target'}}[0]; $header =~ s/gosa_//; + # check local installed events if( exists $event_hash->{$header} ) { # a event exists with the header as name &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5); no strict 'refs'; - @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); + @out_msg_l = &{$event_hash->{$header}."::$header"}( $msg, $msg_hash, $session_id ); + + # check client registered events + } else { + $sql_events = "SELECT * FROM $main::known_clients_tn WHERE ( (macaddress LIKE '$target') OR (hostname='$target') )"; + my $res = $main::known_clients_db->select_dbentry( $sql_events ); + my $l = keys(%$res); + + # set error if no or more than 1 hits are found for sql query + if ( $l != 1) { + @out_msg_l = ('knownclienterror'); + + # found exact 1 hit in db + } else { + my $client_events = $res->{'1'}->{'events'}; + + # client is registered for this event, deliver this message to client + if ($client_events =~ /,$header,/) { + $msg =~ s/
gosa_/
/; + @out_msg_l = ( $msg ); + + # client is not registered for this event, set error + } else { + @out_msg_l = ('noeventerror'); + } + } } # if delivery not possible raise error and return - if( not defined $out_msg_l[0] ) { -# &main::daemon_log("WARNING: GosaPackages got no answer from event handler '$header'", 3); + if (not defined $out_msg_l[0]) { @out_msg_l = (); - } elsif( $out_msg_l[0] eq 'nohandler') { + } elsif ($out_msg_l[0] eq 'nohandler') { &main::daemon_log("$session_id ERROR: GosaPackages: no event handler or core function defined for '$header'", 1); @out_msg_l = (); - } + } elsif ($out_msg_l[0] eq 'knownclienterror') { + &main::daemon_log("$session_id ERROR: no or more than 1 hits are found at known_clients_db with sql query: '$sql_events'", 1); + &main::daemon_log("$session_id WARNING: processing is aborted and message will not be forwarded"); + @out_msg_l = (); + } elsif ($out_msg_l[0] eq 'noeventerror') { + &main::daemon_log("$session_id WARNING: client '$target' is not registered for event '$header', processing is aborted", 1); + @out_msg_l = (); + } return @out_msg_l; } diff --git a/gosa-si/modules/SIPackages.pm b/gosa-si/modules/SIPackages.pm index aa040b874..b14f87ab6 100644 --- a/gosa-si/modules/SIPackages.pm +++ b/gosa-si/modules/SIPackages.pm @@ -393,9 +393,11 @@ sub process_incoming_msg { my $host_name; my $host_key; my @out_msg_l = ("nohandler"); + my $sql_events; # process incoming msg my $header = @{$msg_hash->{header}}[0]; + my $source = @{$msg_hash->{source}}[0]; my @target_l = @{$msg_hash->{target}}; # skip PREFIX @@ -411,8 +413,6 @@ sub process_incoming_msg { if( 1 == length @target_l) { my $target = $target_l[0]; if(&server_matches($target)) { - - if ($header eq 'new_key') { @out_msg_l = &new_key($msg_hash) } elsif ($header eq 'here_i_am') { @@ -423,6 +423,31 @@ sub process_incoming_msg { &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5); no strict 'refs'; @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); + } else { + $sql_events = "SELECT * FROM $main::known_clients_tn WHERE ( (macaddress LIKE '$source') OR (hostname='$source') )"; + my $res = $main::known_clients_db->select_dbentry( $sql_events ); + my $l = keys(%$res); + + # set error if no or more than 1 hits are found for sql query + if ( $l != 1) { + @out_msg_l = ('knownclienterror'); + + # found exact 1 hit in db + } else { + my $client_events = $res->{'1'}->{'events'}; + + # client is registered for this event, deliver this message to client + $header =~ s/^answer_//; + if ($client_events =~ /,$header,/) { + $msg =~ s/
answer_/
/; + $msg =~ s/\S+<\/target>/GOSA<\/target>/; + @out_msg_l = ( $msg ); + + # client is not registered for this event, set error + } else { + @out_msg_l = ('noeventerror'); + } + } } } @@ -432,7 +457,17 @@ sub process_incoming_msg { } elsif( $out_msg_l[0] eq 'nohandler') { &main::daemon_log("$session_id ERROR: SIPackages: no event handler or core function defined for '$header'", 1); @out_msg_l = (); - } + } elsif ($out_msg_l[0] eq 'knownclienterror') { + &main::daemon_log("$session_id ERROR: no or more than 1 hits are found at known_clients_db with sql query: '$sql_events'", 1); + &main::daemon_log("$session_id WARNING: processing is aborted and message will not be forwarded"); + @out_msg_l = (); + } elsif ($out_msg_l[0] eq 'noeventerror') { + &main::daemon_log("$session_id WARNING: client '$target' is not registered for event '$header', processing is aborted", 1); + @out_msg_l = (); + } + + + } else {