[BACK]Return to Trango.pm CVS log [TXT][DIR] Up to [local] / trango / Net-Telnet-Trango / lib / Net / Telnet

Diff for /trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm between version 1.34 and 1.52

version 1.34, 2007/02/05 21:02:07 version 1.52, 2008/02/18 19:13:32
Line 1 
Line 1 
 package Net::Telnet::Trango;  package Net::Telnet::Trango;
   
 # $RedRiver: Trango.pm,v 1.33 2007/02/02 21:26:56 andrew Exp $  # $RedRiver: Trango.pm,v 1.51 2008/02/18 16:37:35 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.01';
   
 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     =>
     sulog       => { decode    => 'sulog',     expect          => $success },        { String => 'su info',  decode => 'all', expect          => $success },
     'exit'      => { no_prompt => 1,           cmd_disconnects => 1 },      su_testrflink =>
     reboot      => { no_prompt => 1,           cmd_disconnects => 1 },        { String => 'su testrflink', decode => 'each', expect    => $success },
     remarks     => { decode    => 'all',       expect          => $success },      save_ss     => { String => 'save ss',      expect          => $success },
     save_sudb   => { String    => 'save sudb', expect          => $success },      opmode      => { decode => 'all',          expect          => $success },
     syslog      => { expect    => $success },      arq         => { decode => 'all' },
     'pipe'  => {},                        # XXX needs a special decode  );
     maclist => { decode => 'maclist' },  
     maclist_reset => { String => 'maclist reset', expect => 'done' },  my %ALIASES = (
     eth_link => { String => 'eth link', expect => $success },      bye     => 'exit',
     su_info  => { String => 'su info',  decode => 'all', expect => $success },      restart => 'reboot',
     su_testrflink =>      Host    => 'host',
       { String => 'su testrflink', decode => 'each', expect => $success },      save_systemseting => 'save_ss',
     save_ss => { String => 'save ss', expect => $success },  );
     opmode  => { decode => 'all',     expect => $success },  
   my %ACCESS = map { $_ => 1 } qw(
     # eth r, w and reset???    firmware_version
     #su password???    host_type
     #_bootloader    is_connected
     #temp    logged_in
     #heater    login_banner
 );    Timeout
     last_lines
 my %ALIASES = (    last_vals
     bye     => 'exit',    last_error
     restart => 'reboot',    Decode
     Host    => 'host',  );
 );  
   sub AUTOLOAD {
 my %ACCESS = map { $_ => 1 } qw(      my $self = shift;
   firmware_version  
   host_type      my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/
   is_connected        or die "Weird: $AUTOLOAD";
   logged_in  
   login_banner      if ( exists $ALIASES{$method} ) {
   Timeout          $method = $ALIASES{$method};
   last_lines          return $self->$method(@_);
   last_vals      }
   last_error  
   Decode      if ( exists $COMMANDS{$method} ) {
 );          my %cmd;
           foreach my $k ( keys %{ $COMMANDS{$method} } ) {
 sub AUTOLOAD {              $cmd{$k} = $COMMANDS{$method}{$k};
     my $self = shift;          }
           $cmd{'String'} ||= $method;
     my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/          $cmd{'args'} .= $SPACE . shift if ( @_ == 1 );
       or die "Weird: $AUTOLOAD";          return $self->cmd( %cmd, @_ );
       }
     if ( exists $ALIASES{$method} ) {  
         $method = $ALIASES{$method};      if ( exists $ACCESS{$method} ) {
         return $self->$method(@_);          my $prev = $PRIVATE{$method};
     }          ( $PRIVATE{$method} ) = @_ if @_;
           return $prev;
     if ( exists $COMMANDS{$method} ) {      }
         my %cmd;  
         foreach my $k ( keys %{ $COMMANDS{$method} } ) {      $method = "SUPER::$method";
             $cmd{$k} = $COMMANDS{$method}{$k};      return $self->$method(@_);
         }  }
         $cmd{'String'} ||= $method;  
         $cmd{'args'} .= ' ' . shift if ( @_ == 1 );  =pod
         return $self->cmd( %cmd, @_ );  
     }  =head2 B<open> - Open a connection to a Trango AP.
   
     if ( exists $ACCESS{$method} ) {  Calls Net::Telnet::open() then makes sure you get a password prompt so
         my $prev = $PRIVATE{$method};  you are ready to login() and parses the login banner so you can get
         ( $PRIVATE{$method} ) = @_ if @_;  host_type() and firmware_version()
         return $prev;  
     }  =cut
   
     $method = "SUPER::$method";  sub open {
     return $self->$method(@_);      my $self = shift;
 }  
       unless ( $self->SUPER::open(@_) ) {
 =pod          $self->last_error( "Couldn't connect to " . $self->host . ":  $!" );
           return;
 =head2 B<open>      }
 - Open a connection to a Trango AP.  
       ## Get to login prompt
 Calls Net::Telnet::open() then makes sure you get a password prompt so      unless (
 you are ready to login() and parses the login banner so you can get          $self->waitfor(
 host_type() and firmware_version()              -match   => '/password: ?$/i',
               -errmode => "return",
 =cut          )
         )
 sub open {      {
     my $self = shift;          $self->last_error( "problem connecting to host ("
                 . $self->host . "): "
     unless ( $self->SUPER::open(@_) ) {                . $self->lastline );
         $self->last_error( "Couldn't connect to " . $self->host . ":  $!" );          return;
         return;      }
     }  
       $self->parse_login_banner( $self->lastline );
     ## Get to login prompt  
     unless (      $self->is_connected(1);
         $self->waitfor(  
             -match   => '/password: ?$/i',      return $self->is_connected;
             -errmode => "return",  }
         )  
       )  =pod
     {  
         $self->last_error( "problem connecting to host ("  =head2 B<login> - Login to the AP.
               . $self->host . "): "  
               . $self->lastline );  Calls open() if not already connected, then sends the password and sets
         return;  logged_in() if successful
     }  
   =cut
     $self->parse_login_banner( $self->lastline );  
   sub login {
     $self->is_connected(1);      my $self = shift;
   
     return $self->is_connected;      unless ( $self->is_connected ) {
 }          $self->open or return;
       }
 =pod  
       my $password = shift;
 =head2 B<login>  
 - Login to the AP.      $self->print($password);
       unless (
 Calls open() if not already connected, then sends the password and sets          $self->waitfor(
 logged_in() if successful              -match   => $self->prompt,
               -errmode => "return",
 =cut          )
         )
 sub login {      {
     my $self = shift;          $self->last_error( "login ($self->host) failed: " . $self->lastline );
           return;
     unless ( $self->is_connected ) {      }
         $self->open or return;  
     }      $self->logged_in(1);
   
     my $password = shift;      return $self->logged_in;
   }
     $self->print($password);  
     unless (  =pod
         $self->waitfor(  
             -match   => $self->prompt,  =head2 B<parse_login_banner> - Converts the login_banner to something useful.
             -errmode => "return",  
         )  Takes a login banner (what you get when you first connect to the Trango)
       )  or reads what is already in login_banner() then parses it and sets
     {  host_type() and firmware_version() as well as login_banner()
         $self->last_error( "login ($self->host) failed: " . $self->lastline );  
         return;  =cut
     }  
   sub parse_login_banner {
     $self->logged_in(1);      my $self = shift;
   
     return $self->logged_in;      if (@_) {
 }          $self->login_banner(@_);
       }
 =pod  
       my $banner = $self->login_banner;
 =head2 B<parse_login_banner>  
 - Converts the login_banner to some useful      my ( $type, $sep1, $subtype, $sep2, $ver ) =
 variables.        $banner =~
         /Welcome to Trango Broadband Wireless,? (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i;
 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      $type .= $sep1 . $subtype;
 host_type() and firmware_version() as well as login_banner()      $ver = $subtype . $sep2 . $ver;
   
 =cut      $self->login_banner($banner);
       $self->host_type($type);
 sub parse_login_banner {      $self->firmware_version($ver);
     my $self = shift;  
       return 1;
     if (@_) {  }
         $self->login_banner(@_);  
     }  =pod
   
     my $banner = $self->login_banner;  =head2 B<linktest> - Link test to SU
   
     my ( $type, $sep1, $subtype, $sep2, $ver ) =  linktest('suid'[, 'pkt len, bytes'[, '# of pkts'[, '# of cycles']]]);
       $banner =~  
       /Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i;  Returns a hash reference to the results of the test
   
     $type .= $sep1 . $subtype;  =cut
     $ver = $subtype . $sep2 . $ver;  
   sub linktest
     $self->login_banner($banner);  {
     $self->host_type($type);      my $self    = shift;
     $self->firmware_version($ver);      my $suid    = shift;
       # These numbers are what I found as defaults when running the command
     return 1;      my $pkt_len = shift || 1600;
 }      my $pkt_cnt = shift || 500;
       my $cycles  = shift || 10;
 =pod  
       my %config  = @_;
 =head2 B<su_password>  
 - Set the password on SUs connected to the AP.      # * 2, one for the FromAP, one FromSU.  Then / 1000 to get to ms.
       # XXX This might need to be changed, this makes the default timeout the
 su_password('new_password'[, 'suid']) If no suid is specified,      # same as $pkt_len, and that might not be enough at slower speeds.
 the default is "all".      $config{Timeout} ||= int(($pkt_len * $pkt_cnt * $cycles * 2 ) / 1000);
   
   $t->su_password('good_pass', 5);      my $string = join $SPACE, 'linktest', $suid, $pkt_len, $pkt_cnt, $cycles;
       return $self->cmd(
 =cut          %config,
           String => $string,
 sub su_password {          decode => 'linktest',
     my $self     = shift;      );
     my $new_pass = shift || '';  
     my $su       = shift || 'all';  }
   
     unless ( defined $new_pass ) {  =pod
         $self->last_error("No new password");  
   =head2 B<su_password> - Set the password on SUs connected to the AP.
         #return;  
     }  su_password('new_password'[, 'suid']) If no suid is specified,
   the default is "all".
     return $self->cmd(  
         String => 'su password ' . $su . ' ' . $new_pass . ' ' . $new_pass,    $t->su_password('good_pass', 5);
         expect => $success,  
     );  =cut
 }  
   sub su_password {
 =pod      my $self     = shift;
       my $new_pass = shift || $EMPTY;
 =head2 B<su_ipconfig>      my $su       = shift || 'all';
 - Change IP configuration on SUs connected to  
 the AP.      unless ( defined $new_pass ) {
           $self->last_error("No new password");
 su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )  
           #return;
   $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );      }
   
 =cut      return $self->cmd(
           String => 'su password ' . $su . $SPACE . $new_pass . $SPACE . $new_pass,
 sub su_ipconfig {          expect => $success,
     my $self = shift;      );
   }
     my $suid        = shift;  
     my $new_ip      = shift;  =pod
     my $new_subnet  = shift;  
     my $new_gateway = shift;  =head2 B<su_ipconfig> - Change IP configuration on SUs connected to the AP.
   
     if ( $suid =~ /\D/ ) {  su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )
         $self->last_error("Invalid suid '$suid'");  
         return;    $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );
     }  
     unless ($new_ip) {  =cut
         $self->last_error("no new_ip passed");  
         return;  sub su_ipconfig {
     }      my $self = shift;
     unless ($new_subnet) {  
         $self->last_error("no new_subnet passed");      my $suid        = shift;
         return;      my $new_ip      = shift;
     }      my $new_subnet  = shift;
     unless ($new_gateway) {      my $new_gateway = shift;
         $self->last_error("no new_gateway passed");  
         return;      if ( $suid =~ /\D/ ) {
     }          $self->last_error("Invalid suid '$suid'");
           return;
     # su ipconfig <suid> <new ip> <new subnet> <new gateway>      }
     return $self->cmd(      unless ($new_ip) {
         String => 'su ipconfig ' . $suid . ' ' . $new_ip . ' '          $self->last_error("no new_ip passed");
           . $new_subnet . ' '          return;
           . $new_gateway,      }
         expect => $success,      unless ($new_subnet) {
     );          $self->last_error("no new_subnet passed");
 }          return;
       }
 =pod      unless ($new_gateway) {
           $self->last_error("no new_gateway passed");
 =head2 B<sudb_view>          return;
 - Returns the output from the sudb view command      }
   
 returns a reference to an array of hashes each containing these keys      # su ipconfig <suid> <new ip> <new subnet> <new gateway>
 'suid', 'type', 'cir', 'mir' and 'mac'      return $self->cmd(
           String => 'su ipconfig ' . $suid . $SPACE . $new_ip . $SPACE
 =cut            . $new_subnet . $SPACE
             . $new_gateway,
 sub sudb_view {          expect => $success,
     my $self = shift;      );
   }
     my $lines = $self->cmd( String => 'sudb view', expect => $success ) || [];  
   =pod
     return unless @{$lines};  
   =head2 B<sudb_view> - Returns the output from the sudb view command
     unless ( $PRIVATE{'Decode'} ) {  
         return $lines;  returns a reference to an array of hashes each containing these keys
     }  'suid', 'type', 'cir', 'mir' and 'mac'
   
     my @sus;  =cut
     foreach ( @{$lines} ) {  
         next unless $_;  sub sudb_view {
         if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) {      my $self = shift;
             my %s = (  
                 suid => $1,      my $lines = $self->cmd( String => 'sudb view', expect => $success ) || [];
                 type => $2,  
                 cir  => $3,      return unless @{$lines};
                 mir  => $4,  
                 mac  => $5,      unless ( $PRIVATE{'Decode'} ) {
             );          return $lines;
       }
             $s{'mac'} =~ s/\s//g;  
             $s{'mac'} = uc( $s{'mac'} );      my @sus;
       foreach ( @{$lines} ) {
             push @sus, \%s;          next unless $_;
         }          if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) {
     }              my %s = (
                   suid => $1,
     return \@sus;                  type => $2,
 }                  cir  => $3,
                   mir  => $4,
 =pod                  mac  => $5,
               );
 =head2 B<sudb_add>  
               $s{'mac'} =~ s/\s//g;
 Takes the following paramaters              $s{'mac'} = uc( $s{'mac'} );
   
         suid : numeric,              push @sus, \%s;
         type : (reg|pr)          }
         cir  : numeric,      }
         mir  : numeric,  
         mac  : Almost any format, it will be reformatted,      return \@sus;
   }
 and returns true on success or undef otherwise.  
   =pod
   $t->sudb_add($suid, 'reg', $cir, $mir, $mac);  
   =head2 B<sudb_add> - Adds an su to the sudb
 You should save_sudb() after calling this, or your changes  will be lost  
 when the AP is rebooted.  Takes the following paramaters
   
 =cut      suid : numeric,
       type : (reg|pr)
 sub sudb_add {      cir  : numeric,
     my $self = shift;      mir  : numeric,
     my $suid = shift;      mac  : Almost any format, it will be reformatted,
     my $type = shift;  
     my $cir  = shift;  and returns true on success or undef otherwise.
     my $mir  = shift;  
     my $mac  = shift;    $t->sudb_add($suid, 'reg', $cir, $mir, $mac);
   
     if ( $suid =~ /\D/ ) {  You should save_sudb() after calling this, or your changes  will be lost
         $self->last_error("Invalid suid '$suid'");  when the AP is rebooted.
         return;  
     }  =cut
   
     unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) {  sub sudb_add {
         $self->last_error("Invalid type '$type'");      my $self = shift;
         return;      my $suid = shift;
     }      my $type = shift;
       my $cir  = shift;
     if ( $cir =~ /\D/ ) {      my $mir  = shift;
         $self->last_error("Invalid CIR '$cir'");      my $mac  = shift;
         return;  
     }      if ( $suid =~ /\D/ ) {
           $self->last_error("Invalid suid '$suid'");
     if ( $mir =~ /\D/ ) {          return;
         $self->last_error("Invalid MIR '$mir'");      }
         return;  
     }      unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) {
           $self->last_error("Invalid type '$type'");
     my $new_mac = $mac;          return;
     $new_mac =~ s/[^0-9A-Fa-f]//;      }
     unless ( length $new_mac == 12 ) {  
         $self->last_error("Invalid MAC '$mac'");      if ( $cir =~ /\D/ ) {
         return;          $self->last_error("Invalid CIR '$cir'");
     }          return;
     $new_mac = join ' ', $new_mac =~ /../g;      }
   
     my $string =      if ( $mir =~ /\D/ ) {
       'sudb add ' . $suid . ' ' . $type . ' ' . $cir . ' ' . $mir . ' '          $self->last_error("Invalid MIR '$mir'");
       . $new_mac;          return;
       }
     return $self->cmd( String => $string, expect => $success );  
 }      my $new_mac = $mac;
       $new_mac =~ s/[^0-9A-Fa-f]//;
 =pod      unless ( length $new_mac == 12 ) {
           $self->last_error("Invalid MAC '$mac'");
 =head2 B<sudb_delete>          return;
       }
 Takes either 'all' or the  suid of the su to delete      $new_mac = join $SPACE, $new_mac =~ /../g;
 and returns true on success or undef otherwise.  
       my $string =
   $t->sudb_delete($suid);        'sudb add ' . $suid . $SPACE . $type . $SPACE . $cir . $SPACE . $mir . $SPACE
         . $new_mac;
 You should save_sudb() after calling this, or your changes  will be lost  
 when the AP is rebooted.      return $self->cmd( String => $string, expect => $success );
   }
 =cut  
   =pod
 sub sudb_delete {  
     my $self = shift;  =head2 B<sudb_delete> - removes an su from the sudb
     my $suid = shift;  
   Takes either 'all' or the  suid of the su to delete
     #if (lc($suid) ne 'all' || $suid =~ /\D/) {  and returns true on success or undef otherwise.
     if ( $suid =~ /\D/ ) {  
         $self->last_error("Invalid suid '$suid'");    $t->sudb_delete($suid);
         return;  
     }  You should save_sudb() after calling this, or your changes  will be lost
   when the AP is rebooted.
     return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );  
 }  =cut
   
 =pod  sub sudb_delete {
       my $self = shift;
 =head2 B<sudb_modify>      my $suid = shift;
   
 Takes either the  suid of the su to change      #if (lc($suid) ne 'all' || $suid =~ /\D/) {
 as well as what you are changing, either "cir, mir or su2su"      if ( $suid =~ /\D/ ) {
 and returns true on success or undef otherwise.          $self->last_error("Invalid suid '$suid'");
           return;
 cir and mir also take a value to set the cir/mir to.      }
   
 su2su takes a group id parameter that is in hex.      return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );
   }
   $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<sudb_modify> - changes the su information in the sudb
   
 =cut  Takes either the  suid of the su to change
   as well as what you are changing, either "cir, mir or su2su"
 sub sudb_modify {  and returns true on success or undef otherwise.
     my $self  = shift;  
     my $suid  = shift;  cir and mir also take a value to set the cir/mir to.
     my $opt   = shift;  
     my $value = shift;  su2su takes a group id parameter that is in hex.
   
     if ( $suid =~ /\D/ ) {    $t->sudb_modify($suid, 'cir', 512);
         $self->last_error("Invalid suid '$suid'");  
         return;  You should save_sudb() after calling this, or your changes  will be lost
     }  when the AP is rebooted.
   
     if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {  =cut
         if ( $value =~ /\D/ ) {  
             $self->last_error("Invalid $opt '$value'");  sub sudb_modify {
             return;      my $self  = shift;
         }      my $suid  = shift;
     }      my $opt   = shift;
     elsif ( lc($opt) eq 'su2su' ) {      my $value = shift;
         if ( $value =~ /[^0-9A-Za-f]/ ) {  
             $self->last_error("Invalid MAC '$value'");      if ( $suid =~ /\D/ ) {
             return;          $self->last_error("Invalid suid '$suid'");
         }          return;
     }      }
     else {  
         $self->last_error("Invalid option '$opt'");      if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {
         return;          if ( $value =~ /\D/ ) {
     }              $self->last_error("Invalid $opt '$value'");
               return;
     my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value;          }
       }
     return $self->cmd( String => $string, expect => $success );      elsif ( lc($opt) eq 'su2su' ) {
 }          if ( $value =~ /[^0-9A-Za-f]/ ) {
               $self->last_error("Invalid MAC '$value'");
 =pod              return;
           }
 =head2 B<enable_tftpd>      }
 - enable the TFTP server      else {
           $self->last_error("Invalid option '$opt'");
 runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing          return;
       }
 =cut  
       my $string = 'sudb modify ' . $suid . $SPACE . $opt . $SPACE . $value;
 sub enable_tftpd {  
     my $self = shift;      return $self->cmd( String => $string, expect => $success );
   }
     my $vals = $self->tftpd( args => 'on' );  
   =pod
     if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) {  
         return $vals;  =head2 B<enable_tftpd> - enable the TFTP server
     }  
     else {  runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing
         return;  
     }  =cut
 }  
   sub enable_tftpd {
 =pod      my $self = shift;
   
 =head2 B<disable_tftpd>      my $vals = $self->tftpd( args => 'on' );
 - disable the TFTP server  
       if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) {
 runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'          return $vals;
       }
 =cut      else {
           return;
 sub disable_tftpd {      }
     my $self = shift;  }
   
     my $vals = $self->tftpd( args => 'off' );  =pod
   
     if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) {  =head2 B<disable_tftpd> - disable the TFTP server
         return $vals;  
     }  runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'
     else {  
         return;  =cut
     }  
 }  sub disable_tftpd {
       my $self = shift;
 =pod  
       my $vals = $self->tftpd( args => 'off' );
 =head2 B<cmd> - runs a command on the AP.  
       if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) {
 This does most of the work.  At the heart, it calls Net::Telnet::cmd()          return $vals;
 but it also does some special stuff for Trango.      }
       else {
 Normally returns the last lines from from the command          return;
       }
 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  
 some of the other commands are called.  =pod
   
 In addition to the Net::Telnet::cmd() options, it also accepts these:  =head2 B<cmd> - runs a command on the AP.
   
 I<decode>  This does most of the work.  At the heart, it calls Net::Telnet::cmd()
 - if this is true, then it will send the output lines to _decode_lines()  but it also does some special stuff for Trango.
 and then returns the decoded output  
   Normally returns the last lines from from the command
 I<no_prompt>  
 - if this is true, it does not wait for a prompt, so you are not stuck  If you are using this, rather than one of the "easy" methods above,
 waiting for something that will never happen.  you probably want to read through the source of this module to see how
   some of the other commands are called.
 I<cmd_disconnects>  
 - if this is true, it then sets logged_in() to false, then it will  In addition to the Net::Telnet::cmd() options, it also accepts these:
 close() the connection and set is_connected() to false  
   I<decode>
 I<expect>  - if this is true, then it will send the output lines to _decode_lines()
 - if this is set (usually to 'Success.') it will check for that in the  and then returns the decoded output
 last line of output and if it does not, will return undef because the  
 command probably failed  I<no_prompt>
   - if this is true, it does not wait for a prompt, so you are not stuck
 I<args>  waiting for something that will never happen.
 - a string containing the command line options that are passed to the  
 command  I<cmd_disconnects>
   - if this is true, it then sets logged_in() to false, then it will
         $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );  close() the connection and set is_connected() to false
   
 =cut  I<expect>
   - if this is set (usually to 'Success.') it will check for that in the
 sub cmd {  last line of output and if it does not, will return undef because the
     my $self = shift;  command probably failed
   
     my @valid_net_telnet_opts = qw(  I<args>
       String  - a string containing the command line options that are passed to the
       Output  command
       Cmd_remove_mode  
       Errmode      $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );
       Input_record_separator  
       Ors  =cut
       Output_record_separator  
       Prompt  sub cmd {
       Rs      my $self = shift;
       Timeout  
     );      my @valid_net_telnet_opts = qw(
         String
     my %cfg;        Output
     if ( @_ == 1 ) {        Cmd_remove_mode
         $cfg{'String'} = shift;        Errmode
     }        Input_record_separator
     elsif ( @_ > 1 ) {        Ors
         %cfg = @_;        Output_record_separator
     }        Prompt
         Rs
     $cfg{'Timeout'} ||= $self->Timeout;        Timeout
       );
     unless ( $cfg{'String'} ) {  
         $self->last_error("No command passed");      my %cfg;
         return;      if ( @_ == 1 ) {
     }          $cfg{'String'} = shift;
       }
     unless ( $self->is_connected ) {      elsif ( @_ > 1 ) {
         $self->last_error("Not connected");          %cfg = @_;
         return;      }
     }  
       $cfg{'Timeout'} ||= $self->Timeout;
     unless ( $self->logged_in ) {  
         $self->last_error("Not logged in");      unless ( $cfg{'String'} ) {
         return;          $self->last_error("No command passed");
     }          return;
       }
     my %cmd;  
     foreach (@valid_net_telnet_opts) {      unless ( $self->is_connected ) {
         if ( exists $cfg{$_} ) {          $self->last_error("Not connected");
             $cmd{$_} = $cfg{$_};          return;
         }      }
     }  
     if ( $cfg{'args'} ) {      unless ( $self->logged_in ) {
         $cmd{'String'} .= ' ' . $cfg{'args'};          $self->last_error("Not logged in");
     }          return;
       }
     my @lines;  
     if ( $cfg{'no_prompt'} ) {      my %cmd;
         $self->print( $cmd{'String'} );      foreach (@valid_net_telnet_opts) {
         @lines = $self->lastline;          if ( exists $cfg{$_} ) {
     }              $cmd{$_} = $cfg{$_};
     else {          }
         @lines = $self->SUPER::cmd(%cmd);      }
     }      if ( $cfg{'args'} ) {
           $cmd{'String'} .= $SPACE . $cfg{'args'};
     $self->last_lines( \@lines );      }
   
     my $vals = 1;      #print "Running cmd $cmd{String}\n";
     if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {      my @lines;
         if ( $cfg{'decode'} eq 'each' ) {      if ( $cfg{'no_prompt'} ) {
             $vals = _decode_each_line(@lines);          $self->print( $cmd{'String'} );
         }          @lines = $self->lastline;
         elsif ( $cfg{'decode'} eq 'sulog' ) {      }
             $vals = _decode_sulog(@lines);      else {
         }          @lines = $self->SUPER::cmd(%cmd);
         elsif ( $cfg{'decode'} eq 'maclist' ) {      }
             $vals = _decode_maclist(@lines);  
         }      $self->last_lines( \@lines );
         else {  
             $vals = _decode_lines(@lines);      my $last = $self->lastline;
         }      my $prompt = $self->prompt;
     }      $prompt =~ s{^/}{}xms;
       $prompt =~ s{/[gixms]*$}{}xms;
     $self->last_vals($vals);      while (@lines && $last =~ qr($prompt)) {
           pop @lines;
     my $last = $self->lastline;          $last = $lines[-1];
       }
     if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) {      $self->last_error($EMPTY);
         if ( $cfg{'cmd_disconnects'} ) {  
             $self->logged_in(0);      my $vals = 1;
             $self->close;      if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {
             $self->is_connected(0);          if ( $cfg{'decode'} eq 'each' ) {
         }              $vals = _decode_each_line(@lines);
           }
         if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {          elsif ( $cfg{'decode'} eq 'sulog' ) {
             return $vals;              $vals = _decode_sulog(@lines);
         }          }
         else {          elsif ( $cfg{'decode'} eq 'maclist' ) {
             return \@lines;              $vals = _decode_maclist(@lines);
         }              if (! $vals) {
     }                  $self->last_error("Error decoding maclist");
     else {              }
         $self->last_error("Error with command ($cfg{'String'}): $last");          }
         return;          elsif ( $cfg{'decode'} eq 'linktest' ) {
     }              $vals = _decode_linktest(@lines);
 }              if (! $vals) {
                   $self->last_error("Error decoding linktest");
 #=item _decode_lines              }
           }
 sub _decode_lines {          else {
     my @lines = @_;              $vals = _decode_lines(@lines);
           }
     my %conf;      }
       $self->last_vals($vals);
     my $key = '';  
     my $val = undef;      if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) {
     my @vals;          if ( $cfg{'cmd_disconnects'} ) {
     my $in_key = 0;              $self->logged_in(0);
     my $in_val = 1;              $self->close;
               $self->is_connected(0);
     foreach my $line (@lines) {          }
         next if $line =~ /$success$/;  
           if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {
         my @chars = split //, $line;              return $vals;
           }
         my $last_key = '';          else {
         foreach my $c (@chars) {              return \@lines;
           }
             if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {      }
                 if ( $c eq '[' ) {      else {
                     $in_key = 1;          my $err;
                     $in_val = 0;          if (grep { /\[ERR\]/ } @lines) {
                 }              $err = _decode_lines(@lines);
                 else {          }
                     $in_key = 0;  
                     $in_val = 1;          if (ref $err eq 'HASH' && $err->{ERR}) {
                 }              $self->last_error($err->{ERR} );
           } else {
                 if ($key) {              $self->last_error("Error with command ($cmd{'String'}): $last");
                     $key =~ s/^\s+//;          }
                     $key =~ s/\s+$//;          return;
       }
                     if ($val) {  }
                         $val =~ s/^\s+//;  
                         $val =~ s/\s+$//;  #=item _decode_lines
                     }  
   sub _decode_lines {
                     if ( $key eq 'Checksum' && $last_key ) {      my @lines = @_;
   
                         # Special case for these bastids.      my %conf;
                         my $new = $last_key;  
                         $new =~ s/\s+\S+$//;      my $key = $EMPTY;
                         $key = $new . " " . $key;      my $val = undef;
                     }      my @vals;
       my $in_key = 0;
                     $conf{$key} = $val;      my $in_val = 1;
                     $last_key   = $key;  
                     $key        = '';      LINE: while (my $line = shift @lines) {
                 }          next LINE if $line =~ /$success\Z/;
                 elsif ($val) {          next LINE if $line =~ /^ \*+ \s+ \d+ \s+ \*+ \Z/xms;
                     push @vals, $val;  
                 }          # Special decode for sysinfo on a TrangoLink 45
                 $val = '';          if ($line =~ /^(.* Channel \s+ Table):\s*(.*)\Z/xms) {
               my $key  = $1;
             }              my $note = $2;
             elsif ( $c eq ']' ) {  
                 $in_val = 1;              my %vals;
                 $in_key = 0;              while ($line = shift @lines) {
                 $c      = shift @chars;                  if ($line =~ /^\Z/) {
                       $conf{$key} = \%vals;
             }                      $conf{$key}{note} = $note;
             elsif ($in_key) {                      next LINE;
                 $key .= $c;                  }
   
             }                  my $decoded = _decode_lines($line);
             elsif ($in_val) {                  if ($decoded) {
                 $val .= $c;                      %vals = (%vals, %{ $decoded });
             }                  }
         }              }
     }          }
           # Another special decode for the TrangoLink
     unless ($key) {          elsif ($line =~ /^
         push @vals, $val;              RF \s Band \s \#
     }              (\d+) \s+
               \( ([^\)]+) \) \s*
     if ( @vals == 1 ) {              (.*)$
         $val = $vals[0];          /xms) {
     }              my $num   = $1;
     elsif (@vals) {              my $band  = $2;
         $val = \@vals;              my $extra = $3;
     }  
     else {              if ($extra =~ /\[/) {
         $val = undef;                  my $decoded = _decode_lines($extra);
     }                  $conf{'RF Band'}{$num} = $decoded;
               }
     if (%conf) {              else {
         $conf{_pre} = $val if $val;                  $conf{'RF Band'}{$num}{$extra} = 1;
         return \%conf;              }
     }              next LINE;
     else {          }
         return $val;  
     }          my @chars = split //, $line;
 }  
           my $last_key = $EMPTY;
 #=item _decode_each_line          foreach my $c (@chars) {
   
 sub _decode_each_line {              if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {
     my @lines = @_;                  if ( $c eq '[' ) {
     my @decoded;                      $in_key = 1;
     foreach my $line (@lines) {                      $in_val = 0;
         my $decoded = _decode_lines($line);                  }
         push @decoded, $decoded if defined $decoded;                  else {
     }                      $in_key = 0;
     return \@decoded;                      $in_val = 1;
 }                  }
   
 #=item _decode_sulog                  if ($key) {
                       $key =~ s/^\s+//;
 sub _decode_sulog {                      $key =~ s/\s+$//;
     my @lines = @_;  
     my @decoded;                      if ($val) {
     my $last_tm;                          $val =~ s/^\s+//;
     foreach my $line (@lines) {                          $val =~ s/\s+$//;
         my $decoded = _decode_lines($line);                      }
   
         if ( defined $decoded ) {                      if ( $key eq 'Checksum' && $last_key ) {
             if ( $decoded->{'tm'} ) {  
                 $last_tm = $decoded->{'tm'};                          # Special case for these bastids.
                 next;                          my $new = $last_key;
             }                          $new =~ s/\s+\S+$//;
             else {                          $key = $new . $SPACE . $key;
                 $decoded->{'tm'} = $last_tm;                      }
             }  
             next unless $last_tm;                      $conf{$key} = $val;
                       $last_key   = $key;
             push @decoded, $decoded if defined $decoded;                      $key        = $EMPTY;
         }                  }
     }                  elsif ($val) {
     return \@decoded;                      push @vals, $val;
 }                  }
                   $val = $EMPTY;
 #=item _decode_maclist  
               }
 sub _decode_maclist {              elsif ( $c eq ']' ) {
     my @lines = @_;                  $in_val = 1;
     my @decoded;                  $in_key = 0;
     my $total_entries = 0;                  $c      = shift @chars;
     my $current_tm    = 0;  
     foreach my $line (@lines) {              }
         $line =~ s/\r?\n$//;              elsif ($in_key) {
         my ( $mac, $loc, $tm ) = $line =~ /                  $key .= $c;
                         ([0-9a-fA-F ]{17})\s+  
                         (.*)\s+              }
                         tm\s+              elsif ($in_val) {
                         (\d+)                  $val .= $c;
                 /x;              }
           }
         if ($mac) {      }
             $mac =~ s/\s+//g;  
             $loc =~ s/^\s+//;      unless ($key) {
             $loc =~ s/\s+$//;          push @vals, $val;
       }
             my $suid = undef;  
             if ( $loc =~ /suid\s+=\s+(\d+)/ ) {      if ( @vals == 1 ) {
                 $suid = $1;          $val = $vals[0];
                 $loc  = undef;      }
             }      elsif (@vals) {
           $val = \@vals;
             push @decoded,      }
               {      else {
                 mac  => $mac,          $val = undef;
                 loc  => $loc,      }
                 tm   => $tm,  
                 suid => $suid,      if (%conf) {
               };          $conf{_pre} = $val if $val;
         }          return \%conf;
         elsif ( $line =~ /(\d+)\s+entries/ ) {      }
             $total_entries = $1;      else {
         }          return $val;
         elsif ( $line =~ /current tm = (\d+)\s+sec/ ) {      }
             $current_tm = $1;  }
         }  
     }  #=item _decode_each_line
   
     map { $_->{'cur_tm'} = $current_tm } @decoded;  sub _decode_each_line {
       my @lines = @_;
     if ( scalar @decoded == $total_entries ) {      my @decoded;
         return \@decoded;      foreach my $line (@lines) {
     }          my $decoded = _decode_lines($line);
     else {          push @decoded, $decoded if defined $decoded;
       }
         # XXX we should have a way to set last error, not sure why we don't      return \@decoded;
         return;  }
     }  
 }  #=item _decode_linktest
   
 1;    # End of Net::Telnet::Trango  sub _decode_linktest {
 __END__      my @lines = @_;
       my %decoded;
 =head1 SEE ALSO      foreach my $line (@lines) {
   
 Trango Documentation -          if ($line =~ s/^(\d+) \s+ //xms) {
 L<http://www.trangobroadband.com/support/product_docs.htm>              my $line_id = $1;
                           my ($tm, $rt);
 L<Net::Telnet>                          if ($line =~ s/\s+ (\d+ \s+ \w+) \s* $//xms) {
                                   $rt = $1;
 =head1 TODO                          }
                           if ($line =~ s/\s+ (\d+ \s+ \w+) \s* $//xms) {
 There are still a lot of commands that are not accessed directly.  If                                  $tm = $1;
 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.              my $d = _decode_lines($line. "\n");
               $decoded{tests}[$line_id] = $d;
 I also want to be able to parse the different types of output from              $decoded{tests}[$line_id]{'time'} = $tm;
 commands like su, sudb all and anything else that would be better              $decoded{tests}[$line_id]{rate}   = $rt;
 available as a perl datastructure.          }
   
 =head1 AUTHOR          else {
               my $d = _decode_lines($line . "\n");
 Andrew Fresh E<lt>andrew@rraz.netE<gt>              if ($d) {
                   while (my ($k, $v) = each %{ $d }) {
 =head1 SUPPORT                      $decoded{$k} = $v;
                   }
 You can find documentation for this module with the perldoc command.             }
           }
     perldoc Net::Telnet::Trango  
       }
 You can also look for information at:      return \%decoded;
   }
 =over 4  
   #=item _decode_sulog
 =item * AnnoCPAN: Annotated CPAN documentation  
   sub _decode_sulog {
 L<http://annocpan.org/dist/Net-Telnet-Trango>      my @lines = @_;
       my @decoded;
 =item * CPAN Ratings      my $last_tm;
       foreach my $line (@lines) {
 L<http://cpanratings.perl.org/d/Net-Telnet-Trango>          my $decoded = _decode_lines($line);
   
 =item * RT: CPAN's request tracker          if ( defined $decoded ) {
               if ( $decoded->{'tm'} ) {
 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Telnet-Trango>                  $last_tm = $decoded->{'tm'};
                   next;
 =item * Search CPAN              }
               else {
 L<http://search.cpan.org/dist/Net-Telnet-Trango>                  $decoded->{'tm'} = $last_tm;
               }
 =back              next unless $last_tm;
   
 =head1 COPYRIGHT AND LICENSE              push @decoded, $decoded if defined $decoded;
           }
 Copyright (C) 2005,2006,2007 by Andrew Fresh      }
       return \@decoded;
 This program is free software; you can redistribute it and/or modify it  }
 under the same terms as Perl itself.  
   #=item _decode_maclist
 =cut  
   sub _decode_maclist {
       my @lines = @_;
       my @decoded;
       my $total_entries = 0;
       my $current_tm    = 0;
       foreach my $line (@lines) {
           $line =~ s/\r?\n$//;
           my ( $mac, $loc, $tm ) = $line =~ /
               ([0-9a-fA-F ]{17})\s+
               (.*)\s+
               tm\s+
               (\d+)
           /x;
   
           if ($mac) {
               $mac =~ s/\s+//g;
               $loc =~ s/^\s+//;
               $loc =~ s/\s+$//;
   
               my $suid = undef;
               if ( $loc =~ /suid\s+=\s+(\d+)/ ) {
                   $suid = $1;
                   $loc  = undef;
               }
   
               push @decoded,
                 {
                   mac  => $mac,
                   loc  => $loc,
                   tm   => $tm,
                   suid => $suid,
                 };
           }
           elsif ( $line =~ /(\d+)\s+entries/ ) {
               $total_entries = $1;
           }
           elsif ( $line =~ /current tm = (\d+)\s+sec/ ) {
               $current_tm = $1;
           }
       }
   
       map { $_->{'cur_tm'} = $current_tm } @decoded;
   
       if ( scalar @decoded == $total_entries ) {
           return \@decoded;
       }
       else {
           return;
       }
   }
   
   1;    # End of Net::Telnet::Trango
   __END__
   
   =head1 SEE ALSO
   
   Trango Documentation -
   L<http://www.trangobroadband.com/support/product_docs.htm>
   
   L<Net::Telnet>
   
   =head1 TODO
   
   There are still a lot of commands that are not accessed directly.  If
   you call them (as cmd("command + args") or whatever) and it works,
   please send me examples that work and I will try to get it incorporated
   into the next version of the script.
   
   I also want to be able to parse the different types of output from
   commands like su, sudb all and anything else that would be better
   available as a perl datastructure.
   
   =head1 AUTHOR
   
   Andrew Fresh E<lt>andrew@rraz.netE<gt>
   
   =head1 SUPPORT
   
   You can find documentation for this module with the perldoc command.
   
       perldoc Net::Telnet::Trango
   
   You can also look for information at:
   
   =over 4
   
   =item * AnnoCPAN: Annotated CPAN documentation
   
   L<http://annocpan.org/dist/Net-Telnet-Trango>
   
   =item * CPAN Ratings
   
   L<http://cpanratings.perl.org/d/Net-Telnet-Trango>
   
   =item * RT: CPAN's request tracker
   
   L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Telnet-Trango>
   
   =item * Search CPAN
   
   L<http://search.cpan.org/dist/Net-Telnet-Trango>
   
   =back
   
   =head1 COPYRIGHT AND LICENSE
   
   Copyright (C) 2005,2006,2007 by Andrew Fresh
   
   This program is free software; you can redistribute it and/or modify it
   under the same terms as Perl itself.
   
   =cut

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

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