[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.38

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

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