line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/local/bin/perl |
2
|
|
|
|
|
|
|
# @(#)Brcd.pm 1.12 |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Net::Telnet::Brcd; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
96980
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
7
|
1
|
|
|
1
|
|
5
|
use Net::Telnet; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
8
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
54
|
|
9
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
10
|
1
|
|
|
1
|
|
5
|
use Socket; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
998
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
13
|
1
|
|
|
1
|
|
6
|
use constant DEBUG => 0; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
88
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
5
|
use base qw(Net::Brcd Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
708
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Variables de gestion du package |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 1.13; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Variables privées |
22
|
|
|
|
|
|
|
my $_brcd_prompt = '\w+:\w+>\s+'; |
23
|
|
|
|
|
|
|
my $_brcd_commit = 'yes, y, no, n'; |
24
|
|
|
|
|
|
|
my $_brcd_continue = 'Type to continue, Q to stop:'; |
25
|
|
|
|
|
|
|
my $_brcd_prompt_re = "/(?:${_brcd_prompt}|${_brcd_continue}|${_brcd_commit})/"; |
26
|
|
|
|
|
|
|
my $_brcd_timeout = 20; # secondes |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
0
|
|
|
0
|
1
|
|
my ($class)=shift; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(); |
32
|
0
|
|
|
|
|
|
bless $self, $class; |
33
|
0
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub proto_connect { |
37
|
0
|
|
|
0
|
1
|
|
my ($self, $switch, $user, $pass) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $proto = new Net::Telnet (Timeout => ${_brcd_timeout}, |
40
|
|
|
|
|
|
|
Prompt => "/${_brcd_prompt}/", |
41
|
|
|
|
|
|
|
); |
42
|
0
|
|
|
|
|
|
$proto->errmode("return"); |
43
|
0
|
0
|
|
|
|
|
unless ($proto->open($switch)) { |
44
|
0
|
|
|
|
|
|
croak __PACKAGE__,": Cannot open connection with '$switch': $!\n"; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
0
|
|
|
|
|
unless ($proto->login($user, $pass)) { |
47
|
0
|
|
|
|
|
|
croak __PACKAGE__,": Cannot login as $user/*****: $!\n"; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
|
$self->{PROTO} = $proto; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Retourne l'objet TELNET |
52
|
0
|
|
|
|
|
|
return $proto; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub cmd { |
57
|
0
|
|
|
0
|
1
|
|
my ($self, $cmd, @cmd)=@_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
DEBUG && warn "DEBUG: $cmd, @cmd\n"; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
my $proto = $self->{PROTO} or croak __PACKAGE__, ": Error - Not connected.\n"; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if (@cmd) { |
64
|
0
|
|
|
|
|
|
$cmd .= ' "' . join('", "', @cmd) . '"'; |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
$self->sendcmd($cmd); |
67
|
|
|
|
|
|
|
#sleep(1); # Temps d'envoi de la commande |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Lecture en passant les continue |
70
|
0
|
|
|
|
|
|
@cmd = (); |
71
|
0
|
|
|
|
|
|
CMD: while (1) { |
72
|
0
|
|
|
|
|
|
my ($str, $match) = $proto->waitfor(${_brcd_prompt_re}); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
DEBUG && warn "DEBUG:: !$match!$str!\n"; |
75
|
0
|
|
|
|
|
|
push @cmd, split m/[\n\r]+/, $str; |
76
|
0
|
0
|
|
|
|
|
if ($match eq ${_brcd_commit}) { |
77
|
0
|
|
|
|
|
|
$proto->print('yes'); |
78
|
0
|
|
|
|
|
|
next CMD; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
0
|
|
|
|
|
if ($match eq ${_brcd_continue}) { |
81
|
0
|
|
|
|
|
|
$proto->print(""); |
82
|
0
|
|
|
|
|
|
next CMD; |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
last CMD; |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
@cmd = grep {defined $_} @cmd; |
|
0
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$self->{OUTPUT} = \@cmd; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return @cmd; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub sendcmd { |
94
|
0
|
|
|
0
|
1
|
|
my ($self, $cmd) = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
my $proto = $self->{PROTO} or croak __PACKAGE__, ": Error - Not connected.\n"; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
DEBUG && $proto->dump_log("/tmp/telnet.log"); |
99
|
0
|
|
|
|
|
|
DEBUG && warn "Execute: $cmd\n"; |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
unless ($proto->print($cmd)) { |
102
|
0
|
|
|
|
|
|
croak __PACKAGE__,": Cannot send '$cmd': $!\n"; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
return 1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub sendeof { |
108
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
my $proto = $self->{PROTO} or croak __PACKAGE__, ": Error - Not connected.\n"; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
unless ($proto->print("\cD")) { |
113
|
0
|
|
|
|
|
|
croak __PACKAGE__,": Cannot Ctrl-D: $!\n"; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
return 1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub readline { |
119
|
0
|
|
|
0
|
1
|
|
my ($self, $arg_ref) = @_; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#my ($str, $match) = $proto->waitfor(m/^\s+/); |
122
|
0
|
0
|
|
|
|
|
my $proto = $self->{PROTO} or croak __PACKAGE__, ": Error - Not connected.\n"; |
123
|
|
|
|
|
|
|
#DEBUG && warn "DEBUG:: <$str>:<$match>\n"; |
124
|
|
|
|
|
|
|
#return $str; |
125
|
0
|
0
|
|
|
|
|
my $str = $proto->getline(($arg_ref?%{$arg_ref}:undef)); |
|
0
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
if ($str =~ m/{_brcd_prompt_re}/) { |
127
|
0
|
|
|
|
|
|
return; |
128
|
|
|
|
|
|
|
} |
129
|
0
|
|
|
|
|
|
return $str; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub DESTROY { |
133
|
0
|
|
|
0
|
|
|
my $self = shift; |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
$self->{PROTO}->close() if exists $self->{PROTO}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |