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

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

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.35

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