File: Makefile.PL

package info (click to toggle)
net-telnet-cisco 1.10-5.3
  • links: PTS
  • area: main
  • in suites: buster, sid
  • size: 160 kB
  • ctags: 32
  • sloc: perl: 792; makefile: 52
file content (147 lines) | stat: -rwxr-xr-x 3,666 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# -*- perl -*-

use ExtUtils::MakeMaker;
use ExtUtils::MakeMaker qw/prompt/;
use Term::ReadKey;
use Cwd;
use Carp;
use t::Utils;

use vars qw/%LOGIN/;
$LOGIN{SAVELOGS} = "n";

# There are two files used to propagate login info:
# ./login.txt and ./tmp.txt.
#
# login.txt is used only for testing. I tire of typing the same login
# info over and over.
#
# tmp.txt is used to hand off the login info collected by Makefile.PL
# to all of the t/*.t tests. This file is written during `perl
# Makefile.PL` deleted after `make test`. It will only be created if
# the project directory has a sufficient level of perms or we can
# set it to 700. This will prevent most snooping attacks.

#------------------------------
# Main
#------------------------------

# Skip the tests here
#get_login();
fix_perms();

WriteMakefile(
    'NAME'		=> 'Net::Telnet::Cisco',
    'VERSION_FROM'	=> 'Cisco.pm',
    'PREREQ_PM'		=> { Net::Telnet    => 3.03,
			     Term::ReadKey  => 2,
			     Test::More	    => 0,
			     Cwd	    => 0,
			     FindBin	    => 0,
			     Socket	    => 0,
			     Sys::Hostname  => 0,
			     Carp	    => 0,
			     Config	    => 0,
			     File::Find	    => 0,
			   },
     ($] ge '5.005') ? (
			AUTHOR	  => 'Joshua Keroes (joshua@cpan.org)',
			ABSTRACT  => 'automate Cisco management',
		       ) : (),
);

exit;

#------------------------------
# Subs
#------------------------------

sub get_login {
    if (-r "login.txt") {
	load("login.txt");
	return;
    }

    print <<EOB;

Net::Telnet::Cisco needs to log into a router to perform it\'s full
suite of tests. To log in, we need a test router, a login, a password,
an optional enable password, and an optional SecurID/TACACS PASSCODE.

To skip these tests, hit "return".

EOB

    my $savemsg = "Save logs? (a)lways | (n)ever | only on (f)ailure:";
    {
	$LOGIN{SAVELOGS} = prompt($savemsg, $LOGIN{SAVELOGS});
	unless ($LOGIN{SAVELOGS} =~ /^[anf]/) {
	    warn qq(That\'s not a "a", "n", or "f". Try again.\n);
	    $LOGIN{SAVELOGS} = '';
	    redo;
	}

	# Only want the first character.
	$LOGIN{SAVELOGS} = substr $LOGIN{SAVELOGS}, 0, 1;
     }

    $LOGIN{ROUTER}   = prompt("Router:",   $LOGIN{ROUTER})	or return;
    $LOGIN{LOGIN}    = prompt("Login:",    $LOGIN{LOGIN})	or return;
    $LOGIN{PASSWD}   = passprompt("Password:", $LOGIN{PASSWD}) or return;
    $LOGIN{ENABLE}   = passprompt("Enable password [optional]:", $LOGIN{ENABLE});
    $LOGIN{PASSCODE} = passprompt("SecurID/TACACS PASSCODE [optional]:", $LOGIN{PASSCODE});
}

sub fix_perms {
    fixmode();

    if (-e 'logs') {
	my $d = cwd();
	die "Please remove '$d/logs', it's in the way\n" unless -d _;
    } else {
	mkdir 'logs' or die "Can't create log dir 'logs/': $!";
    }

    fixmode('logs');

    save("tmp.txt" => %LOGIN ) unless -r 'login.txt';
}


# Lifted from ExtUtils::MakeMaker, with minor mods.
#
# If the user has Term::ReadKey, we can hide any passwords
# they type from shoulder-surfing attacks.
#
# Args: "Question for user", "optional default answer"
sub passprompt ($;$) {
    my ($msg, $def) = @_;

    confess( "passprompt($msg, [$def]) called incorrectly" )
	unless defined $msg;

    local $| = 1;

    my $dispdef	 = defined $def ? "[$def] " : " ";
    $def	 = defined $def ? $def     : "";

    print "$msg $dispdef";

    my $ans;
    my $ISA_TTY = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)); # Pipe?

    if ( $ISA_TTY ) {
	if ( $Term::ReadKey::VERSION ) {
	    ReadMode( 'noecho' );
	    chomp( $ans = ReadLine(0) );
	    ReadMode( 'normal' );
	    print "\n";
	} else {
	    chomp( $ans = <STDIN> );
	}
    } else {
        print "$def\n";
    }

    return $ans ne '' ? $ans : $def;
}