| version 1.22, 2007/01/03 19:40:03 |
version 1.25, 2007/01/17 20:48:46 |
|
|
| package Net::Telnet::Trango; |
package Net::Telnet::Trango; |
| # $RedRiver: Trango.pm,v 1.21 2006/10/05 17:10:39 andrew Exp $ |
# $RedRiver: Trango.pm,v 1.24 2007/01/17 19:00:51 andrew Exp $ |
| use strict; |
use strict; |
| use warnings; |
use warnings; |
| use base 'Net::Telnet'; |
use base 'Net::Telnet'; |
|
|
| |
|
| use Net::Telnet::Trango; |
use Net::Telnet::Trango; |
| my $t = new Net::Telnet::Trango ( Timeout => 5 ); |
my $t = new Net::Telnet::Trango ( Timeout => 5 ); |
| |
|
| $t->open( Host => $fox ) or die "Error connecting: $!"; |
$t->open( Host => $fox ) or die "Error connecting: $!"; |
| |
|
| $t->login('password') or die "Couldn't log in: $!"; |
$t->login('password') or die "Couldn't log in: $!"; |
| |
|
| # Do whatever |
# Do whatever |
| |
|
| $t->exit; |
$t->exit; |
| $t->close; |
$t->close; |
| |
|
|
|
| |
|
| None |
None |
| |
|
| |
=head1 METHODS |
| |
|
| |
=over |
| |
|
| =cut |
=cut |
| |
|
| our $VERSION = '0.01'; |
our $VERSION = '0.01'; |
|
|
| |
|
| =pod |
=pod |
| |
|
| =head1 METHODS |
=back |
| |
|
| =head2 ACCESSORS |
=head2 ACCESSORS |
| |
|
|
|
| returns the output from the last cmd() that was run as an array ref |
returns the output from the last cmd() that was run as an array ref |
| This is usually only set internally |
This is usually only set internally |
| |
|
| |
=item last_error |
| |
|
| |
returns the last error reported. Should contain the the last entry in |
| |
last_lines |
| |
|
| =back |
=back |
| |
|
| =head2 ALIASES |
=head2 ALIASES |
|
|
| |
|
| You need to pass in args => <suid> and it will return the info for that suid. |
You need to pass in args => <suid> and it will return the info for that suid. |
| |
|
| =item su_testrflink |
|
| |
|
| you need to pass in args => <suid> and it will return the rflink test results for that SU. |
|
| |
|
| =item save_ss |
=item save_ss |
| |
|
| saves the config. Returns 1 on success, undef on failure. |
saves the config. Returns 1 on success, undef on failure. |
|
|
| maclist_reset => { String => 'maclist reset', expect => 'done' }, |
maclist_reset => { String => 'maclist reset', expect => 'done' }, |
| eth_link => { String => 'eth link', expect => $success }, |
eth_link => { String => 'eth link', expect => $success }, |
| su_info => { String => 'su info', decode => 'all', expect => $success }, |
su_info => { String => 'su info', decode => 'all', expect => $success }, |
| su_testrflink=> { String => 'su testrflink', decode => 'each', expect => $success }, |
|
| save_ss => { String => 'save ss', expect => $success }, |
save_ss => { String => 'save ss', expect => $success }, |
| opmode => { decode => 'all', expect => $success }, |
opmode => { decode => 'all', expect => $success }, |
| # eth r, w and reset??? |
# eth r, w and reset??? |
|
|
| Timeout |
Timeout |
| last_lines |
last_lines |
| last_vals |
last_vals |
| |
last_error |
| ); |
); |
| |
|
| sub AUTOLOAD |
sub AUTOLOAD |
|
|
| my $self = shift; |
my $self = shift; |
| |
|
| unless ( $self->SUPER::open(@_) ) { |
unless ( $self->SUPER::open(@_) ) { |
| #$! = "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", |
| ) ) { |
) ) { |
| #$! = "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", |
| ) ) { |
) ) { |
| #$! = "login ($self->Host) failed: " . $self->lastline; |
$self->last_error("login ($self->Host) failed: " . $self->lastline); |
| return undef; |
return undef; |
| } |
} |
| |
|
|
|
| |
|
| =item su_password |
=item su_password |
| |
|
| C<su_password('all'|suid, 'new_password')> |
C<su_password('new_password'[, 'suid'])> If no suid is specified, |
| |
the default is "all". |
| |
|
| =cut |
=cut |
| |
|
| sub su_password |
sub su_password |
| { |
{ |
| my $self = shift; |
my $self = shift; |
| my $su = shift || '!'; |
|
| my $new_pass = shift || ''; |
my $new_pass = shift || ''; |
| |
my $su = shift || 'all'; |
| |
|
| unless (defined $su) { |
|
| warn "No su passed!" |
|
| #return undef; |
|
| } |
|
| |
|
| unless (defined $new_pass) { |
unless (defined $new_pass) { |
| warn "No new password!" |
$self->last_error("No new password"); |
| #return undef; |
#return undef; |
| } |
} |
| |
|
|
|
| my $new_subnet = shift; |
my $new_subnet = shift; |
| my $new_gateway = shift; |
my $new_gateway = shift; |
| |
|
| return undef unless $suid =~ /^\d+$/; |
if ($suid =~ /\D/) { |
| return undef unless $new_ip; |
$self->last_error("Invalid suid '$suid'"); |
| return undef unless $new_subnet; |
return undef; |
| return undef unless $new_gateway; |
} |
| |
unless ($new_ip) { |
| |
$self->last_error("no new_ip passed"); |
| |
return undef; |
| |
} |
| |
unless ($new_subnet) { |
| |
$self->last_error("no new_subnet passed"); |
| |
return undef; |
| |
} |
| |
unless ($new_gateway) { |
| |
$self->last_error("no new_gateway passed"); |
| |
return undef; |
| |
} |
| |
|
| # su ipconfig <suid> <new ip> <new subnet> <new gateway> |
# su ipconfig <suid> <new ip> <new subnet> <new gateway> |
| return $self->cmd(String => 'su ipconfig ' . |
return $self->cmd(String => 'su ipconfig ' . |
|
|
| my $mac = shift; |
my $mac = shift; |
| |
|
| if ($suid =~ /\D/) { |
if ($suid =~ /\D/) { |
| |
$self->last_error("Invalid suid '$suid'"); |
| return undef; |
return undef; |
| } |
} |
| |
|
| unless (lc($type) eq 'reg' || lc($type) eq 'pr') { |
unless (lc($type) eq 'reg' || lc($type) eq 'pr') { |
| warn "Invalid type '$type'!"; |
$self->last_error("Invalid type '$type'"); |
| return undef; |
return undef; |
| } |
} |
| |
|
| if ($cir =~ /\D/) { |
if ($cir =~ /\D/) { |
| warn "Invalid CIR '$cir'!"; |
$self->last_error("Invalid CIR '$cir'"); |
| return undef; |
return undef; |
| } |
} |
| |
|
| if ($mir =~ /\D/) { |
if ($mir =~ /\D/) { |
| warn "Invalid MIR '$mir'!"; |
$self->last_error("Invalid MIR '$mir'"); |
| return undef; |
return undef; |
| } |
} |
| |
|
| my $new_mac = $mac; |
my $new_mac = $mac; |
| $new_mac =~ s/[^0-9A-Fa-f]//; |
$new_mac =~ s/[^0-9A-Fa-f]//; |
| unless (length $new_mac == 12) { |
unless (length $new_mac == 12) { |
| warn "Invalid MAC '$mac'!"; |
$self->last_error("Invalid MAC '$mac'"); |
| return undef; |
return undef; |
| } |
} |
| $new_mac = join ' ', $new_mac =~ /../g; |
$new_mac = join ' ', $new_mac =~ /../g; |
|
|
| my $self = shift; |
my $self = shift; |
| my $suid = shift; |
my $suid = shift; |
| |
|
| if (lc($suid) ne 'all' || $suid =~ /\D/) { |
#if (lc($suid) ne 'all' || $suid =~ /\D/) { |
| |
if ($suid =~ /\D/) { |
| |
$self->last_error("Invalid suid '$suid'"); |
| return undef; |
return undef; |
| } |
} |
| |
|
|
|
| my $value = shift; |
my $value = shift; |
| |
|
| if ($suid =~ /\D/) { |
if ($suid =~ /\D/) { |
| |
$self->last_error("Invalid suid '$suid'"); |
| return undef; |
return undef; |
| } |
} |
| |
|
| if (lc($opt) eq 'cir' or lc($opt) eq 'mir') { |
if (lc($opt) eq 'cir' or lc($opt) eq 'mir') { |
| if ($value =~ /\D/) { |
if ($value =~ /\D/) { |
| |
$self->last_error("Invalid $opt '$value'"); |
| return undef; |
return undef; |
| } |
} |
| } elsif (lc($opt) eq 'su2su') { |
} elsif (lc($opt) eq 'su2su') { |
| if ($value =~ /[^0-9A-Za-f]/) { |
if ($value =~ /[^0-9A-Za-f]/) { |
| |
$self->last_error("Invalid MAC '$value'"); |
| return undef; |
return undef; |
| } |
} |
| } else { |
} else { |
| |
$self->last_error("Invalid option '$opt'"); |
| return undef; |
return undef; |
| } |
} |
| |
|
|
|
| $cfg{'Timeout'} ||= $self->Timeout; |
$cfg{'Timeout'} ||= $self->Timeout; |
| |
|
| unless ($cfg{'String'}) { |
unless ($cfg{'String'}) { |
| #$! = "No command passed"; |
$self->last_error("No command passed"); |
| #warn "No command passed\n"; |
|
| return undef; |
return undef; |
| } |
} |
| |
|
| unless ($self->is_connected) { |
unless ($self->is_connected) { |
| #$! = "Not connected"; |
$self->last_error("Not connected"); |
| #warn "Not connected\n"; |
|
| return undef; |
return undef; |
| } |
} |
| |
|
| unless ($self->logged_in) { |
unless ($self->logged_in) { |
| #$! = "Not logged in"; |
$self->last_error("Not logged in"); |
| #warn "Not logged in\n"; |
|
| return undef; |
return undef; |
| } |
} |
| |
|
|
|
| return @lines; |
return @lines; |
| } |
} |
| } else { |
} else { |
| #$! = "Error with command ($cfg{'string'}): $last"; |
$self->last_error("Error with command ($cfg{'String'}): $last"); |
| return undef; |
return undef; |
| } |
} |
| } |
} |