Add support for chronyc command for CentOS 8

https://sourceforge.net/p/webadmin/discussion/600155/thread/a469891f3f

0798cade30
This commit is contained in:
Ilia Rostovtsev
2020-07-03 13:18:02 +03:00
parent 396075b4d9
commit 3548bd3573
3 changed files with 35 additions and 14 deletions

View File

@@ -52,9 +52,17 @@ if ($in{'action'} eq $text{'action_sync'}) {
} elsif ($in{'action'} eq $text{'index_sync'} || $in{'mode'} eq 'ntp') {
# Sync with a time server
$access{'ntp'} || &error($text{'acl_nontp'});
$in{'timeserver'} =~ /\S/ || &error($text{'error_etimeserver'});
if (!$time_is_chrony) {
$in{'timeserver'} =~ /\S/ || &error($text{'error_etimeserver'});
}
$err = &sync_time($in{'timeserver'}, $in{'hardware'});
&error("<pre>".&html_escape($err)."</pre>") if ($err);
if ($err) {
my $err_ = "<pre>".&html_escape($err)."</pre>";
if ($time_out_no_cmd) {
$err_ = $err;
}
&error($err_);
}
# Save settings in module config
&lock_file($module_config_file);

View File

@@ -3,7 +3,7 @@
use strict;
use warnings;
require './time-lib.pl';
our (%in, %text, %config, %access, $base_remote_user, $get_hardware_time_error);
our (%in, %text, %config, %access, $base_remote_user, $get_hardware_time_error, $time_is_chrony);
my ($rawdate, $rawhwdate, %system_date, $rawtime, %hw_date, $txt);
$txt = "";
@@ -159,16 +159,23 @@ if ( ( !$access{ 'sysdate' } && &has_command( "date" ) || !$access{ 'hwdate' } &
print &ui_hidden("mode", "ntp");
print &ui_table_start(&hlink($text{'index_timeserver'}, "timeserver"),
"width=100%", 2, [ "width=30%" ]);
print &ui_table_row($text{'index_addresses'},
&ui_textbox("timeserver", $config{'timeserver'}, 60));
# Show hardware time checkbox
if (&support_hwtime()) {
print &ui_table_row(" ",
&ui_checkbox("hardware", 1, $text{'index_hardware2'},
$config{'timeserver_hardware'}));
if (!$time_is_chrony) {
print &ui_table_row($text{'index_addresses'},
&ui_textbox("timeserver", $config{'timeserver'}, 60));
# Show hardware time checkbox
if (&support_hwtime()) {
print &ui_table_row(" ",
&ui_checkbox("hardware", 1, $text{'index_hardware2'},
$config{'timeserver_hardware'}));
}
}
else {
if (&support_hwtime()) {
print &ui_table_row($text{'action_sync_s'},
&ui_yesno_radio("hardware", $config{'timeserver_hardware'}));
}
}
# Show boot-time checkbox
my $job = &find_webmin_cron_job();

View File

@@ -11,6 +11,8 @@ our ($timezones_file, $currentzone_link, $currentzone_file, $timezones_dir,
$sysclock_file);
our ($get_hardware_time_error);
our $cron_cmd = "$module_config_directory/sync.pl";
our $time_is_chrony = &has_command("chronyc");
our $time_out_no_cmd = 0;
if ($config{'zone_style'}) {
do "$config{'zone_style'}-lib.pl";
}
@@ -40,14 +42,18 @@ my ($server, $hwtoo) = @_;
my @servs = split(/\s+/, $server);
my $servs = join(" ", map { quotemeta($_) } @servs);
my $out;
if (&has_command("ntpdate")) {
if ($time_is_chrony) {
$out = &backquote_logged("chronyc -a makestep 2>&1");
}
elsif (&has_command("ntpdate")) {
$out = &backquote_logged("ntpdate -u $servs 2>&1");
}
elsif (&has_command("sntp")) {
$out = &backquote_logged("sntp -s $servs 2>&1");
}
else {
$out = "Missing ntpdate and sntp commands";
$out = "Missing <tt>chronyc</tt> or <tt>ntpdate</tt> and <tt>sntp</tt> commands";
$time_out_no_cmd = 1;
$? = 1;
}
if ($? && $config{'ntp_only'}) {