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

Diff for /trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm between version 1.36 and 1.41

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

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.41

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