=================================================================== RCS file: /cvs/trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm,v retrieving revision 1.35 retrieving revision 1.38 diff -u -r1.35 -r1.38 --- trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2007/02/05 21:03:40 1.35 +++ trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2007/02/06 16:22:46 1.38 @@ -1,6 +1,6 @@ package Net::Telnet::Trango; -# $RedRiver: Trango.pm,v 1.34 2007/02/05 21:02:07 andrew Exp $ +# $RedRiver: Trango.pm,v 1.37 2007/02/05 23:09:59 andrew Exp $ use strict; use warnings; use base 'Net::Telnet'; @@ -45,6 +45,9 @@ our $VERSION = '0.01'; +my $EMPTY = q{}; +my $SPACE = q{ }; + my %PRIVATE = ( is_connected => 0, logged_in => 0, @@ -52,8 +55,7 @@ =pod -=head2 B -- Creates a new Net::Telnet::Trango object. +=head2 B - Creates a new Net::Telnet::Trango object. new([Options from Net::Telnet,] [Decode => 0,]); @@ -173,60 +175,55 @@ These are usually only set internally. -=head2 B -- returns the firmware version +=head2 B - returns the firmware version Returns the firmware version if available, otherwise undef. It should be available after a successful open(). -=head2 B -- return the type of host you are connected to. +=head2 B - return the type of host you are connected to. returns the type of host from the login banner for example M5830S or M5300S. Should be available after a successful open(). -=head2 B -- Status of the connection to host. +=head2 B - Status of the connection to host. returns 1 when connected, undef otherwise. -=head2 B -- Status of being logged in to the host. +=head2 B - Status of being logged in to the host. returns 1 after a successful login(), 0 if it failed and undef if login() was never called. -=head2 B -- The banner when first connecting to the host. +=head2 B - The banner when first connecting to the host. returns the banner that is displayed when first connected at login. Only set after a successful open(). -=head2 B -- The last lines of output from the last cmd(). +=head2 B - The last lines of output from the last cmd(). returns, as an array ref, the output from the last cmd() that was run. -=head2 B -- A text output of the last error that was encountered. +=head2 B - A text output of the last error that was encountered. returns the last error reported. Probably contains the last entry in last_lines. =head1 ALIASES -=head2 B -- alias of exit() +=head2 B - alias of exit() Does the same as exit() -=head2 B -- alias of reboot() +=head2 B - alias of reboot() Does the same as reboot() +=head2 B - alias of save_ss() + +Does the same as save_ss() + =head1 COMMANDS Most of these are just shortcuts to C METHOD)>, @@ -234,8 +231,7 @@ Specifically they take a named paramater "args", for example: C 'on')> would enable tftpd -=head2 B -- The output from the tftpd command +=head2 B - The output from the tftpd command Returns a hash ref of the decoded output from the command. @@ -243,31 +239,26 @@ Also see enable_tftpd() and disable_tftpd() as those check that it was successfully changed. -=head2 B -- The output from the ver command +=head2 B - The output from the ver command Returns a hash ref of the decoded output from the command. -=head2 B -- The output from the sysinfo command +=head2 B - The output from the sysinfo command Returns a hash ref of the decoded output from the command. -=head2 B -- Exits the connection +=head2 B - Exits the connection exits the command session with the Trango and closes the connection -=head2 B -- Sends a reboot command +=head2 B - Sends a reboot command reboots the Trango and closes the connection -=head2 B -- Set or retrieve the remarks. +=head2 B - Set or retrieve the remarks. Takes an optional argument, which sets the remarks. If there is no argument, returns the current remarks. @@ -275,45 +266,37 @@ my $old_remarks = $t->remarks(); $t->remarks($new_remarks); -=head2 B -- The output from the sulog command +=head2 B - The output from the sulog command Returns an array ref of hashes containing each log line. -=head2 B -- saves the sudb +=head2 B - saves the sudb Returns true on success, undef on failure -=head2 B -- The output from the sulog command +=head2 B - The output from the sulog command Returns a hashref of the output from the syslog command -=head2 B -- the pipe command +=head2 B - the pipe command Returns the output from the pipe command -=head2 B -- retrieves the maclist +=head2 B - retrieves the maclist Returns the output from the maclist command -=head2 B -- resets the maclist. +=head2 B - resets the maclist. No useful output. -=head2 B -- eth list command +=head2 B - eth list command Returns the output from the eth list command -=head2 B -- gets the su info +=head2 B - gets the su info Returns information about the SU. @@ -321,16 +304,18 @@ $t->su_info($suid); -=head2 B -- tests the RF Link to an su +=head2 B - tests the RF Link to an su $t->su_testrflink($suid|'all'); -=head2 B -- saves the config. +=head2 B - saves the config. Returns 1 on success, undef on failure. +=head2 B - sets opmode ap y or returns the opmode + + $t->opmode([ap y]); + =cut my $success = 'Success\\.'; @@ -345,27 +330,23 @@ remarks => { decode => 'all', expect => $success }, save_sudb => { String => 'save sudb', expect => $success }, syslog => { expect => $success }, - 'pipe' => {}, # XXX needs a special decode - maclist => { decode => 'maclist' }, - maclist_reset => { String => 'maclist reset', expect => 'done' }, - eth_link => { String => 'eth link', expect => $success }, - su_info => { String => 'su info', decode => 'all', expect => $success }, + 'pipe' => {}, # XXX needs a special decode + maclist => { decode => 'maclist' }, + maclist_reset => { String => 'maclist reset', expect => 'done' }, + eth_link => { String => 'eth link', expect => $success }, + su_info => + { String => 'su info', decode => 'all', expect => $success }, su_testrflink => - { String => 'su testrflink', decode => 'each', expect => $success }, - save_ss => { String => 'save ss', expect => $success }, - opmode => { decode => 'all', expect => $success }, - - # eth r, w and reset??? - #su password??? - #_bootloader - #temp - #heater + { String => 'su testrflink', decode => 'each', expect => $success }, + save_ss => { String => 'save ss', expect => $success }, + opmode => { decode => 'all', expect => $success }, ); my %ALIASES = ( bye => 'exit', restart => 'reboot', Host => 'host', + save_systemseting => 'save_ss', ); my %ACCESS = map { $_ => 1 } qw( @@ -398,7 +379,7 @@ $cmd{$k} = $COMMANDS{$method}{$k}; } $cmd{'String'} ||= $method; - $cmd{'args'} .= ' ' . shift if ( @_ == 1 ); + $cmd{'args'} .= $SPACE . shift if ( @_ == 1 ); return $self->cmd( %cmd, @_ ); } @@ -414,8 +395,7 @@ =pod -=head2 B -- Open a connection to a Trango AP. +=head2 B - Open a connection to a Trango AP. 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 @@ -454,8 +434,7 @@ =pod -=head2 B -- Login to the AP. +=head2 B - Login to the AP. Calls open() if not already connected, then sends the password and sets logged_in() if successful @@ -490,9 +469,7 @@ =pod -=head2 B -- Converts the login_banner to some useful -variables. +=head2 B - Converts the login_banner to something useful. 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 @@ -525,8 +502,7 @@ =pod -=head2 B -- Set the password on SUs connected to the AP. +=head2 B - Set the password on SUs connected to the AP. su_password('new_password'[, 'suid']) If no suid is specified, the default is "all". @@ -537,7 +513,7 @@ sub su_password { my $self = shift; - my $new_pass = shift || ''; + my $new_pass = shift || $EMPTY; my $su = shift || 'all'; unless ( defined $new_pass ) { @@ -547,16 +523,14 @@ } return $self->cmd( - String => 'su password ' . $su . ' ' . $new_pass . ' ' . $new_pass, + String => 'su password ' . $su . $SPACE . $new_pass . $SPACE . $new_pass, expect => $success, ); } =pod -=head2 B -- Change IP configuration on SUs connected to -the AP. +=head2 B - Change IP configuration on SUs connected to the AP. su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' ) @@ -591,8 +565,8 @@ # su ipconfig return $self->cmd( - String => 'su ipconfig ' . $suid . ' ' . $new_ip . ' ' - . $new_subnet . ' ' + String => 'su ipconfig ' . $suid . $SPACE . $new_ip . $SPACE + . $new_subnet . $SPACE . $new_gateway, expect => $success, ); @@ -600,8 +574,7 @@ =pod -=head2 B -- Returns the output from the sudb view command +=head2 B - Returns the output from the sudb view command returns a reference to an array of hashes each containing these keys 'suid', 'type', 'cir', 'mir' and 'mac' @@ -643,7 +616,7 @@ =pod -=head2 B +=head2 B - Adds an su to the sudb Takes the following paramaters @@ -696,10 +669,10 @@ $self->last_error("Invalid MAC '$mac'"); return; } - $new_mac = join ' ', $new_mac =~ /../g; + $new_mac = join $SPACE, $new_mac =~ /../g; my $string = - 'sudb add ' . $suid . ' ' . $type . ' ' . $cir . ' ' . $mir . ' ' + 'sudb add ' . $suid . $SPACE . $type . $SPACE . $cir . $SPACE . $mir . $SPACE . $new_mac; return $self->cmd( String => $string, expect => $success ); @@ -707,7 +680,7 @@ =pod -=head2 B +=head2 B - removes an su from the sudb Takes either 'all' or the suid of the su to delete and returns true on success or undef otherwise. @@ -734,7 +707,7 @@ =pod -=head2 B +=head2 B - changes the su information in the sudb Takes either the suid of the su to change as well as what you are changing, either "cir, mir or su2su" @@ -779,15 +752,14 @@ return; } - my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value; + my $string = 'sudb modify ' . $suid . $SPACE . $opt . $SPACE . $value; return $self->cmd( String => $string, expect => $success ); } =pod -=head2 B -- enable the TFTP server +=head2 B - enable the TFTP server runs C 'on')> and makes sure that Tftpd is now 'listen'ing @@ -808,8 +780,7 @@ =pod -=head2 B -- disable the TFTP server +=head2 B - disable the TFTP server runs C 'off')> and makes sure that Tftpd is now 'disabled' @@ -916,7 +887,7 @@ } } if ( $cfg{'args'} ) { - $cmd{'String'} .= ' ' . $cfg{'args'}; + $cmd{'String'} .= $SPACE . $cfg{'args'}; } my @lines; @@ -965,7 +936,16 @@ } } else { - $self->last_error("Error with command ($cfg{'String'}): $last"); + my $err; + if (grep { /\[ERR\]/ } @lines) { + $err = _decode_lines(@lines); + } + + if (ref $err eq 'HASH' && $err ->{ERR}) { + $self->last_error($err->{ERR} ); + } else { + $self->last_error("Error with command ($cfg{'String'}): $last"); + } return; } } @@ -977,7 +957,7 @@ my %conf; - my $key = ''; + my $key = $EMPTY; my $val = undef; my @vals; my $in_key = 0; @@ -988,7 +968,7 @@ my @chars = split //, $line; - my $last_key = ''; + my $last_key = $EMPTY; foreach my $c (@chars) { if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) { @@ -1015,17 +995,17 @@ # Special case for these bastids. my $new = $last_key; $new =~ s/\s+\S+$//; - $key = $new . " " . $key; + $key = $new . $SPACE . $key; } $conf{$key} = $val; $last_key = $key; - $key = ''; + $key = $EMPTY; } elsif ($val) { push @vals, $val; } - $val = ''; + $val = $EMPTY; } elsif ( $c eq ']' ) {