[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.34 and 1.57

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

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.57

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