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

version 1.16, 2006/09/07 04:00:07 version 1.36, 2007/02/05 21:09:26
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.35 2007/02/05 21:03:40 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     =>
 =cut        { String => 'su info',  decode => 'all', expect          => $success },
       su_testrflink =>
 sub open        { String => 'su testrflink', decode => 'each', expect    => $success },
 {      save_ss     => { String => 'save ss',      expect          => $success },
   my $self = shift;      opmode      => { decode => 'all',          expect          => $success },
   );
   unless ( $self->SUPER::open(@_) ) {  
     #$! = "Couldn't connect to " . $self->Host . ":  $!";  my %ALIASES = (
     return undef;      bye     => 'exit',
   }      restart => 'reboot',
       Host    => 'host',
   ## Get to login prompt  );
   unless ($self->waitfor(  
       -match => '/password: ?$/i',  my %ACCESS = map { $_ => 1 } qw(
       -errmode => "return",    firmware_version
     ) ) {    host_type
     #$! = "problem connecting to host (" . $self->Host . "): " .    is_connected
     #    $self->lastline;    logged_in
     return undef;    login_banner
   }    Timeout
     last_lines
   $self->parse_login_banner($self->lastline);    last_vals
     last_error
   $self->is_connected(1);    Decode
   );
   return $self->is_connected;  
 }  sub AUTOLOAD {
       my $self = shift;
 =pod  
       my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/
 =item login        or die "Weird: $AUTOLOAD";
   
 Calls open() if not already connected, then sends the password and sets logged_in() if successful      if ( exists $ALIASES{$method} ) {
           $method = $ALIASES{$method};
 =cut          return $self->$method(@_);
       }
 sub login  
 {      if ( exists $COMMANDS{$method} ) {
   my $self = shift;          my %cmd;
           foreach my $k ( keys %{ $COMMANDS{$method} } ) {
   unless ($self->is_connected) {              $cmd{$k} = $COMMANDS{$method}{$k};
     $self->open or return undef;          }
   }          $cmd{'String'} ||= $method;
           $cmd{'args'} .= ' ' . shift if ( @_ == 1 );
   my $password = shift;          return $self->cmd( %cmd, @_ );
       }
   $self->print($password);  
   unless ($self->waitfor(      if ( exists $ACCESS{$method} ) {
     -match => $self->prompt,          my $prev = $PRIVATE{$method};
     -errmode => "return",          ( $PRIVATE{$method} ) = @_ if @_;
   ) ) {          return $prev;
     #$! = "login ($self->Host) failed: " . $self->lastline;      }
     return undef;  
   }      $method = "SUPER::$method";
       return $self->$method(@_);
   $self->logged_in(1);  }
   
   return $self->logged_in;  =pod
 }  
   =head2 B<open>
 =pod  - Open a connection to a Trango AP.
   
 =item parse_login_banner  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
 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()  host_type() and firmware_version()
   
 =cut  =cut
   
 sub parse_login_banner  sub open {
 {      my $self = shift;
   my $self = shift;  
       unless ( $self->SUPER::open(@_) ) {
   if (@_) {          $self->last_error( "Couldn't connect to " . $self->host . ":  $!" );
     $self->login_banner(@_);          return;
   }      }
   
   my $banner = $self->login_banner;      ## Get to login prompt
       unless (
   my ($type, $ver) = $banner =~          $self->waitfor(
     /Welcome to Trango Broadband Wireless (\S+)[\s-]+(.+)$/i;              -match   => '/password: ?$/i',
               -errmode => "return",
   $self->login_banner($banner);          )
   $self->host_type($type);        )
   $self->firmware_version($ver);      {
           $self->last_error( "problem connecting to host ("
   return 1;                . $self->host . "): "
 }                . $self->lastline );
           return;
 =pod      }
   
 =item su_password      $self->parse_login_banner( $self->lastline );
   
 C<su_password('all'|suid, 'new_password')>      $self->is_connected(1);
   
 =cut      return $self->is_connected;
   }
 sub su_password  
 {  =pod
   my $self     = shift;  
   my $su       = shift || '!';  =head2 B<login>
   my $new_pass = shift || '';  - Login to the AP.
   
   unless (defined $su) {  Calls open() if not already connected, then sends the password and sets
     warn "No su passed!"  logged_in() if successful
     #return undef;  
   }  =cut
   
   unless (defined $new_pass) {  sub login {
     warn "No new password!"      my $self = shift;
     #return undef;  
   }      unless ( $self->is_connected ) {
           $self->open or return;
   return $self->cmd(String => 'su password ' .      }
                      $su . ' ' .  
                      $new_pass . ' ' .      my $password = shift;
                      $new_pass,  
                      expect => $success,      $self->print($password);
                     );      unless (
 }          $self->waitfor(
               -match   => $self->prompt,
 =pod              -errmode => "return",
           )
 =item su_ipconfig        )
       {
 C<su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )>          $self->last_error( "login ($self->host) failed: " . $self->lastline );
           return;
 =cut      }
   
 sub su_ipconfig      $self->logged_in(1);
 {  
         my $self        = shift;      return $self->logged_in;
   }
         my $suid        = shift;  
         my $new_ip      = shift;  =pod
         my $new_subnet  = shift;  
         my $new_gateway = shift;  =head2 B<parse_login_banner>
   - Converts the login_banner to some useful
         return undef unless $suid =~ /^\d+$/;  variables.
         return undef unless $new_ip;  
         return undef unless $new_subnet;  Takes a login banner (what you get when you first connect to the Trango)
         return undef unless $new_gateway;  or reads what is already in login_banner() then parses it and sets
   host_type() and firmware_version() as well as login_banner()
         # su ipconfig <suid> <new ip> <new subnet> <new gateway>  
         return $self->cmd(String => 'su ipconfig ' .  =cut
                      $suid       . ' ' .  
                      $new_ip     . ' ' .  sub parse_login_banner {
                      $new_subnet . ' ' .      my $self = shift;
                      $new_gateway,  
                      expect => $success,      if (@_) {
                     );          $self->login_banner(@_);
 }      }
   
 =pod      my $banner = $self->login_banner;
   
 =item sudb_view      my ( $type, $sep1, $subtype, $sep2, $ver ) =
         $banner =~
 returns a reference to an array of hashes each containing:        /Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i;
   
   suid      $type .= $sep1 . $subtype;
   type      $ver = $subtype . $sep2 . $ver;
   cir  
   mir      $self->login_banner($banner);
   mac      $self->host_type($type);
       $self->firmware_version($ver);
 =cut  
       return 1;
 sub sudb_view  }
 {  
   my $self = shift;  =pod
   
   my @lines = $self->cmd( String => 'sudb view', expect => $success );  =head2 B<su_password>
   - Set the password on SUs connected to the AP.
   return undef unless @lines;  
   su_password('new_password'[, 'suid']) If no suid is specified,
   unless ($PRIVATE{'Decode'}) {  the default is "all".
     return @lines;  
   }    $t->su_password('good_pass', 5);
   
   my @sus;  =cut
   foreach (@lines) {  
     next unless $_;  sub su_password {
     if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) {      my $self     = shift;
       my %s = (      my $new_pass = shift || '';
         suid => $1,      my $su       = shift || 'all';
         type => $2,  
         cir  => $3,      unless ( defined $new_pass ) {
         mir  => $4,          $self->last_error("No new password");
         mac  => $5,  
       );          #return;
       }
           $s{'mac'} =~ s/\s//g;  
           $s{'mac'} = uc($s{'mac'});      return $self->cmd(
           String => 'su password ' . $su . ' ' . $new_pass . ' ' . $new_pass,
       push @sus, \%s;          expect => $success,
     }      );
   }  }
   
   return \@sus;  =pod
 }  
   =head2 B<su_ipconfig>
 =pod  - Change IP configuration on SUs connected to
   the AP.
 =item sudb_add  
   su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )
 Takes the following paramaters  
     $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );
         suid : numeric,  
         type : (reg|pr)  =cut
         cir  : numeric,  
         mir  : numeric,  sub su_ipconfig {
         mac  : Almost any format, it will be reformatted,      my $self = shift;
   
 and returns true on success or undef otherwise.      my $suid        = shift;
       my $new_ip      = shift;
 You should save_sudb() after calling this, or your changes  will be lost      my $new_subnet  = shift;
 when the AP is rebooted.      my $new_gateway = shift;
   
 =cut      if ( $suid =~ /\D/ ) {
           $self->last_error("Invalid suid '$suid'");
 sub sudb_add          return;
 {      }
         my $self = shift;      unless ($new_ip) {
         my $suid = shift;          $self->last_error("no new_ip passed");
         my $type = shift;          return;
         my $cir  = shift;      }
         my $mir  = shift;      unless ($new_subnet) {
         my $mac  = shift;          $self->last_error("no new_subnet passed");
           return;
         if ($suid =~ /\D/) {      }
                 return undef;      unless ($new_gateway) {
         }          $self->last_error("no new_gateway passed");
           return;
         unless (lc($type) eq 'reg' || lc($type) eq 'pr') {      }
                 warn "Invalid type '$type'!";  
                 return undef;      # su ipconfig <suid> <new ip> <new subnet> <new gateway>
         }      return $self->cmd(
           String => 'su ipconfig ' . $suid . ' ' . $new_ip . ' '
         if ($cir =~ /\D/) {            . $new_subnet . ' '
                 warn "Invalid CIR '$cir'!";            . $new_gateway,
                 return undef;          expect => $success,
         }      );
   }
         if ($mir =~ /\D/) {  
                 warn "Invalid MIR '$mir'!";  =pod
                 return undef;  
         }  =head2 B<sudb_view>
   - Returns the output from the sudb view command
         my $new_mac = $mac;  
         $new_mac =~ s/[^0-9A-Fa-f]//;  returns a reference to an array of hashes each containing these keys
         unless (length $new_mac == 12) {  'suid', 'type', 'cir', 'mir' and 'mac'
                 warn "Invalid MAC '$mac'!";  
                 return undef;  =cut
         }  
         $new_mac = join ' ', $new_mac =~ /../g;  sub sudb_view {
       my $self = shift;
         my $string = 'sudb add ' .  
                 $suid . ' ' .      my $lines = $self->cmd( String => 'sudb view', expect => $success ) || [];
                 $type . ' ' .  
                 $cir  . ' ' .      return unless @{$lines};
                 $mir  . ' ' .  
                 $new_mac;      unless ( $PRIVATE{'Decode'} ) {
           return $lines;
       }
         return $self->cmd( String => $string, expect => $success );  
 }      my @sus;
       foreach ( @{$lines} ) {
 =pod          next unless $_;
           if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) {
 =item sudb_delete              my %s = (
                   suid => $1,
 Takes either 'all' or the  suid of the su to delete                  type => $2,
 and returns true on success or undef otherwise.                  cir  => $3,
                   mir  => $4,
 You should save_sudb() after calling this, or your changes  will be lost                  mac  => $5,
 when the AP is rebooted.              );
   
 =cut              $s{'mac'} =~ s/\s//g;
               $s{'mac'} = uc( $s{'mac'} );
 sub sudb_delete  
 {              push @sus, \%s;
         my $self = shift;          }
         my $suid = shift;      }
   
         if (lc($suid) ne 'all' || $suid =~ /\D/) {      return \@sus;
                 return undef;  }
         }  
   =pod
         return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );  
 }  =head2 B<sudb_add>
   
 =pod  Takes the following paramaters
   
 =item sudb_modify      suid : numeric,
       type : (reg|pr)
 Takes either the  suid of the su to delete      cir  : numeric,
 as well as what you are changing, either "cir, mir or su2su"      mir  : numeric,
 and returns true on success or undef otherwise.      mac  : Almost any format, it will be reformatted,
   
 cir and mir also take a value to set the cir/mir to.  and returns true on success or undef otherwise.
   
 su2su takes a group id parameter that is in hex.    $t->sudb_add($suid, 'reg', $cir, $mir, $mac);
   
 You should save_sudb() after calling this, or your changes  will be lost  You should save_sudb() after calling this, or your changes  will be lost
 when the AP is rebooted.  when the AP is rebooted.
   
 =cut  =cut
   
 sub sudb_modify  sub sudb_add {
 {      my $self = shift;
         my $self  = shift;      my $suid = shift;
         my $suid  = shift;      my $type = shift;
         my $opt   = shift;      my $cir  = shift;
         my $value = shift;      my $mir  = shift;
       my $mac  = shift;
         if ($suid =~ /\D/) {  
                 return undef;      if ( $suid =~ /\D/ ) {
         }          $self->last_error("Invalid suid '$suid'");
           return;
         if (lc($opt) eq 'cir' or lc($opt) eq 'mir') {      }
                 if ($value =~ /\D/) {  
                         return undef;      unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) {
                 }          $self->last_error("Invalid type '$type'");
         } elsif (lc($opt) eq 'su2su') {          return;
                 if ($value =~ /[^0-9A-Za-f]/) {      }
                         return undef;  
                 }      if ( $cir =~ /\D/ ) {
         } else {          $self->last_error("Invalid CIR '$cir'");
                 return undef;          return;
         }      }
   
         my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value;      if ( $mir =~ /\D/ ) {
           $self->last_error("Invalid MIR '$mir'");
         return $self->cmd( String => $string, expect => $success );          return;
 }      }
   
 =pod      my $new_mac = $mac;
       $new_mac =~ s/[^0-9A-Fa-f]//;
 =item enable_tftpd      unless ( length $new_mac == 12 ) {
           $self->last_error("Invalid MAC '$mac'");
 runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing          return;
       }
 =cut      $new_mac = join ' ', $new_mac =~ /../g;
   
 sub enable_tftpd      my $string =
 {        'sudb add ' . $suid . ' ' . $type . ' ' . $cir . ' ' . $mir . ' '
   my $self = shift;        . $new_mac;
   
   my $vals = $self->tftpd( args => 'on' );      return $self->cmd( String => $string, expect => $success );
   }
   if ($vals->{'Tftpd'} eq 'listen') {  
     return $vals;  =pod
   } else {  
     return undef;  =head2 B<sudb_delete>
   }  
 }  Takes either 'all' or the  suid of the su to delete
   and returns true on success or undef otherwise.
 =pod  
     $t->sudb_delete($suid);
 =item disable_tftpd  
   You should save_sudb() after calling this, or your changes  will be lost
 runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'  when the AP is rebooted.
   
 =cut  =cut
   
 sub disable_tftpd  sub sudb_delete {
 {      my $self = shift;
   my $self = shift;      my $suid = shift;
   
   my $vals = $self->tftpd( args => 'off' );      #if (lc($suid) ne 'all' || $suid =~ /\D/) {
       if ( $suid =~ /\D/ ) {
   if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled') {          $self->last_error("Invalid suid '$suid'");
     return $vals;          return;
   } else {      }
     return undef;  
   }      return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );
 }  }
   
 =pod  =pod
   
 =item cmd  =head2 B<sudb_modify>
   
 This does most of the work.  At the heart, it calls Net::Telnet::cmd() but it also does some special stuff for Trango.  Takes either the  suid of the su to change
   as well as what you are changing, either "cir, mir or su2su"
 Normally returns the last lines from from the command  and returns true on success or undef otherwise.
   
 Also accepts these options:  cir and mir also take a value to set the cir/mir to.
   
 I<decode>  su2su takes a group id parameter that is in hex.
 - if this is true, then it will send the output lines to _decode_lines() and then returns the decoded output  
     $t->sudb_modify($suid, 'cir', 512);
 I<cmd_disconnects>  
 - if this is true, it then sets logged_in() to false, then it will close() the connection and then sets is_connected() to false  You should save_sudb() after calling this, or your changes  will be lost
   when the AP is rebooted.
 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  =cut
   
 I<args>  sub sudb_modify {
 - a string containing the command line options that are passed to the command      my $self  = shift;
       my $suid  = shift;
 =cut      my $opt   = shift;
       my $value = shift;
 sub cmd  
 {      if ( $suid =~ /\D/ ) {
   my $self = shift;          $self->last_error("Invalid suid '$suid'");
           return;
   my @valid_net_telnet_opts = qw(      }
     String  
     Output      if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {
     Cmd_remove_mode          if ( $value =~ /\D/ ) {
     Errmode              $self->last_error("Invalid $opt '$value'");
     Input_record_separator              return;
     Ors          }
     Output_record_separator      }
     Prompt      elsif ( lc($opt) eq 'su2su' ) {
     Rs          if ( $value =~ /[^0-9A-Za-f]/ ) {
     Timeout              $self->last_error("Invalid MAC '$value'");
   );              return;
           }
   my %cfg;      }
   if (@_ == 1) {      else {
     $cfg{'String'} = shift;          $self->last_error("Invalid option '$opt'");
   } elsif (@_ > 1) {          return;
     %cfg = @_;      }
   }  
       my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value;
   $cfg{'Timeout'} ||= $self->Timeout;  
       return $self->cmd( String => $string, expect => $success );
   unless ($cfg{'String'}) {  }
     #$! = "No command passed";  
     #warn "No command passed\n";  =pod
     return undef;  
   }  =head2 B<enable_tftpd>
   - enable the TFTP server
   unless ($self->is_connected) {  
     #$! = "Not connected";  runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing
     #warn "Not connected\n";  
     return undef;  =cut
   }  
   sub enable_tftpd {
   unless ($self->logged_in) {      my $self = shift;
     #$! = "Not logged in";  
     #warn "Not logged in\n";      my $vals = $self->tftpd( args => 'on' );
     return undef;  
   }      if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) {
           return $vals;
       }
   my %cmd;      else {
   foreach (@valid_net_telnet_opts) {          return;
     if (exists $cfg{$_}) {      }
       $cmd{$_} = $cfg{$_};  }
     }  
   }  =pod
   if ($cfg{'args'}) {  
     $cmd{'String'} .= ' ' . $cfg{'args'};  =head2 B<disable_tftpd>
   }  - disable the TFTP server
   my @lines;  
   unless ($cfg{'no_prompt'}) {  runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'
     @lines = $self->SUPER::cmd(%cmd);  
   } else {  =cut
     $self->print($cmd{'String'});  
     @lines = $self->lastline;  sub disable_tftpd {
   }      my $self = shift;
   
   $self->last_lines(\@lines);      my $vals = $self->tftpd( args => 'off' );
   
   my $vals = 1;      if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) {
   if ($PRIVATE{'Decode'} && $cfg{'decode'}) {          return $vals;
     if ($cfg{'decode'} eq 'each') {      }
       $vals = _decode_each_line(@lines);      else {
     } elsif ($cfg{'decode'} eq 'sulog') {          return;
       $vals = _decode_sulog(@lines);      }
     } elsif ($cfg{'decode'} eq 'maclist') {  }
       $vals = _decode_maclist(@lines);  
     } else {  =pod
       $vals = _decode_lines(@lines);  
     }  =head2 B<cmd> - runs a command on the AP.
   }  
   This does most of the work.  At the heart, it calls Net::Telnet::cmd()
   $self->last_vals($vals);  but it also does some special stuff for Trango.
   
   Normally returns the last lines from from the command
   my $last = $self->lastline;  
   If you are using this, rather than one of the "easy" methods above,
   if ((not $cfg{'expect'}) || $last =~ /$cfg{'expect'}$/) {  you probably want to read through the source of this module to see how
     if ($cfg{'cmd_disconnects'}) {  some of the other commands are called.
       $self->logged_in(0);  
       $self->close;  In addition to the Net::Telnet::cmd() options, it also accepts these:
       $self->is_connected(0);  
     }  I<decode>
   - if this is true, then it will send the output lines to _decode_lines()
     if ($PRIVATE{'Decode'} && $cfg{'decode'}) {  and then returns the decoded output
       return $vals;  
     } else {  I<no_prompt>
       return @lines;  - if this is true, it does not wait for a prompt, so you are not stuck
     }  waiting for something that will never happen.
   } else {  
     #$! = "Error with command ($cfg{'string'}): $last";  I<cmd_disconnects>
     return undef;  - if this is true, it then sets logged_in() to false, then it will
   }  close() the connection and set is_connected() to false
 }  
   I<expect>
 #=item _decode_lines  - 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
 sub _decode_lines  command probably failed
 {  
   my @lines = @_;  I<args>
   - a string containing the command line options that are passed to the
   my %conf;  command
   
   my $key = '';      $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );
   my $val = '';  
   my $in_key = 0;  =cut
   my $in_val = 0;  
   sub cmd {
   foreach my $line (@lines) {      my $self = shift;
     next if $line =~ /$success$/;  
       my @valid_net_telnet_opts = qw(
     my @chars = split //, $line;        String
         Output
     my $last_key = '';        Cmd_remove_mode
     foreach my $c (@chars) {        Errmode
         Input_record_separator
       if ($c eq '[' || $c eq "\r" || $c eq "\n") {        Ors
         if ($c eq '[') {        Output_record_separator
           $in_key = 1;        Prompt
           $in_val = 0;        Rs
         } else {        Timeout
           $in_key = 0;      );
           $in_val = 0;  
         }      my %cfg;
       if ( @_ == 1 ) {
         if ($key) {          $cfg{'String'} = shift;
           $key =~ s/^\s+//;      }
           $key =~ s/\s+$//;      elsif ( @_ > 1 ) {
           %cfg = @_;
           $val =~ s/^\s+//;      }
           $val =~ s/\s+$//;  
       $cfg{'Timeout'} ||= $self->Timeout;
           if ($key eq 'Checksum' && $last_key) {  
             # Special case for these bastids.      unless ( $cfg{'String'} ) {
             my $new = $last_key;          $self->last_error("No command passed");
             $new =~ s/\s+\S+$//;          return;
             $key = $new . " " . $key;      }
           }  
       unless ( $self->is_connected ) {
           $last_key = $key;          $self->last_error("Not connected");
           $conf{$key} = $val;          return;
           $key = '';      }
           $val = '';  
         }      unless ( $self->logged_in ) {
           $self->last_error("Not logged in");
       } elsif ($c eq ']') {          return;
         $in_val = 1;      }
         $in_key = 0;  
         $c = shift @chars;      my %cmd;
       foreach (@valid_net_telnet_opts) {
       } elsif ($in_key) {          if ( exists $cfg{$_} ) {
         $key .= $c;              $cmd{$_} = $cfg{$_};
           }
       } elsif ($in_val) {      }
         $val .= $c;      if ( $cfg{'args'} ) {
       }          $cmd{'String'} .= ' ' . $cfg{'args'};
     }      }
   }  
       my @lines;
   if (%conf) {      if ( $cfg{'no_prompt'} ) {
     return \%conf;          $self->print( $cmd{'String'} );
   } else {          @lines = $self->lastline;
     return undef;      }
   }      else {
 }          @lines = $self->SUPER::cmd(%cmd);
       }
 #=item _decode_each_line  
       $self->last_lines( \@lines );
 sub _decode_each_line  
 {      my $vals = 1;
   my @lines = @_;      if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {
   my @decoded;          if ( $cfg{'decode'} eq 'each' ) {
   foreach my $line (@lines) {              $vals = _decode_each_line(@lines);
     my $decoded = _decode_lines($line);          }
     push @decoded, $decoded if defined $decoded;          elsif ( $cfg{'decode'} eq 'sulog' ) {
   }              $vals = _decode_sulog(@lines);
   return \@decoded;          }
 }          elsif ( $cfg{'decode'} eq 'maclist' ) {
               $vals = _decode_maclist(@lines);
 #=item _decode_sulog          }
           else {
 sub _decode_sulog              $vals = _decode_lines(@lines);
 {          }
   my @lines = @_;      }
   my @decoded;  
   my $last_tm;      $self->last_vals($vals);
   foreach my $line (@lines) {  
     my $decoded = _decode_lines($line);      my $last = $self->lastline;
   
     if (defined $decoded) {      if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) {
       if ($decoded->{'tm'}) {          if ( $cfg{'cmd_disconnects'} ) {
         $last_tm = $decoded->{'tm'};              $self->logged_in(0);
         next;              $self->close;
       } else {              $self->is_connected(0);
         $decoded->{'tm'} = $last_tm;          }
       }  
       next unless $last_tm;          if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {
               return $vals;
       push @decoded, $decoded if defined $decoded;          }
     }          else {
   }              return \@lines;
   return \@decoded;          }
 }      }
       else {
 #=item _decode_maclist          $self->last_error("Error with command ($cfg{'String'}): $last");
           return;
 sub _decode_maclist      }
 {  }
         my @lines = @_;  
         my @decoded;  #=item _decode_lines
         my $total_entries = 0;  
         my $current_tm = 0;  sub _decode_lines {
         foreach my $line (@lines) {      my @lines = @_;
                 $line =~ s/\r?\n$//;  
                 my ($mac, $loc, $tm) = $line =~ /      my %conf;
                         ([0-9a-fA-F ]{17})\s+  
                         (.*)\s+      my $key = '';
                         tm\s+      my $val = undef;
                         (\d+)      my @vals;
                 /x;      my $in_key = 0;
       my $in_val = 1;
                 if ($mac) {  
                         $mac =~ s/\s+//g;      foreach my $line (@lines) {
                         $loc =~ s/^\s+//;          next if $line =~ /$success$/;
                         $loc =~ s/\s+$//;  
           my @chars = split //, $line;
                         my $suid = undef;  
                         if ($loc =~ /suid\s+=\s+(\d+)/) {          my $last_key = '';
                                 $suid = $1;          foreach my $c (@chars) {
                                 $loc = undef;  
                         }              if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {
                   if ( $c eq '[' ) {
                         push @decoded, {                      $in_key = 1;
                                 mac  => $mac,                      $in_val = 0;
                                 loc  => $loc,                  }
                                 tm   => $tm,                  else {
                                 suid => $suid,                      $in_key = 0;
                         };                      $in_val = 1;
                 } elsif ($line =~ /(\d+)\s+entries/) {                  }
                         $total_entries = $1;  
                 } elsif ($line =~ /current tm = (\d+)\s+sec/) {                  if ($key) {
                         $current_tm = $1                      $key =~ s/^\s+//;
                 }                      $key =~ s/\s+$//;
         }  
                       if ($val) {
         map { $_->{'cur_tm'} = $current_tm } @decoded;                          $val =~ s/^\s+//;
                           $val =~ s/\s+$//;
         if (scalar @decoded == $total_entries) {                      }
                 return \@decoded;  
         } else {                      if ( $key eq 'Checksum' && $last_key ) {
                 # XXX we should have a way to set last error, not sure why we don't  
                 return undef;                          # Special case for these bastids.
         }                          my $new = $last_key;
 }                          $new =~ s/\s+\S+$//;
                           $key = $new . " " . $key;
 1;                      }
 __END__  
                       $conf{$key} = $val;
 =back                      $last_key   = $key;
                       $key        = '';
 =head1 SEE ALSO                  }
                   elsif ($val) {
 Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm                      push @vals, $val;
                   }
 L<Net::Telnet>                  $val = '';
   
 =head1 TODO              }
               elsif ( $c eq ']' ) {
 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.                  $in_val = 1;
                   $in_key = 0;
 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.                  $c      = shift @chars;
   
 =head1 AUTHOR              }
               elsif ($in_key) {
 Andrew Fresh E<lt>andrew@rraz.netE<gt>                  $key .= $c;
   
 =head1 COPYRIGHT AND LICENSE              }
               elsif ($in_val) {
 Copyright (C) 2005 by Andrew Fresh                  $val .= $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.  
       unless ($key) {
           push @vals, $val;
 =cut      }
   
       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.36

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