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

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

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