[BACK]Return to Trango.pm CVS log [TXT][DIR] Up to [local] / trango / Net-Telnet-Trango / lib / Net / Telnet

Diff for /trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm between version 1.20 and 1.25

version 1.20, 2006/09/12 03:20:39 version 1.25, 2007/01/17 20:48:46
Line 1 
Line 1 
 package Net::Telnet::Trango;  package Net::Telnet::Trango;
 # $RedRiver: Trango.pm,v 1.19 2006/09/12 02:16:43 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';
Line 14 
Line 14 
   
   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;
   
Line 37 
Line 37 
   
 None  None
   
   =head1 METHODS
   
   =over
   
 =cut  =cut
   
 our $VERSION = '0.01';  our $VERSION = '0.01';
Line 160 
Line 164 
   
 =pod  =pod
   
 =head1 METHODS  =back
   
 =head2 ACCESSORS  =head2 ACCESSORS
   
Line 205 
Line 209 
 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
Line 314 
Line 323 
   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 },
   save_ss     => { String => 'save ss', expect => $success },    save_ss     => { String => 'save ss', expect => $success },
     opmode      => { decode => 'all',   expect => $success },
   # eth r, w and reset???    # eth r, w and reset???
   #su password???    #su password???
   #_bootloader    #_bootloader
Line 336 
Line 346 
   Timeout    Timeout
   last_lines    last_lines
   last_vals    last_vals
     last_error
 );  );
   
 sub AUTOLOAD  sub AUTOLOAD
Line 381 
Line 392 
   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;
   }    }
   
Line 390 
Line 401 
       -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;
   }    }
   
Line 426 
Line 437 
     -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;
   }    }
   
Line 469 
Line 480 
   
 =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;
   }    }
   
Line 514 
Line 521 
         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 ' .
Line 606 
Line 625 
         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;
Line 660 
Line 680 
         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;
         }          }
   
Line 692 
Line 714 
         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;
         }          }
   
Line 811 
Line 837 
   $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;
   }    }
   
Line 879 
Line 902 
       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;
   }    }
 }  }

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.25

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>