X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-si%2Fgosa-si-server;h=9d0f7ad9935303f3d141d8cb1486d9942fe25890;hb=8b3cd612afa2c4040e2073736c4fd51d873545a0;hp=485dbdbebe1e48387cc8f5dbe59d82dd1f9260b0;hpb=f4ceb5e562379274f9c35b30ee58edefc81c4c71;p=gosa.git diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 485dbdbeb..9d0f7ad99 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -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,17 +1518,18 @@ 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%') 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'}; my $progress = $hit->{'progress'}; - # Ask OPSI for an update of the running jobs my $result= {}; # For hosts, only return the products that are or get installed @@ -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; @@ -1546,26 +1563,30 @@ sub watch_for_opsi_jobs { if ($product->{'installationStatus'} eq "failed"){ $result->{$product->{'productId'}}= "error"; - unshift(@error_list, $product); + unshift(@error_list, $product->{'productId'}); $error++; } if ($product->{'installationStatus'} eq "installed" && $product->{'actionRequest'} eq "none"){ $result->{$product->{'productId'}}= "installed"; - unshift(@installed_list, $product); + unshift(@installed_list, $product->{'productId'}); $installed++; } if ($product->{'installationStatus'} eq "installing"){ $result->{$product->{'productId'}}= "installing"; - $act_status = "installing - $product"; + $installing++; + $act_status = "installing - ".$product->{'productId'}; } } } - # Estimate "rough" progress - $result->{'progress'}= int($installed * 100 / $products); -print STDERR Dumper($result); + # 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); } @@ -1573,17 +1594,31 @@ print STDERR Dumper($result); $act_status = "error - ".join(", ", @error_list); } if ($progress ne $result->{'progress'} ) { - my $update_statement = "UPDATE $job_queue_tn SET progress='".$result->{'progress'}."', result='$act_status', modified='1' WHERE macaddress='$macaddress'"; + # Updating progress and result + 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) { + # Updateing status + my $done_statement = "UPDATE $job_queue_tn SET modified='1', "; + if ($error) { + $done_statement .= "status='error'"; + } else { + $done_statement .= "status='done'"; + } + $done_statement .= " WHERE macaddress='$macaddress' AND siserver='localhost'"; + my $done_res = $job_db->update_dbentry($done_statement); + } + + } } + $kernel->delay_set('watch_for_opsi_jobs', $job_queue_opsi_delay); } -# 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]; @@ -1900,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'"; @@ -3079,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; } }