=================================================================== RCS file: /cvs/trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2007/01/17 19:00:51 1.24 +++ trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2007/01/17 20:48:46 1.25 @@ -1,5 +1,5 @@ package Net::Telnet::Trango; -# $RedRiver: Trango.pm,v 1.23 2007/01/08 22:16:29 mike Exp $ +# $RedRiver: Trango.pm,v 1.24 2007/01/17 19:00:51 andrew Exp $ use strict; use warnings; use base 'Net::Telnet'; @@ -209,6 +209,11 @@ returns the output from the last cmd() that was run as an array ref This is usually only set internally +=item last_error + +returns the last error reported. Should contain the the last entry in +last_lines + =back =head2 ALIASES @@ -341,6 +346,7 @@ Timeout last_lines last_vals + last_error ); sub AUTOLOAD @@ -386,7 +392,7 @@ my $self = shift; unless ( $self->SUPER::open(@_) ) { - #$! = "Couldn't connect to " . $self->Host . ": $!"; + $self->last_error("Couldn't connect to " . $self->Host . ": $!"); return undef; } @@ -395,8 +401,8 @@ -match => '/password: ?$/i', -errmode => "return", ) ) { - #$! = "problem connecting to host (" . $self->Host . "): " . - # $self->lastline; + $self->last_error("problem connecting to host (" . $self->Host . "): " . + $self->lastline); return undef; } @@ -431,7 +437,7 @@ -match => $self->prompt, -errmode => "return", ) ) { - #$! = "login ($self->Host) failed: " . $self->lastline; + $self->last_error("login ($self->Host) failed: " . $self->lastline); return undef; } @@ -486,7 +492,7 @@ my $su = shift || 'all'; unless (defined $new_pass) { - warn "No new password!" + $self->last_error("No new password"); #return undef; } @@ -515,10 +521,22 @@ my $new_subnet = shift; my $new_gateway = shift; - return undef unless $suid =~ /^\d+$/; - return undef unless $new_ip; - return undef unless $new_subnet; - return undef unless $new_gateway; + if ($suid =~ /\D/) { + $self->last_error("Invalid suid '$suid'"); + return undef; + } + 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 return $self->cmd(String => 'su ipconfig ' . @@ -607,28 +625,29 @@ my $mac = shift; if ($suid =~ /\D/) { + $self->last_error("Invalid suid '$suid'"); return undef; } unless (lc($type) eq 'reg' || lc($type) eq 'pr') { - warn "Invalid type '$type'!"; + $self->last_error("Invalid type '$type'"); return undef; } if ($cir =~ /\D/) { - warn "Invalid CIR '$cir'!"; + $self->last_error("Invalid CIR '$cir'"); return undef; } if ($mir =~ /\D/) { - warn "Invalid MIR '$mir'!"; + $self->last_error("Invalid MIR '$mir'"); return undef; } my $new_mac = $mac; $new_mac =~ s/[^0-9A-Fa-f]//; unless (length $new_mac == 12) { - warn "Invalid MAC '$mac'!"; + $self->last_error("Invalid MAC '$mac'"); return undef; } $new_mac = join ' ', $new_mac =~ /../g; @@ -661,7 +680,9 @@ my $self = 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; } @@ -693,18 +714,22 @@ my $value = shift; if ($suid =~ /\D/) { + $self->last_error("Invalid suid '$suid'"); return undef; } if (lc($opt) eq 'cir' or lc($opt) eq 'mir') { if ($value =~ /\D/) { + $self->last_error("Invalid $opt '$value'"); return undef; } } elsif (lc($opt) eq 'su2su') { if ($value =~ /[^0-9A-Za-f]/) { + $self->last_error("Invalid MAC '$value'"); return undef; } } else { + $self->last_error("Invalid option '$opt'"); return undef; } @@ -812,20 +837,17 @@ $cfg{'Timeout'} ||= $self->Timeout; unless ($cfg{'String'}) { - #$! = "No command passed"; - #warn "No command passed\n"; + $self->last_error("No command passed"); return undef; } unless ($self->is_connected) { - #$! = "Not connected"; - #warn "Not connected\n"; + $self->last_error("Not connected"); return undef; } unless ($self->logged_in) { - #$! = "Not logged in"; - #warn "Not logged in\n"; + $self->last_error("Not logged in"); return undef; } @@ -880,7 +902,7 @@ return @lines; } } else { - #$! = "Error with command ($cfg{'string'}): $last"; + $self->last_error("Error with command ($cfg{'String'}): $last"); return undef; } }