=================================================================== RCS file: /cvs/trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2005/12/30 01:02:41 1.2 +++ trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2005/12/30 19:26:06 1.3 @@ -1,5 +1,5 @@ package Net::Telnet::Trango; -# $RedRiver$ +# $RedRiver: Trango.pm,v 1.2 2005/12/30 01:02:41 andrew Exp $ use strict; use warnings; use base 'Net::Telnet'; @@ -13,12 +13,9 @@ =head1 SYNOPSIS use Net::Telnet::Trango; - my $t = new Net::Telnet::Trango ({ - Host => $fox, - Timeout => 5, - }); + my $t = new Net::Telnet::Trango ( Timeout => 5 ); - my ($type, $version) = $t->open; + my ($type, $version) = $t->open( Host => $fox ); unless (defined $type && defined $version) { die "Error connecting: $!"; @@ -106,9 +103,9 @@ alias of exit() -=item reboot +=item restart -alias of restart() +alias of reboot() =back @@ -226,6 +223,10 @@ updateflash => { decode => 1, expect => $success }, 'exit' => { Prompt => '//', cmd_disconnects => 1 }, reboot => { Prompt => '//', cmd_disconnects => 1 }, + #su password??? + #_bootloader + #temp + #heater ); my %ALIASES = ( @@ -257,6 +258,7 @@ } if (exists $COMMANDS{$method}) { + $method = shift if (@_ == 1); $COMMANDS{$method}{'String'} ||= $method; return $self->cmd(%{ $COMMANDS{$method} }, @_); } @@ -275,21 +277,28 @@ =item new +Same as new from L but has defaults for the trango 'Prompt' + =cut sub new { my $class = shift; - my $args = shift || {}; - $args->{'Timeout'} ||= 5; - $args->{'Prompt'} ||= '/#> *$/'; + my %args; + if (@_ == 1) { + $args{'Host'} = shift; + } else { + %args = @_; + } - foreach my $key (keys %{ $args }) { - $PRIVATE{$key} = $args->{$key}; + $args{'Prompt'} ||= '/#> *$/'; + + 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; return $self; @@ -299,28 +308,26 @@ =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 sub open { my $self = shift; - unless ( $self->SUPER::open( - #Host => $self->Host, - #Errmode => 'return', - ) ) { + unless ( $self->SUPER::open(@_) ) { #$! = "Couldn't connect to " . $self->Host . ": $!"; return undef; } - #$self->dump_log('dump.log'); - ## Login to remote host. + ## Get to login prompt unless ($self->waitfor( - -match => '/password: ?$/i', - -errmode => "return", - ) ) { - #$! = "problem connecting to host (" . $self->Host . "): " . - # $self->lastline; + -match => '/password: ?$/i', + -errmode => "return", + ) ) { + #$! = "problem connecting to host (" . $self->Host . "): " . + # $self->lastline; return undef; } @@ -335,6 +342,8 @@ =item login +Calls open() if not already connected, then sends the password and sets logged_in() if successful + =cut sub login @@ -365,6 +374,8 @@ =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 sub parse_login_banner @@ -391,6 +402,8 @@ =item enable_tftpd +runs C 'on')> and makes sure that Tftpd is now 'listen'ing + =cut sub enable_tftpd @@ -410,6 +423,8 @@ =item disable_tftpd +runs C 'off')> and makes sure that Tftpd is now 'disabled' + =cut sub disable_tftpd @@ -429,6 +444,24 @@ =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 +- if this is true, then it will send the output lines to _decode_lines() and then returns the decoded output + +I +- 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 +- 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 +- a string containing the command line options that are passed to the command + =cut sub cmd @@ -459,19 +492,19 @@ unless ($cfg{'String'}) { #$! = "No command passed"; - warn "No command passed\n"; + #warn "No command passed\n"; return undef; } unless ($self->is_connected) { #$! = "Not connected"; - warn "Not connected\n"; + #warn "Not connected\n"; return undef; } unless ($self->logged_in) { #$! = "Not logged in"; - warn "Not logged in\n"; + #warn "Not logged in\n"; return undef; } @@ -590,8 +623,6 @@ =back =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