version 1.27, 2007/01/31 18:53:29 |
version 1.30, 2007/02/02 17:51:52 |
|
|
package Net::Telnet::Trango; |
package Net::Telnet::Trango; |
# $RedRiver: Trango.pm,v 1.26 2007/01/17 23:15:13 andrew Exp $ |
# $RedRiver: Trango.pm,v 1.29 2007/02/01 17:58:33 andrew Exp $ |
use strict; |
use strict; |
use warnings; |
use warnings; |
use base 'Net::Telnet'; |
use base 'Net::Telnet'; |
|
|
last_lines |
last_lines |
last_vals |
last_vals |
last_error |
last_error |
|
Decode |
); |
); |
|
|
sub AUTOLOAD |
sub AUTOLOAD |
|
|
} |
} |
|
|
if (exists $COMMANDS{$method}) { |
if (exists $COMMANDS{$method}) { |
$COMMANDS{$method}{'String'} ||= $method; |
my %cmd; |
$COMMANDS{$method}{'args'} .= ' ' . shift if (@_ == 1); |
foreach my $k (keys %{ $COMMANDS{$method} }) { |
return $self->cmd(%{ $COMMANDS{$method} }, @_); |
$cmd{$k} = $COMMANDS{$method}{$k}; |
|
} |
|
$cmd{'String'} ||= $method; |
|
$cmd{'args'} .= ' ' . shift if (@_ == 1); |
|
return $self->cmd(%cmd, @_); |
} |
} |
|
|
if (exists $ACCESS{$method}) { |
if (exists $ACCESS{$method}) { |
|
|
|
|
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; |
} |
} |
|
|
## Get to login prompt |
## Get to login prompt |
|
|
) ) { |
) ) { |
$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; |
} |
} |
|
|
$self->parse_login_banner($self->lastline); |
$self->parse_login_banner($self->lastline); |
|
|
my $self = shift; |
my $self = shift; |
|
|
unless ($self->is_connected) { |
unless ($self->is_connected) { |
$self->open or return undef; |
$self->open or return; |
} |
} |
|
|
my $password = shift; |
my $password = shift; |
|
|
-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; |
} |
} |
|
|
$self->logged_in(1); |
$self->logged_in(1); |
|
|
|
|
my $banner = $self->login_banner; |
my $banner = $self->login_banner; |
|
|
my ($type, $ver) = $banner =~ |
my ($type, $sep1, $subtype, $sep2, $ver) = $banner =~ |
/Welcome to Trango Broadband Wireless (\S+)[\s-]+(.+)$/i; |
/Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i; |
|
|
|
$type .= $sep1 . $subtype; |
|
$ver = $subtype . $sep2 . $ver; |
|
|
$self->login_banner($banner); |
$self->login_banner($banner); |
$self->host_type($type); |
$self->host_type($type); |
$self->firmware_version($ver); |
$self->firmware_version($ver); |
|
|
|
|
unless (defined $new_pass) { |
unless (defined $new_pass) { |
$self->last_error("No new password"); |
$self->last_error("No new password"); |
#return undef; |
#return; |
} |
} |
|
|
return $self->cmd(String => 'su password ' . |
return $self->cmd(String => 'su password ' . |
|
|
|
|
if ($suid =~ /\D/) { |
if ($suid =~ /\D/) { |
$self->last_error("Invalid suid '$suid'"); |
$self->last_error("Invalid suid '$suid'"); |
return undef; |
return; |
} |
} |
unless ($new_ip) { |
unless ($new_ip) { |
$self->last_error("no new_ip passed"); |
$self->last_error("no new_ip passed"); |
return undef; |
return; |
} |
} |
unless ($new_subnet) { |
unless ($new_subnet) { |
$self->last_error("no new_subnet passed"); |
$self->last_error("no new_subnet passed"); |
return undef; |
return; |
} |
} |
unless ($new_gateway) { |
unless ($new_gateway) { |
$self->last_error("no new_gateway passed"); |
$self->last_error("no new_gateway passed"); |
return undef; |
return; |
} |
} |
|
|
# su ipconfig <suid> <new ip> <new subnet> <new gateway> |
# su ipconfig <suid> <new ip> <new subnet> <new gateway> |
|
|
{ |
{ |
my $self = shift; |
my $self = shift; |
|
|
my @lines = $self->cmd( String => 'sudb view', expect => $success ); |
my $lines = $self->cmd( String => 'sudb view', expect => $success ) || []; |
|
|
return undef unless @lines; |
return unless @{ $lines }; |
|
|
unless ($PRIVATE{'Decode'}) { |
unless ($PRIVATE{'Decode'}) { |
return \@lines; |
return $lines; |
} |
} |
|
|
my @sus; |
my @sus; |
foreach (@lines) { |
foreach (@{ $lines }) { |
next unless $_; |
next unless $_; |
if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) { |
if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) { |
my %s = ( |
my %s = ( |
|
|
|
|
if ($suid =~ /\D/) { |
if ($suid =~ /\D/) { |
$self->last_error("Invalid suid '$suid'"); |
$self->last_error("Invalid suid '$suid'"); |
return undef; |
return; |
} |
} |
|
|
unless (lc($type) eq 'reg' || lc($type) eq 'pr') { |
unless (lc($type) eq 'reg' || lc($type) eq 'pr') { |
$self->last_error("Invalid type '$type'"); |
$self->last_error("Invalid type '$type'"); |
return undef; |
return; |
} |
} |
|
|
if ($cir =~ /\D/) { |
if ($cir =~ /\D/) { |
$self->last_error("Invalid CIR '$cir'"); |
$self->last_error("Invalid CIR '$cir'"); |
return undef; |
return; |
} |
} |
|
|
if ($mir =~ /\D/) { |
if ($mir =~ /\D/) { |
$self->last_error("Invalid MIR '$mir'"); |
$self->last_error("Invalid MIR '$mir'"); |
return undef; |
return; |
} |
} |
|
|
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) { |
$self->last_error("Invalid MAC '$mac'"); |
$self->last_error("Invalid MAC '$mac'"); |
return undef; |
return; |
} |
} |
$new_mac = join ' ', $new_mac =~ /../g; |
$new_mac = join ' ', $new_mac =~ /../g; |
|
|
|
|
#if (lc($suid) ne 'all' || $suid =~ /\D/) { |
#if (lc($suid) ne 'all' || $suid =~ /\D/) { |
if ($suid =~ /\D/) { |
if ($suid =~ /\D/) { |
$self->last_error("Invalid suid '$suid'"); |
$self->last_error("Invalid suid '$suid'"); |
return undef; |
return; |
} |
} |
|
|
return $self->cmd( String => 'sudb delete ' . $suid, expect => $success ); |
return $self->cmd( String => 'sudb delete ' . $suid, expect => $success ); |
|
|
|
|
if ($suid =~ /\D/) { |
if ($suid =~ /\D/) { |
$self->last_error("Invalid suid '$suid'"); |
$self->last_error("Invalid suid '$suid'"); |
return undef; |
return; |
} |
} |
|
|
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'"); |
$self->last_error("Invalid $opt '$value'"); |
return undef; |
return; |
} |
} |
} 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'"); |
$self->last_error("Invalid MAC '$value'"); |
return undef; |
return; |
} |
} |
} else { |
} else { |
$self->last_error("Invalid option '$opt'"); |
$self->last_error("Invalid option '$opt'"); |
return undef; |
return; |
} |
} |
|
|
my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value; |
my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value; |
|
|
if ($vals->{'Tftpd'} eq 'listen') { |
if ($vals->{'Tftpd'} eq 'listen') { |
return $vals; |
return $vals; |
} else { |
} else { |
return undef; |
return; |
} |
} |
} |
} |
|
|
|
|
if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled') { |
if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled') { |
return $vals; |
return $vals; |
} else { |
} else { |
return undef; |
return; |
} |
} |
} |
} |
|
|
|
|
|
|
unless ($cfg{'String'}) { |
unless ($cfg{'String'}) { |
$self->last_error("No command passed"); |
$self->last_error("No command passed"); |
return undef; |
return; |
} |
} |
|
|
unless ($self->is_connected) { |
unless ($self->is_connected) { |
$self->last_error("Not connected"); |
$self->last_error("Not connected"); |
return undef; |
return; |
} |
} |
|
|
unless ($self->logged_in) { |
unless ($self->logged_in) { |
$self->last_error("Not logged in"); |
$self->last_error("Not logged in"); |
return undef; |
return; |
} |
} |
|
|
|
|
|
|
if ($cfg{'args'}) { |
if ($cfg{'args'}) { |
$cmd{'String'} .= ' ' . $cfg{'args'}; |
$cmd{'String'} .= ' ' . $cfg{'args'}; |
} |
} |
|
|
my @lines; |
my @lines; |
unless ($cfg{'no_prompt'}) { |
if ($cfg{'no_prompt'}) { |
@lines = $self->SUPER::cmd(%cmd); |
|
} else { |
|
$self->print($cmd{'String'}); |
$self->print($cmd{'String'}); |
@lines = $self->lastline; |
@lines = $self->lastline; |
|
} else { |
|
@lines = $self->SUPER::cmd(%cmd); |
} |
} |
|
|
$self->last_lines(\@lines); |
$self->last_lines(\@lines); |
|
|
} |
} |
} else { |
} else { |
$self->last_error("Error with command ($cfg{'String'}): $last"); |
$self->last_error("Error with command ($cfg{'String'}): $last"); |
return undef; |
return; |
} |
} |
} |
} |
|
|
|
|
return \@decoded; |
return \@decoded; |
} else { |
} else { |
# XXX we should have a way to set last error, not sure why we don't |
# XXX we should have a way to set last error, not sure why we don't |
return undef; |
return; |
} |
} |
} |
} |
|
|