Code

Reflect column name change.
[gosa.git] / gosa-si / server / events / gosaTriggered.pm
index 61239b0dc2adae3c911e182009f63f9824d79cf4..e91aa4639d7eb7ab9ea45362e71116ccc038b3c0 100644 (file)
@@ -109,7 +109,7 @@ sub send_user_msg {
 
     # determine new message id
     my $new_msg_id = 1;
-       my $new_msg_id_sql = "SELECT MAX(CAST(id AS INTEGER)) FROM $main::messaging_tn";
+       my $new_msg_id_sql = "SELECT MAX(id) FROM $main::messaging_tn";
     my $new_msg_id_res = $main::messaging_db->exec_statement($new_msg_id_sql);
     if (defined @{@{$new_msg_id_res}[0]}[0] ) {
         $new_msg_id = int(@{@{$new_msg_id_res}[0]}[0]);
@@ -755,31 +755,31 @@ sub trigger_action_wake {
 
 
 sub get_available_kernel {
-        my ($msg, $msg_hash, $session_id) = @_;
-
-        my $source = @{$msg_hash->{'source'}}[0];
-        my $target = @{$msg_hash->{'target'}}[0];
-        my $release= @{$msg_hash->{'release'}}[0];
-
-        my @kernel;
-        # Get Kernel packages for release
-        my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='$release' AND package LIKE 'linux\-image\-%'";
-        my $res_hash = $main::packages_list_db->select_dbentry($sql_statement);
-        my %data;
-        my $i=1;
-
-        foreach my $package (keys %{$res_hash}) {
-                $data{"answer".$i++}= $data{"answer".$i++}= ${$res_hash}{$package}->{'package'};
-        }
-        $data{"answer".$i++}= "default";
-
-        my $out_msg = &build_msg("get_available_kernel", $target, $source, \%data);
-        my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
-        if (defined $forward_to_gosa) {
-            $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
-        }
-
-        return ( $out_msg );
+  my ($msg, $msg_hash, $session_id) = @_;
+
+  my $source = @{$msg_hash->{'source'}}[0];
+  my $target = @{$msg_hash->{'target'}}[0];
+  my $fai_release= @{$msg_hash->{'fai_release'}}[0];
+
+  my @kernel;
+  # Get Kernel packages for release
+  my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='$fai_release' AND package LIKE 'linux\-image\-%'";
+  my $res_hash = $main::packages_list_db->select_dbentry($sql_statement);
+  my %data;
+  my $i=1;
+
+  foreach my $package (keys %{$res_hash}) {
+    $data{"answer".$i++}= $data{"answer".$i++}= ${$res_hash}{$package}->{'package'};
+  }
+  $data{"answer".$i++}= "default";
+
+  my $out_msg = &build_msg("get_available_kernel", $target, $source, \%data);
+  my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+  if (defined $forward_to_gosa) {
+    $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
+  }
+
+  return ( $out_msg );
 }
 
 
@@ -814,12 +814,12 @@ sub trigger_activate_new {
       if($ldap_mesg->count == 1) {
         $ogroup_entry= $ldap_mesg->pop_entry();
       } elsif ($ldap_mesg->count == 0) {
-        &main::daemon_log("ERROR: A GosaGroupOfNames with cn '$ogroup' was not found in base '".$main::ldap_base."'!", 1);
+        &main::daemon_log("$session_id ERROR: A GosaGroupOfNames with cn '$ogroup' was not found in base '".$main::ldap_base."'!", 1);
         $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting' WHERE id = $jobdb_id");
         $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET timestamp = '".&get_time(10)."' WHERE id = $jobdb_id");
         return undef;
       } else {
-        &main::daemon_log("ERROR: More than one ObjectGroups with cn '$ogroup' was found in base '".$main::ldap_base."'!", 1);
+        &main::daemon_log("$session_id ERROR: More than one ObjectGroups with cn '$ogroup' was found in base '".$main::ldap_base."'!", 1);
         $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting' WHERE id = $jobdb_id");
         $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET timestamp = '".&get_time(10)."' WHERE id = $jobdb_id");
         return undef;
@@ -829,7 +829,7 @@ sub trigger_activate_new {
       if(!(defined($base) && (length($base) > 0))) {
         # Subtract the ObjectGroup cn
         $base = $1 if $ogroup_entry->dn =~ /cn=$ogroup,ou=groups,(.*)$/;
-        &main::daemon_log("DEBUG: New base for system with mac address '$mac' is '$base'", 5);
+        &main::daemon_log("$session_id DEBUG: New base for system with mac address '$mac' is '$base'", 5);
       }
     }
 
@@ -845,7 +845,7 @@ sub trigger_activate_new {
 
     # TODO: Find a way to guess an ip address for hosts with no ldap entry (MAC->ARP->IP)
     if($ldap_mesg->count == 1) {
-      &main::daemon_log("DEBUG: One system with mac address '$mac' was found in base '".$main::ldap_base."'!", 5);
+      &main::daemon_log("$session_id DEBUG: One system with mac address '$mac' was found in base '".$main::ldap_base."'!", 5);
       # Get the entry from LDAP
       $ldap_entry= $ldap_mesg->pop_entry();
 
@@ -860,12 +860,12 @@ sub trigger_activate_new {
         # To prevent replication problems just re-queue the job with 10 seconds in the future
         my $moddn_result = $ldap_entry->update($ldap_handle);
         if ($moddn_result->code() != 0) {
-          &main::daemon_log("ERROR: Moving the system with mac address '$mac' to new base '$base' failed (code '".$moddn_result->code()."') with '".$moddn_result->{'errorMessage'}."'!", 1);
+          &main::daemon_log("$session_id ERROR: Moving the system with mac address '$mac' to new base '$base' failed (code '".$moddn_result->code()."') with '".$moddn_result->{'errorMessage'}."'!", 1);
           $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting' WHERE id = $jobdb_id");
           $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET timestamp = '".&get_time(10)."' WHERE id = $jobdb_id");
           return undef;
         } else {
-          &main::daemon_log("INFO: System with mac address '$mac' was moved to base '".$main::ldap_base."'! Re-queuing job.", 4);
+          &main::daemon_log("$session_id INFO: System with mac address '$mac' was moved to base '".$main::ldap_base."'! Re-queuing job.", 4);
           $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting' WHERE id = $jobdb_id");
           $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET timestamp = '".&get_time(10)."' WHERE id = $jobdb_id");
           return undef;
@@ -873,7 +873,7 @@ sub trigger_activate_new {
       }
 
     } elsif ($ldap_mesg->count == 0) {
-      &main::daemon_log("WARNING: No System with mac address '$mac' was found in base '".$main::ldap_base."'! Re-queuing job.", 4);
+      &main::daemon_log("$session_id WARNING: No System with mac address '$mac' was found in base '".$main::ldap_base."'! Re-queuing job.", 4);
       $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting' WHERE id = $jobdb_id");
       $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET timestamp = '".&get_time(60)."' WHERE id = $jobdb_id");
       return undef;
@@ -892,13 +892,13 @@ sub trigger_activate_new {
       my $oclasses = $ldap_entry->get_value('objectClass', asref => 1);
       foreach my $oclass ("FAIobject", "GOhard", "gotoWorkstation") {
         if(!(scalar grep $_ eq $oclass, map {$_ => 1} @$oclasses)) {
-          &main::daemon_log("Adding objectClass $oclass", 1);
+          &main::daemon_log("$session_id INFO: Adding objectClass '$oclass' to system entry with mac adress '$mac'", 1);
           $ldap_entry->add(
             objectClass => $oclass,
           );
           my $oclass_result = $ldap_entry->update($ldap_handle);
           if ($oclass_result->code() != 0) {
-            &main::daemon_log("ERROR: Adding the ObjectClass '$oclass' failed (code '".$oclass_result->code()."') with '".$oclass_result->{'errorMessage'}."'!", 1);
+            &main::daemon_log("$session_id ERROR: Adding the ObjectClass '$oclass' failed (code '".$oclass_result->code()."') with '".$oclass_result->{'errorMessage'}."'!", 1);
           }
         }
       }
@@ -911,7 +911,7 @@ sub trigger_activate_new {
           );
           my $replace_result = $ldap_entry->update($ldap_handle);
           if ($replace_result->code() != 0) {
-            &main::daemon_log("ERROR: Setting the FAIstate to install failed with code '".$replace_result->code()."') and message '".$replace_result->{'errorMessage'}."'!", 1);
+            &main::daemon_log("$session_id ERROR: Setting the FAIstate to install failed with code '".$replace_result->code()."') and message '".$replace_result->{'errorMessage'}."'!", 1);
           }
         }
       } else {
@@ -920,7 +920,7 @@ sub trigger_activate_new {
         );
         my $add_result = $ldap_entry->update($ldap_handle);
         if ($add_result->code() != 0) {
-          &main::daemon_log("ERROR: Setting the FAIstate to install failed with code '".$add_result->code()."') and message '".$add_result->{'errorMessage'}."'!", 1);
+          &main::daemon_log("$session_id ERROR: Setting the FAIstate to install failed with code '".$add_result->code()."') and message '".$add_result->{'errorMessage'}."'!", 1);
         }
       }
 
@@ -929,25 +929,25 @@ sub trigger_activate_new {
       # TODO: Create a new entry
       # $ldap_entry = Net::LDAP::Entry->new();
       # $ldap_entry->dn("cn=$mac,$base");
-      &main::daemon_log("WARNING: No System with mac address '$mac' was found in base '".$main::ldap_base."'! Re-queuing job.", 4);
+      &main::daemon_log("$session_id WARNING: No System with mac address '$mac' was found in base '".$main::ldap_base."'! Re-queuing job.", 4);
       $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting' WHERE id = $jobdb_id");
       $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET timestamp = '".&get_time(10)."' WHERE id = $jobdb_id");
       return undef;
     } else {
-      &main::daemon_log("ERROR: More than one system with mac address '$mac' was found in base '".$main::ldap_base."'!", 1);
+      &main::daemon_log("$session_id ERROR: More than one system with mac address '$mac' was found in base '".$main::ldap_base."'!", 1);
     }
 
     # Add to ObjectGroup
-    if(!(scalar grep $_, map {$_ => 1} $ogroup_entry->get_value('member', asref => 1))) {
+    if(!(scalar grep $_ eq $ldap_entry->dn, @{$ogroup_entry->get_value('member', asref => 1)})) {
       $ogroup_entry->add (
         'member' => $ldap_entry->dn(),
       );
       my $ogroup_result = $ogroup_entry->update($ldap_handle);
       if ($ogroup_result->code() != 0) {
-        &main::daemon_log("ERROR: Updating the ObjectGroup '$ogroup' failed (code '".$ogroup_result->code()."') with '".$ogroup_result->{'errorMessage'}."'!", 1);
+        &main::daemon_log("$session_id ERROR: Updating the ObjectGroup '$ogroup' failed (code '".$ogroup_result->code()."') with '".$ogroup_result->{'errorMessage'}."'!", 1);
       }
     } else {
-      &main::daemon_log("DEBUG: System with mac address '$mac' is already a member of ObjectGroup '$ogroup'.", 5);
+      &main::daemon_log("$session_id DEBUG: System with mac address '$mac' is already a member of ObjectGroup '$ogroup'.", 5);
     }
 
     # Finally set gotoMode to active
@@ -958,10 +958,12 @@ sub trigger_activate_new {
         );
         my $activate_result = $ldap_entry->update($ldap_handle);
         if ($activate_result->code() != 0) {
-          &main::daemon_log("ERROR: Activating system '".$ldap_entry->dn()."' failed (code '".$activate_result->code()."') with '".$activate_result->{'errorMessage'}."'!", 1);
+          &main::daemon_log("$session_id ERROR: Activating system '".$ldap_entry->dn()."' failed (code '".$activate_result->code()."') with '".$activate_result->{'errorMessage'}."'!", 1);
         } else {
           $activate_client = 1;
         }
+      } else {
+          $activate_client = 1;
       }
     } else {
       $ldap_entry->add(
@@ -969,24 +971,32 @@ sub trigger_activate_new {
       );
       my $activate_result = $ldap_entry->update($ldap_handle);
       if ($activate_result->code() != 0) {
-        &main::daemon_log("ERROR: Activating system '".$ldap_entry->dn()."' failed (code '".$activate_result->code()."') with '".$activate_result->{'errorMessage'}."'!", 1);
+        &main::daemon_log("$session_id ERROR: Activating system '".$ldap_entry->dn()."' failed (code '".$activate_result->code()."') with '".$activate_result->{'errorMessage'}."'!", 1);
       } else {
         $activate_client = 1;
       }
     }
 
     if($activate_client == 1) {
+
+        # Create delivery list
+        my @out_msg_l;
+
       # Set job to done
       $main::job_db->exec_statement("UPDATE jobs SET status = 'done' WHERE id = $jobdb_id");
 
+        # Add new_ldap_config message to delivery list
+               my $ldap_out_msg = &ClientPackages::new_ldap_config($mac, $session_id);
+        push(@out_msg_l, $ldap_out_msg);
+
       # create set_activated_for_installation message for delivery
       my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
       my $out_msg = &create_xml_string($out_hash);
-      my @out_msg_l = ($out_msg);
+      push(@out_msg_l, $out_msg);
 
       return @out_msg_l;
     }  else {
-      &main::daemon_log("WARNING: Activating system with mac address '$mac' failed! Re-queuing job.", 4);
+      &main::daemon_log("$session_id WARNING: Activating system with mac address '$mac' failed! Re-queuing job.", 4);
       $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting' WHERE id = $jobdb_id");
       $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET timestamp = '".&get_time(10)."' WHERE id = $jobdb_id");
     }
@@ -1193,7 +1203,7 @@ sub get_hosts_with_module {
         my ($local_ip, $local_port) = split(/:/, $target);
         my $network_interface= &get_interface_for_ip($local_ip);
         my $local_mac = &get_mac_for_interface($network_interface);
-        &add_content2xml_hash($out_hash, "host", $local_mac);
+        &add_content2xml_hash($out_hash, "answer0", $local_mac);
     }
 
     
@@ -1206,7 +1216,7 @@ sub get_hosts_with_module {
         $out_msg =~ s/<\/xml>/<result>host$hit_id<\/result> <\/xml>/;
         my $host_infos = "<ip>".$hit_hash->{'hostname'}."</ip>";
         $host_infos .= " <mac>".$hit_hash->{'macaddress'}."</mac>"; 
-        $out_msg =~  s/<\/xml>/\n<host$hit_id> $host_infos <\/host$hit_id> \n <\/xml>/;
+        $out_msg =~  s/<\/xml>/\n<answer$hit_id> $host_infos <\/answer$hit_id> \n <\/xml>/;
     }
 
     return $out_msg;