[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.33 and 1.39

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

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