From a65a007c1ac2843fb06d1814b664fa73ed8ea464 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Wed, 25 Jun 2014 23:20:31 +0200 Subject: Changed NTP server settings using a treeview --- lib/AdminPanel/Shared/TimeZone.pm | 100 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 3 deletions(-) (limited to 'lib/AdminPanel/Shared') diff --git a/lib/AdminPanel/Shared/TimeZone.pm b/lib/AdminPanel/Shared/TimeZone.pm index 8097d095..1af65086 100644 --- a/lib/AdminPanel/Shared/TimeZone.pm +++ b/lib/AdminPanel/Shared/TimeZone.pm @@ -58,6 +58,9 @@ use DateTime::TimeZone; use Config::Auto; use AdminPanel::Shared::Locales; +use MDK::Common::File; +use MDK::Common::Func; + #============================================================= =head2 new - optional parameters @@ -96,9 +99,79 @@ has 'clock_configuration_file' => ( default => "/etc/sysconfig/clock", ); +#============================================================= + +=head2 new - optional parameters + +=head3 ntp_configuration_file + + optional parameter to set the ntp server configuration file, + default value is /etc/[chrony|ntp].conf + +=cut + +#============================================================= + +has 'ntp_configuration_file' => ( + is => 'rw', + isa => 'Str', + builder => '_ntp_configuration_file_init', +); + +sub _ntp_configuration_file_init { + my $self = shift; + + if (-f "/etc/chrony.conf") { + return "/etc/chrony.conf"; + } + return "/etc/ntp.conf"; +} + +#============================================================= + +=head2 new - optional parameters + +=head3 ntp_program + + optional parameter to set the ntp program that runs into the + system, default value is [chrony|ntp] +=cut + +#============================================================= + +has 'ntp_program' => ( + is => 'rw', + isa => 'Str', + builder => '_ntp_program_init', +); + +sub _ntp_program_init { + my $self = shift; + + if (-f "/etc/chrony.conf") { + return "chrony"; + } + return "ntp"; +} + +#=== globals === + +has 'servername_config_suffix' => ( + is => 'ro', + isa => 'Str', + lazy => 1, + builder => '_servername_config_suffix_init', +); + +sub _servername_config_suffix_init { + my $self = shift; + + return " iburst" if ($self->ntp_program eq "chrony"); + + return ""; +} -#=== global === has 'loc' => ( is => 'rw', lazy => 1, @@ -217,7 +290,6 @@ sub _buildNTPServers { } - #============================================================= =head2 get_timezone_prefix @@ -306,7 +378,7 @@ sub readConfiguration { return $prefs; } - +#left for back compatibility sub _get_ntp_server_tree { my ($self, $zone) = @_; $zone = "-" if ! $zone; @@ -347,6 +419,28 @@ sub ntpServers { } +#============================================================= + +=head2 ntpCurrentServer + +=head3 INPUT + +Input_Parameter: in_par_description + +=head3 DESCRIPTION + +Returns the current ntp server address read from configuration file + +=cut + +#============================================================= + +sub ntpCurrentServer { + my $self = shift; + + MDK::Common::Func::find { $_ ne '127.127.1.0' } map { MDK::Common::Func::if_(/^\s*server\s+(\S*)/, $1) } MDK::Common::File::cat_($self->ntp_configuration_file); +} + no Moose; __PACKAGE__->meta->make_immutable; -- cgit v1.2.1