version 1.26, 2007/01/17 23:15:13 |
version 1.27, 2007/01/31 18:53:29 |
|
|
package Net::Telnet::Trango; |
package Net::Telnet::Trango; |
# $RedRiver: Trango.pm,v 1.25 2007/01/17 20:48:46 andrew Exp $ |
# $RedRiver: Trango.pm,v 1.26 2007/01/17 23:15:13 andrew Exp $ |
use strict; |
use strict; |
use warnings; |
use warnings; |
use base 'Net::Telnet'; |
use base 'Net::Telnet'; |
|
|
|
|
It also takes an optional parameter 'Decode'. If not defined it |
It also takes an optional parameter 'Decode'. If not defined it |
defaults to 1, if it is set to 0, it will not decode the output and |
defaults to 1, if it is set to 0, it will not decode the output and |
instead return an array of the lines that were returned from the |
instead return a reference to an array of the lines that were returned |
command. |
from the command. |
|
|
=cut |
=cut |
|
|
|
|
|
|
=over |
=over |
|
|
=item B<Host> |
|
|
|
- returns the name of the host that you are accessing |
|
|
|
=item B<firmware_version> |
=item B<firmware_version> |
|
|
- returns the firmware version |
- returns the firmware version |
|
|
=cut |
=cut |
|
|
|
|
my $success = 'Success.'; |
my $success = 'Success\\.'; |
my %COMMANDS = ( |
my %COMMANDS = ( |
tftpd => { decode => 'all', expect => $success }, |
tftpd => { decode => 'all', expect => $success }, |
ver => { decode => 'all' }, |
ver => { decode => 'all' }, |
|
|
my %ALIASES = ( |
my %ALIASES = ( |
bye => 'exit', |
bye => 'exit', |
restart => 'reboot', |
restart => 'reboot', |
|
Host => 'host', |
); |
); |
|
|
my %ACCESS = map { $_ => 1 } qw( |
my %ACCESS = map { $_ => 1 } qw( |
firmware_version |
firmware_version |
host_type |
host_type |
Host |
|
is_connected |
is_connected |
logged_in |
logged_in |
login_banner |
login_banner |
|
|
my $self = shift; |
my $self = shift; |
|
|
unless ( $self->SUPER::open(@_) ) { |
unless ( $self->SUPER::open(@_) ) { |
$self->last_error("Couldn't connect to " . $self->Host . ": $!"); |
$self->last_error("Couldn't connect to " . $self->host . ": $!"); |
return undef; |
return undef; |
} |
} |
|
|
|
|
-match => '/password: ?$/i', |
-match => '/password: ?$/i', |
-errmode => "return", |
-errmode => "return", |
) ) { |
) ) { |
$self->last_error("problem connecting to host (" . $self->Host . "): " . |
$self->last_error("problem connecting to host (" . $self->host . "): " . |
$self->lastline); |
$self->lastline); |
return undef; |
return undef; |
} |
} |
|
|
-match => $self->prompt, |
-match => $self->prompt, |
-errmode => "return", |
-errmode => "return", |
) ) { |
) ) { |
$self->last_error("login ($self->Host) failed: " . $self->lastline); |
$self->last_error("login ($self->host) failed: " . $self->lastline); |
return undef; |
return undef; |
} |
} |
|
|
|
|
return undef unless @lines; |
return undef unless @lines; |
|
|
unless ($PRIVATE{'Decode'}) { |
unless ($PRIVATE{'Decode'}) { |
return @lines; |
return \@lines; |
} |
} |
|
|
my @sus; |
my @sus; |
|
|
if ($PRIVATE{'Decode'} && $cfg{'decode'}) { |
if ($PRIVATE{'Decode'} && $cfg{'decode'}) { |
return $vals; |
return $vals; |
} else { |
} else { |
return @lines; |
return \@lines; |
} |
} |
} else { |
} else { |
$self->last_error("Error with command ($cfg{'String'}): $last"); |
$self->last_error("Error with command ($cfg{'String'}): $last"); |
|
|
|
|
my $key = ''; |
my $key = ''; |
my $val = undef; |
my $val = undef; |
|
my @vals; |
my $in_key = 0; |
my $in_key = 0; |
my $in_val = 1; |
my $in_val = 1; |
|
|
|
|
$key =~ s/^\s+//; |
$key =~ s/^\s+//; |
$key =~ s/\s+$//; |
$key =~ s/\s+$//; |
|
|
if (defined $val) { |
if ($val) { |
$val =~ s/^\s+//; |
$val =~ s/^\s+//; |
$val =~ s/\s+$//; |
$val =~ s/\s+$//; |
} |
} |
|
|
$key = $new . " " . $key; |
$key = $new . " " . $key; |
} |
} |
|
|
$last_key = $key; |
|
$conf{$key} = $val; |
$conf{$key} = $val; |
|
$last_key = $key; |
$key = ''; |
$key = ''; |
$val = ''; |
} elsif ($val) { |
} |
push @vals, $val; |
|
} |
|
$val = ''; |
|
|
} elsif ($c eq ']') { |
} elsif ($c eq ']') { |
$in_val = 1; |
$in_val = 1; |
|
|
} |
} |
} |
} |
|
|
|
unless ($key) { |
|
push @vals, $val; |
|
} |
|
|
|
if (@vals == 1) { |
|
$val = $vals[0]; |
|
} elsif (@vals) { |
|
$val= \@vals; |
|
} else { |
|
$val = undef; |
|
} |
|
|
if (%conf) { |
if (%conf) { |
|
$conf{_pre} = $val if $val; |
return \%conf; |
return \%conf; |
} else { |
} else { |
return $val; |
return $val; |