summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/dhcpv6-client-show-leases.pl4
-rw-r--r--scripts/maya-date.py214
-rwxr-xr-xscripts/ping1
-rw-r--r--scripts/rename-image.pl6
-rwxr-xr-xscripts/show-dhcp-leases.pl2
-rw-r--r--scripts/show-image-storage.pl8
-rwxr-xr-xscripts/ssh-server-key14
-rwxr-xr-xscripts/vyatta-boot-image.pl39
-rwxr-xr-xscripts/vyatta-image-tools.pl10
-rwxr-xr-xscripts/vyatta-op-dns-forwarding.pl350
-rwxr-xr-xscripts/vyatta-show-dhclient.pl2
-rw-r--r--scripts/vyatta-show-snmp-ifmib138
-rw-r--r--scripts/vyatta-show-snmp-v3.pl168
-rwxr-xr-xscripts/vyatta-show-snmp.pl123
-rwxr-xr-xscripts/vyatta-show-version255
-rwxr-xr-xscripts/vyatta-tshark-interface-port.pl92
-rwxr-xr-xscripts/vyatta-tshark.pl150
-rw-r--r--scripts/vyos-openvpn-remoteconfig.pl122
18 files changed, 172 insertions, 1526 deletions
diff --git a/scripts/dhcpv6-client-show-leases.pl b/scripts/dhcpv6-client-show-leases.pl
index 44be689..761a3e6 100644
--- a/scripts/dhcpv6-client-show-leases.pl
+++ b/scripts/dhcpv6-client-show-leases.pl
@@ -55,7 +55,7 @@ sub log_msg {
# Main section.
#
-opendir (my $dir, "/var/lib/dhcp3");
+opendir (my $dir, "/var/lib/dhcp");
my @lease_files;
while (my $f = readdir $dir) {
if ($f =~ /^dhclient_v6_(\w+).leases$/) {
@@ -74,7 +74,7 @@ my %ghash = ();
foreach my $lease_filename (@lease_files) {
my @lines=();
- open(my $f, '<', "/var/lib/dhcp3/$lease_filename")
+ open(my $f, '<', "/var/lib/dhcp/$lease_filename")
or die "Can't open lease file for reading: $lease_filename\n";
@lines = <$f>;
diff --git a/scripts/maya-date.py b/scripts/maya-date.py
deleted file mode 100644
index 6f0918c..0000000
--- a/scripts/maya-date.py
+++ /dev/null
@@ -1,214 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (c) 2013 Daniil Baturin <daniil at baturin dot org>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-import sys
-
-class MayaDate(object):
- """ Converts number of days since UNIX epoch
- to the Maya calendar date.
-
- Ancient Maya people used three independent calendars for
- different purposes.
-
- Long count calendar is for recording historical events.
- It and represents the number of days passed
- since some date in the past the Maya believed is the day
- our world was created.
-
- Tzolkin calendar is for religious purposes, it has
- two independent cycles of 13 and 20 days, where 13 day
- cycle days are numbered, and 20 day cycle days are named.
-
- Haab calendar is for agriculture and daily life, it's a
- 365 day calendar with 18 months 20 days each, and 5
- nameless days.
-
- The smallest unit of long count calendar is one day (kin)
-
- """
-
- """ The long count calendar uses five different base 18 or base 20
- cycles. Long-count date is writtin in dot separated format
- from longest to shortest cycle,
- <baktun>.<katun>.<tun>.<winal>.<kin>
- for example, "13.0.0.9.2".
-
- Classic version actually used by the ancient Maya wraps around
- every 13th baktun, but modern researchers often use longer cycles
- such as piktun = 20 baktun.
-
- """
- kin = 1
- winal = 20 # 20 kin
- tun = 360 # 18 winal
- katun = 7200 # 20 tun
- baktun = 144000 # 20 katun
-
- """ Tzolk'in date is composed of two independent cycles.
- Dates repeat every 260 days, 13 Ajaw is considered the end
- of tzolk'in.
-
- Every day of the 20 day cycle has unique name, we number
- them from zero so it's easier to map remainder to day:
- """
- tzolkin_days = { 0: "Imix'",
- 1: "Ik'",
- 2: "Ak'b'al",
- 3: "K'an",
- 4: "Chikchan",
- 5: "Kimi",
- 6: "Manik'",
- 7: "Lamat",
- 8: "Muluk",
- 9: "Ok",
- 10: "Chuwen",
- 11: "Eb'",
- 12: "B'en",
- 13: "Ix",
- 14: "Men",
- 15: "Kib'",
- 16: "Kab'an",
- 17: "Etz'nab'",
- 18: "Kawak",
- 19: "Ajaw" }
-
- """ As said above, haab (year) has 19 months. Only 18 are
- true months of 20 days each, the remaining 5 days called "wayeb"
- do not really belong to any month, but we think of them as a pseudo-month
- for convenience.
-
- Also, note that days of the month are actually numbered from 0, not from 1,
- it's not for technical reasons.
- """
- haab_months = { 0: "Pop",
- 1: "Wo'",
- 2: "Sip",
- 3: "Sotz'",
- 4: "Sek",
- 5: "Xul",
- 6: "Yaxk'in'",
- 7: "Mol",
- 8: "Ch'en",
- 9: "Yax",
- 10: "Sak'",
- 11: "Keh",
- 12: "Mak",
- 13: "K'ank'in",
- 14: "Muwan'",
- 15: "Pax",
- 16: "K'ayab",
- 17: "Kumk'u",
- 18: "Wayeb'" }
-
- """ Now we need to map the beginning of UNIX epoch
- (Jan 1 1970 00:00 UTC) to the beginning of the long count
- calendar (0.0.0.0.0, 4 Ajaw, 8 Kumk'u).
-
- The problem with mapping the long count calendar to
- any other is that its start date is not known exactly.
-
- The most widely accepted hypothesis suggests it was
- August 11, 3114 BC gregorian date. In this case UNIX epoch
- starts on 12.17.16.7.5, 13 Chikchan, 3 K'ank'in
-
- It's known as Goodman-Martinez-Thompson (GMT) correlation
- constant.
- """
- start_days = 1856305
-
- """ Seconds in day, for conversion from timestamp """
- seconds_in_day = 60 * 60 * 24
-
- def __init__(self, timestamp):
- if timestamp is None:
- self.days = self.start_days
- else:
- self.days = self.start_days + (int(timestamp) // self.seconds_in_day)
-
- def long_count_date(self):
- """ Returns long count date string """
- days = self.days
-
- cur_baktun = days // self.baktun
- days = days % self.baktun
-
- cur_katun = days // self.katun
- days = days % self.katun
-
- cur_tun = days // self.tun
- days = days % self.tun
-
- cur_winal = days // self.winal
- days = days % self.winal
-
- cur_kin = days
-
- longcount_string = "{0}.{1}.{2}.{3}.{4}".format( cur_baktun,
- cur_katun,
- cur_tun,
- cur_winal,
- cur_kin )
- return(longcount_string)
-
- def tzolkin_date(self):
- """ Returns tzolkin date string """
- days = self.days
-
- """ The start date is not the beginning of both cycles,
- it's 4 Ajaw. So we need to add 4 to the 13 days cycle day,
- and substract 1 from the 20 day cycle to get correct result.
- """
- tzolkin_13 = (days + 4) % 13
- tzolkin_20 = (days - 1) % 20
-
- tzolkin_string = "{0} {1}".format(tzolkin_13, self.tzolkin_days[tzolkin_20])
-
- return(tzolkin_string)
-
- def haab_date(self):
- """ Returns haab date string.
-
- The time start on 8 Kumk'u rather than 0 Pop, which is
- 17 days before the new haab, so we need to substract 17
- from the current date to get correct result.
- """
- days = self.days
-
- haab_day = (days - 17) % 365
- haab_month = haab_day // 20
- haab_day_of_month = haab_day % 20
-
- haab_string = "{0} {1}".format(haab_day_of_month, self.haab_months[haab_month])
-
- return(haab_string)
-
- def date(self):
- return("{0}, {1}, {2}".format( self.long_count_date(), self.tzolkin_date(), self.haab_date() ))
-
-try:
- timestamp = sys.argv[1]
-except:
- print("Please specify timestamp in the argument")
- sys.exit(1)
-
-maya_date = MayaDate(timestamp)
-print(maya_date.date())
diff --git a/scripts/ping b/scripts/ping
index c0fae36..b72ea54 100755
--- a/scripts/ping
+++ b/scripts/ping
@@ -40,6 +40,7 @@ use strict;
use warnings;
use NetAddr::IP;
use feature ":5.10";
+use experimental 'smartmatch';
sub get_options {
my ($opt, $args) = @_;
diff --git a/scripts/rename-image.pl b/scripts/rename-image.pl
index 2c77d70..591c29d 100644
--- a/scripts/rename-image.pl
+++ b/scripts/rename-image.pl
@@ -27,7 +27,7 @@ use File::Temp qw/ tempfile tempdir /;
use File::Copy;
use Sys::Syslog qw/:standard :macros/;
-my $UNION_BOOT = '/live/image/boot';
+my $UNION_BOOT = '/lib/live/mount/persistence/boot';
my $XEN_DEFAULT_IMAGE = "$UNION_BOOT/%%default_image";
my $old_name;
@@ -43,7 +43,7 @@ if (!defined($old_name) || !defined($new_name)) {
exit 1;
}
-my $image_path = "/live/image/boot";
+my $image_path = "/lib/live/mount/persistence/boot";
if (! -e "$image_path") {
# must be running on old non-image installed system
@@ -80,7 +80,7 @@ if ($cur_name =~ s/BOOT_IMAGE=\/boot\///) {
# On Xen/pygrub systems, we figure out the running version by
# looking at the bind mount of /boot.
$cur_name = `mount | awk '/on \\/boot / { print \$1 }'`;
- $cur_name =~ s/\/live\/image\/boot\///;
+ $cur_name =~ s/\/lib\/live\/mount\/persistence\/boot\///;
chomp($cur_name);
}
}
diff --git a/scripts/show-dhcp-leases.pl b/scripts/show-dhcp-leases.pl
index a7a918a..431a13c 100755
--- a/scripts/show-dhcp-leases.pl
+++ b/scripts/show-dhcp-leases.pl
@@ -22,7 +22,7 @@
use strict;
-opendir (my $dir, "/var/lib/dhcp3");
+opendir (my $dir, "/var/lib/dhcp");
my @leases;
while (my $f = readdir $dir) {
($f =~ /^dhclient_([\w.]+)_lease$/) && push @leases, $1;
diff --git a/scripts/show-image-storage.pl b/scripts/show-image-storage.pl
index f8de35e..863b913 100644
--- a/scripts/show-image-storage.pl
+++ b/scripts/show-image-storage.pl
@@ -40,8 +40,8 @@ sub better_units {
#
# Figure out where the images live...
-my $imagedir = "/live/image/boot";
-my $livecd = "/live/image/live";
+my $imagedir = "/lib/live/mount/persistence/boot";
+my $livecd = "/lib/live/mount/persistence/live";
if (! -e $imagedir) {
if (-d $livecd) {
die "System running on Live-CD\n";
@@ -73,11 +73,11 @@ foreach my $image (@bootlist_arr) {
($total, $garbage) = split(' ', $string);
$total = better_units($total);
- $string = `du -s -h $imagedir/$image --exclude live-rw`;
+ $string = `du -s -h $imagedir/$image --exclude rw`;
($read_only, $garbage) = split(' ', $string);
$read_only = better_units($read_only);
- $string = `du -s -h $imagedir/$image/live-rw`;
+ $string = `du -s -h $imagedir/$image/rw`;
($read_write, $garbage) = split(' ', $string);
$read_write = better_units($read_write);
diff --git a/scripts/ssh-server-key b/scripts/ssh-server-key
new file mode 100755
index 0000000..949d314
--- /dev/null
+++ b/scripts/ssh-server-key
@@ -0,0 +1,14 @@
+regen_host_keys ()
+{
+ sudo /bin/rm -v /etc/ssh/ssh_host_*
+ sudo dpkg-reconfigure openssh-server
+ sudo /etc/init.d/ssh restart
+}
+
+echo "Do you really want to remove the existing SSH host keys? "
+${vyatta_bindir}/yesno
+
+if [ $? -eq 0 ]
+then
+ regen_host_keys
+fi
diff --git a/scripts/vyatta-boot-image.pl b/scripts/vyatta-boot-image.pl
index 52d5198..d3ca5e8 100755
--- a/scripts/vyatta-boot-image.pl
+++ b/scripts/vyatta-boot-image.pl
@@ -31,14 +31,14 @@ use File::Copy;
#
# Constants
#
-my $UNION_BOOT = '/live/image/boot';
+my $UNION_BOOT = '/lib/live/mount/persistence/boot';
my $UNION_GRUB_CFG = "$UNION_BOOT/grub/grub.cfg";
my $VER_FILE = '/opt/vyatta/etc/version';
my $OLD_IMG_VER_STR = 'Old-non-image-installation';
my $OLD_GRUB_CFG = '/boot/grub/grub.cfg';
my $DISK_BOOT = '/boot';
my $XEN_DEFAULT_IMAGE = "$UNION_BOOT/%%default_image";
-my $LIVE_CD = '/live/image/live';
+my $LIVE_CD = '/lib/live/mount/medium/live';
#
# Globals
@@ -102,7 +102,7 @@ sub parseGrubCfg {
# old install
$ehash{'ver'} = $OLD_IMG_VER_STR;
}
- if (/console=tty0.*console=ttyS0/) {
+ if (/console=tty0.*console=ttyS[0-9]/) {
$ehash{'term'} = 'serial';
} else {
$ehash{'term'} = 'kvm';
@@ -226,32 +226,31 @@ sub image_vyatta_version {
my ($image_name) = @_;
my $vers;
- my $dpkg_path = "var/lib/dpkg";
my $image_path;
if ($image_name eq $OLD_IMG_VER_STR) {
$image_path = "";
} else {
- $image_path = "/live/image/boot/$image_name/live-rw";
+ $image_path = "/lib/live/mount/persistence/boot/$image_name/rw";
}
- $image_path .= "/var/lib/dpkg";
+ $image_path .= "/opt/vyatta/etc/version";
if ( -e $image_path ) {
- $vers = `dpkg-query --admindir=$image_path --showformat='\${Version}' --show vyatta-version`;
+ $vers = `cat $image_path | awk '{print \$2}'`;
return $vers;
} else {
if ($image_name eq $OLD_IMG_VER_STR) {
return "unknown";
}
- my @squash_files = glob("/live/image/boot/$image_name/*.squashfs");
+ my @squash_files = glob("/lib/live/mount/persistence/boot/$image_name/*.squashfs");
foreach my $squash_file (@squash_files) {
if (-e $squash_file) {
system("sudo mkdir /tmp/squash_mount");
system("sudo mount -o loop,ro -t squashfs $squash_file /tmp/squash_mount");
- $image_path = "/tmp/squash_mount/var/lib/dpkg";
- my $vers = `dpkg-query --admindir=$image_path --showformat='\${Version}' --show vyatta-version`;
+ $image_path = "/tmp/squash_mount/opt/vyatta/etc/version";
+ my $vers = `cat $image_path | awk '{print \$2}'`;
system("sudo umount /tmp/squash_mount");
system("sudo rmdir /tmp/squash_mount");
return $vers;
@@ -410,7 +409,7 @@ sub curVer {
# On Xen/pygrub systems, we figure out the running version by
# looking at the bind mount of /boot.
$vers = `mount | awk '/on \\/boot / { print \$1 }'`;
- $vers =~ s/\/live\/image\/boot\///;
+ $vers =~ s/\/lib\/live\/mount\/persistence\/boot\///;
chomp($vers);
}
@@ -432,15 +431,15 @@ sub del_non_image_files {
system("echo Deleting disk-based system files at: `date` >> $logfile");
system("echo Run by: `whoami` >> $logfile");
- foreach my $entry (glob("/live/image/*")) {
- if ($entry eq "/live/image/boot") {
- print "Skipping $entry.\n";
- } else {
- print "Deleting $entry...";
- system ("echo deleting $entry >> $logfile");
- system ("rm -rf $entry >> $logfile 2>&1");
- print "\n";
- }
+ foreach my $entry (glob("/lib/live/mount/persistence/*")) {
+ if ($entry eq "/lib/live/mount/persistence/boot") {
+ print "Skipping $entry.\n";
+ } else {
+ print "Deleting $entry...";
+ system ("echo deleting $entry >> $logfile");
+ system ("rm -rf $entry >> $logfile 2>&1");
+ print "\n";
+ }
}
system ("echo done at: `date` >> $logfile");
}
diff --git a/scripts/vyatta-image-tools.pl b/scripts/vyatta-image-tools.pl
index 6bcfd7d..2dd95df 100755
--- a/scripts/vyatta-image-tools.pl
+++ b/scripts/vyatta-image-tools.pl
@@ -50,7 +50,7 @@ sub conv_file {
if ($topdir eq "running") {
$file = "/$file";
} elsif (lc($topdir) eq 'disk-install') {
- $file = "/live/image/$file";
+ $file = "/lib/live/mount/persistence/$file";
} elsif (lc($topdir) eq 'tftp') {
$file = $filein;
$topdir = 'url';
@@ -64,11 +64,11 @@ sub conv_file {
$file = $filein;
$topdir = 'url';
} else {
- if (!-d "/live/image/boot/$topdir/live-rw"){
+ if (!-d "/lib/live/mount/persistence/boot/$topdir/rw"){
print "Image $topdir not found!\n";
exit 1;
}
- $file = "/live/image/boot/$topdir/live-rw/$file";
+ $file = "/lib/live/mount/persistence/boot/$topdir/rw/$file";
}
return ($topdir, $file);
}
@@ -78,9 +78,9 @@ sub conv_file_to_rel {
if ($topdir eq "running"){
$filename =~ s?/?$topdir://?;
} elsif ($topdir eq "disk-install") {
- $filename =~ s?/live/image/?$topdir://?;
+ $filename =~ s?/lib/live/mount/persistence/?$topdir://?;
} else {
- $filename =~ s?/live/image/boot/$topdir/live-rw/?$topdir://?;
+ $filename =~ s?/lib/live/mount/persistence/boot/$topdir/rw/?$topdir://?;
}
return $filename;
}
diff --git a/scripts/vyatta-op-dns-forwarding.pl b/scripts/vyatta-op-dns-forwarding.pl
deleted file mode 100755
index 5f94c15..0000000
--- a/scripts/vyatta-op-dns-forwarding.pl
+++ /dev/null
@@ -1,350 +0,0 @@
-#!/usr/bin/perl
-#
-# Module: vyatta-op-dns-forwarding.pl
-#
-# **** 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) 2008 Vyatta, Inc.
-# All Rights Reserved.
-#
-# Author: Mohit Mehta
-# Date: August 2008
-# Description: Script to execute op-mode commands for DNS forwarding
-#
-# **** End License ****
-#
-
-use lib "/opt/vyatta/share/perl5/";
-use Getopt::Long;
-use Vyatta::Config;
-use strict;
-use warnings;
-
-my $show_stats_output="";
-my $show_nameservers_output="";
-my $dnsmasq_log='/var/log/dnsmasq.log';
-
-sub get_cache_stats {
- my ($cache_size, $queries_forwarded, $queries_answered_locally, $entries_inserted, $entries_removed);
-
- my $grepped_line = `grep 'cache size' $dnsmasq_log`;
- my @split_line = split(/\s+/, $grepped_line);
- my @temp_split = split(/,/, $split_line[6]);
- $cache_size = $temp_split[0];
- @temp_split = split(/\//, $split_line[7]);
- $entries_removed = $temp_split[0];
- $entries_inserted = $temp_split[1];
-
- $grepped_line = `grep 'queries forwarded' $dnsmasq_log`;
- @split_line = split(/\s+/, $grepped_line);
- @temp_split = split(/,/, $split_line[6]);
- $queries_forwarded = $temp_split[0];
- $queries_answered_locally = $split_line[10];
-
- $show_stats_output .= "----------------\n";
- $show_stats_output .= "Cache statistics\n";
- $show_stats_output .= "----------------\n";
- $show_stats_output .= "Cache size: $cache_size\n";
- $show_stats_output .= "Queries forwarded: $queries_forwarded\n";
- $show_stats_output .= "Queries answered locally: $queries_answered_locally\n";
- $show_stats_output .= "Total DNS entries inserted into cache: $entries_inserted\n";
- $show_stats_output .= "DNS entries removed from cache before expiry: $entries_removed\n";
-
-}
-
-sub get_nameserver_stats {
-
- $show_stats_output .= "\n---------------------\n";
- $show_stats_output .= "Nameserver statistics\n";
- $show_stats_output .= "---------------------\n";
-
- #To show overridden domain servers seperately, we need to compare IPs
- #configured for the domain overrides in the config with the stats.
-
- my $vyatta_config = new Vyatta::Config;
- $vyatta_config->setLevel("service dns forwarding");
-
- my @domains = $vyatta_config->listOrigNodes("domain");
- my @domain_servers_list;
-
- #build a list of servers that are overriding global nameservers
- if (@domains) {
- foreach my $domain (@domains) {
- push(@domain_servers_list, $vyatta_config->returnOrigValue("domain $domain server"));
- }
- }
- my $found_overrides = 0;
- my $show_stats_overrides;
- my @grepped_lines = `grep ': server' $dnsmasq_log`;
- foreach my $lines (@grepped_lines) {
- my @each_line = split(/\s+/, $lines);
- my $nameserver_word = $each_line[5];
- my @nameserver_split = split(/#/, $nameserver_word);
- my $nameserver = $nameserver_split[0];
- my $queries_sent_word = $each_line[8];
- my @queries_sent_split = split(/,/, $queries_sent_word);
- my $queries_sent = $queries_sent_split[0];
- my $queries_retried_failed = $each_line[12];
-
- if (grep {$_ eq $nameserver}@domain_servers_list) {
- if (!$found_overrides) {
- $found_overrides = 1;
- $show_stats_overrides .= "\nDomain Override Servers\n\n";
- }
- $show_stats_overrides .= "Server: $nameserver\nQueries sent: $queries_sent\nQueries retried or failed: $queries_retried_failed\n\n";
- } else {
- $show_stats_output .= "Server: $nameserver\nQueries sent: $queries_sent\nQueries retried or failed: $queries_retried_failed\n\n";
- }
- }
- if (defined($show_stats_overrides)) {
- $show_stats_output .= $show_stats_overrides;
- }
-}
-
-sub print_stats {
- print $show_stats_output;
-}
-
-sub get_dns_nameservers {
- my $vyatta_config = new Vyatta::Config;
-
- $vyatta_config->setLevel("service dns forwarding");
- my $use_system_nameservers = $vyatta_config->existsOrig("system");
- my @use_dhcp_nameservers = $vyatta_config->returnOrigValues("dhcp");
- my @use_nameservers = $vyatta_config->returnOrigValues("name-server");
- my @resolv_conf_nameservers = `grep "^nameserver" /etc/resolv.conf`;
- my @dnsmasq_conf_nameservers = `grep "server=" /etc/dnsmasq.conf`;
- my @dnsmasq_running = `ps ax | grep dnsmasq | grep -v grep`;
-
- if (!(defined $use_system_nameservers) && (@use_dhcp_nameservers == 0) && (@use_nameservers == 0)) {
-
- # no specific nameservers specified under DNS forwarding, so dnsmasq is getting nameservers from /etc/resolv.conf
-
- if (! @resolv_conf_nameservers > 0){
- $show_nameservers_output .= "No DNS servers present to forward queries to.\n";
- if (! @dnsmasq_running > 0){
- $show_nameservers_output .= "DNS forwarding has not been configured either.\n";
- }
- } else {
- if (! @dnsmasq_running > 0){
- $show_nameservers_output .= "\n**DNS forwarding has not been configured**\n\n";
- }
- $show_nameservers_output .= "-----------------------------------------------\n";
- if ( @dnsmasq_running > 0){
- $show_nameservers_output .= " Nameservers configured for DNS forwarding\n";
- } else {
- $show_nameservers_output .= " Nameservers NOT configured for DNS forwarding\n";
- }
- $show_nameservers_output .= "-----------------------------------------------\n";
- foreach my $line (@resolv_conf_nameservers) {
- my @split_line = split(/\s+/, $line);
- my $nameserver = $split_line[1];
- my $nameserver_via = "system";
- if (@split_line > 2) {
- my @dhclient_resolv_files = `ls /etc/resolv.conf.dhclient-new-* 2>/dev/null`;
- foreach my $each_dhcp_resolv_conf (@dhclient_resolv_files) {
- my @ns_dhclient_resolv=`grep "$nameserver\$" $each_dhcp_resolv_conf`;
- if ( @ns_dhclient_resolv > 0) {
- my @dhclient_file_array = split(/-/, $each_dhcp_resolv_conf);
- $nameserver_via = $dhclient_file_array[2];
- chomp $nameserver_via;
- $nameserver_via = 'dhcp ' . $nameserver_via;
- }
- }
- # check here if nameserver_via is still system, if yes then search /etc/ppp/resolv-interface.conf
- if ($nameserver_via eq "system") {
- my @ppp_resolv_files = `ls /etc/ppp/resolv-*conf 2>/dev/null`;
- foreach my $each_ppp_resolv_conf (@ppp_resolv_files) {
- my @ns_ppp_resolv=`grep "$nameserver\$" $each_ppp_resolv_conf`;
- if ( @ns_ppp_resolv > 0) {
- my @ppp_file_array = split(/-/, $each_ppp_resolv_conf);
- @ppp_file_array = split(/\./, $ppp_file_array[1]);
- $nameserver_via = $ppp_file_array[0];
- chomp $nameserver_via;
- $nameserver_via = 'ppp ' . $nameserver_via;
- }
- }
- }
- }
- $show_nameservers_output .= "$nameserver available via '$nameserver_via'\n";
- }
- }
- $show_nameservers_output .= "\n";
- } else {
-
- # nameservers specified under DNS forwarding, so dnsmasq getting nameservers from /etc/dnsmasq.conf
-
- my @active_nameservers;
- my $active_nameserver_count = 0;
- $show_nameservers_output .= "-----------------------------------------------\n";
- $show_nameservers_output .= " Nameservers configured for DNS forwarding\n";
- $show_nameservers_output .= "-----------------------------------------------\n";
- my $show_nameservers_output_dhcp;
- my $show_nameservers_output_domain;
- my $show_nameservers_output_nameserver;
-
- my $line_flag;
- ## server=/test.com/1.1.1.1
- foreach my $line (@dnsmasq_conf_nameservers) {
- my @split_line = split(/=/, $line);
- my @nameserver_array = split(/\s+/, $split_line[1]);
- my $nameserver = $nameserver_array[0];
- my $domain;
- my @domain_tokens;
-
- if ($nameserver_array[2] eq "domain-override")
- {
- #$nameserver has /test.com/1.1.1.1, seperate it.
- @domain_tokens = split(/\//, $nameserver);
- if (!defined($line_flag)) {
- $line_flag = 1;
- $show_nameservers_output_domain .= "\n";
- $show_nameservers_output_domain .= "Domain Overrides:\n";
- $show_nameservers_output_domain .= "\n";
- }
- }
- $active_nameservers[$active_nameserver_count] = $nameserver;
- $active_nameserver_count++;
- my $nameserver_via = $nameserver_array[2];
- if (@nameserver_array > 3){
- my $dhcp_interface = $nameserver_array[3];
- $show_nameservers_output_dhcp .= "$nameserver available via '$nameserver_via $dhcp_interface'\n";
- } elsif (@domain_tokens) {
- $show_nameservers_output_domain .= "$domain_tokens[1] uses $domain_tokens[2]\n";
- } else {
- $show_nameservers_output_nameserver .= "$nameserver available via '$nameserver_via'\n";
- }
- }
- if (defined ($show_nameservers_output_nameserver)) {
- $show_nameservers_output .= $show_nameservers_output_nameserver;
- }
- if (defined ($show_nameservers_output_dhcp)) {
- $show_nameservers_output .= $show_nameservers_output_dhcp;
- }
- if (defined ($show_nameservers_output_domain)) {
- $show_nameservers_output .= $show_nameservers_output_domain ;
- }
-
- # then you need to get nameservers from /etc/resolv.conf that are not in dnsmasq.conf to show them as inactive
-
- my $active_dnsmasq_nameserver;
- my $output_inactive_nameservers = 0;
- foreach my $resolv_conf_line (@resolv_conf_nameservers) {
- my @resolv_conf_split_line = split(/\s+/, $resolv_conf_line);
- my $resolv_conf_nameserver = $resolv_conf_split_line[1];
- $active_dnsmasq_nameserver = 0;
- my $resolv_nameserver_via = "system";
- foreach my $dnsmasq_nameserver (@active_nameservers) {
- if ($dnsmasq_nameserver eq $resolv_conf_nameserver) {
- $active_dnsmasq_nameserver = 1;
- }
- }
- if ($active_dnsmasq_nameserver == 0) {
- if ($output_inactive_nameservers == 0){
- $output_inactive_nameservers = 1;
- $show_nameservers_output .= "\n-----------------------------------------------\n";
- $show_nameservers_output .= " Nameservers NOT configured for DNS forwarding\n";
- $show_nameservers_output .= "-----------------------------------------------\n";
- }
- if (@resolv_conf_split_line > 2) {
- my @dhclient_resolv_files = `ls /etc/resolv.conf.dhclient-new-* 2>/dev/null`;
- foreach my $each_dhcp_resolv_conf (@dhclient_resolv_files) {
- chomp $each_dhcp_resolv_conf;
- my @ns_dhclient_resolv=`grep "$resolv_conf_nameserver\$" $each_dhcp_resolv_conf`;
- if ( @ns_dhclient_resolv > 0) {
- my @dhclient_file_array = split(/-/, $each_dhcp_resolv_conf);
- $resolv_nameserver_via = $dhclient_file_array[2];
- chomp $resolv_nameserver_via;
- $resolv_nameserver_via = 'dhcp ' . $resolv_nameserver_via;
- }
- }
- # check here if resolv_nameserver_via is still system, if yes then search /etc/ppp/resolv-interface.conf
- if ($resolv_nameserver_via eq "system") {
- my @ppp_resolv_files = `ls /etc/ppp/resolv-*conf 2>/dev/null`;
- foreach my $each_ppp_resolv_conf (@ppp_resolv_files) {
- my @ns_ppp_resolv=`grep "$resolv_conf_nameserver\$" $each_ppp_resolv_conf`;
- if ( @ns_ppp_resolv > 0) {
- my @ppp_file_array = split(/-/, $each_ppp_resolv_conf);
- @ppp_file_array = split(/\./, $ppp_file_array[1]);
- $resolv_nameserver_via = $ppp_file_array[0];
- chomp $resolv_nameserver_via;
- $resolv_nameserver_via = 'ppp ' . $resolv_nameserver_via;
- }
- }
- }
- }
-
- $show_nameservers_output .= "$resolv_conf_nameserver available via '$resolv_nameserver_via'\n";
- }
- }
- $show_nameservers_output .= "\n";
- }
-}
-
-sub print_nameservers {
- print $show_nameservers_output;
-}
-
-sub wait_for_write {
-
- my $last_size = (stat($dnsmasq_log))[7];
- my $cnt=0;
- while(1) {
- system("usleep 10000"); # sleep for 0.01 second
- my $curr_size = (stat($dnsmasq_log))[7];
- if( $curr_size == $last_size ) {
- # Not modified
- $cnt++;
- last if($cnt > 1);
- } else {
- # Modified\n
- $cnt=0;
- }
- $last_size = $curr_size;
- }
-
-}
-
-#
-# main
-#
-my ($clear_cache, $clear_all, $show_statistics, $show_nameservers);
-
-GetOptions("clear-cache!" => \$clear_cache,
- "clear-all!" => \$clear_all,
- "show-statistics!" => \$show_statistics,
- "show-nameservers!" => \$show_nameservers);
-
-if (defined $clear_cache) {
- system("kill -1 `pidof dnsmasq`");
-}
-
-if (defined $clear_all) {
- system("/etc/init.d/dnsmasq restart >&/dev/null");
-}
-
-if (defined $show_statistics) {
- system("echo > $dnsmasq_log; kill -10 `pidof dnsmasq`");
- wait_for_write;
- get_cache_stats;
- get_nameserver_stats;
- print_stats;
-}
-
-if (defined $show_nameservers) {
- get_dns_nameservers;
- print_nameservers;
-}
-
-exit 0;
-
-# end of file
diff --git a/scripts/vyatta-show-dhclient.pl b/scripts/vyatta-show-dhclient.pl
index 5064c1c..40e284b 100755
--- a/scripts/vyatta-show-dhclient.pl
+++ b/scripts/vyatta-show-dhclient.pl
@@ -28,7 +28,7 @@ use POSIX;
use strict;
use warnings;
-my $lease_dir = '/var/lib/dhcp3';
+my $lease_dir = '/var/lib/dhcp';
sub dhclient_get_lease_files {
my ($intf) = @_;
diff --git a/scripts/vyatta-show-snmp-ifmib b/scripts/vyatta-show-snmp-ifmib
deleted file mode 100644
index 8fb1004..0000000
--- a/scripts/vyatta-show-snmp-ifmib
+++ /dev/null
@@ -1,138 +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.
-#
-# Author: Stephen Hemminger
-# Date: Novemember 2010
-# Description: Script for show snmp ifmib
-#
-# **** End License ****
-
-use strict;
-use warnings;
-use Getopt::Long;
-use POSIX qw(strtol);
-
-# This is used to show values corresponding to to results IF-MIB.
-my %interfaces;
-
-sub show_ifindex {
- foreach my $ifname (@_) {
- my $info = $interfaces{$ifname};
- my $ifindex = $info->{'ifIndex'};
- printf "%s: ifIndex = %d\n", $ifname, $ifindex;
- }
-}
-
-sub show_ifalias {
- foreach my $ifname (@_) {
- my $info = $interfaces{$ifname};
- my $ifalias = $info->{'ifAlias'};
- printf "%s: ifAlias = %s\n", $ifname,
- defined($ifalias) ? $ifalias : $ifname;
- }
-}
-
-sub read_sysfs {
- my $filename = shift;
-
- open( my $f, '<', $filename )
- or return; # not a PCI device
-
- my $val = <$f>;
- close $f;
-
- return strtol($val);
-}
-
-# Imitate code in net-snmp to lookup PC
-# TODO - move to common code extension (and handle USB?)
-sub pci_info {
- my $ifname = shift;
- my $vendor_id = read_sysfs("/sys/class/net/$ifname/device/vendor");
- my $device_id = read_sysfs("/sys/class/net/$ifname/device/device");
-
- return unless ( defined($vendor_id) && defined($device_id) );
-
- my $cmd = sprintf("lspci -m -d %04x:%04x", $vendor_id, $device_id);
- open( my $pci, '-|', $cmd )
- or die "Can't run $cmd";
- my $info = <$pci>;
- close $pci;
-
- return unless $info;
-
- # extract vendor and device description from output
- $info =~ /^\S+ "[^"]*" "([^"]*)" "([^"]*)"/;
-
- return "$1 $2";
-}
-
-sub show_ifdescr {
- foreach my $ifname (@_) {
- my $ifdescr = pci_info($ifname);
-
- printf "%s: ifDescr = %s\n", $ifname,
- defined($ifdescr) ? $ifdescr : $ifname;
- }
-}
-
-sub show_all {
- foreach my $ifname (@_) {
- my $info = $interfaces{$ifname};
- my $ifindex = $info->{'ifIndex'};
- my $ifalias = $info->{'ifAlias'};
- my $ifdescr = pci_info($ifname);
-
- printf "%s: ifIndex = %d\n", $ifname, $ifindex;
-
- my $pad = sprintf( "%-*s", length($ifname) + 1, " " );
- printf "%s ifAlias = %s\n", $pad, $ifalias if ($ifalias);
- printf "%s ifDescr = %s\n", $pad, $ifdescr if ($ifdescr);
- }
-}
-
-my $show = \&show_all;
-
-GetOptions(
- "ifindex" => sub { $show = \&show_ifindex },
- "ifalias" => sub { $show = \&show_ifalias },
- "ifdescr" => sub { $show = \&show_ifdescr },
-) or die "Unknown option\n";
-
-# List of all interfaces that currently exist on system
-# includes interfaces that may be outside Vyatta CLI because
-# they still show up in SNMP
-open( my $ip, '-|', 'ip li' )
- or die "Can't run ip command\n";
-
-my $ifname;
-while (<$ip>) {
- if (/^(\d+): ([^:]*): /) {
- $ifname = $2;
- $interfaces{$ifname} = { 'ifIndex' => $1 };
- }
- elsif (/^ +alias (.*)$/) {
- $interfaces{$ifname}->{'ifAlias'} = $1;
- }
-}
-close $ip;
-
-if (@ARGV) {
- $show->(@ARGV);
-}
-else {
- $show->( sort keys %interfaces );
-}
diff --git a/scripts/vyatta-show-snmp-v3.pl b/scripts/vyatta-show-snmp-v3.pl
deleted file mode 100644
index dc81623..0000000
--- a/scripts/vyatta-show-snmp-v3.pl
+++ /dev/null
@@ -1,168 +0,0 @@
-#! /usr/bin/perl
-
-use Getopt::Long;
-
-sub show_view() {
- print <<END;
-
-SNMPv3 Views:
-
-END
-
- foreach my $view ( listNodes("view") ) {
- print "View : $view\nOIDs :\n";
- foreach my $oid ( listNodes("view $view oid") ) {
- my $exclude = '';
- $exclude = ' exclude'
- if ( isExists("view $view oid $oid exclude") );
- my $mask = '';
- if ( isExists("view $view oid $oid mask") ) {
- my $value = returnValue("view $view oid $oid mask");
- $mask = " mask $value";
- }
- print " .$oid$exclude$mask\n";
- }
- print "\n";
- }
-}
-
-sub show_group() {
- print <<END;
-
-SNMPv3 Groups:
-
-Group View
------ ----
-END
-
- foreach my $group ( listNodes("group") ) {
- my $view = returnValue("group $group view");
- my $mode = returnValue("group $group mode");
- if ( length($group) >= 20 ) {
- print "$group\n $view($mode)\n";
- }
- else {
- $~ = "GROUP_FORMAT";
- format GROUP_FORMAT =
-@<<<<<<<<<<<<<<<<<< @*(@*)
-$group $view $mode
-.
- write;
- }
- }
- print "\n";
-}
-
-sub show_user() {
- print <<END;
-
-SNMPv3 Users:
-
-User Auth Priv Mode Group
----- ---- ---- ---- -----
-END
-
- foreach my $user ( listNodes("user") ) {
- my $auth = returnValue("user $user auth type");
- my $priv = returnValue("user $user privacy type");
- my $mode = returnValue("user $user mode");
- my $group = returnValue("user $user group");
- if ( length($user) >= 20 ) {
- print "$user\n $auth $priv $mode $group\n";
- }
- else {
- $~ = "USER_FORMAT";
- format USER_FORMAT =
-@<<<<<<<<<<<<<<<<<< @<<< @<<< @<<< @*
-$user $auth $priv $mode $group
-.
- write;
- }
- }
- print "\n";
-}
-
-sub show_trap() {
- print <<END;
-
-SNMPv3 Trap-targets:
-
-Tpap-target Port Protocol Auth Priv Type EngineID User
------------ ---- -------- ---- ---- ---- -------- ----
-END
-
- foreach my $trap ( listNodes("trap-target") ) {
- my $auth = returnValue("trap-target $trap auth type");
- my $priv = returnValue("trap-target $trap privacy type");
- my $type = returnValue("trap-target $trap type");
- my $port = returnValue("trap-target $trap port");
- my $user = returnValue("trap-target $trap user");
- my $protocol = returnValue("trap-target $trap protocol");
- my $engineid = returnValue("trap-target $trap engineid");
- if ( length($trap) >= 30 ) {
- $~ = "TRAP_BIG_FORMAT";
- format TRAP_BIG_FORMAT =
-^*
-$trap
- @<<<<< @<<<<<<< @<<< @<<< @<<<<< @<<<<<<<<<<<<<<<<<<<<... @*
-$port $protocol $auth $priv $type $engineid $user
-.
- write;
- }
- else {
- $~ = "TRAP_FORMAT";
- format TRAP_FORMAT =
-@<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<< @<<<<<<< @<<< @<<< @<<<<< @<<<<<<<<<<<<<<<<<<<<... @*
-$trap $port $protocol $auth $priv $type $engineid $user
-.
- write;
- }
- }
- print "\n";
-}
-
-sub show_all() {
- show_user();
- show_group();
- show_view();
- show_trap();
-}
-
-sub listNodes {
- my $path = shift;
- my @nodes =
- split( ' ', `cli-shell-api listActiveNodes service snmp v3 $path` );
- return map { substr $_, 1, -1 } @nodes;
-}
-
-sub returnValue {
- my $path = shift;
- my $value = `cli-shell-api returnActiveValue service snmp v3 $path`;
- return $value;
-}
-
-sub isExists {
- my $path = shift;
- system("cli-shell-api existsActive service snmp v3 $path");
- return !$?;
-}
-
-my $all;
-my $view;
-my $group;
-my $user;
-my $trap;
-
-GetOptions(
- "all!" => \$all,
- "view!" => \$view,
- "group!" => \$group,
- "user!" => \$user,
- "trap!" => \$trap,
-);
-
-show_all() if ($all);
-show_view() if ($view);
-show_group() if ($group);
-show_user() if ($user);
-show_trap() if ($trap);
diff --git a/scripts/vyatta-show-snmp.pl b/scripts/vyatta-show-snmp.pl
deleted file mode 100755
index 634b3cc..0000000
--- a/scripts/vyatta-show-snmp.pl
+++ /dev/null
@@ -1,123 +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.
-#
-# Author: Stephen Hemminger
-# Date: January 2010
-# Description: Script to display SNMP information
-#
-# **** End License ****
-#
-use strict;
-use warnings;
-use Getopt::Long;
-use NetAddr::IP;
-
-my $SNMPDCFG = '/etc/snmp/snmpd.conf';
-my $SNMPSTATUS = '/usr/bin/snmpstatus';
-my $password_file = '/config/snmp/superuser_pass';
-
-# generate list of communities in configuration file
-sub read_config {
- my %community;
-
- die "Service SNMP does not configured.\n" if (! -e $SNMPDCFG);
-
- open( my $cfg, '<', $SNMPDCFG )
- or die "Can't open $SNMPDCFG : $!\n";
-
- while (<$cfg>) {
- chomp;
- s/#.*$//;
- my @cols = split;
- next
- unless ( $#cols > 0
- && ( $cols[0] eq 'rocommunity' || $cols[0] eq 'rwcommunity' ) );
-
- my $addr = ( $#cols > 1 ) ? $cols[2] : "0.0.0.0/0";
- $community{ $cols[1] } = NetAddr::IP->new($addr);
- }
- close $cfg;
-
- return \%community;
-}
-
-# expand list of available communities for allowed: tag
-sub show_all {
- my $community = read_config();
-
- print join( ' ', keys( %{$community} ) ), "\n";
- exit 0;
-}
-
-# check status of any accessible community on localhost
-sub status_any {
- my $cref = read_config();
- my %community = %{$cref};
- my $localhost = new NetAddr::IP('localhost');
-
- if (scalar(%community)) {
- foreach my $c ( keys %community ) {
- my $addr = $community{$c};
- status( $c, $localhost->addr() ) if ( $addr->contains($localhost) );
- }
- }
- status_v3();
-
-}
-
-sub status_v3 {
- open (my $file, '<' , $password_file) or die "Couldn't open $password_file - $!";
- my $superuser_pass = do { local $/; <$file> };
- close $file;
- open ($file, '<', $SNMPDCFG) or die "Couldn't open $SNMPDCFG - $!";
- my $superuser_login = '';
- while (my $line = <$file>) {
- if ($line =~ /^iquerySecName (.*)$/) {
- $superuser_login = $1;
- }
- }
- close $file;
- exec $SNMPSTATUS, '-v3', '-l', 'authNoPriv', '-u', $superuser_login, '-A', $superuser_pass, 'localhost';
-}
-
-# check status of one community
-sub status {
- my ( $community, $host ) = @_;
- $host = 'localhost' unless defined($host);
-
- print "Status of SNMP community $community on $host\n";
- exec $SNMPSTATUS, '-v1', '-c', $community, $host;
- die "Can't exec $SNMPSTATUS : $!";
-}
-
-sub usage {
- print "usage: $0 [--community=name [--host=hostname]]\n";
- print " $0 --allowed\n";
- exit 1;
-}
-
-my ( $host, $community, $allowed );
-
-GetOptions(
- "host=s" => \$host,
- "community=s" => \$community,
- "allowed" => \$allowed,
-) or usage();
-
-show_all() if ($allowed);
-status( $community, $host ) if ( defined($community) );
-status_any();
-
diff --git a/scripts/vyatta-show-version b/scripts/vyatta-show-version
deleted file mode 100755
index dd4f7bc..0000000
--- a/scripts/vyatta-show-version
+++ /dev/null
@@ -1,255 +0,0 @@
-#!/usr/bin/perl -w
-#
-# Module: show_version
-#
-# **** 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) 2005-2013 Vyatta, Inc.
-# All Rights Reserved.
-#
-# Author: Rick Balocca
-# Date: 2007
-# Description:
-#
-# **** End License ****
-#
-use strict;
-use warnings;
-
-#
-# Global hash of debians in the base install and now.
-#
-my $rHoH_base_debs;
-my $rHoH_now_debs;
-
-my $base = '/opt/vyatta/etc';
-my $versionfile = "$base/version";
-my $buildfile = "$base/build.txt";
-my $debsfile = "$base/deb-versions.txt";
-
-sub echo_file {
- my ($file) = @_;
-
- my @lines = ();
- if (!(-e $file)) {
- return @lines;
- }
-
- open(my $FH, '<', $file) or die "Unable to open [$file]\n";
- @lines=<$FH>;
- close($FH);
- return @lines;
-}
-
-# This follows the chain from /boot/grub/menu.cfg which
-# boots /boot/vmlinuz to find the version of kernel running
-sub get_image_type {
- my $kernel = readlink('/boot/vmlinuz');
- my $version;
-
- unless (defined($kernel)) {
- warn "Can not read link /boot/vmlinuz: $!\n";
- return;
- }
-
- unless ($kernel =~ /^vmlinuz-.*-([^-]*)-(vyatta|vyos)(.*)$/) {
- warn "Unknown kernel version: $kernel\n";
- return;
- }
-
- # XXX: Maybe just check 'uname -m' ?
- if ($1 eq '586') {
- $version = "x86 32-bit";
- } elsif ($1 eq "amd64") {
- $version = "x86 64-bit";
- } else {
- $version = $1;
- }
-
- if ($3 eq '-virt') {
- $version .= " Virtual"
- }
-
- return $version;
-}
-
-#
-# convert the "dpkg -l" output have same format as deb-versions.txt
-#
-sub get_pkg_version {
- my @lines = @_;
-
- my @new_lines = ();
- foreach my $line (@lines) {
- if ($line =~ /^[D\|\+]/) {
- next; # skip header
- }
- my ($status, $pkg, $version) = split(/[ \t\n]+/, $line, 4);
- if ($status =~ /^i/) {
- push(@new_lines, "$pkg $version");
- }
- }
- return @new_lines;
-}
-
-sub read_pkg_file {
- my @pkgs_list = @_;
-
- my %HoH = ();
- my ($name, $version);
- foreach my $line (@pkgs_list) {
- ($name, $version) = split(/[ \t\n]+/, $line, 3);
- $HoH{$name}{'version'} = $version;
- }
- return \%HoH;
-}
-
-sub show_added {
- for my $name (sort keys %$rHoH_now_debs) {
- if (!$rHoH_base_debs->{$name}) {
- printf("Aii %-25s %-25s\n",
- $name, $rHoH_now_debs->{$name}->{'version'});
- }
- }
-}
-
-sub show_deleted {
- for my $name (sort keys %$rHoH_base_debs) {
- if (!$rHoH_now_debs->{$name}) {
- printf("X %-25s %-25s\n",
- $name, $rHoH_base_debs->{$name}->{'version'});
- }
- }
-}
-
-sub show_upgraded_downgraded {
- my ($up_down) = @_;
-
- my ($symbol, $op, $ver_base, $ver_now, $cmd);
- if ($up_down eq "upgraded") {
- $symbol = "U";
- $op = "lt";
- } else {
- $symbol = "D";
- $op = "gt";
- }
- for my $name (sort keys %$rHoH_base_debs) {
- if ($rHoH_now_debs->{$name}) {
- $ver_base = $rHoH_base_debs->{$name}{'version'};
- $ver_now = $rHoH_now_debs->{$name}{'version'};
- if ($ver_base ne $ver_now) {
- $cmd = "dpkg --compare-versions \"$ver_base\" $op \"$ver_now\"";
- if (!system($cmd)) {
- printf("%sii %-25s %-20s (baseline: %s)\n",
- $symbol, $name, $ver_now, $ver_base);
- }
- }
- }
- }
-}
-
-sub show_upgraded {
- show_upgraded_downgraded("upgraded");
-}
-
-sub show_downgraded {
- show_upgraded_downgraded("downgraded");
-}
-
-sub show_all {
- show_added();
- show_deleted();
- show_upgraded();
- show_downgraded();
-}
-
-my %options = (
- "added" => \&show_added,
- "deleted", => \&show_deleted,
- "upgraded" => \&show_upgraded,
- "downgraded" => \&show_downgraded,
- "all" => \&show_all,
-);
-
-#
-# main
-#
-my $hv = `hvinfo`;
-if (defined($hv) && $hv ne "") {
- $versionfile .= "-virt";
-}
-print(&echo_file($versionfile));
-print(&echo_file($buildfile));
-
-my $type = get_image_type();
-if ($type) {
- print "System type: $type\n";
-}
-
-my $booted = `grep -e '^overlayfs.*/filesystem.squashfs' /proc/mounts`;
-if (defined($booted) && $booted ne "") {
- $booted="livecd";
-} else {
- my $image_boot = `grep -e '^overlayfs /' /proc/mounts`;
- if ($image_boot ne "") {
- $booted="image";
- } else {
- $booted="disk";
- }
-}
-print "Boot via: $booted\n";
-
-if (defined($hv) && $hv ne "") {
- chomp $hv;
- print "Hypervisor: $hv\n";
-}
-
-
-my $plat_model = `sudo /usr/sbin/dmidecode -s system-product-name`;
-chomp $plat_model;
-my $plat_sn = `sudo /usr/sbin/dmidecode -s system-serial-number`;
-chomp $plat_sn;
-my $plat_uuid = `sudo /usr/sbin/dmidecode -s system-uuid`;
-chomp $plat_uuid;
-
-if (defined $plat_model && $plat_model ne "" && $plat_model ne " ") {
- print "HW model: $plat_model\n"
-}
-
-if (defined $plat_sn && $plat_sn ne "" && $plat_sn ne " ") {
- print "HW S/N: $plat_sn\n"
-}
-
-if (defined $plat_uuid && $plat_uuid ne "" && $plat_uuid ne " ") {
- print "HW UUID: $plat_uuid\n"
-}
-
-my $uptime = `uptime`;
-if (defined $uptime && $uptime ne "") {
- print "Uptime: $uptime\n";
-}
-
-if (!(-e $debsfile)) {
- exit 0;
-}
-print "\n";
-$rHoH_base_debs = read_pkg_file(&echo_file($debsfile));
-$rHoH_now_debs = read_pkg_file(get_pkg_version(`dpkg -l 2> /dev/null`));
-
-if ($#ARGV == 0) {
- if ($options{$ARGV[0]}) {
- $options{$ARGV[0]}->();
- } else {
- print "Usage: showversion [added|deleted|upgraded|downgraded|all]\n";
- exit 1;
- }
-}
diff --git a/scripts/vyatta-tshark-interface-port.pl b/scripts/vyatta-tshark-interface-port.pl
deleted file mode 100755
index aa750e5..0000000
--- a/scripts/vyatta-tshark-interface-port.pl
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/usr/bin/perl
-#
-# Module: vyatta-tshark-interface-port.pl
-#
-# **** 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) 2006, 2007, 2008 Vyatta, Inc.
-# All Rights Reserved.
-#
-# Author: Mohit Mehta
-# Date: April 2008
-# Description: tshark on a given port for a given interface from vyatta cli
-#
-# **** End License ****
-#
-
-use lib "/opt/vyatta/share/perl5/";
-
-use strict;
-use warnings;
-
-sub check_if_interface_is_tsharkable {
- my $interface = shift;
-
- my @grep_tshark_interfaces = `sudo /usr/bin/tshark -D | grep $interface`;
- my $any_interface;
-
- for my $count (0 .. $#grep_tshark_interfaces) {
- my @temp = split(/ /,$grep_tshark_interfaces[$count]);
- chomp $temp[1];
- $grep_tshark_interfaces[$count] = $temp[1];
- }
-
- my $exact_match = 0;
- for my $count (0 .. $#grep_tshark_interfaces) {
- if ($grep_tshark_interfaces[$count] eq $interface) {
- $exact_match = 1;
- $any_interface = $grep_tshark_interfaces[$count];
- }
- }
- if ($exact_match == 0 || $any_interface eq 'any') {
- print "Unable to capture traffic on $interface\n";
- exit 1;
- }
-}
-
-#
-# main
-#
-
-my $intf = $ARGV[0];
-
-check_if_interface_is_tsharkable($intf);
-
-if ($#ARGV > 0){
- my $port = $ARGV[1];
- my $not_port = $ARGV[2];
- if ($port =~ /[a-zA-Z]/){
- print "Port number has to be numeric. Allowed values: <1-65535>\n";
- exit 1;
- } else {
- if (($port > 0) and ($port < 65536)){
- if ($not_port == 0){
- print "Capturing traffic on $intf port $port ...\n";
- exec "sudo /usr/bin/tshark -n -i $intf port $port 2> /dev/null";
- } else {
- print "Capturing traffic on $intf excluding port $port ...\n";
- exec "sudo /usr/bin/tshark -n -i $intf not port $port 2> /dev/null";
- }
- } else {
- print "Invalid port number. Allowed values: <1-65535>\n";
- exit 1;
- }
-
- }
-} else {
- print "Capturing traffic on $intf ...\n";
- exec "sudo /usr/bin/tshark -n -i $intf 2> /dev/null";
-}
-
-exit 0;
-
-#end of file
diff --git a/scripts/vyatta-tshark.pl b/scripts/vyatta-tshark.pl
deleted file mode 100755
index 5423cfc..0000000
--- a/scripts/vyatta-tshark.pl
+++ /dev/null
@@ -1,150 +0,0 @@
-#!/usr/bin/perl
-#
-# Module: vyatta-tshark-interface-port.pl
-#
-# **** 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) 2006, 2007, 2008 Vyatta, Inc.
-# All Rights Reserved.
-#
-# Author: John Southworth
-# Date: Sept. 2011
-# Description: run tshark on a given interface with options
-#
-# **** End License ****
-#
-
-use lib "/opt/vyatta/share/perl5/";
-
-use strict;
-use warnings;
-use Getopt::Long;
-
-sub check_if_interface_is_tsharkable {
- my $interface = shift;
-
- my @grep_tshark_interfaces = `/usr/bin/tshark -D | grep $interface`;
- my $any_interface;
-
- for my $count (0 .. $#grep_tshark_interfaces) {
- my @temp = split(/ /,$grep_tshark_interfaces[$count]);
- chomp $temp[1];
- $grep_tshark_interfaces[$count] = $temp[1];
- }
-
- my $exact_match = 0;
- for my $count (0 .. $#grep_tshark_interfaces) {
- if ($grep_tshark_interfaces[$count] eq $interface) {
- $exact_match = 1;
- $any_interface = $grep_tshark_interfaces[$count];
- }
- }
- if ($exact_match == 0 || $any_interface eq 'any') {
- print "Unable to capture traffic on $interface\n";
- exit 1;
- }
-}
-
-my ($detail,$filter,$intf,$unlimited,$save,$files,$size);
-
-#
-# The size parameter can have one of the following
-# unit suffixes:
-#
-# - [kK] KiB (1024 bytes)
-# - [mM] MiB (1048576 bytes)
-# - [gG] GiB (1073741824 bytes)
-# - [tT] TiB (109951162778 bytes)
-#
-# Note: tshark's default size unit is KiB
-sub parse_size {
- my ( $name, $parm ) = @_;
- my %mult = ('T' => 1073741824, 't' => 1073741824,
- 'G' => 1048576, 'g' => 1048576,
- 'M' => 1024, 'm' => 1024,
- 'K' => 1, 'k' => 1);
-
- die "Invalid parameter: $name" if ($name ne "size");
- my ( $value, $unit ) = $parm =~ m/^([0-9]+)([kKmMgGtT])?$/;
- die "Invalid size specified" unless $value;
- $unit = "K" unless $unit;
- $size = $value * $mult{$unit};
-}
-
-#
-# main
-#
-
-my $result = GetOptions("detail!" => \$detail,
- "filter=s" => \$filter,
- "save=s" => \$save,
- "intf=s" => \$intf,
- "unlimited!" => \$unlimited,
- "files=i" => \$files,
- "size=s" => \&parse_size);
-
-if (! $result) {
- print "Invalid option specifications\n";
- exit 1;
-}
-
-check_if_interface_is_tsharkable($intf);
-
-if (defined($save)){
- if (!($save =~ /.*\.pcap/)) {
- print("Please name your file <filename>.pcap\n");
- exit 1;
- }
- my $options = "";
-
- # the CLI will make sure that files is not defined w/o size also
- $options .= " -a filesize:$size" if defined($size);
- $options .= " -b files:$files" if defined($files);
- exec "/usr/bin/tshark -i $intf -w '$save' $options";
- exit 0;
-}
-
-if (defined($filter)) {
- if (defined($detail)) {
- if (defined($unlimited)){
- print "Capturing traffic on $intf ...\n";
- exec "/usr/bin/tshark -n -i $intf -V $filter 2> /dev/null";
- } else {
- print "Capturing traffic on $intf ...\n";
- exec "/usr/bin/tshark -n -i $intf -c 1000 -V $filter 2> /dev/null";
- }
- } elsif (defined($unlimited)) {
- print "Capturing traffic on $intf ...\n";
- exec "/usr/bin/tshark -n -i $intf $filter 2> /dev/null";
- } else {
- print "Capturing traffic on $intf ...\n";
- exec "/usr/bin/tshark -n -i $intf -c 1000 $filter 2> /dev/null";
- }
-} elsif (defined($detail)) {
- if (defined($unlimited)) {
- print "Capturing traffic on $intf ...\n";
- exec "/usr/bin/tshark -n -i $intf -V 2> /dev/null";
- } else {
- print "Capturing traffic on $intf ...\n";
- exec "/usr/bin/tshark -n -i $intf -c 1000 -V 2> /dev/null";
- }
-} elsif (defined($unlimited)) {
- print "Capturing traffic on $intf ...\n";
- exec "/usr/bin/tshark -n -i $intf 2> /dev/null";
-} else {
- print "Capturing traffic on $intf ...\n";
- exec "/usr/bin/tshark -n -i $intf -c 1000 2> /dev/null";
-}
-
-exit 0;
-
-#end of file
diff --git a/scripts/vyos-openvpn-remoteconfig.pl b/scripts/vyos-openvpn-remoteconfig.pl
new file mode 100644
index 0000000..1777d08
--- /dev/null
+++ b/scripts/vyos-openvpn-remoteconfig.pl
@@ -0,0 +1,122 @@
+#!/usr/bin/perl
+#
+# Copyright (C) 2017 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later 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, see <http://www.gnu.org/licenses/>.
+
+use lib "/opt/vyatta/share/perl5/";
+use Vyatta::Config;
+
+use warnings;
+use strict;
+
+sub auth_warning
+{
+ print("NOTE: authentication options are deliberately left out,\n");
+ print("since we cannot know file paths on a remote system\n\n");
+}
+
+my $config = new Vyatta::Config;
+
+my $intf = $ARGV[0];
+if(!defined($intf))
+{
+ print("OpenVPN interface is not specified!\n");
+ exit(1);
+}
+
+my $remote = $ARGV[1];
+if(!defined($remote))
+{
+ print("Remote side platform is not specified!\n");
+ exit(1);
+}
+
+if(!$config->exists("interfaces openvpn $intf"))
+{
+ print("OpenVPN interface $intf does not exist!\n");
+ exit(1);
+}
+
+$config->setLevel("interfaces openvpn $intf");
+
+my $mode = $config->returnValue('mode');
+
+my $localhost = $config->returnValue("local-host");
+my $localport = $config->returnValue("local-port");
+my $remotehost = $config->returnValue("remote-host");
+my $remoteaddr = $config->returnValue("remote-address");
+my $remoteport = $config->returnValue("remote-port");
+my $cipher = $config->returnValue("encryption");
+my $hash = $config->returnValue("hash");
+my $protocol = $config->returnValue("protocol");
+my $persist = $config->exists("persistent-tunnel");
+my $tlsrole = $config->returnValue("tls role");
+my $devtype = $config->returnValue("device-type");
+my @options = $config->returnValues("openvpn-option");
+
+# local-addr is a tag node...
+# Let's limit it to only the first address for now,
+# since remote-address is limited to only one address anyway!
+my @localaddrs = $config->listNodes('local-address');
+my $localaddr = undef;
+if(@localaddrs) {
+ $localaddr = $localaddrs[0];
+}
+
+if($mode eq 'client')
+{
+ print("It is impossible to produce a complete server config from a client config!\n");
+ exit(1);
+}
+elsif($mode eq 'site-to-site')
+{
+ if($remote eq 'vyos')
+ {
+ auth_warning;
+
+ print("edit interfaces openvpn $intf\n");
+ print("set mode site-to-site\n");
+ print("set device-type $devtype\n") if defined($devtype);
+ print("set remote-host $localhost\n") if defined($localhost);
+ print("set remote-address $localaddr\n") if defined($localaddr);
+ print("set remote-port $localport\n") if defined($localport);
+ print("set local-host $remotehost\n") if defined($remotehost);
+ print("set local-address $remoteaddr\n") if defined($remoteaddr);
+ print("set local-port $remoteport\n") if defined($remoteport);
+ print("set protocol $protocol\n") if defined($protocol);
+ print("set encryption $cipher\n") if defined($cipher);
+ print("set hash $hash\n") if defined($hash);
+
+ for my $o (@options) { print("set openvpn-option \"$o\"\n"); }
+
+ print "tls role passive\n" if (defined($tlsrole) && ($tlsrole eq 'active'));
+ print "tls role active\n" if (defined($tlsrole) && ($tlsrole eq 'passive'));
+ print("top\n");
+ }
+}
+elsif($mode eq 'server')
+{
+ if($remote eq 'vyos')
+ {
+ auth_warning;
+
+ print("edit interfaces openvpn $intf\n");
+ print("set mode client");
+ print("set device-type $devtype\n") if defined($devtype);
+ print("set remote-host $localhost\n") if defined($localhost);
+ print("set remote-port $localport\n") if defined($localport);
+ print("set protocol $protocol\n") if defined($protocol);
+ print("top\n");
+ }
+}