[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.30 and 1.34

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

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.34

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