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

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

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