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

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

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