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

Diff for /trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm between version 1.37 and 1.46

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

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.46

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