aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.PL4
-rw-r--r--lib/AdminPanel/Module/Clock.pm50
-rw-r--r--lib/AdminPanel/Shared/TimeZone.pm100
3 files changed, 135 insertions, 19 deletions
diff --git a/Makefile.PL b/Makefile.PL
index 8f4a2878..5a335892 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -40,6 +40,10 @@ WriteMakefile(
"Data::Password::Meter" => 0,
"Digest::MD5" => 0,
"IO::All" => 0,
+ #Mandriva
+ "MDK::Common::File" => 0,
+ "MDK::Common::Func" => 0,
+
"Modern::Perl" => 1.03,
"autodie" => 2.20,
},
diff --git a/lib/AdminPanel/Module/Clock.pm b/lib/AdminPanel/Module/Clock.pm
index 673aacc7..734f6922 100644
--- a/lib/AdminPanel/Module/Clock.pm
+++ b/lib/AdminPanel/Module/Clock.pm
@@ -60,7 +60,6 @@ use AdminPanel::Shared::Locales;
use AdminPanel::Shared::TimeZone;
use AdminPanel::Shared::Services;# qw (services);
-
use Time::Piece;
use yui;
@@ -174,7 +173,7 @@ sub _get_NTPservers {
my $self = shift;
my $servs = $self->sh_tz->ntpServers();
- [ map { "$servs->{$_}: $_" } sort { $servs->{$a} cmp $servs->{$b} || $a cmp $b } keys %$servs ];
+ [ map { "$servs->{$_}|$_" } sort { $servs->{$a} cmp $servs->{$b} || $a cmp $b } keys %$servs ];
}
sub _adminClockPanel {
@@ -209,30 +208,34 @@ sub _adminClockPanel {
$dateField->setValue($day);
$timeField->setValue($time);
+ $hbox = $factory->createHBox($layout);
+ my $ntpFrame = $factory->createCheckBoxFrame($hbox, $self->loc->N("Enable Network Time Protocol"), 0);
+# $ntpFrame->setWeight($yui::YD_HORIZ, 1);
+
+ my $vbox = $factory->createVBox( $ntpFrame );
+ my $hbox1 = $factory->createHBox($factory->createLeft($vbox));
+ $factory->createLabel($hbox1,$self->loc->N("Server:"));
+ my $ntpLabel = $factory->createLabel($hbox1, $self->loc->N("not defined"));
+# $ntpLabel->setWeight($yui::YD_HORIZ, 1);
+ my $defServer = $self->sh_tz->ntpCurrentServer();
+ #- strip digits from \d+.foo.pool.ntp.org
+ $defServer =~ s/^\d+\.//;
+ $ntpLabel->setLabel($defServer);
+ $hbox1 = $factory->createLeft($vbox);
+ my $changeNTPButton = $factory->createPushButton($hbox1, $self->loc->N("Change NTP server"));
+
$factory->createHSpacing($hbox, 1.0);
my $frame = $factory->createFrame ($hbox, $self->loc->N("TimeZone"));
- my $vbox = $factory->createVBox( $frame );
+ $vbox = $factory->createVBox( $frame );
my $timezone = $self->sh_tz->readConfiguration();
my $timeZoneLbl = $factory->createLabel($vbox, $self->loc->N("not defined"));
+# $timeZoneLbl->setWeight($yui::YD_HORIZ, 1);
if (exists $timezone->{ZONE}) {
$timeZoneLbl->setValue($timezone->{ZONE});
}
my $changeTZButton = $factory->createPushButton($vbox, $self->loc->N("Change Time Zone"));
- $hbox = $factory->createHBox($layout);
- my $ntpFrame = $factory->createCheckBoxFrame($hbox, $self->loc->N("Enable Network Time Protocol"), 0);
-# $ntpFrame->setWeight($yui::YD_HORIZ, 1);
-
- $vbox = $factory->createVBox( $ntpFrame );
- $factory->createLabel($vbox, $self->loc->N("Your computer can synchronize its clock with a remote time server using NTP"));
- my $hbox1 = $factory->createHBox($vbox);
- $factory->createLabel($hbox1,$self->loc->N("Server:"));
- my $ntpServers = $factory->createComboBox( $hbox1, "" );
- my $servers = $self->_get_NTPservers();
- my $itemCollection = $self->sh_gui->arrayListToYItemCollection({item_list => $servers,});
- $ntpServers->addItems($itemCollection);
-
#######################
@@ -253,6 +256,9 @@ sub _adminClockPanel {
# End Dialof layout
+ # get only once
+ my $NTPservers = $self->_get_NTPservers();
+
while(1) {
my $event = $dialog->waitForEvent(1000);
my $eventType = $event->eventType();
@@ -276,6 +282,18 @@ sub _adminClockPanel {
### TODO manage OK pressed ###
last;
}
+ elsif ($widget == $changeNTPButton) {
+ my $item = $self->sh_gui->ask_fromTreeList({title => $self->loc->N("NTP server - DrakClock"),
+ header => $self->loc->N("Choose your NTP server"),
+ default_button => 1,
+ item_separator => '|',
+ default_item => $defServer,
+ skip_path => 1,
+ list => $NTPservers});
+ if ($item) {
+ $ntpLabel->setValue($item);
+ }
+ }
elsif ($widget == $changeTZButton) {
my $timezones = $self->sh_tz->getTimeZones();
if (!$timezones || scalar (@{$timezones}) == 0) {
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;