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

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

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