[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.26 and 1.35

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

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