/usr/share/perl5/EBox/NTP.pm is in zentyal-ntp 2.3.6+quantal1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | # Copyright (C) 2008-2012 eBox Technologies S.L.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# 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 EBox::NTP;
use strict;
use warnings;
use base qw(EBox::Module::Service);
use EBox::Objects;
use EBox::Gettext;
use EBox::Service;
use EBox::Menu::Item;
use EBox::Menu::Folder;
use Error qw(:try);
use EBox::Validate qw(:all);
use EBox::Sudo;
use EBox;
use constant NTPCONFFILE => '/etc/ntp.conf';
sub _create
{
my $class = shift;
my $self = $class->SUPER::_create(name => 'ntp',
printableName => 'NTP',
@_);
bless($self, $class);
return $self;
}
sub isRunning
{
my ($self) = @_;
# return undef if service is not enabled
# otherwise it might be misleading if time synchronization is set
($self->isEnabled()) or return undef;
return EBox::Service::running('ebox.ntpd');
}
# Method: actions
#
# Override EBox::Module::Service::actions
#
sub actions
{
return [
{
'action' => __('Remove ntp init script link and networking hooks (if-up.d and dhclient)'),
'reason' => __('Zentyal will take care of starting and stopping ' .
'the services.'),
'module' => 'ntp'
}
];
}
# Method: usedFiles
#
# Override EBox::Module::Service::usedFiles
#
sub usedFiles
{
return [
{
'file' => NTPCONFFILE,
'module' => 'ntp',
'reason' => __('NTP configuration file')
}
];
}
# Method: initialSetup
#
# Overrides:
# EBox::Module::Base::initialSetup
#
sub initialSetup
{
my ($self, $version) = @_;
# Create default rules and services and add default servers
# only if installing the first time
unless ($version) {
my $servers = $self->model('Servers');
for my $i (0..2) {
$servers->add(server => "$i.pool.ntp.org");
}
my $services = EBox::Global->modInstance('services');
my $fw = EBox::Global->modInstance('firewall');
my $serviceName = 'ntp';
unless ($services->serviceExists(name => $serviceName)) {
$services->addMultipleService(
'name' => $serviceName,
'printableName' => 'NTP',
'description' => __('Network Time Protocol'),
'readOnly' => 1,
'services' => [ { protocol => 'udp',
sourcePort => 'any',
destinationPort => 123 } ] );
$fw->setInternalService($serviceName, 'deny');
}
$fw->saveConfigRecursive();
}
}
sub _syncDate
{
my ($self) = @_;
if ($self->synchronized) {
my $exserver = $self->firstServer();
return unless $exserver;
try {
EBox::Sudo::root("/usr/sbin/ntpdate $exserver");
} catch EBox::Exceptions::Internal with {
EBox::warn("Couldn't execute ntpdate $exserver");
};
}
}
sub _preSetConf
{
my ($self) = @_;
try {
$self->_stopService();
sleep 2;
$self->_syncDate();
} otherwise {};
}
sub _daemons
{
return [ { name => 'ebox.ntpd' } ];
}
# Method: synchronized
#
# Enable/disable the synchronization service to external ntp servers
#
# Returns:
#
# boolean - True enable, undef disable
#
sub synchronized
{
my ($self) = @_;
my $sync = $self->model('Settings')->syncValue();
if (defined($sync) and ($sync == 0)) {
$sync = undef;
}
return $sync;
}
# Method: servers
#
# Returns the list of external ntp servers
#
# Returns:
#
# array - holding the ntp servers
sub servers
{
my ($self) = @_;
my $model = $self->model('Servers');
my @servers =
map { $model->row($_)->valueByName('server') } @{$model->ids()};
return @servers;
}
# Method: firstServer
#
# Returns the first external NTP server
sub firstServer
{
my ($self) = @_;
my @servers = $self->servers();
return $servers[0];
}
# Method: _setConf
#
# Overrides base method. It writes the NTP configuration
#
sub _setConf
{
my ($self) = @_;
my @array = ();
my @servers = $self->servers;
my $synch = 'no';
my $active = 'no';
($self->synchronized) and $synch = 'yes';
($self->isEnabled()) and $active = 'yes';
push(@array, 'active' => $active);
push(@array, 'synchronized' => $synch);
push(@array, 'servers' => \@servers);
$self->writeConfFile(NTPCONFFILE, "ntp/ntp.conf.mas", \@array);
}
# Method: menu
#
# Overrides EBox::Module method.
#
sub menu
{
my ($self, $root) = @_;
$root->add(new EBox::Menu::Item('text' => $self->printableName(),
'url' => 'NTP/Composite/General',
'separator' => 'Infrastructure',
'order' => 445));
}
1;
|