initial commit of file from CVS for e-smith-ntp on Wed 12 Jul 09:00:21 BST 2023

This commit is contained in:
Brian Read
2023-07-12 09:00:21 +01:00
parent 59f5643b62
commit 4d143a42fe
37 changed files with 3230 additions and 2 deletions

View File

@@ -0,0 +1 @@
smeserver.pool.ntp.org

View File

@@ -0,0 +1 @@
enabled

View File

@@ -0,0 +1 @@
service

View File

@@ -0,0 +1,7 @@
{
my $ntpd = $DB->get('ntpd');
return unless $ntpd;
return if $ntpd->prop('SyncToHWClockSupported');
$ntpd->set_prop('status', 'enabled') unless ($ntpd->prop('status') || 'disabled') eq 'enabled';
}

View File

@@ -0,0 +1,8 @@
{
my $pool = $DB->get_prop('ntpd', 'NTPServer');
return unless defined $pool;
if ($pool eq 'pool.ntp.org')
{
$DB->set_prop('ntpd', 'NTPServer', 'smeserver.pool.ntp.org')
}
}

View File

@@ -0,0 +1,66 @@
#!/usr/bin/perl -w
#----------------------------------------------------------------------
# copyright (C) 2001-2005 Mitel Networks Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#----------------------------------------------------------------------
package esmith;
use strict;
use Errno;
use esmith::ConfigDB;
use esmith::templates;
my $db = esmith::ConfigDB->open or die "Could not open config db";
# Obtain the TimeZone configuration database value
my $timezone = $db->get("TimeZone");
if (defined $timezone)
{
$timezone = $timezone->value;
}
else
{
# Initialise timezone from /etc/sysconfig/clock if not already set
if (open(CLOCK, "/etc/sysconfig/clock"))
{
while(<CLOCK>)
{
$timezone = $1 if /^ZONE="(.*)"/;
last if defined $timezone;
}
close(CLOCK) or warn("Could not close CLOCK: $!");
}
else
{
warn("Could not open /etc/sysconfig/clock: $!");
}
# If all else fails ...
$timezone = "US/Eastern" unless defined $timezone;
$db->new_record('TimeZone')->set_value($timezone);
}
# Undo the previous symlink and remake it to the correct time zone
unlink "/etc/localtime";
symlink "../usr/share/zoneinfo/$timezone", "/etc/localtime";
# Process the template for /etc/sysconfig/clock
processTemplate ({TEMPLATE_PATH => "/etc/sysconfig/clock"});
exit (0);

View File

@@ -0,0 +1,4 @@
#!/bin/sh
/bin/date "$2"
/sbin/clock -u -w

View File

@@ -0,0 +1,239 @@
<lexicon lang="en-us">
<entry>
<base>FORM_TITLE</base>
<trans>Date and time configuration</trans>
</entry>
<entry>
<base>INITIAL_DESC</base>
<trans>
This is where you configure the date and time of this server. You may use an existing network time server or
manually set the date and time for your time zone.
</trans>
</entry>
<entry>
<base>SET_DATE_TITLE</base>
<trans>Set Date and Time</trans>
</entry>
<entry>
<base>COULD_NOT_OPEN_TZ_FILE</base>
<trans>Error: Could not open timezone file for reading: </trans>
</entry>
<entry>
<base>JANUARY</base>
<trans>January</trans>
</entry>
<entry>
<base>FEBRUARY</base>
<trans>February</trans>
</entry>
<entry>
<base>MARCH</base>
<trans>March</trans>
</entry>
<entry>
<base>APRIL</base>
<trans>April</trans>
</entry>
<entry>
<base>MAY</base>
<trans>May</trans>
</entry>
<entry>
<base>JUNE</base>
<trans>June</trans>
</entry>
<entry>
<base>JULY</base>
<trans>July</trans>
</entry>
<entry>
<base>AUGUST</base>
<trans>August</trans>
</entry>
<entry>
<base>SEPTEMBER</base>
<trans>September</trans>
</entry>
<entry>
<base>OCTOBER</base>
<trans>October</trans>
</entry>
<entry>
<base>NOVEMBER</base>
<trans>November</trans>
</entry>
<entry>
<base>DECEMBER</base>
<trans>December</trans>
</entry>
<entry>
<base>NEW_M/D/Y</base>
<trans>New month/day/year:</trans>
</entry>
<entry>
<base>NEW_H/M/S</base>
<trans>New hour/min/sec:</trans>
</entry>
<entry>
<base>AM/PM_AND_TZ</base>
<trans>AM/PM and time zone:</trans>
</entry>
<entry>
<base>NTP_ENABLE_DESC</base>
<trans>
The server can periodically synchronize the system clock to a network time protocol (NTP) server. If you select this option, enter the hostname or IP address of the NTP server below.
</trans>
</entry>
<entry>
<base>NTP_CONFIGURE_DESC</base>
<trans>
The server is periodically synchronizing the system clock to the network time protocol (NTP) server specified below. To synchronize to a different NTP server, enter a different hostname or IP address in the field below.
</trans>
</entry>
<entry>
<base>NTP_DISABLE_DESC</base>
<trans>
Choose this option to stop syncronizing the system clock to the NTP
server. When the NTP service is disabled, you can set the system date
and time manually from this page.
</trans>
</entry>
<entry>
<base>NTP_SERVER</base>
<trans>NTP Server</trans>
</entry>
<entry>
<base>VERIFY_DATE_AND_TIME</base>
<trans>Verify date and time</trans>
</entry>
<entry>
<base>NEW_DATE_AND_TIME</base>
<trans>New date and time setting:</trans>
</entry>
<entry>
<base>SETTING_DATE_AND_TIME</base>
<trans>Setting date and time</trans>
</entry>
<entry>
<base>INVALID_DAY</base>
<trans>Error: invalid day of month: </trans>
</entry>
<entry>
<base>BETWEEN_1_AND_31</base>
<trans>Please choose a day between 1 and 31.</trans>
</entry>
<entry>
<base>INVALID_YEAR</base>
<trans>Error: invalid year: </trans>
</entry>
<entry>
<base>FOUR_DIGIT_YEAR</base>
<trans>Please choose a four-digit year between 1900 and 2200.</trans>
</entry>
<entry>
<base>INVALID_HOUR</base>
<trans>Error: invalid hour: </trans>
</entry>
<entry>
<base>BETWEEN_1_AND_12</base>
<trans>Please choose an hour between 1 and 12.</trans>
</entry>
<entry>
<base>INVALID_MINUTE</base>
<trans>Error: invalid minute: </trans>
</entry>
<entry>
<base>BETWEEN_0_AND_59</base>
<trans>Please choose a minute between 0 and 59.</trans>
</entry>
<entry>
<base>INVALID_SECOND</base>
<trans>Error: invalid second</trans>
</entry>
<entry>
<base>INVALID_MONTH</base>
<trans>Error: invalid month</trans>
</entry>
<entry>
<base>MONTH_BETWEEN_1_AND_12</base>
<trans>Please choose a month value between 1 and 12.</trans>
</entry>
<entry>
<base>UPDATING_CLOCK</base>
<trans>
<![CDATA[
System clock is being updated. Please wait for a few seconds,
then click <A HREF="datetime?page=1&wherenext=Verify" TARGET="main">here</A>
to verify changes.
]]>
</trans>
</entry>
<entry>
<base>ERR_SETTING_CLOCK</base>
<trans>Error occurred while setting system time and hardware clock.</trans>
</entry>
<entry>
<base>SERVER_DISABLED</base>
<trans>Network time server disabled successfully</trans>
</entry>
<entry>
<base>SERVER_DISABLED_DESC</base>
<trans>
<![CDATA[
You have disabled this service: The server will rely on its internal
clock, and <b>will not</b> try to synchronize from a time server.
]]>
</trans>
</entry>
<entry>
<base>ERR_CHANGING_TS</base>
<trans>Error while changing network time server setting</trans>
</entry>
<entry>
<base>INVALID_NTP_ADDR</base>
<trans>Invalid NTP server address: </trans>
</entry>
<entry>
<base>SETTINGS_CHANGED</base>
<trans>Network time server setting changed successfully</trans>
</entry>
<entry>
<base>SYNC_WITH</base>
<trans>This server is now configured to synchronize periodically
(via the Internet) with:
</trans>
</entry>
<entry>
<base>INVALID_NTP_SERVER</base>
<trans>
<![CDATA[
Invalid NTP server, the server <b>will not</b> try to synchronize
from a time server.
]]>
</trans>
</entry>
<entry>
<base>NETWORK_TIME_SERVER</base>
<trans>Network Time Server</trans>
</entry>
<entry>
<base>NTP_CONFIGURE_TITLE</base>
<trans>Configure Network Time Server</trans>
</entry>
<entry>
<base>NTP_ENABLE_TITLE</base>
<trans>Enable Network Time Server</trans>
</entry>
<entry>
<base>NTP_DISABLE_TITLE</base>
<trans>Disable Network Time Server</trans>
</entry>
<entry>
<base>CURRENT_SETTING</base>
<trans>Current setting</trans>
</entry>
<entry>
<base>Date and time</base>
<trans>Date and time</trans>
</entry>
</lexicon>

View File

@@ -0,0 +1,8 @@
/var/log/ntp.log \{
missingok
weekly
rotate 24
compress
notifempty
copytruncate
\}

View File

@@ -0,0 +1,19 @@
{
# vim: ft=perl:
my $server = $ntpd{NTPServer} || '';
return "# sync to hw clock" if $server =~ m#^\s*$#;
if ( ($ntpd{'SupportLargeDrift'} || 'disabled') eq 'enabled' ){
$OUT .= "tinker panic 0\n";
}
if ($server =~ /pool.ntp.org/)
{
# The 0, 1, 2, 3 prefixes ensure NTP pool round-robin
$OUT .= "server $_.$server\n" for (0..3);
}
else
{
$OUT .= "server $server\n";
}
}

View File

@@ -0,0 +1,9 @@
{
$OUT = '';
unless ( ($ntpd{'SupportLargeDrift'} || 'disabled') eq 'enabled' ){
$OUT .= <<EOF;
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
EOF
}
}

View File

@@ -0,0 +1,3 @@
{
$OUT = "driftfile /var/lib/ntp/drift";
}

View File

@@ -0,0 +1,2 @@
restrict default noquery

View File

@@ -0,0 +1 @@
restrict 127.0.0.1

View File

@@ -0,0 +1,19 @@
{
my $NTPenabled = $ntpd{'status'} || 'disabled';
my $server = $ntpd{NTPServer} || '';
if ($NTPenabled eq 'enabled')
{
if ($server =~ /pool.ntp.org/)
{
$OUT .= "0.$server";
}
else
{
$OUT .= "$server";
}
}
else
{
$OUT .= "# ntpd service is disabled";
}
}

View File

@@ -0,0 +1,4 @@
#ntp
:programname, isequal, "ntpd" /var/log/ntp.log
& stop

View File

@@ -0,0 +1,5 @@
{
my $timezone = $TimeZone || "US/Eastern";
$OUT .= "ZONE=\"$timezone\"";
}

View File

@@ -0,0 +1,3 @@
{
$OUT .= "UTC=true";
}

View File

@@ -0,0 +1,3 @@
{
$OUT .= "ARC=false";
}

View File

@@ -0,0 +1,4 @@
# nut ntpd specific subservices
# this would conflict with ntpd
disable ntpdate.service

View File

@@ -0,0 +1,20 @@
[Service]
{
# memory limit to catch any memory leak before it kills the system
use constant MIN_MEMORY_LIMIT => 35000000;
# If there is a memory limit in the database and it is below the minimum, delete it.
if (defined $ntpd{MemLimit} && $ntpd{MemLimit} < MIN_MEMORY_LIMIT)
{
$DB->get_prop_and_delete('ntpd','MemLimit');
delete $ntpd{MemLimit};
}
$OUT .= "MemoryLimit=";
$OUT .= $ntpd{MemLimit} || MIN_MEMORY_LIMIT;
$OUT .= "\n";
}
ExecStartPre=-/sbin/e-smith/expand-template /etc/ntp.conf
ExecStartPre=-/sbin/e-smith/systemd/initializedate
Restart=always

View File

@@ -0,0 +1,2 @@
[Install]
WantedBy=sme-server.target

View File

@@ -0,0 +1,47 @@
#!/usr/bin/perl -wT
#----------------------------------------------------------------------
# heading : Configuration
# description : Date and time
# navigation : 6000 6100
#
# Copyright (c) 2001 Mitel Networks Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Technical support for this program is available from e-smith, inc.
# Please visit our web site www.e-smith.com for details.
#----------------------------------------------------------------------
use strict;
use esmith::FormMagick::Panel::datetime;
my $panel = esmith::FormMagick::Panel::datetime->new();
$|=1;
$panel->display();
__DATA__
<form title="FORM_TITLE" header="/etc/e-smith/web/common/head.tmpl"
footer="/etc/e-smith/web/common/foot.tmpl">
<page name="First" pre-event="print_status_message()"
post-event="performAndShowResult()">
<description>INITIAL_DESC</description>
<subroutine src="showInitial()"/>
</page>
<page name="Verify" pre-event="turn_off_buttons">
<title>VERIFY_DATE_AND_TIME</title>
<subroutine src="verifyResult()"/>
</page>
</form>