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

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

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