index 3f5bc8ca20036a2439e013b8ff4d761bbe0c6a4a..17a731bab481a6e701b1116f1c57a743b8e81728 100644 (file)
use XML::Simple;
use File::Spec;
use Data::Dumper;
-use GOSA::DBsqlite;
+use GOSA::DBmysql;
use MIME::Base64;
my $event_dir = "/usr/lib/gosa-si/server/GosaPackages";
}
}
+# build vice versa event_hash, event_name => module
+my $event2module_hash = {};
+while (my ($module, $mod_events) = each %$event_hash) {
+ while (my ($event_name, $nothing) = each %$mod_events) {
+ $event2module_hash->{$event_name} = $module;
+ }
+
+}
+
## FUNCTIONS #################################################################
sub get_module_info {
my @info = ($main::gosa_address,
$main::gosa_passwd,
+ $event_hash,
);
return \@info;
}
foreach my $out_msg ( @msg_l ) {
# determine the correct outgoing source address to the corresponding target address
$out_msg =~ /<target>(\S*)<\/target>/;
- my $act_server_ip = &main::get_local_ip_for_remote_ip(sprintf("%s", $1 =~ /^([0-9\.]*?):.*$/));
+ my $act_target = $1;
+ $act_target =~ s/GOSA/$main::server_address/;
+ my $act_server_ip = &main::get_local_ip_for_remote_ip(sprintf("%s", $act_target =~ /^([0-9\.]*?):.*$/));
# Patch the correct outgoing source address
if ($out_msg =~ /<source>GOSA<\/source>/ ) {
$out_msg =~ s/<source>GOSA<\/source>/<source>$act_server_ip:$main::server_port<\/source>/g;
}
- # Patch the correct outgoing forward_to_gosa address
- if ($out_msg =~ /<forward_to_gosa>(\S+),(\d+)<\/forward_to_gosa>/ ) {
- $out_msg =~ s/<forward_to_gosa>\S+<\/forward_to_gosa>/<forward_to_gosa>$act_server_ip:$main::server_port,$session_id<\/forward_to_gosa>/;
- } else {
- $out_msg =~ s/<\/xml>/<forward_to_gosa>$act_server_ip:$main::server_port,$session_id<\/forward_to_gosa> <\/xml>/;
- }
-
# Add to each outgoing message the current POE session id
$out_msg =~ s/<\/xml>/<session_id>$session_id<\/session_id><\/xml>/;
my $target = @{$msg_hash->{'target'}}[0];
# check local installed events
- if( exists $event_hash->{$header} ) {
+ if( exists $event2module_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);
+ &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event2module_hash->{$header}."'", 5);
no strict 'refs';
- @out_msg_l = &{$event_hash->{$header}."::$header"}( $msg, $msg_hash, $session_id );
+ @out_msg_l = &{$event2module_hash->{$header}."::$header"}( $msg, $msg_hash, $session_id );
# check client registered events
} else {
# client is registered for this event, deliver this message to client
if ($client_events =~ /,$header,/) {
+ &main::daemon_log("$session_id INFO: client '$target' is registerd for event '$header', forward message to client.", 5);
@out_msg_l = ( $msg );
# client is not registered for this event, set error
$header =~ s/job_//;
my $target = @{$msg_hash->{'target'}}[0];
- # if no timestamp is specified, use 19700101000000
+ # If no timestamp is specified, use 19700101000000
my $timestamp = "19700101000000";
if( exists $msg_hash->{'timestamp'} ) {
$timestamp = @{$msg_hash->{'timestamp'}}[0];
}
- #if no macaddress is specified, raise error
+ # If no macaddress is specified, raise error
my $macaddress;
if( exists $msg_hash->{'macaddress'} ) {
$macaddress = @{$msg_hash->{'macaddress'}}[0];
"</xml>";
}
- # if mac address is already known in ldap, set plain_name to 'cn'
+ # Determine plain_name for host
my $plain_name;
- my $ldap_handle = &main::get_ldap_handle($session_id);
- if( not defined $ldap_handle ) {
- &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
- $plain_name = "none";
-
- # try to fetch a 'real name'
- } else {
- my $mesg = $ldap_handle->search(
- base => $main::ldap_base,
- scope => 'sub',
- attrs => ['cn'],
- filter => "(macAddress=$macaddress)");
- if($mesg->code) {
- &main::daemon_log($mesg->error, 1);
- $plain_name = "none";
- } else {
- my $entry= $mesg->entry(0);
- $plain_name = $entry->get_value("cn");
- }
- }
+ if ($header eq "opsi_install_client") { # Opsi installing clients use hostId as plain_name
+ if (not exists $msg_hash->{'hostId'}) {
+ $error++;
+ &daemon_log("$session_id ERROR: opsi_install_client-message has no xml-tag 'hostID', job was not created: $msg", 1);
+ } else {
+ $plain_name = $msg_hash->{'hostId'}[0];
+ $header = "trigger_action_reinstall"
+ }
+ } else { # Try to determine plain_name via ladp search
+ my $ldap_handle = &main::get_ldap_handle($session_id);
+ if( not defined $ldap_handle ) {
+ &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
+ $plain_name = "none";
+ } else {
+ my $mesg = $ldap_handle->search(
+ base => $main::ldap_base,
+ scope => 'sub',
+ attrs => ['cn'],
+ filter => "(macAddress=$macaddress)");
+ if($mesg->code || ($mesg->count!=1)) {
+ &main::daemon_log($mesg->error, 1);
+ $plain_name = "none";
+ } else {
+ my $entry= $mesg->entry(0);
+ $plain_name = $entry->get_value("cn");
+ }
+ }
+ }
+
+ # Add job to job queue
if( $error == 0 ) {
- # add job to job queue
my $func_dic = {table=>$main::job_queue_tn,
primkey=>['macaddress', 'headertag'],
timestamp=>$timestamp,