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

version 1.37, 2007/02/05 23:09:59 version 1.41, 2007/02/07 20:08:32
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.40 2007/02/06 21:15:28 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]]  #  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> - return the type of host you are connected to.  
   It should be available after a successful open().
 returns the type of host from the login banner for example M5830S or M5300S.    
   =head2 B<host_type> - return the type of host you are connected to.
 Should be available after a successful open().  
   returns the type of host from the login banner for example M5830S or M5300S.
 =head2 B<is_connected> - Status of the connection to host.  
   Should be available after a successful open().
 returns 1 when connected, undef otherwise.  
   =head2 B<is_connected> - Status of the connection to host.
 =head2 B<logged_in> - Status of being logged in to the host.  
   returns 1 when connected, undef otherwise.
 returns 1 after a successful login(), 0 if it failed and undef if  
 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
   login() was never called.
 returns the banner that is displayed when first connected at login.    
 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.
   Only set after a successful open().
 returns, as an array ref, the output from the last cmd() that was run.  
   =head2 B<last_lines> - 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  
 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
   last_lines.
 =head2 B<bye> - alias of exit()  
   =head1 ALIASES
 Does the same as exit()  
   =head2 B<bye> - alias of exit()
 =head2 B<restart> - alias of reboot()  
   Does the same as exit()
 Does the same as reboot()  
   =head2 B<restart> - alias of reboot()
 =head1 COMMANDS  
   Does the same as reboot()
 Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>,  
 as such they accept the same options as C<cmd()>.    =head2 B<save_systemsetting> - alias of save_ss()
 Specifically they take a named paramater "args", for example:  
 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  Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>,
 command.  as such they accept the same options as C<cmd()>.
   Specifically they take a named paramater "args", for example:
 Also see enable_tftpd() and disable_tftpd() as those check that it was  C<tftpd(args =E<gt> 'on')> would enable tftpd
 successfully changed.  
   =head2 B<tftpd> - The output from the tftpd command
 =head2 B<ver> - The output from the ver command  
   Returns a hash ref of the decoded output from the
 Returns a hash ref of the decoded output from the  command.
 command.  
   Also see enable_tftpd() and disable_tftpd() as those check that it was
 =head2 B<sysinfo> - The output from the sysinfo command  successfully changed.
   
 Returns a hash ref of the decoded output from the  =head2 B<ver> - The output from the ver command
 command.  
   Returns a hash ref of the decoded output from the
 =head2 B<exit> - Exits the connection  command.
   
 exits the command session with the Trango and closes  =head2 B<sysinfo> - The output from the sysinfo command
 the connection  
   Returns a hash ref of the decoded output from the
 =head2 B<reboot> - Sends a reboot command  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
   the connection
 Takes an optional argument, which sets the remarks.    
 If there is no argument, returns the current remarks.  =head2 B<reboot> - Sends a reboot command
   
   my $old_remarks = $t->remarks();  reboots the Trango and closes the connection
   $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
   line.
 Returns a hashref of the output from the syslog command  
   =head2 B<save_sudb> - saves the sudb
 =head2 B<pipe> - the pipe command  
   Returns true on success, undef on failure
 Returns the output from the pipe command  
   =head2 B<syslog> - The output from the sulog command
 =head2 B<maclist> - retrieves the maclist  
   Returns a hashref of the output from the syslog command
 Returns the output from the maclist command  
   =head2 B<pipe> - the pipe command
 =head2 B<maclist_reset> - resets the maclist.    
   Returns the output from the pipe command
 No useful output.  
   =head2 B<maclist> - retrieves the maclist
 =head2 B<eth_list> - eth list command  
   Returns the output from the maclist command
 Returns the output from the eth list 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
   command after it to appear to fail.  I am not sure why.
 =head2 B<su_testrflink> - tests the RF Link to an su  
   =head2 B<su_info> - gets the su info
   $t->su_testrflink($suid|'all');  
   Returns information about the SU.
 =head2 B<save_ss> - saves the config.    
   You need to pass in the $suid and it will return the info for that suid.
 Returns 1 on success, undef on failure.  
     $t->su_info($suid);
 =head2 B<opmode> - sets opmode ap y or returns the opmode  
   =head2 B<su_testrflink> - tests the RF Link to an su
     $t->opmode([ap y]);  
     $t->su_testrflink($suid|'all');
 =cut  
   =head2 B<save_ss> - saves the config.
 my $success  = 'Success\\.';  
 my %COMMANDS = (  Returns 1 on success, undef on failure.
     tftpd       => { decode    => 'all',       expect          => $success },  
     ver         => { decode    => 'all' },  =head2 B<opmode> - sets opmode ap y or returns the opmode
     sysinfo     => { decode    => 'all',       expect          => $success },  
     updateflash => { decode    => 'all',       expect          => $success },      $t->opmode([ap y]);
     sulog       => { decode    => 'sulog',     expect          => $success },  
     'exit'      => { no_prompt => 1,           cmd_disconnects => 1 },  =cut
     reboot      => { no_prompt => 1,           cmd_disconnects => 1 },  
     remarks     => { decode    => 'all',       expect          => $success },  my $success  = 'Success\\.';
     save_sudb   => { String    => 'save sudb', expect          => $success },  my %COMMANDS = (
     syslog      => { expect    => $success },      tftpd       => { decode    => 'all',       expect          => $success },
     'pipe'      => {},                        # XXX needs a special decode      ver         => { decode    => 'all' },
     maclist     => { decode => 'maclist' },      sysinfo     => { decode    => 'all',       expect          => $success },
     maclist_reset => { String => 'maclist reset', expect       => 'done' },      updateflash => { decode    => 'all',       expect          => $success },
     eth_link    => { String => 'eth link',     expect          => $success },      sulog       => { decode    => 'sulog',     expect          => $success },
     su_info     =>      'exit'      => { no_prompt => 1,           cmd_disconnects => 1 },
       { String => 'su info',  decode => 'all', expect          => $success },      reboot      => { no_prompt => 1,           cmd_disconnects => 1 },
     su_testrflink =>      remarks     => { decode    => 'all',       expect          => $success },
       { String => 'su testrflink', decode => 'each', expect    => $success },      save_sudb   => { String    => 'save sudb', expect          => $success },
     save_ss     => { String => 'save ss',      expect          => $success },      syslog      => { expect    => $success },
     opmode      => { decode => 'all',          expect          => $success },      '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 =>
 );        { String => 'su testrflink', decode => 'each', expect    => $success },
       save_ss     => { String => 'save ss',      expect          => $success },
 my %ACCESS = map { $_ => 1 } qw(      opmode      => { decode => 'all',          expect          => $success },
   firmware_version  );
   host_type  
   is_connected  my %ALIASES = (
   logged_in      bye     => 'exit',
   login_banner      restart => 'reboot',
   Timeout      Host    => 'host',
   last_lines      save_systemseting => 'save_ss',
   last_vals  );
   last_error  
   Decode  my %ACCESS = map { $_ => 1 } qw(
 );    firmware_version
     host_type
 sub AUTOLOAD {    is_connected
     my $self = shift;    logged_in
     login_banner
     my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/    Timeout
       or die "Weird: $AUTOLOAD";    last_lines
     last_vals
     if ( exists $ALIASES{$method} ) {    last_error
         $method = $ALIASES{$method};    Decode
         return $self->$method(@_);  );
     }  
   sub AUTOLOAD {
     if ( exists $COMMANDS{$method} ) {      my $self = shift;
         my %cmd;  
         foreach my $k ( keys %{ $COMMANDS{$method} } ) {      my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/
             $cmd{$k} = $COMMANDS{$method}{$k};        or die "Weird: $AUTOLOAD";
         }  
         $cmd{'String'} ||= $method;      if ( exists $ALIASES{$method} ) {
         $cmd{'args'} .= ' ' . shift if ( @_ == 1 );          $method = $ALIASES{$method};
         return $self->cmd( %cmd, @_ );          return $self->$method(@_);
     }      }
   
     if ( exists $ACCESS{$method} ) {      if ( exists $COMMANDS{$method} ) {
         my $prev = $PRIVATE{$method};          my %cmd;
         ( $PRIVATE{$method} ) = @_ if @_;          foreach my $k ( keys %{ $COMMANDS{$method} } ) {
         return $prev;              $cmd{$k} = $COMMANDS{$method}{$k};
     }          }
           $cmd{'String'} ||= $method;
     $method = "SUPER::$method";          $cmd{'args'} .= $SPACE . shift if ( @_ == 1 );
     return $self->$method(@_);          return $self->cmd( %cmd, @_ );
 }      }
   
 =pod      if ( exists $ACCESS{$method} ) {
           my $prev = $PRIVATE{$method};
 =head2 B<open> - Open a connection to a Trango AP.          ( $PRIVATE{$method} ) = @_ if @_;
           return $prev;
 Calls Net::Telnet::open() then makes sure you get a password prompt so      }
 you are ready to login() and parses the login banner so you can get  
 host_type() and firmware_version()      $method = "SUPER::$method";
       return $self->$method(@_);
 =cut  }
   
 sub open {  =pod
     my $self = shift;  
   =head2 B<open> - Open a connection to a Trango AP.
     unless ( $self->SUPER::open(@_) ) {  
         $self->last_error( "Couldn't connect to " . $self->host . ":  $!" );  Calls Net::Telnet::open() then makes sure you get a password prompt so
         return;  you are ready to login() and parses the login banner so you can get
     }  host_type() and firmware_version()
   
     ## Get to login prompt  =cut
     unless (  
         $self->waitfor(  sub open {
             -match   => '/password: ?$/i',      my $self = shift;
             -errmode => "return",  
         )      unless ( $self->SUPER::open(@_) ) {
       )          $self->last_error( "Couldn't connect to " . $self->host . ":  $!" );
     {          return;
         $self->last_error( "problem connecting to host ("      }
               . $self->host . "): "  
               . $self->lastline );      ## Get to login prompt
         return;      unless (
     }          $self->waitfor(
               -match   => '/password: ?$/i',
     $self->parse_login_banner( $self->lastline );              -errmode => "return",
           )
     $self->is_connected(1);        )
       {
     return $self->is_connected;          $self->last_error( "problem connecting to host ("
 }                . $self->host . "): "
                 . $self->lastline );
 =pod          return;
       }
 =head2 B<login> - Login to the AP.  
       $self->parse_login_banner( $self->lastline );
 Calls open() if not already connected, then sends the password and sets  
 logged_in() if successful      $self->is_connected(1);
   
 =cut      return $self->is_connected;
   }
 sub login {  
     my $self = shift;  =pod
   
     unless ( $self->is_connected ) {  =head2 B<login> - 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> - Converts the login_banner to something useful.
     if (@_) {  
         $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
   host_type() and firmware_version() as well as login_banner()
     my $banner = $self->login_banner;  
   =cut
     my ( $type, $sep1, $subtype, $sep2, $ver ) =  
       $banner =~  sub parse_login_banner {
       /Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i;      my $self = shift;
   
     $type .= $sep1 . $subtype;      if (@_) {
     $ver = $subtype . $sep2 . $ver;          $self->login_banner(@_);
       }
     $self->login_banner($banner);  
     $self->host_type($type);      my $banner = $self->login_banner;
     $self->firmware_version($ver);  
       my ( $type, $sep1, $subtype, $sep2, $ver ) =
     return 1;        $banner =~
 }        /Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i;
   
 =pod      $type .= $sep1 . $subtype;
       $ver = $subtype . $sep2 . $ver;
 =head2 B<su_password> - Set the password on SUs connected to the AP.  
       $self->login_banner($banner);
 su_password('new_password'[, 'suid']) If no suid is specified,      $self->host_type($type);
 the default is "all".      $self->firmware_version($ver);
   
   $t->su_password('good_pass', 5);      return 1;
   }
 =cut  
   =pod
 sub su_password {  
     my $self     = shift;  =head2 B<su_password> - Set the password on SUs connected to the AP.
     my $new_pass = shift || '';  
     my $su       = shift || 'all';  su_password('new_password'[, 'suid']) If no suid is specified,
   the default is "all".
     unless ( defined $new_pass ) {  
         $self->last_error("No new password");    $t->su_password('good_pass', 5);
   
         #return;  =cut
     }  
   sub su_password {
     return $self->cmd(      my $self     = shift;
         String => 'su password ' . $su . ' ' . $new_pass . ' ' . $new_pass,      my $new_pass = shift || $EMPTY;
         expect => $success,      my $su       = shift || 'all';
     );  
 }      unless ( defined $new_pass ) {
           $self->last_error("No new password");
 =pod  
           #return;
 =head2 B<su_ipconfig> - Change IP configuration on SUs connected to the AP.      }
   
 su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )      return $self->cmd(
           String => 'su password ' . $su . $SPACE . $new_pass . $SPACE . $new_pass,
   $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );          expect => $success,
       );
 =cut  }
   
 sub su_ipconfig {  =pod
     my $self = shift;  
   =head2 B<su_ipconfig> - Change IP configuration on SUs connected to the AP.
     my $suid        = shift;  
     my $new_ip      = shift;  su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )
     my $new_subnet  = shift;  
     my $new_gateway = shift;    $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );
   
     if ( $suid =~ /\D/ ) {  =cut
         $self->last_error("Invalid suid '$suid'");  
         return;  sub su_ipconfig {
     }      my $self = shift;
     unless ($new_ip) {  
         $self->last_error("no new_ip passed");      my $suid        = shift;
         return;      my $new_ip      = shift;
     }      my $new_subnet  = shift;
     unless ($new_subnet) {      my $new_gateway = shift;
         $self->last_error("no new_subnet passed");  
         return;      if ( $suid =~ /\D/ ) {
     }          $self->last_error("Invalid suid '$suid'");
     unless ($new_gateway) {          return;
         $self->last_error("no new_gateway passed");      }
         return;      unless ($new_ip) {
     }          $self->last_error("no new_ip passed");
           return;
     # su ipconfig <suid> <new ip> <new subnet> <new gateway>      }
     return $self->cmd(      unless ($new_subnet) {
         String => 'su ipconfig ' . $suid . ' ' . $new_ip . ' '          $self->last_error("no new_subnet passed");
           . $new_subnet . ' '          return;
           . $new_gateway,      }
         expect => $success,      unless ($new_gateway) {
     );          $self->last_error("no new_gateway passed");
 }          return;
       }
 =pod  
       # su ipconfig <suid> <new ip> <new subnet> <new gateway>
 =head2 B<sudb_view> - Returns the output from the sudb view command      return $self->cmd(
           String => 'su ipconfig ' . $suid . $SPACE . $new_ip . $SPACE
 returns a reference to an array of hashes each containing these keys            . $new_subnet . $SPACE
 'suid', 'type', 'cir', 'mir' and 'mac'            . $new_gateway,
           expect => $success,
 =cut      );
   }
 sub sudb_view {  
     my $self = shift;  =pod
   
     my $lines = $self->cmd( String => 'sudb view', expect => $success ) || [];  =head2 B<sudb_view> - Returns the output from the sudb view command
   
     return unless @{$lines};  returns a reference to an array of hashes each containing these keys
   'suid', 'type', 'cir', 'mir' and 'mac'
     unless ( $PRIVATE{'Decode'} ) {  
         return $lines;  =cut
     }  
   sub sudb_view {
     my @sus;      my $self = shift;
     foreach ( @{$lines} ) {  
         next unless $_;      my $lines = $self->cmd( String => 'sudb view', expect => $success ) || [];
         if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) {  
             my %s = (      return unless @{$lines};
                 suid => $1,  
                 type => $2,      unless ( $PRIVATE{'Decode'} ) {
                 cir  => $3,          return $lines;
                 mir  => $4,      }
                 mac  => $5,  
             );      my @sus;
       foreach ( @{$lines} ) {
             $s{'mac'} =~ s/\s//g;          next unless $_;
             $s{'mac'} = uc( $s{'mac'} );          if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) {
               my %s = (
             push @sus, \%s;                  suid => $1,
         }                  type => $2,
     }                  cir  => $3,
                   mir  => $4,
     return \@sus;                  mac  => $5,
 }              );
   
 =pod              $s{'mac'} =~ s/\s//g;
               $s{'mac'} = uc( $s{'mac'} );
 =head2 B<sudb_add> - Adds an su to the sudb  
               push @sus, \%s;
 Takes the following paramaters          }
       }
     suid : numeric,  
     type : (reg|pr)      return \@sus;
     cir  : numeric,  }
     mir  : numeric,  
     mac  : Almost any format, it will be reformatted,  =pod
   
 and returns true on success or undef otherwise.  =head2 B<sudb_add> - Adds an su to the sudb
   
   $t->sudb_add($suid, 'reg', $cir, $mir, $mac);  Takes the following paramaters
   
 You should save_sudb() after calling this, or your changes  will be lost      suid : numeric,
 when the AP is rebooted.      type : (reg|pr)
       cir  : numeric,
 =cut      mir  : numeric,
       mac  : Almost any format, it will be reformatted,
 sub sudb_add {  
     my $self = shift;  and returns true on success or undef otherwise.
     my $suid = shift;  
     my $type = shift;    $t->sudb_add($suid, 'reg', $cir, $mir, $mac);
     my $cir  = shift;  
     my $mir  = shift;  You should save_sudb() after calling this, or your changes  will be lost
     my $mac  = shift;  when the AP is rebooted.
   
     if ( $suid =~ /\D/ ) {  =cut
         $self->last_error("Invalid suid '$suid'");  
         return;  sub sudb_add {
     }      my $self = shift;
       my $suid = shift;
     unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) {      my $type = shift;
         $self->last_error("Invalid type '$type'");      my $cir  = shift;
         return;      my $mir  = shift;
     }      my $mac  = shift;
   
     if ( $cir =~ /\D/ ) {      if ( $suid =~ /\D/ ) {
         $self->last_error("Invalid CIR '$cir'");          $self->last_error("Invalid suid '$suid'");
         return;          return;
     }      }
   
     if ( $mir =~ /\D/ ) {      unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) {
         $self->last_error("Invalid MIR '$mir'");          $self->last_error("Invalid type '$type'");
         return;          return;
     }      }
   
     my $new_mac = $mac;      if ( $cir =~ /\D/ ) {
     $new_mac =~ s/[^0-9A-Fa-f]//;          $self->last_error("Invalid CIR '$cir'");
     unless ( length $new_mac == 12 ) {          return;
         $self->last_error("Invalid MAC '$mac'");      }
         return;  
     }      if ( $mir =~ /\D/ ) {
     $new_mac = join ' ', $new_mac =~ /../g;          $self->last_error("Invalid MIR '$mir'");
           return;
     my $string =      }
       'sudb add ' . $suid . ' ' . $type . ' ' . $cir . ' ' . $mir . ' '  
       . $new_mac;      my $new_mac = $mac;
       $new_mac =~ s/[^0-9A-Fa-f]//;
     return $self->cmd( String => $string, expect => $success );      unless ( length $new_mac == 12 ) {
 }          $self->last_error("Invalid MAC '$mac'");
           return;
 =pod      }
       $new_mac = join $SPACE, $new_mac =~ /../g;
 =head2 B<sudb_delete> - removes an su from the sudb  
       my $string =
 Takes either 'all' or the  suid of the su to delete        'sudb add ' . $suid . $SPACE . $type . $SPACE . $cir . $SPACE . $mir . $SPACE
 and returns true on success or undef otherwise.        . $new_mac;
   
   $t->sudb_delete($suid);      return $self->cmd( String => $string, expect => $success );
   }
 You should save_sudb() after calling this, or your changes  will be lost  
 when the AP is rebooted.  =pod
   
 =cut  =head2 B<sudb_delete> - removes an su from the sudb
   
 sub sudb_delete {  Takes either 'all' or the  suid of the su to delete
     my $self = shift;  and returns true on success or undef otherwise.
     my $suid = shift;  
     $t->sudb_delete($suid);
     #if (lc($suid) ne 'all' || $suid =~ /\D/) {  
     if ( $suid =~ /\D/ ) {  You should save_sudb() after calling this, or your changes  will be lost
         $self->last_error("Invalid suid '$suid'");  when the AP is rebooted.
         return;  
     }  =cut
   
     return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );  sub sudb_delete {
 }      my $self = shift;
       my $suid = shift;
 =pod  
       #if (lc($suid) ne 'all' || $suid =~ /\D/) {
 =head2 B<sudb_modify> - changes the su information in the sudb      if ( $suid =~ /\D/ ) {
           $self->last_error("Invalid suid '$suid'");
 Takes either the  suid of the su to change          return;
 as well as what you are changing, either "cir, mir or su2su"      }
 and returns true on success or undef otherwise.  
       return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );
 cir and mir also take a value to set the cir/mir to.  }
   
 su2su takes a group id parameter that is in hex.  =pod
   
   $t->sudb_modify($suid, 'cir', 512);  =head2 B<sudb_modify> - changes the su information in the sudb
   
 You should save_sudb() after calling this, or your changes  will be lost  Takes either the  suid of the su to change
 when the AP is rebooted.  as well as what you are changing, either "cir, mir or su2su"
   and returns true on success or undef otherwise.
 =cut  
   cir and mir also take a value to set the cir/mir to.
 sub sudb_modify {  
     my $self  = shift;  su2su takes a group id parameter that is in hex.
     my $suid  = shift;  
     my $opt   = shift;    $t->sudb_modify($suid, 'cir', 512);
     my $value = shift;  
   You should save_sudb() after calling this, or your changes  will be lost
     if ( $suid =~ /\D/ ) {  when the AP is rebooted.
         $self->last_error("Invalid suid '$suid'");  
         return;  =cut
     }  
   sub sudb_modify {
     if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {      my $self  = shift;
         if ( $value =~ /\D/ ) {      my $suid  = shift;
             $self->last_error("Invalid $opt '$value'");      my $opt   = shift;
             return;      my $value = shift;
         }  
     }      if ( $suid =~ /\D/ ) {
     elsif ( lc($opt) eq 'su2su' ) {          $self->last_error("Invalid suid '$suid'");
         if ( $value =~ /[^0-9A-Za-f]/ ) {          return;
             $self->last_error("Invalid MAC '$value'");      }
             return;  
         }      if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {
     }          if ( $value =~ /\D/ ) {
     else {              $self->last_error("Invalid $opt '$value'");
         $self->last_error("Invalid option '$opt'");              return;
         return;          }
     }      }
       elsif ( lc($opt) eq 'su2su' ) {
     my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value;          if ( $value =~ /[^0-9A-Za-f]/ ) {
               $self->last_error("Invalid MAC '$value'");
     return $self->cmd( String => $string, expect => $success );              return;
 }          }
       }
 =pod      else {
           $self->last_error("Invalid option '$opt'");
 =head2 B<enable_tftpd> - enable the TFTP server          return;
       }
 runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing  
       my $string = 'sudb modify ' . $suid . $SPACE . $opt . $SPACE . $value;
 =cut  
       return $self->cmd( String => $string, expect => $success );
 sub enable_tftpd {  }
     my $self = shift;  
   =pod
     my $vals = $self->tftpd( args => 'on' );  
   =head2 B<enable_tftpd> - enable the TFTP server
     if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) {  
         return $vals;  runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing
     }  
     else {  =cut
         return;  
     }  sub enable_tftpd {
 }      my $self = shift;
   
 =pod      my $vals = $self->tftpd( args => 'on' );
   
 =head2 B<disable_tftpd> - disable the TFTP server      if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) {
           return $vals;
 runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'      }
       else {
 =cut          return;
       }
 sub disable_tftpd {  }
     my $self = shift;  
   =pod
     my $vals = $self->tftpd( args => 'off' );  
   =head2 B<disable_tftpd> - disable the TFTP server
     if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) {  
         return $vals;  runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'
     }  
     else {  =cut
         return;  
     }  sub disable_tftpd {
 }      my $self = shift;
   
 =pod      my $vals = $self->tftpd( args => 'off' );
   
 =head2 B<cmd> - runs a command on the AP.      if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) {
           return $vals;
 This does most of the work.  At the heart, it calls Net::Telnet::cmd()      }
 but it also does some special stuff for Trango.      else {
           return;
 Normally returns the last lines from from the command      }
   }
 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  =pod
 some of the other commands are called.  
   =head2 B<cmd> - runs a command on the AP.
 In addition to the Net::Telnet::cmd() options, it also accepts these:  
   This does most of the work.  At the heart, it calls Net::Telnet::cmd()
 I<decode>  but it also does some special stuff for Trango.
 - if this is true, then it will send the output lines to _decode_lines()  
 and then returns the decoded output  Normally returns the last lines from from the command
   
 I<no_prompt>  If you are using this, rather than one of the "easy" methods above,
 - if this is true, it does not wait for a prompt, so you are not stuck  you probably want to read through the source of this module to see how
 waiting for something that will never happen.  some of the other commands are called.
   
 I<cmd_disconnects>  In addition to the Net::Telnet::cmd() options, it also accepts these:
 - if this is true, it then sets logged_in() to false, then it will  
 close() the connection and set is_connected() to false  I<decode>
   - if this is true, then it will send the output lines to _decode_lines()
 I<expect>  and then returns the decoded output
 - 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  I<no_prompt>
 command probably failed  - if this is true, it does not wait for a prompt, so you are not stuck
   waiting for something that will never happen.
 I<args>  
 - a string containing the command line options that are passed to the  I<cmd_disconnects>
 command  - if this is true, it then sets logged_in() to false, then it will
   close() the connection and set is_connected() to false
     $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );  
   I<expect>
 =cut  - 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
 sub cmd {  command probably failed
     my $self = shift;  
   I<args>
     my @valid_net_telnet_opts = qw(  - a string containing the command line options that are passed to the
       String  command
       Output  
       Cmd_remove_mode      $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );
       Errmode  
       Input_record_separator  =cut
       Ors  
       Output_record_separator  sub cmd {
       Prompt      my $self = shift;
       Rs  
       Timeout      my @valid_net_telnet_opts = qw(
     );        String
         Output
     my %cfg;        Cmd_remove_mode
     if ( @_ == 1 ) {        Errmode
         $cfg{'String'} = shift;        Input_record_separator
     }        Ors
     elsif ( @_ > 1 ) {        Output_record_separator
         %cfg = @_;        Prompt
     }        Rs
         Timeout
     $cfg{'Timeout'} ||= $self->Timeout;      );
   
     unless ( $cfg{'String'} ) {      my %cfg;
         $self->last_error("No command passed");      if ( @_ == 1 ) {
         return;          $cfg{'String'} = shift;
     }      }
       elsif ( @_ > 1 ) {
     unless ( $self->is_connected ) {          %cfg = @_;
         $self->last_error("Not connected");      }
         return;  
     }      $cfg{'Timeout'} ||= $self->Timeout;
   
     unless ( $self->logged_in ) {      unless ( $cfg{'String'} ) {
         $self->last_error("Not logged in");          $self->last_error("No command passed");
         return;          return;
     }      }
   
     my %cmd;      unless ( $self->is_connected ) {
     foreach (@valid_net_telnet_opts) {          $self->last_error("Not connected");
         if ( exists $cfg{$_} ) {          return;
             $cmd{$_} = $cfg{$_};      }
         }  
     }      unless ( $self->logged_in ) {
     if ( $cfg{'args'} ) {          $self->last_error("Not logged in");
         $cmd{'String'} .= ' ' . $cfg{'args'};          return;
     }      }
   
     my @lines;      my %cmd;
     if ( $cfg{'no_prompt'} ) {      foreach (@valid_net_telnet_opts) {
         $self->print( $cmd{'String'} );          if ( exists $cfg{$_} ) {
         @lines = $self->lastline;              $cmd{$_} = $cfg{$_};
     }          }
     else {      }
         @lines = $self->SUPER::cmd(%cmd);      if ( $cfg{'args'} ) {
     }          $cmd{'String'} .= $SPACE . $cfg{'args'};
       }
     $self->last_lines( \@lines );  
       my @lines;
     my $vals = 1;      if ( $cfg{'no_prompt'} ) {
     if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {          $self->print( $cmd{'String'} );
         if ( $cfg{'decode'} eq 'each' ) {          @lines = $self->lastline;
             $vals = _decode_each_line(@lines);      }
         }      else {
         elsif ( $cfg{'decode'} eq 'sulog' ) {          @lines = $self->SUPER::cmd(%cmd);
             $vals = _decode_sulog(@lines);      }
         }  
         elsif ( $cfg{'decode'} eq 'maclist' ) {      $self->last_lines( \@lines );
             $vals = _decode_maclist(@lines);  
         }      my $vals = 1;
         else {      if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {
             $vals = _decode_lines(@lines);          if ( $cfg{'decode'} eq 'each' ) {
         }              $vals = _decode_each_line(@lines);
     }          }
           elsif ( $cfg{'decode'} eq 'sulog' ) {
     $self->last_vals($vals);              $vals = _decode_sulog(@lines);
           }
     my $last = $self->lastline;          elsif ( $cfg{'decode'} eq 'maclist' ) {
               $vals = _decode_maclist(@lines);
     if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) {              if (! $vals) {
         if ( $cfg{'cmd_disconnects'} ) {                  $self->last_error("Error decoding maclist");
             $self->logged_in(0);              }
             $self->close;          }
             $self->is_connected(0);          else {
         }              $vals = _decode_lines(@lines);
           }
         if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {      }
             return $vals;  
         }      $self->last_vals($vals);
         else {  
             return \@lines;      my $last = $self->lastline;
         }  
     }      if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) {
     else {          if ( $cfg{'cmd_disconnects'} ) {
         $self->last_error("Error with command ($cfg{'String'}): $last");              $self->logged_in(0);
         return;              $self->close;
     }              $self->is_connected(0);
 }          }
   
 #=item _decode_lines          if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {
               return $vals;
 sub _decode_lines {          }
     my @lines = @_;          else {
               return \@lines;
     my %conf;          }
       }
     my $key = '';      else {
     my $val = undef;          my $err;
     my @vals;          if (grep { /\[ERR\]/ } @lines) {
     my $in_key = 0;              $err = _decode_lines(@lines);
     my $in_val = 1;          }
   
     foreach my $line (@lines) {          if (ref $err eq 'HASH' && $err ->{ERR}) {
         next if $line =~ /$success$/;              $self->last_error($err->{ERR} );
           } else {
         my @chars = split //, $line;              $self->last_error("Error with command ($cfg{'String'}): $last");
           }
         my $last_key = '';          return;
         foreach my $c (@chars) {      }
   }
             if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {  
                 if ( $c eq '[' ) {  #=item _decode_lines
                     $in_key = 1;  
                     $in_val = 0;  sub _decode_lines {
                 }      my @lines = @_;
                 else {  
                     $in_key = 0;      my %conf;
                     $in_val = 1;  
                 }      my $key = $EMPTY;
       my $val = undef;
                 if ($key) {      my @vals;
                     $key =~ s/^\s+//;      my $in_key = 0;
                     $key =~ s/\s+$//;      my $in_val = 1;
   
                     if ($val) {      foreach my $line (@lines) {
                         $val =~ s/^\s+//;          next if $line =~ /$success$/;
                         $val =~ s/\s+$//;  
                     }          my @chars = split //, $line;
   
                     if ( $key eq 'Checksum' && $last_key ) {          my $last_key = $EMPTY;
           foreach my $c (@chars) {
                         # Special case for these bastids.  
                         my $new = $last_key;              if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {
                         $new =~ s/\s+\S+$//;                  if ( $c eq '[' ) {
                         $key = $new . " " . $key;                      $in_key = 1;
                     }                      $in_val = 0;
                   }
                     $conf{$key} = $val;                  else {
                     $last_key   = $key;                      $in_key = 0;
                     $key        = '';                      $in_val = 1;
                 }                  }
                 elsif ($val) {  
                     push @vals, $val;                  if ($key) {
                 }                      $key =~ s/^\s+//;
                 $val = '';                      $key =~ s/\s+$//;
   
             }                      if ($val) {
             elsif ( $c eq ']' ) {                          $val =~ s/^\s+//;
                 $in_val = 1;                          $val =~ s/\s+$//;
                 $in_key = 0;                      }
                 $c      = shift @chars;  
                       if ( $key eq 'Checksum' && $last_key ) {
             }  
             elsif ($in_key) {                          # Special case for these bastids.
                 $key .= $c;                          my $new = $last_key;
                           $new =~ s/\s+\S+$//;
             }                          $key = $new . $SPACE . $key;
             elsif ($in_val) {                      }
                 $val .= $c;  
             }                      $conf{$key} = $val;
         }                      $last_key   = $key;
     }                      $key        = $EMPTY;
                   }
     unless ($key) {                  elsif ($val) {
         push @vals, $val;                      push @vals, $val;
     }                  }
                   $val = $EMPTY;
     if ( @vals == 1 ) {  
         $val = $vals[0];              }
     }              elsif ( $c eq ']' ) {
     elsif (@vals) {                  $in_val = 1;
         $val = \@vals;                  $in_key = 0;
     }                  $c      = shift @chars;
     else {  
         $val = undef;              }
     }              elsif ($in_key) {
                   $key .= $c;
     if (%conf) {  
         $conf{_pre} = $val if $val;              }
         return \%conf;              elsif ($in_val) {
     }                  $val .= $c;
     else {              }
         return $val;          }
     }      }
 }  
       unless ($key) {
 #=item _decode_each_line          push @vals, $val;
       }
 sub _decode_each_line {  
     my @lines = @_;      if ( @vals == 1 ) {
     my @decoded;          $val = $vals[0];
     foreach my $line (@lines) {      }
         my $decoded = _decode_lines($line);      elsif (@vals) {
         push @decoded, $decoded if defined $decoded;          $val = \@vals;
     }      }
     return \@decoded;      else {
 }          $val = undef;
       }
 #=item _decode_sulog  
       if (%conf) {
 sub _decode_sulog {          $conf{_pre} = $val if $val;
     my @lines = @_;          return \%conf;
     my @decoded;      }
     my $last_tm;      else {
     foreach my $line (@lines) {          return $val;
         my $decoded = _decode_lines($line);      }
   }
         if ( defined $decoded ) {  
             if ( $decoded->{'tm'} ) {  #=item _decode_each_line
                 $last_tm = $decoded->{'tm'};  
                 next;  sub _decode_each_line {
             }      my @lines = @_;
             else {      my @decoded;
                 $decoded->{'tm'} = $last_tm;      foreach my $line (@lines) {
             }          my $decoded = _decode_lines($line);
             next unless $last_tm;          push @decoded, $decoded if defined $decoded;
       }
             push @decoded, $decoded if defined $decoded;      return \@decoded;
         }  }
     }  
     return \@decoded;  #=item _decode_sulog
 }  
   sub _decode_sulog {
 #=item _decode_maclist      my @lines = @_;
       my @decoded;
 sub _decode_maclist {      my $last_tm;
     my @lines = @_;      foreach my $line (@lines) {
     my @decoded;          my $decoded = _decode_lines($line);
     my $total_entries = 0;  
     my $current_tm    = 0;          if ( defined $decoded ) {
     foreach my $line (@lines) {              if ( $decoded->{'tm'} ) {
         $line =~ s/\r?\n$//;                  $last_tm = $decoded->{'tm'};
         my ( $mac, $loc, $tm ) = $line =~ /                  next;
             ([0-9a-fA-F ]{17})\s+              }
             (.*)\s+              else {
             tm\s+                  $decoded->{'tm'} = $last_tm;
             (\d+)              }
         /x;              next unless $last_tm;
   
         if ($mac) {              push @decoded, $decoded if defined $decoded;
             $mac =~ s/\s+//g;          }
             $loc =~ s/^\s+//;      }
             $loc =~ s/\s+$//;      return \@decoded;
   }
             my $suid = undef;  
             if ( $loc =~ /suid\s+=\s+(\d+)/ ) {  #=item _decode_maclist
                 $suid = $1;  
                 $loc  = undef;  sub _decode_maclist {
             }      my @lines = @_;
       my @decoded;
             push @decoded,      my $total_entries = 0;
               {      my $current_tm    = 0;
                 mac  => $mac,      foreach my $line (@lines) {
                 loc  => $loc,          $line =~ s/\r?\n$//;
                 tm   => $tm,          my ( $mac, $loc, $tm ) = $line =~ /
                 suid => $suid,              ([0-9a-fA-F ]{17})\s+
               };              (.*)\s+
         }              tm\s+
         elsif ( $line =~ /(\d+)\s+entries/ ) {              (\d+)
             $total_entries = $1;          /x;
         }  
         elsif ( $line =~ /current tm = (\d+)\s+sec/ ) {          if ($mac) {
             $current_tm = $1;              $mac =~ s/\s+//g;
         }              $loc =~ s/^\s+//;
     }              $loc =~ s/\s+$//;
   
     map { $_->{'cur_tm'} = $current_tm } @decoded;              my $suid = undef;
               if ( $loc =~ /suid\s+=\s+(\d+)/ ) {
     if ( scalar @decoded == $total_entries ) {                  $suid = $1;
         return \@decoded;                  $loc  = undef;
     }              }
     else {  
               push @decoded,
         # XXX we should have a way to set last error, not sure why we don't                {
         return;                  mac  => $mac,
     }                  loc  => $loc,
 }                  tm   => $tm,
                   suid => $suid,
 1;    # End of Net::Telnet::Trango                };
 __END__          }
           elsif ( $line =~ /(\d+)\s+entries/ ) {
 =head1 SEE ALSO              $total_entries = $1;
           }
 Trango Documentation -          elsif ( $line =~ /current tm = (\d+)\s+sec/ ) {
 L<http://www.trangobroadband.com/support/product_docs.htm>              $current_tm = $1;
           }
 L<Net::Telnet>      }
   
 =head1 TODO      map { $_->{'cur_tm'} = $current_tm } @decoded;
   
 There are still a lot of commands that are not accessed directly.  If      if ( scalar @decoded == $total_entries ) {
 you call them (as cmd("command + args") or whatever) and it works,          return \@decoded;
 please send me examples that work and I will try to get it incorporated      }
 into the next version of the script.      else {
           return;
 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.  
   1;    # End of Net::Telnet::Trango
 =head1 AUTHOR  __END__
   
 Andrew Fresh E<lt>andrew@rraz.netE<gt>  =head1 SEE ALSO
   
 =head1 SUPPORT  Trango Documentation -
   L<http://www.trangobroadband.com/support/product_docs.htm>
 You can find documentation for this module with the perldoc command.  
   L<Net::Telnet>
     perldoc Net::Telnet::Trango  
   =head1 TODO
 You can also look for information at:  
   There are still a lot of commands that are not accessed directly.  If
 =over 4  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
 =item * AnnoCPAN: Annotated CPAN documentation  into the next version of the script.
   
 L<http://annocpan.org/dist/Net-Telnet-Trango>  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
 =item * CPAN Ratings  available as a perl datastructure.
   
 L<http://cpanratings.perl.org/d/Net-Telnet-Trango>  =head1 AUTHOR
   
 =item * RT: CPAN's request tracker  Andrew Fresh E<lt>andrew@rraz.netE<gt>
   
 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Telnet-Trango>  =head1 SUPPORT
   
 =item * Search CPAN  You can find documentation for this module with the perldoc command.
   
 L<http://search.cpan.org/dist/Net-Telnet-Trango>      perldoc Net::Telnet::Trango
   
 =back  You can also look for information at:
   
 =head1 COPYRIGHT AND LICENSE  =over 4
   
 Copyright (C) 2005,2006,2007 by Andrew Fresh  =item * AnnoCPAN: Annotated CPAN documentation
   
 This program is free software; you can redistribute it and/or modify it  L<http://annocpan.org/dist/Net-Telnet-Trango>
 under the same terms as Perl itself.  
   =item * CPAN Ratings
 =cut  
   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.41

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