=================================================================== RCS file: /cvs/trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm,v retrieving revision 1.16 retrieving revision 1.24 diff -u -r1.16 -r1.24 --- trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2006/09/07 04:00:07 1.16 +++ trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2007/01/17 19:00:51 1.24 @@ -1,5 +1,5 @@ package Net::Telnet::Trango; -# $RedRiver: Trango.pm,v 1.14 2006/09/07 02:49:34 andrew Exp $ +# $RedRiver: Trango.pm,v 1.23 2007/01/08 22:16:29 mike Exp $ use strict; use warnings; use base 'Net::Telnet'; @@ -14,13 +14,13 @@ use Net::Telnet::Trango; my $t = new Net::Telnet::Trango ( Timeout => 5 ); - + $t->open( Host => $fox ) or die "Error connecting: $!"; $t->login('password') or die "Couldn't log in: $!"; - + # Do whatever - + $t->exit; $t->close; @@ -28,12 +28,19 @@ Perl access to the telnet interface on Trango Foxes, SUs and APs. -Another handy feature is that it will parse the output from certain commands that is in the format "[key1] value1 [key2] value2" and put those in a hashref that is returned. This makes using the output from things like sysinfo very easy to do. +Another handy feature is that it will parse the output from certain +commands that is in the format "[key1] value1 [key2] value2" and put +those in a hashref that is returned. This makes using the output from +things like sysinfo very easy to do. =head2 EXPORT None +=head1 METHODS + +=over + =cut our $VERSION = '0.01'; @@ -157,7 +164,7 @@ =pod -=head1 METHODS +=back =head2 ACCESSORS @@ -192,7 +199,8 @@ =item login_banner -returns the banner that is displayed when first connected at login. Only set after a successful open() +returns the banner that is displayed when first connected at login. +Only set after a successful open() This is usually only set internally @@ -219,7 +227,9 @@ =head2 COMMANDS -Most of these are just shortcuts to C METHOD)>, as such they accept the same options as C. Specifically they take a named paramater "args", for example: +Most of these are just shortcuts to C METHOD)>, +as such they accept the same options as C. +Specifically they take a named paramater "args", for example: C 'on')> would enable tftpd =over @@ -246,6 +256,11 @@ reboots the trango and closes the connection +=item remarks + +Takes an optional argument, which sets the remarks. +If there is no argument, returns the current remarks. + =item sulog returns an array ref of hashes containing each log line. @@ -274,6 +289,14 @@ returns the output from the eth list command +=item su_info + +You need to pass in args => and it will return the info for that suid. + +=item save_ss + +saves the config. Returns 1 on success, undef on failure. + =cut @@ -286,12 +309,16 @@ sulog => { decode => 'sulog', expect => $success }, 'exit' => { no_prompt => 1, cmd_disconnects => 1 }, reboot => { no_prompt => 1, cmd_disconnects => 1 }, + 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 }, + save_ss => { String => 'save ss', expect => $success }, + opmode => { decode => 'all', expect => $success }, # eth r, w and reset??? #su password??? #_bootloader @@ -329,8 +356,8 @@ } if (exists $COMMANDS{$method}) { - $method = shift if (@_ == 1); $COMMANDS{$method}{'String'} ||= $method; + $COMMANDS{$method}{'args'} .= ' ' . shift if (@_ == 1); return $self->cmd(%{ $COMMANDS{$method} }, @_); } @@ -348,7 +375,9 @@ =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() +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 @@ -382,7 +411,8 @@ =item login -Calls open() if not already connected, then sends the password and sets logged_in() if successful +Calls open() if not already connected, then sends the password and sets +logged_in() if successful =cut @@ -414,7 +444,9 @@ =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() +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 @@ -442,21 +474,17 @@ =item su_password -C +C If no suid is specified, +the default is "all". =cut sub su_password { my $self = shift; - my $su = shift || '!'; my $new_pass = shift || ''; + my $su = shift || 'all'; - unless (defined $su) { - warn "No su passed!" - #return undef; - } - unless (defined $new_pass) { warn "No new password!" #return undef; @@ -731,23 +759,29 @@ =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. +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 +- 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 +- 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 +- 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 +- a string containing the command line options that are passed to the +command =cut @@ -860,9 +894,9 @@ my %conf; my $key = ''; - my $val = ''; + my $val = undef; my $in_key = 0; - my $in_val = 0; + my $in_val = 1; foreach my $line (@lines) { next if $line =~ /$success$/; @@ -878,15 +912,17 @@ $in_val = 0; } else { $in_key = 0; - $in_val = 0; + $in_val = 1; } if ($key) { $key =~ s/^\s+//; $key =~ s/\s+$//; - $val =~ s/^\s+//; - $val =~ s/\s+$//; + if (defined $val) { + $val =~ s/^\s+//; + $val =~ s/\s+$//; + } if ($key eq 'Checksum' && $last_key) { # Special case for these bastids. @@ -918,7 +954,7 @@ if (%conf) { return \%conf; } else { - return undef; + return $val; } } @@ -1018,15 +1054,21 @@ =head1 SEE ALSO -Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm +Trango Documentation - +http://www.trangobroadband.com/support/product_docs.htm L =head1 TODO -There are still a lot of commands that are not accessed directly. If you call them (as cmd("command + args") or whatever) and it works, please send me examples that work and I will try to get it incorporated into the next version of the script. +There are still a lot of commands that are not accessed directly. If +you call them (as cmd("command + args") or whatever) and it works, +please send me examples that work and I will try to get it incorporated +into the next version of the script. -I also want to be able to parse the different types of output from commands like su, sudb all and anything else that would be better available as a perl datastructure. +I also want to be able to parse the different types of output from +commands like su, sudb all and anything else that would be better +available as a perl datastructure. =head1 AUTHOR