[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.58

version 1.37, 2007/02/05 23:09:59 version 1.58, 2009/07/13 17:33:45
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.57 2009/07/09 21:50:03 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.04';
   
 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+
     }              (\d+)
               \s+
     my $new_mac = $mac;              ([[:xdigit:]\s]+)
     $new_mac =~ s/[^0-9A-Fa-f]//;          $/ixms
     unless ( length $new_mac == 12 ) {              )
         $self->last_error("Invalid MAC '$mac'");          {
         return;              my %s = (
     }                  suid  => $1,
     $new_mac = join ' ', $new_mac =~ /../g;                  su2su => $2 ? $2 : undef,
                   type  => $3 == 1 ? 'reg' : $3 == 5 ? 'pri' : $3,
     my $string =                  cir   => $4,
       'sudb add ' . $suid . ' ' . $type . ' ' . $cir . ' ' . $mir . ' '                  mir   => $5,
       . $new_mac;                  mac   => $6,
               );
     return $self->cmd( String => $string, expect => $success );  
 }              $s{'mac'} =~ s/\s//gxms;
               $s{'mac'} = uc( $s{'mac'} );
 =pod  
               push @sus, \%s;
 =head2 B<sudb_delete> - removes an su from the sudb          }
       }
 Takes either 'all' or the  suid of the su to delete  
 and returns true on success or undef otherwise.      return \@sus;
   }
   $t->sudb_delete($suid);  
   =pod
 You should save_sudb() after calling this, or your changes  will be lost  
 when the AP is rebooted.  =head2 B<sudb_add> - Adds an su to the sudb
   
 =cut  Takes the following paramaters
   
 sub sudb_delete {      suid : numeric,
     my $self = shift;      type : (reg|pr)
     my $suid = shift;      cir  : numeric,
       mir  : numeric,
     #if (lc($suid) ne 'all' || $suid =~ /\D/) {      mac  : Almost any format, it will be reformatted,
     if ( $suid =~ /\D/ ) {  
         $self->last_error("Invalid suid '$suid'");  and returns true on success or undef otherwise.
         return;  
     }    $t->sudb_add($suid, 'reg', $cir, $mir, $mac);
   
     return $self->cmd( String => 'sudb delete ' . $suid, 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_modify> - changes the su information in the sudb  sub sudb_add {
       my $self = shift;
 Takes either the  suid of the su to change      my $suid = shift;
 as well as what you are changing, either "cir, mir or su2su"      my $type = shift;
 and returns true on success or undef otherwise.      my $cir  = shift;
       my $mir  = shift;
 cir and mir also take a value to set the cir/mir to.      my $mac  = shift;
   
 su2su takes a group id parameter that is in hex.      if ( $suid =~ /\D/ ) {
           $self->last_error("Invalid suid '$suid'");
   $t->sudb_modify($suid, 'cir', 512);          return;
       }
 You should save_sudb() after calling this, or your changes  will be lost  
 when the AP is rebooted.      unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) {
           $self->last_error("Invalid type '$type'");
 =cut          return;
       }
 sub sudb_modify {  
     my $self  = shift;      if ( $cir =~ /\D/ ) {
     my $suid  = shift;          $self->last_error("Invalid CIR '$cir'");
     my $opt   = shift;          return;
     my $value = shift;      }
   
     if ( $suid =~ /\D/ ) {      if ( $mir =~ /\D/ ) {
         $self->last_error("Invalid suid '$suid'");          $self->last_error("Invalid MIR '$mir'");
         return;          return;
     }      }
   
     if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {      my $new_mac = $mac;
         if ( $value =~ /\D/ ) {      $new_mac =~ s/[^0-9A-Fa-f]//g;
             $self->last_error("Invalid $opt '$value'");      unless ( length $new_mac == 12 ) {
             return;          $self->last_error("Invalid MAC '$mac'");
         }          return;
     }      }
     elsif ( lc($opt) eq 'su2su' ) {      $new_mac = join $SPACE, $new_mac =~ /../g;
         if ( $value =~ /[^0-9A-Za-f]/ ) {  
             $self->last_error("Invalid MAC '$value'");      my $string
             return;          = 'sudb add '
         }          . $suid
     }          . $SPACE
     else {          . $type
         $self->last_error("Invalid option '$opt'");          . $SPACE
         return;          . $cir
     }          . $SPACE
           . $mir
     my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value;          . $SPACE
           . $new_mac;
     return $self->cmd( String => $string, expect => $success );  
 }      return $self->cmd( String => $string, expect => $success );
   }
 =pod  
   =pod
 =head2 B<enable_tftpd> - enable the TFTP server  
   =head2 B<sudb_delete> - removes an su from the sudb
 runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing  
   Takes either 'all' or the  suid of the su to delete
 =cut  and returns true on success or undef otherwise.
   
 sub enable_tftpd {    $t->sudb_delete($suid);
     my $self = shift;  
   You should save_sudb() after calling this, or your changes  will be lost
     my $vals = $self->tftpd( args => 'on' );  when the AP is rebooted.
   
     if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) {  =cut
         return $vals;  
     }  sub sudb_delete {
     else {      my $self = shift;
         return;      my $suid = shift;
     }  
 }      #if (lc($suid) ne 'all' || $suid =~ /\D/) {
       if ( $suid =~ /\D/ ) {
 =pod          $self->last_error("Invalid suid '$suid'");
           return;
 =head2 B<disable_tftpd> - disable the TFTP server      }
   
 runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'      return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );
   }
 =cut  
   =pod
 sub disable_tftpd {  
     my $self = shift;  =head2 B<sudb_modify> - changes the su information in the sudb
   
     my $vals = $self->tftpd( args => 'off' );  Takes either the  suid of the su to change
   as well as what you are changing, either "cir, mir or su2su"
     if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) {  and returns true on success or undef otherwise.
         return $vals;  
     }  cir and mir also take a value to set the cir/mir to.
     else {  
         return;  su2su takes a group id parameter that is in hex.
     }  
 }    $t->sudb_modify($suid, 'cir', 512);
   
 =pod  You should save_sudb() after calling this, or your changes  will be lost
   when the AP is rebooted.
 =head2 B<cmd> - runs a command on the AP.  
   =cut
 This does most of the work.  At the heart, it calls Net::Telnet::cmd()  
 but it also does some special stuff for Trango.  sub sudb_modify {
       my $self  = shift;
 Normally returns the last lines from from the command      my $suid  = shift;
       my $opt   = shift;
 If you are using this, rather than one of the "easy" methods above,      my $value = shift;
 you probably want to read through the source of this module to see how  
 some of the other commands are called.      if ( $suid =~ /\D/ ) {
           $self->last_error("Invalid suid '$suid'");
 In addition to the Net::Telnet::cmd() options, it also accepts these:          return;
       }
 I<decode>  
 - if this is true, then it will send the output lines to _decode_lines()      if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {
 and then returns the decoded output          if ( $value =~ /\D/ ) {
               $self->last_error("Invalid $opt '$value'");
 I<no_prompt>              return;
 - if this is true, it does not wait for a prompt, so you are not stuck          }
 waiting for something that will never happen.      }
       elsif ( lc($opt) eq 'su2su' ) {
 I<cmd_disconnects>          if ( $value =~ /[^0-9A-Za-f]/ ) {
 - if this is true, it then sets logged_in() to false, then it will              $self->last_error("Invalid MAC '$value'");
 close() the connection and set is_connected() to false              return;
           }
 I<expect>      }
 - if this is set (usually to 'Success.') it will check for that in the      else {
 last line of output and if it does not, will return undef because the          $self->last_error("Invalid option '$opt'");
 command probably failed          return;
       }
 I<args>  
 - a string containing the command line options that are passed to the      my $string = 'sudb modify ' . $suid . $SPACE . $opt . $SPACE . $value;
 command  
       return $self->cmd( String => $string, expect => $success );
     $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );  }
   
 =cut  =pod
   
 sub cmd {  =head2 B<enable_tftpd> - enable the TFTP server
     my $self = shift;  
   runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing
     my @valid_net_telnet_opts = qw(  
       String  =cut
       Output  
       Cmd_remove_mode  sub enable_tftpd {
       Errmode      my $self = shift;
       Input_record_separator  
       Ors      my $vals = $self->tftpd( args => 'on' );
       Output_record_separator  
       Prompt      if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) {
       Rs          return $vals;
       Timeout      }
     );      else {
           return;
     my %cfg;      }
     if ( @_ == 1 ) {  }
         $cfg{'String'} = shift;  
     }  =pod
     elsif ( @_ > 1 ) {  
         %cfg = @_;  =head2 B<disable_tftpd> - disable the TFTP server
     }  
   runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'
     $cfg{'Timeout'} ||= $self->Timeout;  
   =cut
     unless ( $cfg{'String'} ) {  
         $self->last_error("No command passed");  sub disable_tftpd {
         return;      my $self = shift;
     }  
       my $vals = $self->tftpd( args => 'off' );
     unless ( $self->is_connected ) {  
         $self->last_error("Not connected");      if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) {
         return;          return $vals;
     }      }
       else {
     unless ( $self->logged_in ) {          return;
         $self->last_error("Not logged in");      }
         return;  }
     }  
   =pod
     my %cmd;  
     foreach (@valid_net_telnet_opts) {  =head2 B<cmd> - runs a command on the AP.
         if ( exists $cfg{$_} ) {  
             $cmd{$_} = $cfg{$_};  This does most of the work.  At the heart, it calls Net::Telnet::cmd()
         }  but it also does some special stuff for Trango.
     }  
     if ( $cfg{'args'} ) {  Normally returns the last lines from from the command
         $cmd{'String'} .= ' ' . $cfg{'args'};  
     }  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 @lines;  some of the other commands are called.
     if ( $cfg{'no_prompt'} ) {  
         $self->print( $cmd{'String'} );  In addition to the Net::Telnet::cmd() options, it also accepts these:
         @lines = $self->lastline;  
     }  I<decode>
     else {  - if this is true, then it will send the output lines to _decode_lines()
         @lines = $self->SUPER::cmd(%cmd);  and then returns the decoded output
     }  
   I<no_prompt>
     $self->last_lines( \@lines );  - if this is true, it does not wait for a prompt, so you are not stuck
   waiting for something that will never happen.
     my $vals = 1;  
     if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {  I<cmd_disconnects>
         if ( $cfg{'decode'} eq 'each' ) {  - if this is true, it then sets logged_in() to false, then it will
             $vals = _decode_each_line(@lines);  close() the connection and set is_connected() to false
         }  
         elsif ( $cfg{'decode'} eq 'sulog' ) {  I<expect>
             $vals = _decode_sulog(@lines);  - 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
         elsif ( $cfg{'decode'} eq 'maclist' ) {  command probably failed
             $vals = _decode_maclist(@lines);  
         }  I<args>
         else {  - a string containing the command line options that are passed to the
             $vals = _decode_lines(@lines);  command
         }  
     }      $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );
   
     $self->last_vals($vals);  =cut
   
     my $last = $self->lastline;  sub cmd {
       my $self = shift;
     if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) {  
         if ( $cfg{'cmd_disconnects'} ) {      my @valid_net_telnet_opts = qw(
             $self->logged_in(0);          String
             $self->close;          Output
             $self->is_connected(0);          Cmd_remove_mode
         }          Errmode
           Input_record_separator
         if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {          Ors
             return $vals;          Output_record_separator
         }          Prompt
         else {          Rs
             return \@lines;          Timeout
         }      );
     }  
     else {      my %cfg;
         $self->last_error("Error with command ($cfg{'String'}): $last");      if ( @_ == 1 ) {
         return;          $cfg{'String'} = shift;
     }      }
 }      elsif ( @_ > 1 ) {
           %cfg = @_;
 #=item _decode_lines      }
   
 sub _decode_lines {      $cfg{'Timeout'} ||= $self->Timeout;
     my @lines = @_;  
       unless ( $cfg{'String'} ) {
     my %conf;          $self->last_error("No command passed");
           return;
     my $key = '';      }
     my $val = undef;  
     my @vals;      unless ( $self->is_connected ) {
     my $in_key = 0;          $self->last_error("Not connected");
     my $in_val = 1;          return;
       }
     foreach my $line (@lines) {  
         next if $line =~ /$success$/;      unless ( $self->logged_in ) {
           $self->last_error("Not logged in");
         my @chars = split //, $line;          return;
       }
         my $last_key = '';  
         foreach my $c (@chars) {      my %cmd;
       foreach (@valid_net_telnet_opts) {
             if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {          if ( exists $cfg{$_} ) {
                 if ( $c eq '[' ) {              $cmd{$_} = $cfg{$_};
                     $in_key = 1;          }
                     $in_val = 0;      }
                 }      if ( $cfg{'args'} ) {
                 else {          $cmd{'String'} .= $SPACE . $cfg{'args'};
                     $in_key = 0;      }
                     $in_val = 1;  
                 }      #print "Running cmd $cmd{String}\n";
       my @lines;
                 if ($key) {      if ( $cfg{'no_prompt'} ) {
                     $key =~ s/^\s+//;          $self->print( $cmd{'String'} );
                     $key =~ s/\s+$//;          @lines = $self->lastline;
       }
                     if ($val) {      else {
                         $val =~ s/^\s+//;          @lines = $self->SUPER::cmd(%cmd);
                         $val =~ s/\s+$//;      }
                     }  
       $self->last_lines( \@lines );
                     if ( $key eq 'Checksum' && $last_key ) {  
       my $last   = $self->lastline;
                         # Special case for these bastids.      my $prompt = $self->prompt;
                         my $new = $last_key;      $prompt =~ s{^/}{}xms;
                         $new =~ s/\s+\S+$//;      $prompt =~ s{/[gixms]*$}{}xms;
                         $key = $new . " " . $key;      while ( @lines && $last =~ qr($prompt) ) {
                     }          pop @lines;
           $last = $lines[-1];
                     $conf{$key} = $val;      }
                     $last_key   = $key;      $self->last_error($EMPTY);
                     $key        = '';  
                 }      my $vals = 1;
                 elsif ($val) {      if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {
                     push @vals, $val;          if ( $cfg{'decode'} eq 'each' ) {
                 }              $vals = _decode_each_line(@lines);
                 $val = '';          }
           elsif ( $cfg{'decode'} eq 'sulog' ) {
             }              $vals = _decode_sulog(@lines);
             elsif ( $c eq ']' ) {          }
                 $in_val = 1;          elsif ( $cfg{'decode'} eq 'maclist' ) {
                 $in_key = 0;              $vals = _decode_maclist(@lines);
                 $c      = shift @chars;              if ( !$vals ) {
                   $self->last_error("Error decoding maclist");
             }              }
             elsif ($in_key) {          }
                 $key .= $c;          elsif ( $cfg{'decode'} eq 'linktest' ) {
               $vals = _decode_linktest(@lines);
             }              if ( !$vals ) {
             elsif ($in_val) {                  $self->last_error("Error decoding linktest");
                 $val .= $c;              }
             }          }
         }          else {
     }              $vals = _decode_lines(@lines);
           }
     unless ($key) {      }
         push @vals, $val;      $self->last_vals($vals);
     }  
       if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) {
     if ( @vals == 1 ) {          if ( $cfg{'cmd_disconnects'} ) {
         $val = $vals[0];              $self->logged_in(0);
     }              $self->close;
     elsif (@vals) {              $self->is_connected(0);
         $val = \@vals;          }
     }  
     else {          if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {
         $val = undef;              return $vals;
     }          }
           else {
     if (%conf) {              return \@lines;
         $conf{_pre} = $val if $val;          }
         return \%conf;      }
     }      else {
     else {          my $err;
         return $val;          if ( grep {/\[ERR\]/} @lines ) {
     }              $err = _decode_lines(@lines);
 }          }
   
 #=item _decode_each_line          if ( ref $err eq 'HASH' && $err->{ERR} ) {
               $self->last_error( $err->{ERR} );
 sub _decode_each_line {          }
     my @lines = @_;          else {
     my @decoded;              $self->last_error("Error with command ($cmd{'String'}): $last");
     foreach my $line (@lines) {          }
         my $decoded = _decode_lines($line);          return;
         push @decoded, $decoded if defined $decoded;      }
     }  }
     return \@decoded;  
 }  #=item _decode_lines
   
 #=item _decode_sulog  sub _decode_lines {
       my @lines = @_;
 sub _decode_sulog {  
     my @lines = @_;      my %conf;
     my @decoded;  
     my $last_tm;      my $key = $EMPTY;
     foreach my $line (@lines) {      my $val = undef;
         my $decoded = _decode_lines($line);      my @vals;
       my $in_key = 0;
         if ( defined $decoded ) {      my $in_val = 1;
             if ( $decoded->{'tm'} ) {  
                 $last_tm = $decoded->{'tm'};  LINE: while ( my $line = shift @lines ) {
                 next;          next LINE if $line =~ /$success\Z/;
             }          next LINE if $line =~ /^ \*+ \s+ \d+ \s+ \*+ \Z/xms;
             else {  
                 $decoded->{'tm'} = $last_tm;          # Special decode for sysinfo on a TrangoLink 45
             }          if ( $line =~ /^(.* Channel \s+ Table):\s*(.*)\Z/xms ) {
             next unless $last_tm;              my $key  = $1;
               my $note = $2;
             push @decoded, $decoded if defined $decoded;  
         }              my %vals;
     }              while ( $line = shift @lines ) {
     return \@decoded;                  if ( $line =~ /^\Z/ ) {
 }                      $conf{$key} = \%vals;
                       $conf{$key}{note} = $note;
 #=item _decode_maclist                      next LINE;
                   }
 sub _decode_maclist {  
     my @lines = @_;                  my $decoded = _decode_lines($line);
     my @decoded;                  if ($decoded) {
     my $total_entries = 0;                      %vals = ( %vals, %{$decoded} );
     my $current_tm    = 0;                  }
     foreach my $line (@lines) {              }
         $line =~ s/\r?\n$//;          }
         my ( $mac, $loc, $tm ) = $line =~ /  
             ([0-9a-fA-F ]{17})\s+          # Another special decode for the TrangoLink
             (.*)\s+          elsif (
             tm\s+              $line =~ /^
             (\d+)              RF \s Band \s \#
         /x;              (\d+) \s+
               \( ([^\)]+) \) \s*
         if ($mac) {              (.*)$
             $mac =~ s/\s+//g;          /xms
             $loc =~ s/^\s+//;              )
             $loc =~ s/\s+$//;          {
               my $num   = $1;
             my $suid = undef;              my $band  = $2;
             if ( $loc =~ /suid\s+=\s+(\d+)/ ) {              my $extra = $3;
                 $suid = $1;  
                 $loc  = undef;              if ( $extra =~ /\[/ ) {
             }                  my $decoded = _decode_lines($extra);
                   $conf{'RF Band'}{$num} = $decoded;
             push @decoded,              }
               {              else {
                 mac  => $mac,                  $conf{'RF Band'}{$num}{$extra} = 1;
                 loc  => $loc,              }
                 tm   => $tm,              next LINE;
                 suid => $suid,          }
               };  
         }          my @chars = split //, $line;
         elsif ( $line =~ /(\d+)\s+entries/ ) {  
             $total_entries = $1;          my $last_key = $EMPTY;
         }          foreach my $c (@chars) {
         elsif ( $line =~ /current tm = (\d+)\s+sec/ ) {  
             $current_tm = $1;              if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {
         }                  if ( $c eq '[' ) {
     }                      $in_key = 1;
                       $in_val = 0;
     map { $_->{'cur_tm'} = $current_tm } @decoded;                  }
                   else {
     if ( scalar @decoded == $total_entries ) {                      $in_key = 0;
         return \@decoded;                      $in_val = 1;
     }                  }
     else {  
                   if ($key) {
         # XXX we should have a way to set last error, not sure why we don't                      $key =~ s/^\s+//;
         return;                      $key =~ s/\s+$//;
     }  
 }                      if ($val) {
                           $val =~ s/^\s+//;
 1;    # End of Net::Telnet::Trango                          $val =~ s/\s+$//;
 __END__                      }
   
 =head1 SEE ALSO                      if ( $key eq 'Checksum' && $last_key ) {
   
 Trango Documentation -                          # Special case for these bastids.
 L<http://www.trangobroadband.com/support/product_docs.htm>                          my $new = $last_key;
                           $new =~ s/\s+\S+$//;
 L<Net::Telnet>                          $key = $new . $SPACE . $key;
                       }
 =head1 TODO  
                       $conf{$key} = $val;
 There are still a lot of commands that are not accessed directly.  If                      $last_key   = $key;
 you call them (as cmd("command + args") or whatever) and it works,                      $key        = $EMPTY;
 please send me examples that work and I will try to get it incorporated                  }
 into the next version of the script.                  elsif ($val) {
                       push @vals, $val;
 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                  $val = $EMPTY;
 available as a perl datastructure.  
               }
 =head1 AUTHOR              elsif ( $c eq ']' ) {
                   $in_val = 1;
 Andrew Fresh E<lt>andrew@rraz.netE<gt>                  $in_key = 0;
                   $c      = shift @chars;
 =head1 SUPPORT  
               }
 You can find documentation for this module with the perldoc command.              elsif ($in_key) {
                   $key .= $c;
     perldoc Net::Telnet::Trango  
               }
 You can also look for information at:              elsif ($in_val) {
                   $val .= $c;
 =over 4              }
           }
 =item * AnnoCPAN: Annotated CPAN documentation      }
   
 L<http://annocpan.org/dist/Net-Telnet-Trango>      unless ($key) {
           push @vals, $val;
 =item * CPAN Ratings      }
   
 L<http://cpanratings.perl.org/d/Net-Telnet-Trango>      if ( @vals == 1 ) {
           $val = $vals[0];
 =item * RT: CPAN's request tracker      }
       elsif (@vals) {
 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Telnet-Trango>          $val = \@vals;
       }
 =item * Search CPAN      else {
           $val = undef;
 L<http://search.cpan.org/dist/Net-Telnet-Trango>      }
   
 =back      if (%conf) {
           $conf{_pre} = $val if $val;
 =head1 COPYRIGHT AND LICENSE          return \%conf;
       }
 Copyright (C) 2005,2006,2007 by Andrew Fresh      else {
           return $val;
 This program is free software; you can redistribute it and/or modify it      }
 under the same terms as Perl itself.  }
   
 =cut  #=item _decode_each_line
   
   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.58

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