| version 1.32, 2007/02/02 18:59:50 | version 1.37, 2007/02/05 23:09:59 | 
|  |  | 
| package Net::Telnet::Trango; | package Net::Telnet::Trango; | 
| # $RedRiver: Trango.pm,v 1.31 2007/02/02 18:54:22 andrew Exp $ |  | 
| use strict; | # $RedRiver: Trango.pm,v 1.36 2007/02/05 21:09:26 andrew Exp $ | 
| use warnings; | use strict; | 
| use base 'Net::Telnet'; | use warnings; | 
|  | use base 'Net::Telnet'; | 
| =pod |  | 
|  | =pod | 
| =head1 NAME |  | 
|  | =head1 NAME | 
| Net::Telnet::Trango |  | 
| - Perl extension for accessing the Trango telnet interface | Net::Telnet::Trango | 
|  | - Perl extension for accessing the Trango telnet interface | 
| =head1 SYNOPSIS |  | 
|  | =head1 SYNOPSIS | 
| use Net::Telnet::Trango; |  | 
| my $t = new Net::Telnet::Trango ( Timeout => 5 ); | use Net::Telnet::Trango; | 
|  | 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->close; | $t->exit; | 
|  | $t->close; | 
| =head1 DESCRIPTION |  | 
|  | =head1 DESCRIPTION | 
| Perl access to the telnet interface on Trango Foxes, SUs and APs. |  | 
|  | 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 | Another handy feature is that it will parse the output from certain | 
| those in a hashref that is returned.  This makes using the output from | commands that is in the format "[key1] value1 [key2] value2" and put | 
| things like sysinfo very easy to do. | those in a hashref that is returned.  This makes using the output from | 
|  | things like sysinfo very easy to do. | 
| =head2 EXPORT |  | 
|  | =head2 EXPORT | 
| None |  | 
|  | None | 
| =head1 METHODS |  | 
|  | =head1 METHODS | 
| =over |  | 
|  | =cut | 
| =cut |  | 
|  | our $VERSION = '0.01'; | 
| our $VERSION = '0.01'; |  | 
|  | my %PRIVATE = ( | 
| my %PRIVATE = ( | is_connected => 0, | 
| is_connected => 0, | logged_in    => 0, | 
| logged_in => 0, | ); | 
| ); |  | 
|  | =pod | 
| =pod |  | 
|  | =head2 B<new> - Creates a new Net::Telnet::Trango object. | 
| =item B<new> |  | 
|  | new([Options from Net::Telnet,] | 
| - Creates a new Net::Telnet::Trango object. | [Decode => 0,]); | 
|  |  | 
| new([Options from Net::Telnet,] | Same as new from L<Net::Telnet> but sets the default Trango Prompt: | 
| [Decode => 0,]); | '/#> *$/' | 
|  |  | 
| Same as new from L<Net::Telnet> but sets the default Trango Prompt: | It also takes an optional parameter 'Decode'.  If not defined it | 
| '/#> *$/' | defaults to 1, if it is set to 0, it will not decode the output and | 
|  | instead return a reference to an array of the lines that were returned | 
| It also takes an optional parameter 'Decode'.  If not defined it | from the command. | 
| defaults to 1, if it is set to 0, it will not decode the output and |  | 
| instead return a reference to an array of the lines that were returned | =cut | 
| from the command. |  | 
|  | sub new { | 
| =cut | my $class = shift; | 
|  |  | 
| sub new | my %args; | 
| { | if ( @_ == 1 ) { | 
| my $class = shift; | $args{'Host'} = shift; | 
|  | } | 
| my %args; | else { | 
| if (@_ == 1) { | %args = @_; | 
| $args{'Host'} = shift; | } | 
| } else { |  | 
| %args = @_; | $args{'Prompt'} ||= '/#> *$/'; | 
| } |  | 
|  | foreach my $key ( keys %args ) { | 
| $args{'Prompt'}  ||= '/#> *$/'; | $PRIVATE{$key} = $args{$key}; | 
|  | } | 
| foreach my $key (keys %args) { | $PRIVATE{'Decode'} = 1 unless defined $PRIVATE{'Decode'}; | 
| $PRIVATE{$key} = $args{$key}; | delete $args{'Decode'}; | 
| } |  | 
| $PRIVATE{'Decode'} = 1 unless defined $PRIVATE{'Decode'}; | my $self = $class->SUPER::new(%args); | 
| delete $args{'Decode'}; | bless $self if ref $self; | 
|  |  | 
| my $self = $class->SUPER::new(%args); | return $self; | 
| bless $self if ref $self; | } | 
|  |  | 
| return $self; | #  _password <new password> <new password> | 
| } | #  ? [command] | 
|  | #  apsearch <secs> <ch#> <h|v> [<ch#> <h|v>]... | 
| #  _password <new password> <new password> | #  arp -bcast <on|off> | 
| #  ? [command] | #  bcastscant <all|suid> <ch#> <h|v> [<ch#> <h|v> ... | 
| #  apsearch <secs> <ch#> <h|v> [<ch#> <h|v>]... | #  bye | 
| #  arp -bcast <on|off> | #  cf2cf ap [default|<size>] | 
| #  bcastscant <all|suid> <ch#> <h|v> [<ch#> <h|v> ... | #  date | 
| #  bye | #  date <month> <day> <year> | 
| #  cf2cf ap [default|<size>] | #  freq scantable | 
| #  date | #  freq channeltable | 
| #  date <month> <day> <year> | #  freq writescan [<ch#> <h|v>] | 
| #  freq scantable | #  freq writechannel [<ch#> <freq>] ... | 
| #  freq channeltable | #  freq <ch #> <h|v> | 
| #  freq writescan [<ch#> <h|v>] | #  help [command] | 
| #  freq writechannel [<ch#> <freq>] ... | #  heater [<on temp> <off temp>] | 
| #  freq <ch #> <h|v> | #  ipconfig [<new ip> <new subnet mask> <new gateway>] | 
| #  help [command] | #  log [<# of entries, 1..179>] | 
| #  heater [<on temp> <off temp>] | #  log <sum> <# of entries, 1..179> | 
| #  ipconfig [<new ip> <new subnet mask> <new gateway>] | #  logout | 
| #  log [<# of entries, 1..179>] | #  opmode [ap [y]] | 
| #  log <sum> <# of entries, 1..179> | #  password | 
| #  logout | #  ping <ip addr> | 
| #  opmode [ap [y]] | #  polar <h|v> | 
| #  password | #  power <setism|setunii> <max|min|<dBm>> | 
| #  ping <ip addr> | #  reboot | 
| #  polar <h|v> | #  restart | 
| #  power <setism|setunii> <max|min|<dBm>> | #  remarks [<str>] | 
| #  reboot | #  rfrxthreshold [<ism|unii> <-90|-85|-80|-75|-70|-65>] | 
| #  restart | #  rfrxth [<ism|unii> <-90|-85|-80|-75|-70|-65>] | 
| #  remarks [<str>] | #  sysinfo | 
| #  rfrxthreshold [<ism|unii> <-90|-85|-80|-75|-70|-65>] | #  set suid <id> | 
| #  rfrxth [<ism|unii> <-90|-85|-80|-75|-70|-65>] | #  set apid <id> | 
| #  sysinfo | #  set baseid <id> | 
| #  set suid <id> | #  set defaultopmode [<ap|su> <min,0..10>] | 
| #  set apid <id> | #  set defaultopmode off | 
| #  set baseid <id> | #  set snmpcomm [<read | write | trap (id or setall)> <str>] | 
| #  set defaultopmode [<ap|su> <min,0..10>] | #  set mir [on|off] | 
| #  set defaultopmode off | #  set mir threshold <kbps> | 
| #  set snmpcomm [<read | write | trap (id or setall)> <str>] | #  set rssitarget [<ism|unii> <dBm>] | 
| #  set mir [on|off] | #  set serviceradius [<ism | unii> <miles>] | 
| #  set mir threshold <kbps> | #  ssrssi <ch #> <h|v> | 
| #  set rssitarget [<ism|unii> <dBm>] | #  su [<suid>|all] | 
| #  set serviceradius [<ism | unii> <miles>] | #  su changechannel <all|suid> <ch#> <h|v> | 
| #  ssrssi <ch #> <h|v> | #  su ipconfig <suid> <new ip> <new subnet> <new gateway> | 
| #  su [<suid>|all] | #  su [live|poweroff|priority] | 
| #  su changechannel <all|suid> <ch#> <h|v> | #  su <ping|info|status> <suid> | 
| #  su ipconfig <suid> <new ip> <new subnet> <new gateway> | #  su powerleveling <all|suid> | 
| #  su [live|poweroff|priority] | #  su reboot <all|suid> | 
| #  su <ping|info|status> <suid> | #  su restart <all|suid> | 
| #  su powerleveling <all|suid> | #  su testrflink <all|suid> [r] | 
| #  su reboot <all|suid> | #  su testrflink <setlen> [64..1600] | 
| #  su restart <all|suid> | #  su testrflink <aptx> [20..100] | 
| #  su testrflink <all|suid> [r] | #  su sw <suid|all> <sw #> <on|off> | 
| #  su testrflink <setlen> [64..1600] | #  sudb [dload | view] | 
| #  su testrflink <aptx> [20..100] | #  sudb add <suid> pr <cir,kbps> <mir,kbps> <device id,hex> | 
| #  su sw <suid|all> <sw #> <on|off> | #  sudb add <suid> reg <cir,kbps> <mir,kbps> <device id,hex> | 
| #  sudb [dload | view] | #  sudb delete <all|<suid>> | 
| #  sudb add <suid> pr <cir,kbps> <mir,kbps> <device id,hex> | #  sudb modify <suid> <cir|mir> <kbps> | 
| #  sudb add <suid> reg <cir,kbps> <mir,kbps> <device id,hex> | #  sudb modify <suid> <su2su> <group id,hex> | 
| #  sudb delete <all|<suid>> | #  sudb view | 
| #  sudb modify <suid> <cir|mir> <kbps> | #  sulog [lastmins | sampleperiod <1..60>] | 
| #  sudb modify <suid> <su2su> <group id,hex> | #  sulog [<# of entry,1..18>] | 
| #  sudb view | #  survey <ism|unii> <time, sec> <h|v> | 
| #  sulog [lastmins | sampleperiod <1..60>] | #  sw [<sw #> <on|off>] | 
| #  sulog [<# of entry,1..18>] | #  temp | 
| #  survey <ism|unii> <time, sec> <h|v> | #  tftpd [on|off] | 
| #  sw [<sw #> <on|off>] | #  time | 
| #  temp | #  time <hour> <min> <sec> | 
| #  tftpd [on|off] | #  save <mainimage|fpgaimage> <current chksum> <new chksum> | 
| #  time | #  save <systemsetting|sudb> | 
| #  time <hour> <min> <sec> | #  updateflash <mainimage|fpgaimage> <current chksum> <new chksum> | 
| #  save <mainimage|fpgaimage> <current chksum> <new chksum> | #  updateflash <systemsetting|sudb> | 
| #  save <systemsetting|sudb> |  | 
| #  updateflash <mainimage|fpgaimage> <current chksum> <new chksum> | =pod | 
| #  updateflash <systemsetting|sudb> |  | 
|  | =head1 ACCESSORS | 
| =pod |  | 
|  | These are usually only set internally. | 
| =back |  | 
|  | =head2 B<firmware_version> - returns the firmware version | 
| =head2 ACCESSORS |  | 
|  | Returns the firmware version if available, otherwise undef. | 
| These are usually only set internally. |  | 
|  | It should be available after a successful open(). | 
| =over |  | 
|  | =head2 B<host_type> - return the type of host you are connected to. | 
| =item B<firmware_version> |  | 
|  | returns the type of host from the login banner for example M5830S or M5300S. | 
| - returns the firmware version |  | 
|  | Should be available after a successful open(). | 
| Returns the firmware version if available, otherwise undef. |  | 
|  | =head2 B<is_connected> - Status of the connection to host. | 
| It should be available after a successful open(). |  | 
|  | returns 1 when connected, undef otherwise. | 
| =item B<host_type> |  | 
|  | =head2 B<logged_in> - Status of being logged in to the host. | 
| - return the type of host you are connected to. |  | 
|  | returns 1 after a successful login(), 0 if it failed and undef if | 
| returns the type of host from the login banner for example M5830S or M5300S. | login() was never called. | 
|  |  | 
| Should be available after a successful open(). | =head2 B<login_banner> - The banner when first connecting to the host. | 
|  |  | 
| =item B<is_connected> | returns the banner that is displayed when first connected at login. | 
|  | Only set after a successful open(). | 
| - Status of the connection to host. |  | 
|  | =head2 B<last_lines> - The last lines of output from the last cmd(). | 
| returns 1 when connected, undef otherwise. |  | 
|  | returns, as an array ref, the output from the last cmd() that was run. | 
| =item B<logged_in> |  | 
|  | =head2 B<last_error> - A text output of the last error that was encountered. | 
| - Status of being logged in to the host. |  | 
|  | returns the last error reported.  Probably contains the last entry in | 
| returns 1 after a successful login(), 0 if it failed and undef if | last_lines. | 
| login() was never called. |  | 
|  | =head1 ALIASES | 
| =item B<login_banner> |  | 
|  | =head2 B<bye> - alias of exit() | 
| - The banner when first connecting to the host. |  | 
|  | Does the same as exit() | 
| returns the banner that is displayed when first connected at login. |  | 
| Only set after a successful open(). | =head2 B<restart> - alias of reboot() | 
|  |  | 
| =item B<last_lines> | Does the same as reboot() | 
|  |  | 
| - The last lines of output from the last cmd(). | =head1 COMMANDS | 
|  |  | 
| returns, as an array ref, the output from the last cmd() that was run. | Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>, | 
|  | as such they accept the same options as C<cmd()>. | 
| =item B<last_error> | Specifically they take a named paramater "args", for example: | 
|  | C<tftpd(args =E<gt> 'on')> would enable tftpd | 
| - A text output of the last error that was encountered. |  | 
|  | =head2 B<tftpd> - The output from the tftpd command | 
| returns the last error reported.  Probably contains the last entry in |  | 
| last_lines. | Returns a hash ref of the decoded output from the | 
|  | command. | 
| =back |  | 
|  | Also see enable_tftpd() and disable_tftpd() as those check that it was | 
| =head2 ALIASES | successfully changed. | 
|  |  | 
| =over | =head2 B<ver> - The output from the ver command | 
|  |  | 
| =item B<bye> | Returns a hash ref of the decoded output from the | 
|  | command. | 
| - alias of L<exit()>. |  | 
|  | =head2 B<sysinfo> - The output from the sysinfo command | 
| =item B<restart> |  | 
|  | Returns a hash ref of the decoded output from the | 
| - alias of L<reboot()>. | command. | 
|  |  | 
| =back | =head2 B<exit> - Exits the connection | 
|  |  | 
| =head2 COMMANDS | exits the command session with the Trango and closes | 
|  | the connection | 
| Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>, |  | 
| as such they accept the same options as C<cmd()>. | =head2 B<reboot> - Sends a reboot command | 
| Specifically they take a named paramater "args", for example: |  | 
| C<tftpd(args =E<gt> 'on')> would enable tftpd | reboots the Trango and closes the connection | 
|  |  | 
| =over | =head2 B<remarks> - Set or retrieve the remarks. | 
|  |  | 
| =item B<tftpd> | Takes an optional argument, which sets the remarks. | 
|  | If there is no argument, returns the current remarks. | 
| - Returns a hash ref of the decoded output from the |  | 
| command. | my $old_remarks = $t->remarks(); | 
|  | $t->remarks($new_remarks); | 
| Also see enable_tftpd() and disable_tftpd() as those check that it was |  | 
| successfully changed. | =head2 B<sulog> - The output from the sulog command | 
|  |  | 
| =item B<ver> | Returns an array ref of hashes containing each log | 
|  | line. | 
| - Returns a hash ref of the decoded output from the |  | 
| command. | =head2 B<save_sudb> - saves the sudb | 
|  |  | 
| =item B<sysinfo> | Returns true on success, undef on failure | 
|  |  | 
| - Returns a hash ref of the decoded output from the | =head2 B<syslog> - The output from the sulog command | 
| command. |  | 
|  | Returns a hashref of the output from the syslog command | 
| =item B<exit> |  | 
|  | =head2 B<pipe> - the pipe command | 
| - exits the command session with the Trango and closes |  | 
| the connection | Returns the output from the pipe command | 
|  |  | 
| =item B<reboot> | =head2 B<maclist> - retrieves the maclist | 
|  |  | 
| - reboots the Trango and closes the connection | Returns the output from the maclist command | 
|  |  | 
| =item B<remarks> | =head2 B<maclist_reset> - resets the maclist. | 
|  |  | 
| - Set or retrieve the remarks. | No useful output. | 
|  |  | 
| Takes an optional argument, which sets the remarks. | =head2 B<eth_list> - eth list command | 
| If there is no argument, returns the current remarks. |  | 
|  | Returns the output from the eth list command | 
| my $old_remarks = $t->remarks(); |  | 
| $t->remarks($new_remarks); |  | 
|  | =head2 B<su_info> - gets the su info | 
| =item B<sulog> |  | 
|  | Returns information about the SU. | 
| - returns an array ref of hashes containing each log |  | 
| line. | You need to pass in the $suid and it will return the info for that suid. | 
|  |  | 
| =item B<save_sudb> | $t->su_info($suid); | 
|  |  | 
| - returns true on success, undef on failure | =head2 B<su_testrflink> - tests the RF Link to an su | 
|  |  | 
| =item B<syslog> | $t->su_testrflink($suid|'all'); | 
|  |  | 
| - returns the output from the syslog command | =head2 B<save_ss> - saves the config. | 
|  |  | 
| =item B<pipe> | Returns 1 on success, undef on failure. | 
|  |  | 
| - returns the output from the pipe command | =head2 B<opmode> - sets opmode ap y or returns the opmode | 
|  |  | 
| =item B<maclist> | $t->opmode([ap y]); | 
|  |  | 
| -  returns the output from the maclist command | =cut | 
|  |  | 
| =item B<maclist_reset> | my $success  = 'Success\\.'; | 
|  | my %COMMANDS = ( | 
| - resets the maclist. | tftpd       => { decode    => 'all',       expect          => $success }, | 
|  | ver         => { decode    => 'all' }, | 
| No useful output. | sysinfo     => { decode    => 'all',       expect          => $success }, | 
|  | updateflash => { decode    => 'all',       expect          => $success }, | 
| =item B<eth_list> | sulog       => { decode    => 'sulog',     expect          => $success }, | 
|  | 'exit'      => { no_prompt => 1,           cmd_disconnects => 1 }, | 
| - returns the output from the eth list command | reboot      => { no_prompt => 1,           cmd_disconnects => 1 }, | 
|  | remarks     => { decode    => 'all',       expect          => $success }, | 
| =item B<su_info> | save_sudb   => { String    => 'save sudb', expect          => $success }, | 
|  | syslog      => { expect    => $success }, | 
| - returns information about the SU. | 'pipe'      => {},                        # XXX needs a special decode | 
|  | maclist     => { decode => 'maclist' }, | 
| You need to pass in the $suid and it will return the info for that suid. | maclist_reset => { String => 'maclist reset', expect       => 'done' }, | 
|  | eth_link    => { String => 'eth link',     expect          => $success }, | 
| $t->su_info($suid); | su_info     => | 
|  | { String => 'su info',  decode => 'all', expect          => $success }, | 
| =item B<su_testrflink> | su_testrflink => | 
|  | { String => 'su testrflink', decode => 'each', expect    => $success }, | 
| - tests the RF Link to an su | save_ss     => { String => 'save ss',      expect          => $success }, | 
|  | opmode      => { decode => 'all',          expect          => $success }, | 
| $t->su_testrflink($suid|'all'); | ); | 
|  |  | 
| =item B<save_ss> | my %ALIASES = ( | 
|  | bye     => 'exit', | 
| - saves the config. | restart => 'reboot', | 
|  | Host    => 'host', | 
| Returns 1 on success, undef on failure. | ); | 
|  |  | 
| =cut | my %ACCESS = map { $_ => 1 } qw( | 
|  | firmware_version | 
|  | host_type | 
| my $success = 'Success\\.'; | is_connected | 
| my %COMMANDS = ( | logged_in | 
| tftpd       => { decode => 'all',   expect => $success }, | login_banner | 
| ver         => { decode => 'all' }, | Timeout | 
| sysinfo     => { decode => 'all',   expect => $success }, | last_lines | 
| updateflash => { decode => 'all',   expect => $success }, | last_vals | 
| sulog       => { decode => 'sulog', expect => $success }, | last_error | 
| 'exit'      => { no_prompt => 1, cmd_disconnects => 1 }, | Decode | 
| reboot      => { no_prompt => 1, cmd_disconnects => 1 }, | ); | 
| remarks     => { decode => 'all', expect => $success }, |  | 
| save_sudb   => { String => 'save sudb', expect => $success }, | sub AUTOLOAD { | 
| syslog      => { expect => $success }, | my $self = shift; | 
| 'pipe'      => { }, # XXX needs a special decode |  | 
| maclist     => { decode => 'maclist' }, | my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/ | 
| maclist_reset => { String => 'maclist reset', expect => 'done' }, | or die "Weird: $AUTOLOAD"; | 
| eth_link    => { String => 'eth link', expect => $success }, |  | 
| su_info     => { String => 'su info', decode => 'all', expect => $success }, | if ( exists $ALIASES{$method} ) { | 
| su_testrflink => { String => 'su testrflink', decode => 'each', expect => $success }, | $method = $ALIASES{$method}; | 
| save_ss     => { String => 'save ss', expect => $success }, | return $self->$method(@_); | 
| opmode      => { decode => 'all',   expect => $success }, | } | 
| # eth r, w and reset??? |  | 
| #su password??? | if ( exists $COMMANDS{$method} ) { | 
| #_bootloader | my %cmd; | 
| #temp | foreach my $k ( keys %{ $COMMANDS{$method} } ) { | 
| #heater | $cmd{$k} = $COMMANDS{$method}{$k}; | 
| ); | } | 
|  | $cmd{'String'} ||= $method; | 
| my %ALIASES = ( | $cmd{'args'} .= ' ' . shift if ( @_ == 1 ); | 
| bye     => 'exit', | return $self->cmd( %cmd, @_ ); | 
| restart => 'reboot', | } | 
| Host    => 'host', |  | 
| ); | if ( exists $ACCESS{$method} ) { | 
|  | my $prev = $PRIVATE{$method}; | 
| my %ACCESS = map { $_ => 1 } qw( | ( $PRIVATE{$method} ) = @_ if @_; | 
| firmware_version | return $prev; | 
| host_type | } | 
| is_connected |  | 
| logged_in | $method = "SUPER::$method"; | 
| login_banner | return $self->$method(@_); | 
| Timeout | } | 
| last_lines |  | 
| last_vals | =pod | 
| last_error |  | 
| Decode | =head2 B<open> - Open a connection to a Trango AP. | 
| ); |  | 
|  | Calls Net::Telnet::open() then makes sure you get a password prompt so | 
| sub AUTOLOAD | you are ready to login() and parses the login banner so you can get | 
| { | host_type() and firmware_version() | 
| my $self = shift; |  | 
|  | =cut | 
| my ($method) = (our $AUTOLOAD) =~ /^.*::(\w+)$/ |  | 
| or die "Weird: $AUTOLOAD"; | sub open { | 
|  | my $self = shift; | 
| if (exists $ALIASES{$method}) { |  | 
| $method = $ALIASES{$method}; | unless ( $self->SUPER::open(@_) ) { | 
| return $self->$method(@_); | $self->last_error( "Couldn't connect to " . $self->host . ":  $!" ); | 
| } | return; | 
|  | } | 
| if (exists $COMMANDS{$method}) { |  | 
| my %cmd; | ## Get to login prompt | 
| foreach my $k (keys %{ $COMMANDS{$method} }) { | unless ( | 
| $cmd{$k} = $COMMANDS{$method}{$k}; | $self->waitfor( | 
| } | -match   => '/password: ?$/i', | 
| $cmd{'String'} ||= $method; | -errmode => "return", | 
| $cmd{'args'}   .= ' ' . shift if (@_ == 1); | ) | 
| return $self->cmd(%cmd, @_); | ) | 
| } | { | 
|  | $self->last_error( "problem connecting to host (" | 
| if (exists $ACCESS{$method}) { | . $self->host . "): " | 
| my $prev = $PRIVATE{$method}; | . $self->lastline ); | 
| ($PRIVATE{$method}) = @_ if @_; | return; | 
| return $prev; | } | 
| } |  | 
|  | $self->parse_login_banner( $self->lastline ); | 
| $method = "SUPER::$method"; |  | 
| return $self->$method(@_); | $self->is_connected(1); | 
| } |  | 
|  | return $self->is_connected; | 
| =pod | } | 
|  |  | 
| =item B<open> | =pod | 
|  |  | 
| - Open a connection to a Trango AP. | =head2 B<login> - Login to the AP. | 
|  |  | 
| Calls Net::Telnet::open() then makes sure you get a password prompt so | Calls open() if not already connected, then sends the password and sets | 
| you are ready to login() and parses the login banner so you can get | logged_in() if successful | 
| host_type() and firmware_version() |  | 
|  | =cut | 
| =cut |  | 
|  | sub login { | 
| sub open | my $self = shift; | 
| { |  | 
| my $self = shift; | unless ( $self->is_connected ) { | 
|  | $self->open or return; | 
| unless ( $self->SUPER::open(@_) ) { | } | 
| $self->last_error("Couldn't connect to " . $self->host . ":  $!"); |  | 
| return; | my $password = shift; | 
| } |  | 
|  | $self->print($password); | 
| ## Get to login prompt | unless ( | 
| unless ($self->waitfor( | $self->waitfor( | 
| -match => '/password: ?$/i', | -match   => $self->prompt, | 
| -errmode => "return", | -errmode => "return", | 
| ) ) { | ) | 
| $self->last_error("problem connecting to host (" . $self->host . "): " . | ) | 
| $self->lastline); | { | 
| return; | $self->last_error( "login ($self->host) failed: " . $self->lastline ); | 
| } | return; | 
|  | } | 
| $self->parse_login_banner($self->lastline); |  | 
|  | $self->logged_in(1); | 
| $self->is_connected(1); |  | 
|  | return $self->logged_in; | 
| return $self->is_connected; | } | 
| } |  | 
|  | =pod | 
| =pod |  | 
|  | =head2 B<parse_login_banner> - Converts the login_banner to something useful. | 
| =item B<login> |  | 
|  | Takes a login banner (what you get when you first connect to the Trango) | 
| - Login to the AP. | or reads what is already in login_banner() then parses it and sets | 
|  | host_type() and firmware_version() as well as login_banner() | 
| Calls open() if not already connected, then sends the password and sets |  | 
| logged_in() if successful | =cut | 
|  |  | 
| =cut | sub parse_login_banner { | 
|  | my $self = shift; | 
| sub login |  | 
| { | if (@_) { | 
| my $self = shift; | $self->login_banner(@_); | 
|  | } | 
| unless ($self->is_connected) { |  | 
| $self->open or return; | my $banner = $self->login_banner; | 
| } |  | 
|  | my ( $type, $sep1, $subtype, $sep2, $ver ) = | 
| my $password = shift; | $banner =~ | 
|  | /Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i; | 
| $self->print($password); |  | 
| unless ($self->waitfor( | $type .= $sep1 . $subtype; | 
| -match => $self->prompt, | $ver = $subtype . $sep2 . $ver; | 
| -errmode => "return", |  | 
| ) ) { | $self->login_banner($banner); | 
| $self->last_error("login ($self->host) failed: " . $self->lastline); | $self->host_type($type); | 
| return; | $self->firmware_version($ver); | 
| } |  | 
|  | return 1; | 
| $self->logged_in(1); | } | 
|  |  | 
| return $self->logged_in; | =pod | 
| } |  | 
|  | =head2 B<su_password> - Set the password on SUs connected to the AP. | 
| =pod |  | 
|  | su_password('new_password'[, 'suid']) If no suid is specified, | 
| =item B<parse_login_banner> | the default is "all". | 
|  |  | 
| - Converts the login_banner to some useful | $t->su_password('good_pass', 5); | 
| variables. |  | 
|  | =cut | 
| 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 | sub su_password { | 
| host_type() and firmware_version() as well as login_banner() | my $self     = shift; | 
|  | my $new_pass = shift || ''; | 
| =cut | my $su       = shift || 'all'; | 
|  |  | 
| sub parse_login_banner | unless ( defined $new_pass ) { | 
| { | $self->last_error("No new password"); | 
| my $self = shift; |  | 
|  | #return; | 
| if (@_) { | } | 
| $self->login_banner(@_); |  | 
| } | return $self->cmd( | 
|  | String => 'su password ' . $su . ' ' . $new_pass . ' ' . $new_pass, | 
| my $banner = $self->login_banner; | expect => $success, | 
|  | ); | 
| my ($type, $sep1, $subtype, $sep2, $ver) = $banner =~ | } | 
| /Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i; |  | 
|  | =pod | 
| $type .= $sep1 . $subtype; |  | 
| $ver = $subtype . $sep2 . $ver; | =head2 B<su_ipconfig> - Change IP configuration on SUs connected to the AP. | 
|  |  | 
| $self->login_banner($banner); | su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' ) | 
| $self->host_type($type); |  | 
| $self->firmware_version($ver); | $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' ); | 
|  |  | 
| return 1; | =cut | 
| } |  | 
|  | sub su_ipconfig { | 
| =pod | my $self = shift; | 
|  |  | 
| =item B<su_password> | my $suid        = shift; | 
|  | my $new_ip      = shift; | 
| - Set the password on SUs connected to the AP. | my $new_subnet  = shift; | 
|  | my $new_gateway = shift; | 
| su_password('new_password'[, 'suid']) If no suid is specified, |  | 
| the default is "all". | if ( $suid =~ /\D/ ) { | 
|  | $self->last_error("Invalid suid '$suid'"); | 
| $t->su_password('good_pass', 5); | return; | 
|  | } | 
| =cut | unless ($new_ip) { | 
|  | $self->last_error("no new_ip passed"); | 
| sub su_password | return; | 
| { | } | 
| my $self     = shift; | unless ($new_subnet) { | 
| my $new_pass = shift || ''; | $self->last_error("no new_subnet passed"); | 
| my $su       = shift || 'all'; | return; | 
|  | } | 
| unless (defined $new_pass) { | unless ($new_gateway) { | 
| $self->last_error("No new password"); | $self->last_error("no new_gateway passed"); | 
| #return; | return; | 
| } | } | 
|  |  | 
| return $self->cmd(String => 'su password ' . | # su ipconfig <suid> <new ip> <new subnet> <new gateway> | 
| $su . ' ' . | return $self->cmd( | 
| $new_pass . ' ' . | String => 'su ipconfig ' . $suid . ' ' . $new_ip . ' ' | 
| $new_pass, | . $new_subnet . ' ' | 
| expect => $success, | . $new_gateway, | 
| ); | expect => $success, | 
| } | ); | 
|  | } | 
| =pod |  | 
|  | =pod | 
| =item B<su_ipconfig> |  | 
|  | =head2 B<sudb_view> - Returns the output from the sudb view command | 
| - Change IP configuration on SUs connected to |  | 
| the AP. | returns a reference to an array of hashes each containing these keys | 
|  | 'suid', 'type', 'cir', 'mir' and 'mac' | 
| su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' ) |  | 
|  | =cut | 
| $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' ); |  | 
|  | sub sudb_view { | 
| =cut | my $self = shift; | 
|  |  | 
| sub su_ipconfig | my $lines = $self->cmd( String => 'sudb view', expect => $success ) || []; | 
| { |  | 
| my $self        = shift; | return unless @{$lines}; | 
|  |  | 
| my $suid        = shift; | unless ( $PRIVATE{'Decode'} ) { | 
| my $new_ip      = shift; | return $lines; | 
| my $new_subnet  = shift; | } | 
| my $new_gateway = shift; |  | 
|  | my @sus; | 
| if ($suid =~ /\D/) { | foreach ( @{$lines} ) { | 
| $self->last_error("Invalid suid '$suid'"); | next unless $_; | 
| return; | if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) { | 
| } | my %s = ( | 
| unless ($new_ip) { | suid => $1, | 
| $self->last_error("no new_ip passed"); | type => $2, | 
| return; | cir  => $3, | 
| } | mir  => $4, | 
| unless ($new_subnet) { | mac  => $5, | 
| $self->last_error("no new_subnet passed"); | ); | 
| return; |  | 
| } | $s{'mac'} =~ s/\s//g; | 
| unless ($new_gateway) { | $s{'mac'} = uc( $s{'mac'} ); | 
| $self->last_error("no new_gateway passed"); |  | 
| return; | push @sus, \%s; | 
| } | } | 
|  | } | 
| # su ipconfig <suid> <new ip> <new subnet> <new gateway> |  | 
| return $self->cmd(String => 'su ipconfig ' . | return \@sus; | 
| $suid       . ' ' . | } | 
| $new_ip     . ' ' . |  | 
| $new_subnet . ' ' . | =pod | 
| $new_gateway, |  | 
| expect => $success, | =head2 B<sudb_add> - Adds an su to the sudb | 
| ); |  | 
| } | Takes the following paramaters | 
|  |  | 
| =pod | suid : numeric, | 
|  | type : (reg|pr) | 
| =item B<sudb_view> | cir  : numeric, | 
|  | mir  : numeric, | 
| - Returns the output from the sudb view command | mac  : Almost any format, it will be reformatted, | 
|  |  | 
| returns a reference to an array of hashes each containing these keys | and returns true on success or undef otherwise. | 
| 'suid', 'type', 'cir', 'mir' and 'mac' |  | 
|  | $t->sudb_add($suid, 'reg', $cir, $mir, $mac); | 
| =cut |  | 
|  | You should save_sudb() after calling this, or your changes  will be lost | 
| sub sudb_view | when the AP is rebooted. | 
| { |  | 
| my $self = shift; | =cut | 
|  |  | 
| my $lines = $self->cmd( String => 'sudb view', expect => $success ) || []; | sub sudb_add { | 
|  | my $self = shift; | 
| return unless @{ $lines }; | my $suid = shift; | 
|  | my $type = shift; | 
| unless ($PRIVATE{'Decode'}) { | my $cir  = shift; | 
| return $lines; | my $mir  = shift; | 
| } | my $mac  = shift; | 
|  |  | 
| my @sus; | if ( $suid =~ /\D/ ) { | 
| foreach (@{ $lines }) { | $self->last_error("Invalid suid '$suid'"); | 
| next unless $_; | return; | 
| if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) { | } | 
| my %s = ( |  | 
| suid => $1, | unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) { | 
| type => $2, | $self->last_error("Invalid type '$type'"); | 
| cir  => $3, | return; | 
| mir  => $4, | } | 
| mac  => $5, |  | 
| ); | if ( $cir =~ /\D/ ) { | 
|  | $self->last_error("Invalid CIR '$cir'"); | 
| $s{'mac'} =~ s/\s//g; | return; | 
| $s{'mac'} = uc($s{'mac'}); | } | 
|  |  | 
| push @sus, \%s; | if ( $mir =~ /\D/ ) { | 
| } | $self->last_error("Invalid MIR '$mir'"); | 
| } | return; | 
|  | } | 
| return \@sus; |  | 
| } | my $new_mac = $mac; | 
|  | $new_mac =~ s/[^0-9A-Fa-f]//; | 
| =pod | unless ( length $new_mac == 12 ) { | 
|  | $self->last_error("Invalid MAC '$mac'"); | 
| =item B<sudb_add> | return; | 
|  | } | 
| Takes the following paramaters | $new_mac = join ' ', $new_mac =~ /../g; | 
|  |  | 
| suid : numeric, | my $string = | 
| type : (reg|pr) | 'sudb add ' . $suid . ' ' . $type . ' ' . $cir . ' ' . $mir . ' ' | 
| cir  : numeric, | . $new_mac; | 
| mir  : numeric, |  | 
| mac  : Almost any format, it will be reformatted, | return $self->cmd( String => $string, expect => $success ); | 
|  | } | 
| and returns true on success or undef otherwise. |  | 
|  | =pod | 
| $t->sudb_add($suid, 'reg', $cir, $mir, $mac); |  | 
|  | =head2 B<sudb_delete> - removes an su from the sudb | 
| You should save_sudb() after calling this, or your changes  will be lost |  | 
| when the AP is rebooted. | Takes either 'all' or the  suid of the su to delete | 
|  | and returns true on success or undef otherwise. | 
| =cut |  | 
|  | $t->sudb_delete($suid); | 
| sub sudb_add |  | 
| { | You should save_sudb() after calling this, or your changes  will be lost | 
| my $self = shift; | when the AP is rebooted. | 
| my $suid = shift; |  | 
| my $type = shift; | =cut | 
| my $cir  = shift; |  | 
| my $mir  = shift; | sub sudb_delete { | 
| my $mac  = shift; | my $self = shift; | 
|  | my $suid = shift; | 
| if ($suid =~ /\D/) { |  | 
| $self->last_error("Invalid suid '$suid'"); | #if (lc($suid) ne 'all' || $suid =~ /\D/) { | 
| return; | if ( $suid =~ /\D/ ) { | 
| } | $self->last_error("Invalid suid '$suid'"); | 
|  | return; | 
| unless (lc($type) eq 'reg' || lc($type) eq 'pr') { | } | 
| $self->last_error("Invalid type '$type'"); |  | 
| return; | return $self->cmd( String => 'sudb delete ' . $suid, expect => $success ); | 
| } | } | 
|  |  | 
| if ($cir =~ /\D/) { | =pod | 
| $self->last_error("Invalid CIR '$cir'"); |  | 
| return; | =head2 B<sudb_modify> - changes the su information in the sudb | 
| } |  | 
|  | Takes either the  suid of the su to change | 
| if ($mir =~ /\D/) { | as well as what you are changing, either "cir, mir or su2su" | 
| $self->last_error("Invalid MIR '$mir'"); | and returns true on success or undef otherwise. | 
| return; |  | 
| } | cir and mir also take a value to set the cir/mir to. | 
|  |  | 
| my $new_mac = $mac; | su2su takes a group id parameter that is in hex. | 
| $new_mac =~ s/[^0-9A-Fa-f]//; |  | 
| unless (length $new_mac == 12) { | $t->sudb_modify($suid, 'cir', 512); | 
| $self->last_error("Invalid MAC '$mac'"); |  | 
| return; | You should save_sudb() after calling this, or your changes  will be lost | 
| } | when the AP is rebooted. | 
| $new_mac = join ' ', $new_mac =~ /../g; |  | 
|  | =cut | 
| my $string = 'sudb add ' . |  | 
| $suid . ' ' . | sub sudb_modify { | 
| $type . ' ' . | my $self  = shift; | 
| $cir  . ' ' . | my $suid  = shift; | 
| $mir  . ' ' . | my $opt   = shift; | 
| $new_mac; | my $value = shift; | 
|  |  | 
|  | if ( $suid =~ /\D/ ) { | 
| return $self->cmd( String => $string, expect => $success ); | $self->last_error("Invalid suid '$suid'"); | 
| } | return; | 
|  | } | 
| =pod |  | 
|  | if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) { | 
| =item B<sudb_delete> | if ( $value =~ /\D/ ) { | 
|  | $self->last_error("Invalid $opt '$value'"); | 
| Takes either 'all' or the  suid of the su to delete | return; | 
| and returns true on success or undef otherwise. | } | 
|  | } | 
| $t->sudb_delete($suid); | elsif ( lc($opt) eq 'su2su' ) { | 
|  | if ( $value =~ /[^0-9A-Za-f]/ ) { | 
| You should save_sudb() after calling this, or your changes  will be lost | $self->last_error("Invalid MAC '$value'"); | 
| when the AP is rebooted. | return; | 
|  | } | 
| =cut | } | 
|  | else { | 
| sub sudb_delete | $self->last_error("Invalid option '$opt'"); | 
| { | return; | 
| my $self = shift; | } | 
| my $suid = shift; |  | 
|  | my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value; | 
| #if (lc($suid) ne 'all' || $suid =~ /\D/) { |  | 
| if ($suid =~ /\D/) { | return $self->cmd( String => $string, expect => $success ); | 
| $self->last_error("Invalid suid '$suid'"); | } | 
| return; |  | 
| } | =pod | 
|  |  | 
| return $self->cmd( String => 'sudb delete ' . $suid, expect => $success ); | =head2 B<enable_tftpd> - enable the TFTP server | 
| } |  | 
|  | runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing | 
| =pod |  | 
|  | =cut | 
| =item B<sudb_modify> |  | 
|  | sub enable_tftpd { | 
| Takes either the  suid of the su to change | my $self = shift; | 
| as well as what you are changing, either "cir, mir or su2su" |  | 
| and returns true on success or undef otherwise. | my $vals = $self->tftpd( args => 'on' ); | 
|  |  | 
| cir and mir also take a value to set the cir/mir to. | if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) { | 
|  | return $vals; | 
| su2su takes a group id parameter that is in hex. | } | 
|  | else { | 
| $t->sudb_modify($suid, 'cir', 512); | return; | 
|  | } | 
| You should save_sudb() after calling this, or your changes  will be lost | } | 
| when the AP is rebooted. |  | 
|  | =pod | 
| =cut |  | 
|  | =head2 B<disable_tftpd> - disable the TFTP server | 
| sub sudb_modify |  | 
| { | runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled' | 
| my $self  = shift; |  | 
| my $suid  = shift; | =cut | 
| my $opt   = shift; |  | 
| my $value = shift; | sub disable_tftpd { | 
|  | my $self = shift; | 
| if ($suid =~ /\D/) { |  | 
| $self->last_error("Invalid suid '$suid'"); | my $vals = $self->tftpd( args => 'off' ); | 
| return; |  | 
| } | if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) { | 
|  | return $vals; | 
| if (lc($opt) eq 'cir' or lc($opt) eq 'mir') { | } | 
| if ($value =~ /\D/) { | else { | 
| $self->last_error("Invalid $opt '$value'"); | return; | 
| return; | } | 
| } | } | 
| } elsif (lc($opt) eq 'su2su') { |  | 
| if ($value =~ /[^0-9A-Za-f]/) { | =pod | 
| $self->last_error("Invalid MAC '$value'"); |  | 
| return; | =head2 B<cmd> - runs a command on the AP. | 
| } |  | 
| } else { | This does most of the work.  At the heart, it calls Net::Telnet::cmd() | 
| $self->last_error("Invalid option '$opt'"); | but it also does some special stuff for Trango. | 
| return; |  | 
| } | Normally returns the last lines from from the command | 
|  |  | 
| my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value; | If you are using this, rather than one of the "easy" methods above, | 
|  | you probably want to read through the source of this module to see how | 
| return $self->cmd( String => $string, expect => $success ); | some of the other commands are called. | 
| } |  | 
|  | In addition to the Net::Telnet::cmd() options, it also accepts these: | 
| =pod |  | 
|  | I<decode> | 
| =item B<enable_tftpd> | - if this is true, then it will send the output lines to _decode_lines() | 
|  | and then returns the decoded output | 
| - enable the TFTP server |  | 
|  | I<no_prompt> | 
| runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing | - if this is true, it does not wait for a prompt, so you are not stuck | 
|  | waiting for something that will never happen. | 
| =cut |  | 
|  | I<cmd_disconnects> | 
| sub enable_tftpd | - if this is true, it then sets logged_in() to false, then it will | 
| { | close() the connection and set is_connected() to false | 
| my $self = shift; |  | 
|  | I<expect> | 
| my $vals = $self->tftpd( args => 'on' ); | - 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 | 
| if ($vals->{'Tftpd'} eq 'listen') { | command probably failed | 
| return $vals; |  | 
| } else { | I<args> | 
| return; | - a string containing the command line options that are passed to the | 
| } | command | 
| } |  | 
|  | $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 ); | 
| =pod |  | 
|  | =cut | 
| =item B<disable_tftpd> |  | 
|  | sub cmd { | 
| - disable the TFTP server | my $self = shift; | 
|  |  | 
| runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled' | my @valid_net_telnet_opts = qw( | 
|  | String | 
| =cut | Output | 
|  | Cmd_remove_mode | 
| sub disable_tftpd | Errmode | 
| { | Input_record_separator | 
| my $self = shift; | Ors | 
|  | Output_record_separator | 
| my $vals = $self->tftpd( args => 'off' ); | Prompt | 
|  | Rs | 
| if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled') { | Timeout | 
| return $vals; | ); | 
| } else { |  | 
| return; | my %cfg; | 
| } | if ( @_ == 1 ) { | 
| } | $cfg{'String'} = shift; | 
|  | } | 
| =pod | elsif ( @_ > 1 ) { | 
|  | %cfg = @_; | 
| =item B<cmd> | } | 
|  |  | 
| - runs a command on the AP. | $cfg{'Timeout'} ||= $self->Timeout; | 
|  |  | 
| This does most of the work.  At the heart, it calls Net::Telnet::cmd() | unless ( $cfg{'String'} ) { | 
| but it also does some special stuff for Trango. | $self->last_error("No command passed"); | 
|  | return; | 
| Normally returns the last lines from from the command | } | 
|  |  | 
| If you are using this, rather than one of the "easy" methods above, | unless ( $self->is_connected ) { | 
| you probably want to read through the source of this module to see how | $self->last_error("Not connected"); | 
| some of the other commands are called. | return; | 
|  | } | 
| In addition to the Net::Telnet::cmd() options, it also accepts these: |  | 
|  | unless ( $self->logged_in ) { | 
| I<decode> | $self->last_error("Not logged in"); | 
|  | return; | 
| - if this is true, then it will send the output lines to _decode_lines() | } | 
| and then returns the decoded output |  | 
|  | my %cmd; | 
| I<no_prompt> | foreach (@valid_net_telnet_opts) { | 
|  | if ( exists $cfg{$_} ) { | 
| - if this is true, it does not wait for a prompt, so you are not stuck | $cmd{$_} = $cfg{$_}; | 
| waiting for something that will never happen. | } | 
|  | } | 
| I<cmd_disconnects> | if ( $cfg{'args'} ) { | 
|  | $cmd{'String'} .= ' ' . $cfg{'args'}; | 
| - if this is true, it then sets logged_in() to false, then it will | } | 
| close() the connection and set is_connected() to false |  | 
|  | my @lines; | 
| I<expect> | if ( $cfg{'no_prompt'} ) { | 
|  | $self->print( $cmd{'String'} ); | 
| - if this is set (usually to 'Success.') it will check for that in the | @lines = $self->lastline; | 
| last line of output and if it does not, will return undef because the | } | 
| command probably failed | else { | 
|  | @lines = $self->SUPER::cmd(%cmd); | 
| I<args> | } | 
|  |  | 
| - a string containing the command line options that are passed to the | $self->last_lines( \@lines ); | 
| command |  | 
|  | my $vals = 1; | 
| $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 ); | if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) { | 
|  | if ( $cfg{'decode'} eq 'each' ) { | 
| =cut | $vals = _decode_each_line(@lines); | 
|  | } | 
| sub cmd | elsif ( $cfg{'decode'} eq 'sulog' ) { | 
| { | $vals = _decode_sulog(@lines); | 
| my $self = shift; | } | 
|  | elsif ( $cfg{'decode'} eq 'maclist' ) { | 
| my @valid_net_telnet_opts = qw( | $vals = _decode_maclist(@lines); | 
| String | } | 
| Output | else { | 
| Cmd_remove_mode | $vals = _decode_lines(@lines); | 
| Errmode | } | 
| Input_record_separator | } | 
| Ors |  | 
| Output_record_separator | $self->last_vals($vals); | 
| Prompt |  | 
| Rs | my $last = $self->lastline; | 
| Timeout |  | 
| ); | if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) { | 
|  | if ( $cfg{'cmd_disconnects'} ) { | 
| my %cfg; | $self->logged_in(0); | 
| if (@_ == 1) { | $self->close; | 
| $cfg{'String'} = shift; | $self->is_connected(0); | 
| } elsif (@_ > 1) { | } | 
| %cfg = @_; |  | 
| } | if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) { | 
|  | return $vals; | 
| $cfg{'Timeout'} ||= $self->Timeout; | } | 
|  | else { | 
| unless ($cfg{'String'}) { | return \@lines; | 
| $self->last_error("No command passed"); | } | 
| return; | } | 
| } | else { | 
|  | $self->last_error("Error with command ($cfg{'String'}): $last"); | 
| unless ($self->is_connected) { | return; | 
| $self->last_error("Not connected"); | } | 
| return; | } | 
| } |  | 
|  | #=item _decode_lines | 
| unless ($self->logged_in) { |  | 
| $self->last_error("Not logged in"); | sub _decode_lines { | 
| return; | my @lines = @_; | 
| } |  | 
|  | my %conf; | 
|  |  | 
| my %cmd; | my $key = ''; | 
| foreach (@valid_net_telnet_opts) { | my $val = undef; | 
| if (exists $cfg{$_}) { | my @vals; | 
| $cmd{$_} = $cfg{$_}; | my $in_key = 0; | 
| } | my $in_val = 1; | 
| } |  | 
| if ($cfg{'args'}) { | foreach my $line (@lines) { | 
| $cmd{'String'} .= ' ' . $cfg{'args'}; | next if $line =~ /$success$/; | 
| } |  | 
|  | my @chars = split //, $line; | 
| my @lines; |  | 
| if ($cfg{'no_prompt'}) { | my $last_key = ''; | 
| $self->print($cmd{'String'}); | foreach my $c (@chars) { | 
| @lines = $self->lastline; |  | 
| } else { | if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) { | 
| @lines = $self->SUPER::cmd(%cmd); | if ( $c eq '[' ) { | 
| } | $in_key = 1; | 
|  | $in_val = 0; | 
| $self->last_lines(\@lines); | } | 
|  | else { | 
| my $vals = 1; | $in_key = 0; | 
| if ($PRIVATE{'Decode'} && $cfg{'decode'}) { | $in_val = 1; | 
| if ($cfg{'decode'} eq 'each') { | } | 
| $vals = _decode_each_line(@lines); |  | 
| } elsif ($cfg{'decode'} eq 'sulog') { | if ($key) { | 
| $vals = _decode_sulog(@lines); | $key =~ s/^\s+//; | 
| } elsif ($cfg{'decode'} eq 'maclist') { | $key =~ s/\s+$//; | 
| $vals = _decode_maclist(@lines); |  | 
| } else { | if ($val) { | 
| $vals = _decode_lines(@lines); | $val =~ s/^\s+//; | 
| } | $val =~ s/\s+$//; | 
| } | } | 
|  |  | 
| $self->last_vals($vals); | if ( $key eq 'Checksum' && $last_key ) { | 
|  |  | 
|  | # Special case for these bastids. | 
| my $last = $self->lastline; | my $new = $last_key; | 
|  | $new =~ s/\s+\S+$//; | 
| if ((not $cfg{'expect'}) || $last =~ /$cfg{'expect'}$/) { | $key = $new . " " . $key; | 
| if ($cfg{'cmd_disconnects'}) { | } | 
| $self->logged_in(0); |  | 
| $self->close; | $conf{$key} = $val; | 
| $self->is_connected(0); | $last_key   = $key; | 
| } | $key        = ''; | 
|  | } | 
| if ($PRIVATE{'Decode'} && $cfg{'decode'}) { | elsif ($val) { | 
| return $vals; | push @vals, $val; | 
| } else { | } | 
| return \@lines; | $val = ''; | 
| } |  | 
| } else { | } | 
| $self->last_error("Error with command ($cfg{'String'}): $last"); | elsif ( $c eq ']' ) { | 
| return; | $in_val = 1; | 
| } | $in_key = 0; | 
| } | $c      = shift @chars; | 
|  |  | 
| #=item _decode_lines | } | 
|  | elsif ($in_key) { | 
| sub _decode_lines | $key .= $c; | 
| { |  | 
| my @lines = @_; | } | 
|  | elsif ($in_val) { | 
| my %conf; | $val .= $c; | 
|  | } | 
| my $key = ''; | } | 
| my $val = undef; | } | 
| my @vals; |  | 
| my $in_key = 0; | unless ($key) { | 
| my $in_val = 1; | push @vals, $val; | 
|  | } | 
| foreach my $line (@lines) { |  | 
| next if $line =~ /$success$/; | if ( @vals == 1 ) { | 
|  | $val = $vals[0]; | 
| my @chars = split //, $line; | } | 
|  | elsif (@vals) { | 
| my $last_key = ''; | $val = \@vals; | 
| foreach my $c (@chars) { | } | 
|  | else { | 
| if ($c eq '[' || $c eq "\r" || $c eq "\n") { | $val = undef; | 
| if ($c eq '[') { | } | 
| $in_key = 1; |  | 
| $in_val = 0; | if (%conf) { | 
| } else { | $conf{_pre} = $val if $val; | 
| $in_key = 0; | return \%conf; | 
| $in_val = 1; | } | 
| } | else { | 
|  | return $val; | 
| if ($key) { | } | 
| $key =~ s/^\s+//; | } | 
| $key =~ s/\s+$//; |  | 
|  | #=item _decode_each_line | 
| if ($val) { |  | 
| $val =~ s/^\s+//; | sub _decode_each_line { | 
| $val =~ s/\s+$//; | my @lines = @_; | 
| } | my @decoded; | 
|  | foreach my $line (@lines) { | 
| if ($key eq 'Checksum' && $last_key) { | my $decoded = _decode_lines($line); | 
| # Special case for these bastids. | push @decoded, $decoded if defined $decoded; | 
| my $new = $last_key; | } | 
| $new =~ s/\s+\S+$//; | return \@decoded; | 
| $key = $new . " " . $key; | } | 
| } |  | 
|  | #=item _decode_sulog | 
| $conf{$key} = $val; |  | 
| $last_key = $key; | sub _decode_sulog { | 
| $key = ''; | my @lines = @_; | 
| } elsif ($val) { | my @decoded; | 
| push @vals, $val; | my $last_tm; | 
| } | foreach my $line (@lines) { | 
| $val = ''; | my $decoded = _decode_lines($line); | 
|  |  | 
| } elsif ($c eq ']') { | if ( defined $decoded ) { | 
| $in_val = 1; | if ( $decoded->{'tm'} ) { | 
| $in_key = 0; | $last_tm = $decoded->{'tm'}; | 
| $c = shift @chars; | next; | 
|  | } | 
| } elsif ($in_key) { | else { | 
| $key .= $c; | $decoded->{'tm'} = $last_tm; | 
|  | } | 
| } elsif ($in_val) { | next unless $last_tm; | 
| $val .= $c; |  | 
| } | push @decoded, $decoded if defined $decoded; | 
| } | } | 
| } | } | 
|  | return \@decoded; | 
| unless ($key) { | } | 
| push @vals, $val; |  | 
| } | #=item _decode_maclist | 
|  |  | 
| if (@vals == 1) { | sub _decode_maclist { | 
| $val = $vals[0]; | my @lines = @_; | 
| } elsif (@vals) { | my @decoded; | 
| $val= \@vals; | my $total_entries = 0; | 
| } else { | my $current_tm    = 0; | 
| $val = undef; | foreach my $line (@lines) { | 
| } | $line =~ s/\r?\n$//; | 
|  | my ( $mac, $loc, $tm ) = $line =~ / | 
| if (%conf) { | ([0-9a-fA-F ]{17})\s+ | 
| $conf{_pre} = $val if $val; | (.*)\s+ | 
| return \%conf; | tm\s+ | 
| } else { | (\d+) | 
| return $val; | /x; | 
| } |  | 
| } | if ($mac) { | 
|  | $mac =~ s/\s+//g; | 
| #=item _decode_each_line | $loc =~ s/^\s+//; | 
|  | $loc =~ s/\s+$//; | 
| sub _decode_each_line |  | 
| { | my $suid = undef; | 
| my @lines = @_; | if ( $loc =~ /suid\s+=\s+(\d+)/ ) { | 
| my @decoded; | $suid = $1; | 
| foreach my $line (@lines) { | $loc  = undef; | 
| my $decoded = _decode_lines($line); | } | 
| push @decoded, $decoded if defined $decoded; |  | 
| } | push @decoded, | 
| return \@decoded; | { | 
| } | mac  => $mac, | 
|  | loc  => $loc, | 
| #=item _decode_sulog | tm   => $tm, | 
|  | suid => $suid, | 
| sub _decode_sulog | }; | 
| { | } | 
| my @lines = @_; | elsif ( $line =~ /(\d+)\s+entries/ ) { | 
| my @decoded; | $total_entries = $1; | 
| my $last_tm; | } | 
| foreach my $line (@lines) { | elsif ( $line =~ /current tm = (\d+)\s+sec/ ) { | 
| my $decoded = _decode_lines($line); | $current_tm = $1; | 
|  | } | 
| if (defined $decoded) { | } | 
| if ($decoded->{'tm'}) { |  | 
| $last_tm = $decoded->{'tm'}; | map { $_->{'cur_tm'} = $current_tm } @decoded; | 
| next; |  | 
| } else { | if ( scalar @decoded == $total_entries ) { | 
| $decoded->{'tm'} = $last_tm; | return \@decoded; | 
| } | } | 
| next unless $last_tm; | else { | 
|  |  | 
| push @decoded, $decoded if defined $decoded; | # XXX we should have a way to set last error, not sure why we don't | 
| } | return; | 
| } | } | 
| return \@decoded; | } | 
| } |  | 
|  | 1;    # End of Net::Telnet::Trango | 
| #=item _decode_maclist | __END__ | 
|  |  | 
| sub _decode_maclist | =head1 SEE ALSO | 
| { |  | 
| my @lines = @_; | Trango Documentation - | 
| my @decoded; | L<http://www.trangobroadband.com/support/product_docs.htm> | 
| my $total_entries = 0; |  | 
| my $current_tm = 0; | L<Net::Telnet> | 
| foreach my $line (@lines) { |  | 
| $line =~ s/\r?\n$//; | =head1 TODO | 
| my ($mac, $loc, $tm) = $line =~ / |  | 
| ([0-9a-fA-F ]{17})\s+ | There are still a lot of commands that are not accessed directly.  If | 
| (.*)\s+ | you call them (as cmd("command + args") or whatever) and it works, | 
| tm\s+ | please send me examples that work and I will try to get it incorporated | 
| (\d+) | into the next version of the script. | 
| /x; |  | 
|  | I also want to be able to parse the different types of output from | 
| if ($mac) { | commands like su, sudb all and anything else that would be better | 
| $mac =~ s/\s+//g; | available as a perl datastructure. | 
| $loc =~ s/^\s+//; |  | 
| $loc =~ s/\s+$//; | =head1 AUTHOR | 
|  |  | 
| my $suid = undef; | Andrew Fresh E<lt>andrew@rraz.netE<gt> | 
| if ($loc =~ /suid\s+=\s+(\d+)/) { |  | 
| $suid = $1; | =head1 SUPPORT | 
| $loc = undef; |  | 
| } | You can find documentation for this module with the perldoc command. | 
|  |  | 
| push @decoded, { | perldoc Net::Telnet::Trango | 
| mac  => $mac, |  | 
| loc  => $loc, | You can also look for information at: | 
| tm   => $tm, |  | 
| suid => $suid, | =over 4 | 
| }; |  | 
| } elsif ($line =~ /(\d+)\s+entries/) { | =item * AnnoCPAN: Annotated CPAN documentation | 
| $total_entries = $1; |  | 
| } elsif ($line =~ /current tm = (\d+)\s+sec/) { | L<http://annocpan.org/dist/Net-Telnet-Trango> | 
| $current_tm = $1 |  | 
| } | =item * CPAN Ratings | 
| } |  | 
|  | L<http://cpanratings.perl.org/d/Net-Telnet-Trango> | 
| map { $_->{'cur_tm'} = $current_tm } @decoded; |  | 
|  | =item * RT: CPAN's request tracker | 
| if (scalar @decoded == $total_entries) { |  | 
| return \@decoded; | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Telnet-Trango> | 
| } else { |  | 
| # XXX we should have a way to set last error, not sure why we don't | =item * Search CPAN | 
| return; |  | 
| } | L<http://search.cpan.org/dist/Net-Telnet-Trango> | 
| } |  | 
|  | =back | 
| 1; |  | 
| __END__ | =head1 COPYRIGHT AND LICENSE | 
|  |  | 
| =back | Copyright (C) 2005,2006,2007 by Andrew Fresh | 
|  |  | 
| =head1 SEE ALSO | This program is free software; you can redistribute it and/or modify it | 
|  | under the same terms as Perl itself. | 
| Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm |  | 
|  | =cut | 
| L<Net::Telnet> |  | 
|  |  | 
| =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. |  | 
|  |  | 
| 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 |  | 
|  |  | 
| Andrew Fresh E<lt>andrew@rraz.netE<gt> |  | 
|  |  | 
| =head1 COPYRIGHT AND LICENSE |  | 
|  |  | 
| Copyright (C) 2005,2006,2007 by Andrew Fresh |  | 
|  |  | 
| This library is free software; you can redistribute it and/or modify |  | 
| it under the same terms as Perl itself, either Perl version 5.8.7 or, |  | 
| at your option, any later version of Perl 5 you may have available. |  | 
|  |  | 
| =cut |  |