Code

bugfix: wrong changelog file for deb packages
[gosa.git] / gosa-si / gosa-si-server
index 1aeaeffdda0a3dfedeb975de47872cab45c695cb..9d0f7ad9935303f3d141d8cb1486d9942fe25890 100755 (executable)
@@ -451,6 +451,7 @@ sub import_modules {
                        }
                }
     }   
+
     close (DIR);
 }
 
@@ -540,7 +541,7 @@ sub check_key_and_xml_validity {
         }
     };
     if($@) {
-        daemon_log("$session_id DEBUG: do not understand the message: $@", 7);
+        daemon_log("$session_id ERROR: do not understand the message: $@", 1);
         $msg = undef;
         $msg_hash = undef;
     }
@@ -1396,9 +1397,9 @@ sub process_task {
                     &update_jobdb_status_for_send_msgs($answer, $error);
                 }
 
-                # target of msg is a mac address
+                # Target of msg is a mac address
                 elsif( $answer_target =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ) {
-                    daemon_log("$session_id INFO: target is mac address '$answer_target', looking for host in known_clients", 5);
+                    daemon_log("$session_id INFO: target is mac address '$answer_target', looking for host in known_clients and foreign_clients", 5);
                     my $sql_statement = "SELECT * FROM known_clients WHERE macaddress LIKE '$answer_target'";
                     my $query_res = $known_clients_db->select_dbentry( $sql_statement );
                     my $found_ip_flag = 0;
@@ -1411,11 +1412,40 @@ sub process_task {
                         &update_jobdb_status_for_send_msgs($answer, $error);
                         $found_ip_flag++ ;
                     }   
+                    if ($found_ip_flag == 0) {
+                        my $sql = "SELECT * FROM $foreign_clients_tn WHERE macaddress LIKE '$answer_target'";
+                        my $res = $foreign_clients_db->select_dbentry($sql);
+                        while( my ($hit_num, $hit) = each %{ $res } ) {
+                            my $host_name = $hit->{hostname};
+                            my $reg_server = $hit->{regserver};
+                            daemon_log("$session_id INFO: found host '$host_name' with mac '$answer_target', registered at '$reg_server'", 5);
+                            
+                            # Fetch key for reg_server
+                            my $reg_server_key;
+                            my $sql = "SELECT * FROM $known_server_tn WHERE hostname='$reg_server'";
+                            my $res = $known_server_db->select_dbentry($sql);
+                            if (exists $res->{1}) {
+                                $reg_server_key = $res->{1}->{'hostkey'}; 
+                            } else {
+                                daemon_log("$session_id ERROR: cannot find hostkey for '$host_name' in '$known_server_tn'", 1); 
+                                daemon_log("$session_id ERROR: unable to forward answer to correct registration server, processing is aborted!", 1); 
+                                $reg_server_key = undef;
+                            }
+
+                            # Send answer to server where client is registered
+                            if (defined $reg_server_key) {
+                                $answer =~ s/$answer_target/$host_name/g;
+                                my $error = &send_msg_to_target($answer, $reg_server, $reg_server_key, $answer_header, $session_id);
+                                &update_jobdb_status_for_send_msgs($answer, $error);
+                                $found_ip_flag++ ;
+                            }
+                        }
+                    }
                     if( $found_ip_flag == 0) {
                         daemon_log("$session_id WARNING: no host found in known_clients with mac address '$answer_target'", 3);
                     }
 
-                #  answer is for one specific host   
+                # Answer is for one specific host   
                 } else {
                     # get encrypt_key
                     my $encrypt_key = &get_encrypt_key($answer_target);
@@ -1468,21 +1498,6 @@ sub session_start {
 }
 
 
-sub check_opsi_res {
-    my $res= shift;
-    if($res) {
-        if ($res->is_error) {
-            &main::daemon_log("ERROR: opsi configed communication failed: ".$res->error_message, 1);
-        } else {
-            return 1;
-        }
-    } else {
-        &main::daemon_log("ERROR: opsi configed communication failed: ".$opsi_client->status_line, 1);
-    }
-    return 0;
-}
-
-
 sub watch_for_done_jobs {
     #CHECK: $heap for what?
     my ($kernel,$heap) = @_[KERNEL, HEAP];
@@ -1503,12 +1518,13 @@ sub watch_for_done_jobs {
 sub watch_for_opsi_jobs {
     my ($kernel) = $_[KERNEL];
 
-    my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE ((headertag='opsi_install_client') AND (status='processing'))";
+    # This is not very nice to look for opsi install jobs, but headertag has to be trigger_action_reinstall. The only way to identify a 
+    # opsi install job is to parse the xml message. There is still the correct header.
+    my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE ((xmlmessage LIKE '%opsi_install_client</header>%') AND (status='processing') AND (siserver='localhost'))";
        my $res = $job_db->select_dbentry( $sql_statement );
 
     # Ask OPSI for an update of the running jobs
     while (my ($id, $hit) = each %$res ) {
-
         # Determine current parameters of the job
         my $hostId = $hit->{'plainname'};
         my $macaddress = $hit->{'macaddress'};
@@ -1525,10 +1541,11 @@ sub watch_for_opsi_jobs {
         };
         
         my $hres = $opsi_client->call($opsi_url, $callobj);
-        if (&check_opsi_res($hres)) {
+        #my ($hres_err, $hres_err_string) = &check_opsi_res($hres);
+        if (not &check_opsi_res($hres)) {
             my $htmp= $hres->result->{$hostId};
         
-            # check state != not_installed or action == setup -> load and add
+            # Check state != not_installed or action == setup -> load and add
             my $products= 0;
             my $installed= 0;
             my $installing = 0;
@@ -1562,10 +1579,14 @@ sub watch_for_opsi_jobs {
                 }
             }
         
-        # Estimate "rough" progress
-            $result->{'progress'}= int($installed * 100 / $products);
+            # Estimate "rough" progress, avoid division by zero
+            if ($products == 0) {
+                $result->{'progress'}= 0;
+            } else {
+                $result->{'progress'}= int($installed * 100 / $products);
+            }
 
-        # Set updates in job queue
+            # Set updates in job queue
             if ((not $error) && (not $installing) && ($installed)) {
                 $act_status = "installed - ".join(", ", @installed_list);
             }
@@ -1574,8 +1595,7 @@ sub watch_for_opsi_jobs {
             }
             if ($progress ne $result->{'progress'} ) {
                 # Updating progress and result 
-                my $update_statement = "UPDATE $job_queue_tn SET modified='1', ";
-                $update_statement .= "progress='".$result->{'progress'}."', result='$act_status' WHERE macaddress='$macaddress'";
+                my $update_statement = "UPDATE $job_queue_tn SET modified='1', progress='".$result->{'progress'}."', result='$act_status' WHERE macaddress='$macaddress' AND siserver='localhost'";
                 my $update_res = $job_db->update_dbentry($update_statement);
             }
             if ($progress eq 100) { 
@@ -1586,7 +1606,7 @@ sub watch_for_opsi_jobs {
                 } else {
                     $done_statement .= "status='done'";
                 }
-                $done_statement .= " WHERE macaddress='$macaddress'";
+                $done_statement .= " WHERE macaddress='$macaddress' AND siserver='localhost'";
                 my $done_res = $job_db->update_dbentry($done_statement);
             }
 
@@ -1598,8 +1618,7 @@ sub watch_for_opsi_jobs {
 }
 
 
-# if a job got an update or was modified anyway, send to all other si-server an update message
-# of this jobs
+# If a job got an update or was modified anyway, send to all other si-server an update message of this jobs.
 sub watch_for_modified_jobs {
     my ($kernel,$heap) = @_[KERNEL, HEAP];
 
@@ -1916,7 +1935,7 @@ sub watch_for_old_known_clients {
                 );
 
         $dt->add( seconds => 2 * int($hit->{'keylifetime'}) );
-        $expired_timestamp = $dt->ymd('').$dt->hms('')."\n";
+        $expired_timestamp = $dt->ymd('').$dt->hms('');
         if ($act_time > $expired_timestamp) {
             my $hostname = $hit->{'hostname'};
             my $del_sql = "DELETE FROM $known_clients_tn WHERE hostname='$hostname'"; 
@@ -3095,9 +3114,9 @@ if ( !$server_domain) {
     # Try our DNS Searchlist
     for my $domain(get_dns_domains()) {
         chomp($domain);
-        my @tmp_domains= &get_server_addresses($domain);
-        if(@tmp_domains) {
-            for my $tmp_server(@tmp_domains) {
+        my ($tmp_domains, $error_string) = &get_server_addresses($domain);
+        if(@$tmp_domains) {
+            for my $tmp_server(@$tmp_domains) {
                 push @tmp_servers, $tmp_server;
             }
         }