script/cisco-pass.pl untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 77 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use warnings;
5 use Getopt::Long qw(:config no_ignore_case); #bundling
6 use Pod::Usage;
7  
8 use Cisco::Management;
9  
10 my $PASSWORD_LINES = "( password 7 )|(-server key 7 )|( key-string 7 )";
11 my %opt;
12 my ($opt_help, $opt_man);
13  
14 GetOptions(
15 'encrypt:s' => \$opt{encrypt},
16 'help!' => \$opt_help,
17 'man!' => \$opt_man
18 ) or pod2usage(-verbose => 0);
19  
20 pod2usage(-verbose => 1) if defined $opt_help;
21 pod2usage(-verbose => 2) if defined $opt_man;
22  
23 # Make sure at least one host was provided
24 if (!@ARGV) {
25 pod2usage(-verbose => 0, -message => "$0: argument required\n")
26 }
27  
28 if (defined($opt{encrypt})) {
29 if (my $passwd = Cisco::Management->password_encrypt($ARGV[0], $opt{encrypt})) {
30 print "$_\n" for (@{$passwd})
31 } else {
32 printf "Error - %s\n", Cisco::Management->error
33 }
34 } else {
35 my @passwords;
36 my $linecnt = 0;
37 if (-e $ARGV[0]) {
38 open(IN, $ARGV[0]);
39 while (<IN>) {
40 chomp $_;
41 if ($_ =~ $PASSWORD_LINES) { push @passwords, "($linecnt) " . $_; }
42 $linecnt++
43 }
44 close (IN)
45 } else {
46 push @passwords, $ARGV[0]
47 }
48  
49 for (@passwords) {
50 my @parts = split(/ /,$_);
51 if (my $passwd = Cisco::Management->password_decrypt($parts[$#parts])) {
52 if ($linecnt > 0) {
53 print "@parts = $passwd\n"
54 } else {
55 print "$passwd\n"
56 }
57 } else {
58 printf "Error - %s\n", Cisco::Management->error
59 }
60 }
61 }
62  
63 __END__