From ad66b06d22156e79301129c7a93c1d0ea7a063b2 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Tue, 19 Aug 2008 09:51:35 +0000 Subject: [PATCH] * update: gosa-si-server, handling of new_ntp_config * bugfix: some WARNINGs are changed to ERRORs git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12242 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 35 ++++++++++- gosa-si/modules/ClientPackages.pm | 85 +++++++++++++++++++++++++- gosa-si/modules/ServerPackages.pm | 4 +- gosa-si/server/events/gosaTriggered.pm | 23 +++++++ gosa-si/tests/client.php | 27 ++++---- 5 files changed, 156 insertions(+), 18 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index f815130f1..2e362facd 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -1397,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; @@ -1412,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); diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index c64264a1b..911e12121 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -330,10 +330,10 @@ sub process_incoming_msg { @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"); + &main::daemon_log("$session_id ERROR: processing is aborted and message will not be forwarded", 1); @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); + &main::daemon_log("$session_id ERROR: client '$target' is not registered for event '$header', processing is aborted", 1); @out_msg_l = (); } @@ -514,6 +514,10 @@ sub here_i_am { push(@out_msg_l, $hardware_config_out); } + # Send client ntp server + + + # notify registered client to all other server my %mydata = ( 'client' => $source, 'macaddress' => $mac_address); my $mymsg = &build_msg('new_foreign_client', $main::server_address, "KNOWN_SERVER", \%mydata); @@ -574,6 +578,83 @@ sub who_has_i_do { } +sub new_ntp_config { + my ($address, $session_id) = @_; + my $ntp_msg; + + # Build LDAP connection + my $ldap_handle = &main::get_ldap_handle($session_id); + if( not defined $ldap_handle ) { + &main::daemon_log("$session_id ERROR: cannot connect to ldap: $ldap_uri", 1); + return; + } + + # Perform search + my $ldap_res = $ldap_handle->search( base => $ldap_base, + scope => 'sub', + attrs => ['gotoNtpServer'], + filter => "(&(objectClass=GOhard)(macaddress=$address))"); + if($ldap_res->code) { + &main::daemon_log("$session_id ".$ldap_res->error, 1); + return; + } + + # Sanity check + if ($ldap_res->count != 1) { + &main::daemon_log("$session_id ERROR: client with mac address $address not found/unique/active - not sending ldap config". + "\n\tbase: $ldap_base". + "\n\tscope: sub". + "\n\tattrs: gotoNtpServer". + "\n\tfilter: (&(objectClass=GOhard)(macaddress=$address))", 1); + return; + } + + my $entry= $ldap_res->entry(0); + my $dn= $entry->dn; + my @ntp_servers= $entry->get_value("gotoNtpServer"); + + # If no ntp server is specified at host, just have a look at the object group of the host + # Perform object group search + if ((not @ntp_servers) || (@ntp_servers == 0)) { + my $ldap_res = $ldap_handle->search( base => $ldap_base, + scope => 'sub', + attrs => ['gotoNtpServer'], + filter => "(&(objectClass=gosaGroupOfNames)(member=$dn))"); + if($ldap_res->code) { + &main::daemon_log("$session_id ".$ldap_res->error, 1); + return; + } + + # Sanity check + if ($ldap_res->count != 1) { + &main::daemon_log("$session_id ERROR: client with mac address $address not found/unique/active - not sending ldap config". + "\n\tbase: $ldap_base". + "\n\tscope: sub". + "\n\tattrs: gotoNtpServer". + "\n\tfilter: (&(objectClass=gosaGroupOfNames)(member=$dn))", 1); + return; + } + + my $entry= $ldap_res->entry(0); + @ntp_servers= $entry->get_value("gotoNtpServer"); + } + + # Return if no ntp server specified + if ((not @ntp_servers) || (@ntp_servers == 0)) { + &main::daemon_log("$session_id WARNING: no ntp server specified for this host '$address'", 3); + return; + } + + # Add each ntp server to 'ntp_config' message + my $ntp_msg_hash = &create_xml_hash("ntp_config", $server_address, $address); + foreach my $ntp_server (@ntp_servers) { + &add_content2xml_hash($ntp_msg_hash, "server", $ntp_server); + } + + return &create_xml_string($ntp_msg_hash); +} + + #=== FUNCTION ================================================================ # NAME: new_ldap_config # PARAMETERS: address - string - ip address and port of a host diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm index d50cdea16..66184387d 100644 --- a/gosa-si/modules/ServerPackages.pm +++ b/gosa-si/modules/ServerPackages.pm @@ -97,10 +97,10 @@ sub process_incoming_msg { @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", 3); + &main::daemon_log("$session_id ERROR: processing is aborted and message will not be forwarded", 1); @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", 3); + &main::daemon_log("$session_id ERROR: client '$target' is not registered for event '$header', processing is aborted", 1); @out_msg_l = (); } diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index d429ffe7b..2f74dfd76 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -10,6 +10,7 @@ my @events = ( "get_login_usr_for_client", "get_client_for_login_usr", "gen_smb_hash", + "trigger_reload_ntp_config", "trigger_reload_ldap_config", "ping", "network_completition", @@ -403,6 +404,28 @@ sub detect_hardware { } +sub trigger_reload_ntp_config { + my ($msg, $msg_hash, $session_id) = @_ ; + my $target = @{$msg_hash->{target}}[0]; + + # Sanity check of macaddress + # TODO + + my $macaddress = @{$msg_hash->{macaddress}}[0]; + + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + + my $out_msg = &ClientPackages::new_ntp_config($macaddress, $session_id); + my @out_msg_l = ( $out_msg ); + + return @out_msg_l; + +} sub trigger_reload_ldap_config { my ($msg, $msg_hash, $session_id) = @_ ; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 65512c140..772cc39f6 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -121,50 +121,50 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_opsi_get_netboot_products
GOSA GOSA
"; # Get netboot product for specific host - #$data = "
gosa_opsi_get_netboot_products
GOSA GOSA limux-cl-2.intranet.gonicus.de
"; + #$data = "
gosa_opsi_get_netboot_products
GOSA GOSA linux-cl-2.intranet.gonicus.de
"; # Get all localboot products #$data = "
gosa_opsi_get_local_products
GOSA GOSA
"; # Get localboot product for specific host - #$data = "
gosa_opsi_get_local_products
GOSA GOSA limux-cl-2.intranet.gonicus.de
"; + #$data = "
gosa_opsi_get_local_products
GOSA GOSA linux-cl-2.intranet.gonicus.de
"; # Get product properties - global #$data = "
gosa_opsi_get_product_properties
GOSA GOSA firefox
"; # Get product properties - per host - #$data = "
gosa_opsi_get_product_properties
GOSA GOSA firefox limux-cl-2.intranet.gonicus.de
"; + #$data = "
gosa_opsi_get_product_properties
GOSA GOSA firefox linux-cl-2.intranet.gonicus.de
"; # Set product properties - global #$data = "
gosa_opsi_set_product_properties
GOSA 00:01:6c:9d:b9:fa firefox askbeforeinstfalse
"; # Set product properties - per host - #$data = "
gosa_opsi_set_product_properties
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de firefox askbeforeinst false
"; + #$data = "
gosa_opsi_set_product_properties
GOSA 00:01:6c:9d:b9:fa linux-cl-2.intranet.gonicus.de firefox askbeforeinst false
"; # Get hardware inventory - #$data = "
gosa_opsi_get_client_hardware
GOSA GOSA limux-cl-2.intranet.gonicus.de
"; + #$data = "
gosa_opsi_get_client_hardware
GOSA GOSA linux-cl-2.intranet.gonicus.de
"; # Get software inventory - #$data = "
gosa_opsi_get_client_software
GOSA GOSA limux-cl-2.intranet.gonicus.de
"; + #$data = "
gosa_opsi_get_client_software
GOSA GOSA linux-cl-2.intranet.gonicus.de
"; # List Opsi clients #$data = "
gosa_opsi_list_clients
GOSA GOSA
"; # Delete Opsi client - #$data = "
gosa_opsi_del_client
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de
"; + #$data = "
gosa_opsi_del_client
GOSA 00:01:6c:9d:b9:fa linux-cl-2.intranet.gonicus.de
"; # Install Opsi client # Please do always use 'job_...' and never 'gosa_...' otherways the job will never appear in job queue - $data = "
job_opsi_install_client
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de 00:11:25:4b:8c:e5
"; + #$data = "
job_opsi_install_client
GOSA 00:01:6c:9d:b9:fa linux-cl-2.intranet.gonicus.de 00:11:25:4b:8c:e5
"; # Add Opsi client - #$data = "
gosa_opsi_add_client
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de 00:11:25:4b:8c:e5 Test halt 1.2.3.4 Im a note
"; + #$data = "
gosa_opsi_add_client
GOSA 00:01:6c:9d:b9:fa linux-cl-2.intranet.gonicus.de 00:11:25:4b:8c:e5 Test halt 1.2.3.4 Im a note
"; # Add product to Opsi client - #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 limux-cl-2.intranet.gonicus.de winxppro
"; + #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 linux-cl-2.intranet.gonicus.de winxppro
"; # Delete product from Opsi client - #$data = "
gosa_opsi_del_product_from_client
GOSA 00:01:6c:9d:b9:fa limux-cl-1.intranet.gonicus.de 00:11:25:4b:8c:e5 softprod
"; + #$data = "
gosa_opsi_del_product_from_client
GOSA 00:01:6c:9d:b9:fa linux-cl-1.intranet.gonicus.de 00:11:25:4b:8c:e5 softprod
"; ######################### @@ -186,6 +186,11 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_import_dak_key
GOSA 00:01:6c:9d:b9:fa
"; #$data = "
gosa_remove_dak_key
GOSA 00:01:6c:9d:b9:fa
"; + + ############################## + # NTP reload + $data = "
gosa_trigger_reload_ntp_config
GOSA GOSA 00:11:25:4B:8C:E5
"; + $sock->write($data); $answer = "nothing"; $answer = $sock->read(); -- 2.30.2