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

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

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.37

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