[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.2 and 1.3

version 1.2, 2005/12/30 01:02:41 version 1.3, 2005/12/30 19:26:06
Line 1 
Line 1 
 package Net::Telnet::Trango;  package Net::Telnet::Trango;
 # $RedRiver$  # $RedRiver: Trango.pm,v 1.2 2005/12/30 01:02:41 andrew Exp $
 use strict;  use strict;
 use warnings;  use warnings;
 use base 'Net::Telnet';  use base 'Net::Telnet';
Line 13 
Line 13 
 =head1 SYNOPSIS  =head1 SYNOPSIS
   
   use Net::Telnet::Trango;    use Net::Telnet::Trango;
   my $t = new Net::Telnet::Trango ({    my $t = new Net::Telnet::Trango ( Timeout => 5 );
     Host    => $fox,  
     Timeout => 5,  
   });  
       
   my ($type, $version) = $t->open;    my ($type, $version) = $t->open( Host => $fox );
       
   unless (defined $type && defined $version) {    unless (defined $type && defined $version) {
     die "Error connecting: $!";      die "Error connecting: $!";
Line 106 
Line 103 
   
 alias of exit()  alias of exit()
   
 =item reboot  =item restart
   
 alias of restart()  alias of reboot()
   
 =back  =back
   
Line 226 
Line 223 
   updateflash => { decode => 1, expect => $success },    updateflash => { decode => 1, expect => $success },
   'exit'      => { Prompt => '//', cmd_disconnects => 1 },    'exit'      => { Prompt => '//', cmd_disconnects => 1 },
   reboot      => { Prompt => '//', cmd_disconnects => 1 },    reboot      => { Prompt => '//', cmd_disconnects => 1 },
     #su password???
     #_bootloader
     #temp
     #heater
 );  );
   
 my %ALIASES = (  my %ALIASES = (
Line 257 
Line 258 
   }    }
   
   if (exists $COMMANDS{$method}) {    if (exists $COMMANDS{$method}) {
       $method = shift if (@_ == 1);
     $COMMANDS{$method}{'String'} ||= $method;      $COMMANDS{$method}{'String'} ||= $method;
     return $self->cmd(%{ $COMMANDS{$method} }, @_);      return $self->cmd(%{ $COMMANDS{$method} }, @_);
   }    }
Line 275 
Line 277 
   
 =item new  =item new
   
   Same as new from L<Net::Telnet> but has defaults for the trango 'Prompt'
   
 =cut  =cut
   
 sub new  sub new
 {  {
   my $class = shift;    my $class = shift;
   my $args = shift || {};  
   
   $args->{'Timeout'} ||= 5;    my %args;
   $args->{'Prompt'}  ||= '/#> *$/';    if (@_ == 1) {
       $args{'Host'} = shift;
     } else {
       %args = @_;
     }
   
   foreach my $key (keys %{ $args }) {    $args{'Prompt'}  ||= '/#> *$/';
     $PRIVATE{$key} = $args->{$key};  
     foreach my $key (keys %args) {
       $PRIVATE{$key} = $args{$key};
   }    }
   
   my $self = $class->SUPER::new(%{ $args });    my $self = $class->SUPER::new(%args);
   bless $self if ref $self;    bless $self if ref $self;
   
   return $self;    return $self;
Line 299 
Line 308 
   
 =item open  =item open
   
   Calls Net::Telnet::open() then makes sure you get a password prompt so you are ready to login() and parses the login banner so you can get host_type() and firmware_version()
   
 =cut  =cut
   
 sub open  sub open
 {  {
   my $self = shift;    my $self = shift;
   
   unless ( $self->SUPER::open(    unless ( $self->SUPER::open(@_) ) {
       #Host => $self->Host,  
       #Errmode => 'return',  
   ) ) {  
     #$! = "Couldn't connect to " . $self->Host . ":  $!";      #$! = "Couldn't connect to " . $self->Host . ":  $!";
     return undef;      return undef;
   }    }
   #$self->dump_log('dump.log');  
   
   ## Login to remote host.    ## Get to login prompt
   unless ($self->waitfor(    unless ($self->waitfor(
     -match => '/password: ?$/i',        -match => '/password: ?$/i',
     -errmode => "return",        -errmode => "return",
   ) ) {      ) ) {
   #$! = "problem connecting to host (" . $self->Host . "): " .      #$! = "problem connecting to host (" . $self->Host . "): " .
   #    $self->lastline;      #    $self->lastline;
     return undef;      return undef;
   }    }
   
Line 335 
Line 342 
   
 =item login  =item login
   
   Calls open() if not already connected, then sends the password and sets logged_in() if successful
   
 =cut  =cut
   
 sub login  sub login
Line 365 
Line 374 
   
 =item parse_login_banner  =item parse_login_banner
   
   Takes a login banner (what you get when you first connect to the Trango) or reads what is already in login_banner() then parses it and sets host_type() and firmware_version() as well as login_banner()
   
 =cut  =cut
   
 sub parse_login_banner  sub parse_login_banner
Line 391 
Line 402 
   
 =item enable_tftpd  =item enable_tftpd
   
   runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing
   
 =cut  =cut
   
 sub enable_tftpd  sub enable_tftpd
Line 410 
Line 423 
   
 =item disable_tftpd  =item disable_tftpd
   
   runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'
   
 =cut  =cut
   
 sub disable_tftpd  sub disable_tftpd
Line 429 
Line 444 
   
 =item cmd  =item cmd
   
   This does most of the work.  At the heart, it calls Net::Telnet::cmd() but it also does some special stuff for Trango.
   
   Normally returns the last lines from from the command
   
   Also accepts these options:
   
   I<decode>
   - if this is true, then it will send the output lines to _decode_lines() and then returns the decoded output
   
   I<cmd_disconnects>
   - if this is true, it then sets logged_in() to false, then it will close() the connection and then sets is_connected() to false
   
   I<expect>
   - if this is set (usually to 'Success.') it will check for that in the last line of output and if it does not, will return undef because the command probably failed
   
   I<args>
   - a string containing the command line options that are passed to the command
   
 =cut  =cut
   
 sub cmd  sub cmd
Line 459 
Line 492 
   
   unless ($cfg{'String'}) {    unless ($cfg{'String'}) {
     #$! = "No command passed";      #$! = "No command passed";
     warn "No command passed\n";      #warn "No command passed\n";
     return undef;      return undef;
   }    }
   
   unless ($self->is_connected) {    unless ($self->is_connected) {
     #$! = "Not connected";      #$! = "Not connected";
     warn "Not connected\n";      #warn "Not connected\n";
     return undef;      return undef;
   }    }
   
   unless ($self->logged_in) {    unless ($self->logged_in) {
     #$! = "Not logged in";      #$! = "Not logged in";
     warn "Not logged in\n";      #warn "Not logged in\n";
     return undef;      return undef;
   }    }
   
Line 590 
Line 623 
 =back  =back
   
 =head1 SEE ALSO  =head1 SEE ALSO
   
 If you have a web site set up for your module, mention it here.  
   
 Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm  Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm
   

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

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