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

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

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