[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.34 and 1.44

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

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