From: rettenbe Date: Tue, 19 Aug 2008 13:40:46 +0000 (+0000) Subject: update: client side implementation of new_ntp_config X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3e920ea38e98875606769cf3cb16ba8f1c76a182;p=gosa.git update: client side implementation of new_ntp_config git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12246 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/client/events/corefunctions.pm b/gosa-si/client/events/corefunctions.pm index 5ccf16119..4f5bd3629 100644 --- a/gosa-si/client/events/corefunctions.pm +++ b/gosa-si/client/events/corefunctions.pm @@ -4,6 +4,7 @@ use Exporter; my @events = ( "get_events", "registered", + "new_ntp_config", "new_ldap_config", "new_key", "generate_hw_digest", # no implementations @@ -23,6 +24,7 @@ use File::Basename; my ($ldap_enabled, $offline_enabled, $ldap_config, $pam_config, $nss_config, $fai_logpath); +my $chrony_file = "/etc/chrony/chrony.conf"; my %cfg_defaults = ( "client" => { @@ -151,6 +153,56 @@ sub server_leaving { return; } +## @method new_ntp_config +# Updates the server options in /etc/chrony/chrony.conf and restarts the chrony service +# @param msg - STRING - xml message with tag server +# @param msg_hash - HASHREF - message information parsed into a hash +sub new_ntp_config { + my ($msg, $msg_hash) = @_ ; + + # Sanity check of incoming message + if ((not exists $msg_hash->{'server'}) || (not @{$msg_hash->{'server'}} >= 1) ) { + &main::daemon_log("ERROR: 'new_ntp_config'-message does not contain a ntp server: $msg", 1); + return; + } + + # Fetch the new ntp server from incoming message + my @ntp_servers = $msg_hash->{'server'}; + my $ntp_servers_string = "server\t".join("\nserver\t", @ntp_servers)."\n"; + my $found_server_flag = 0; + + # Substitute existing server with new ntp server + open (FILE, "+<$chrony_file"); + my @file = ; + foreach my $line (@file) { + if ($line =~ /^server /) { + if ($found_server_flag) { + $line =~ s/^server [\s\S]+$//; + } else { + $line =~ s/^server [\s\S]+$/$ntp_servers_string/; + } + $found_server_flag++; + } + } + + # Append new server if no old server configuration found + if (not $found_server_flag) { + push(@file, "\n# ntp server configuration written by GOsa-si\n"); + push(@file, $ntp_servers_string); + } + + # Write changes to file and close it + print FILE join("", @file); + close FILE; + &main::daemon_log("INFO: wrote new configuration file: $chrony_file", 5); + + # Restart chrony deamon + my $res = qx(/etc/init.d/chrony force-reload); + &main::daemon_log("INFO: restart chrony daemon: $res", 5); + + return; +} + sub new_ldap_config { my ($msg, $msg_hash) = @_ ; diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index 911e12121..d4ec76321 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -601,7 +601,7 @@ sub new_ntp_config { # 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". + &main::daemon_log("$session_id ERROR: client with mac address $address not found/unique/active - not sending ntp config". "\n\tbase: $ldap_base". "\n\tscope: sub". "\n\tattrs: gotoNtpServer". @@ -627,7 +627,7 @@ sub new_ntp_config { # 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". + &main::daemon_log("$session_id ERROR: client with mac address $address not found/unique/active - not sending ntp config". "\n\tbase: $ldap_base". "\n\tscope: sub". "\n\tattrs: gotoNtpServer". @@ -646,7 +646,7 @@ sub new_ntp_config { } # Add each ntp server to 'ntp_config' message - my $ntp_msg_hash = &create_xml_hash("ntp_config", $server_address, $address); + my $ntp_msg_hash = &create_xml_hash("new_ntp_config", $server_address, $address); foreach my $ntp_server (@ntp_servers) { &add_content2xml_hash($ntp_msg_hash, "server", $ntp_server); } diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 772cc39f6..158da47ac 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -189,7 +189,8 @@ for($count = 1; $count <= $zahl; $count++) ############################## # NTP reload - $data = "
gosa_trigger_reload_ntp_config
GOSA GOSA 00:11:25:4B:8C:E5
"; + #$data = "
gosa_trigger_reload_ntp_config
GOSA GOSA 00:11:25:4B:8C:E5
"; + $data = "
gosa_trigger_reload_ntp_config
GOSA GOSA 00:01:6c:9d:b9:fa
"; $sock->write($data); $answer = "nothing";