summaryrefslogtreecommitdiff
path: root/scripts/system/vyatta_update_ntp.pl
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2018-06-24 12:50:17 +0200
committerDaniil Baturin <daniil@baturin.org>2018-06-24 12:50:17 +0200
commitbacecf80ea16d3cd30dc7c98c98af013b2adc258 (patch)
tree2b1d6f48708ace28ae4f6c9893ee50f6f390c6b7 /scripts/system/vyatta_update_ntp.pl
parent0d8e75e2e808ccf366a1527647a6353c09d92237 (diff)
parent0f19dc57ed6588c083eee8aa9aee09b92b441b08 (diff)
downloadvyatta-cfg-system-lithium.tar.gz
vyatta-cfg-system-lithium.zip
Merge branch 'current' into lithiumlithium
Conflicts: debian/changelog scripts/snmp/vyatta-snmp-v3.pl scripts/snmp/vyatta-snmp.pl templates/interfaces/tunnel/node.def templates/system/sysctl/custom/node.def
Diffstat (limited to 'scripts/system/vyatta_update_ntp.pl')
-rwxr-xr-xscripts/system/vyatta_update_ntp.pl120
1 files changed, 0 insertions, 120 deletions
diff --git a/scripts/system/vyatta_update_ntp.pl b/scripts/system/vyatta_update_ntp.pl
deleted file mode 100755
index 36a2807e..00000000
--- a/scripts/system/vyatta_update_ntp.pl
+++ /dev/null
@@ -1,120 +0,0 @@
-#! /usr/bin/perl
-
-# **** License ****
-# 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.
-#
-# This code was originally developed by Vyatta, Inc.
-# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
-# All Rights Reserved.
-#
-# **** End License ****
-
-# Filter ntp.conf - remove old servers and add current ones
-
-use strict;
-use lib "/opt/vyatta/share/perl5";
-use Vyatta::Config;
-use NetAddr::IP;
-use Getopt::Long;
-
-my $dhclient_script = 0;
-
-GetOptions("dhclient-script=i" => \$dhclient_script,
-);
-
-sub ntp_format {
- my ($cidr_or_host) = @_;
- my $ip = NetAddr::IP->new($cidr_or_host);
- if (defined($ip)) {
- my $address = $ip->addr();
- my $mask = $ip->mask();
-
- if ($ip->masklen() == 32) {
- if ($ip->version() == 6) {
- return "-6 $address";
- } else {
- return "$address";
- }
- } else {
- if ($ip->version() == 6) {
- return "-6 $address mask $mask";
- } else {
- return "$address mask $mask";
- }
- }
- } else {
- return undef;
- }
-}
-
-my @ntp;
-if (-e '/etc/ntp.conf') {
- open (my $file, '<', '/etc/ntp.conf')
- or die("$0: Error! Unable to open '/etc/ntp.conf' for input: $!\n");
- @ntp = <$file>;
- close ($file);
-}
-
-open (my $output, '>', '/etc/ntp.conf')
- or die("$0: Error! Unable to open '/etc/ntp.conf' for output: $!\n");
-
-my $cfg = new Vyatta::Config;
-$cfg->setLevel("system ntp");
-
-foreach my $line (@ntp) {
- if ($line =~ /^# VyOS CLI configuration options/) {
- print $output $line;
- print $output "\n";
- last;
- } else {
- print $output $line;
- }
-}
-
-my @servers;
-my @clients;
-
-if ($dhclient_script == 1) {
- @servers = $cfg->listOrigNodes("server");
- @clients = $cfg->returnOrigValues("client address");
-} else {
- @servers = $cfg->listNodes("server");
- @clients = $cfg->returnValues("client address");
-}
-
-if (scalar(@servers) > 0) {
- print $output "# Servers\n\n";
- foreach my $server (@servers) {
- my $server_addr = ntp_format($server);
- if (defined($server_addr)) {
- print $output "server $server_addr iburst";
- for my $property (qw(dynamic noselect preempt prefer)) {
- if ($dhclient_script == 1) {
- print $output " $property" if ($cfg->existsOrig("server $server $property"));
- } else {
- print $output " $property" if ($cfg->exists("server $server $property"));
- }
- }
- print $output "\nrestrict $server_addr nomodify notrap nopeer noquery\n";
- }
- }
- print $output "\n";
-}
-
-if (scalar(@clients) > 0) {
- print $output "# Clients\n\n";
- foreach my $client (@clients) {
- my $address = ntp_format($client);
- print $output "restrict $address nomodify notrap nopeer\n";
- }
- print $output "\n";
-}
-
-exit 0;