From e711d30377c4681e75d91f7e7202497b9ba18132 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Wed, 13 Jun 2018 13:01:53 +0200 Subject: T689: remove files no longer needed after merging PR#14 into vyos-1x. --- scripts/maya-date.py | 214 --------------------------------------------------- 1 file changed, 214 deletions(-) delete mode 100644 scripts/maya-date.py (limited to 'scripts') 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 -# -# 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, - .... - 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()) -- cgit v1.2.3 From 418c6cfefcdf13cf6b96dd628bcd1d75046f179b Mon Sep 17 00:00:00 2001 From: Christian Poessinger 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 (limited to 'scripts') 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 <= 20 ) { - print "$group\n $view($mode)\n"; - } - else { - $~ = "GROUP_FORMAT"; - format GROUP_FORMAT = -@<<<<<<<<<<<<<<<<<< @*(@*) -$group $view $mode -. - write; - } - } - print "\n"; -} - -sub show_user() { - print <= 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 <= 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