From 418c6cfefcdf13cf6b96dd628bcd1d75046f179b Mon Sep 17 00:00:00 2001
From: Christian Poessinger <christian@poessinger.com>
Date: Thu, 14 Jun 2018 21:17:51 +0200
Subject: T683: remove old Perl scripts for 'show snmp'

---
 Makefile.am                    |   3 -
 scripts/vyatta-show-snmp-ifmib | 138 ---------------------------------
 scripts/vyatta-show-snmp-v3.pl | 168 -----------------------------------------
 scripts/vyatta-show-snmp.pl    | 123 ------------------------------
 4 files changed, 432 deletions(-)
 delete mode 100644 scripts/vyatta-show-snmp-ifmib
 delete mode 100644 scripts/vyatta-show-snmp-v3.pl
 delete mode 100755 scripts/vyatta-show-snmp.pl

diff --git a/Makefile.am b/Makefile.am
index ad9c01a..0a1f89b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -29,9 +29,6 @@ bin_SCRIPTS     += scripts/show-users.pl
 bin_SCRIPTS     += scripts/show-dhcp-leases.pl
 bin_SCRIPTS     += scripts/vyatta-boot-image.pl
 bin_SCRIPTS	+= scripts/vyatta-sudo
-bin_SCRIPTS	+= scripts/vyatta-show-snmp.pl
-bin_SCRIPTS	+= scripts/vyatta-show-snmp-ifmib
-bin_SCRIPTS	+= scripts/vyatta-show-snmp-v3.pl
 bin_SCRIPTS	+= scripts/rename-image.pl
 bin_SCRIPTS	+= scripts/show-image-storage.pl
 bin_SCRIPTS	+= scripts/vyatta-remote-copy.pl
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();
-
-- 
cgit v1.2.3