[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.32 and 1.38

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

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.38

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