[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.8 and 1.59

version 1.8, 2006/06/29 01:39:52 version 1.59, 2009/07/31 22:44:33
Line 1 
Line 1 
 package Net::Telnet::Trango;  package Net::Telnet::Trango;
 # $RedRiver: Trango.pm,v 1.7 2006/06/28 22:33:18 andrew Exp $  
 use strict;  # $RedRiver: Trango.pm,v 1.58 2009/07/13 16:33:45 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 => $ap ) 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 APs and SUs.
   
 =head2 EXPORT  A 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
 None  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.05';
   
 =item new  my $EMPTY = q{};
   my $SPACE = q{ };
 Same as new from L<Net::Telnet> but has defaults for the trango 'Prompt'  
   =pod
 =cut  
   =head2 B<new> - Creates a new Net::Telnet::Trango object.
 sub new  
 {      new([Options from Net::Telnet,]
   my $class = shift;          [Decode => 0,]);
   
   my %args;  Same as new from L<Net::Telnet> but sets the default Trango Prompt:
   if (@_ == 1) {  '/[\$#]>\s*\Z/'
     $args{'Host'} = shift;  
   } else {  It also takes an optional parameter 'Decode'.  If not defined it
     %args = @_;  defaults to 1, if it is set to 0, it will not decode the output and
   }  instead return a reference to an array of the lines that were returned
   from the command.
   $args{'Prompt'}  ||= '/#> *$/';  
   =cut
   foreach my $key (keys %args) {  
     $PRIVATE{$key} = $args{$key};  sub new {
   }      my $class = shift;
   
   my $self = $class->SUPER::new(%args);      my %args = ();
   bless $self if ref $self;      if ( @_ == 1 ) {
           $args{'Host'} = shift;
   return $self;      }
 }      else {
           %args = @_;
 #  _password <new password> <new password>      }
 #  ? [command]  
 #  apsearch <secs> <ch#> <h|v> [<ch#> <h|v>]...      $args{'Prompt'} ||= '/[\$#]>\s*\r?\n?$/';
 #  arp -bcast <on|off>  
 #  bcastscant <all|suid> <ch#> <h|v> [<ch#> <h|v> ...      my $decode = $args{'Decode'};
 #  bye      delete $args{'Decode'};
 #  cf2cf ap [default|<size>]  
 #  date      my $self = $class->SUPER::new(%args);
 #  date <month> <day> <year>      bless $self if ref $self;
 #  freq scantable  
 #  freq channeltable      $args{Decode}       = defined $decode ? $decode : 1;
 #  freq writescan [<ch#> <h|v>]      $args{is_connected} = 0;
 #  freq writechannel [<ch#> <freq>] ...      $args{logged_in}    = 0;
 #  freq <ch #> <h|v>  
 #  help [command]      *$self->{net_telnet_trango} = \%args;
 #  heater [<on temp> <off temp>]  
 #  ipconfig [<new ip> <new subnet mask> <new gateway>]      return $self;
 #  log [<# of entries, 1..179>]  }
 #  log <sum> <# of entries, 1..179>  
 #  logout  #  _password <new password> <new password>
 #  opmode [ap [y]]  #  ? [command]
 #  password  #  apsearch <secs> <ch#> <h|v> [<ch#> <h|v>]...
 #  ping <ip addr>  #  arp -bcast <on|off>
 #  polar <h|v>  #  bcastscant <all|suid> <ch#> <h|v> [<ch#> <h|v> ...
 #  power <setism|setunii> <max|min|<dBm>>  #  bye
 #  reboot  #  cf2cf ap [default|<size>]
 #  restart  #  date
 #  remarks [<str>]  #  date <month> <day> <year>
 #  rfrxthreshold [<ism|unii> <-90|-85|-80|-75|-70|-65>]  #  freq scantable
 #  rfrxth [<ism|unii> <-90|-85|-80|-75|-70|-65>]  #  freq channeltable
 #  sysinfo  #  freq writescan [<ch#> <h|v>]
 #  set suid <id>  #  freq writechannel [<ch#> <freq>] ...
 #  set apid <id>  #  freq <ch #> <h|v>
 #  set baseid <id>  #  help [command]
 #  set defaultopmode [<ap|su> <min,0..10>]  #  heater [<on temp> <off temp>]
 #  set defaultopmode off  #  ipconfig [<new ip> <new subnet mask> <new gateway>]
 #  set snmpcomm [<read | write | trap (id or setall)> <str>]  #  linktest <suid> [<pkt len, bytes> [<# of pkts> [<# of cycle>]]]
 #  set mir [on|off]  #  log [<# of entries, 1..179>]
 #  set mir threshold <kbps>  #  log <sum> <# of entries, 1..179>
 #  set rssitarget [<ism|unii> <dBm>]  #  logout
 #  set serviceradius [<ism | unii> <miles>]  #  opmode [ap [y]]
 #  ssrssi <ch #> <h|v>  #  password
 #  su [<suid>|all]  #  ping <ip addr>
 #  su changechannel <all|suid> <ch#> <h|v>  #  polar <h|v>
 #  su ipconfig <suid> <new ip> <new subnet> <new gateway>  #  power <setism|setunii> <max|min|<dBm>>
 #  su [live|poweroff|priority]  #  reboot
 #  su <ping|info|status> <suid>  #  restart
 #  su powerleveling <all|suid>  #  remarks [<str>]
 #  su reboot <all|suid>  #  rfrxthreshold [<ism|unii> <-90|-85|-80|-75|-70|-65>]
 #  su restart <all|suid>  #  rfrxth [<ism|unii> <-90|-85|-80|-75|-70|-65>]
 #  su testrflink <all|suid> [r]  #  sysinfo
 #  su testrflink <setlen> [64..1600]  #  set suid <id>
 #  su testrflink <aptx> [20..100]  #  set apid <id>
 #  su sw <suid|all> <sw #> <on|off>  #  set baseid <id>
 #  sudb [dload | view]  #  set defaultopmode [<ap|su> <min,0..10>]
 #  sudb add <suid> pr <cir,kbps> <mir,kbps> <device id,hex>  #  set defaultopmode off
 #  sudb add <suid> reg <cir,kbps> <mir,kbps> <device id,hex>  #  set snmpcomm [<read | write | trap (id or setall)> <str>]
 #  sudb delete <all|<suid>>  #  set mir [on|off]
 #  sudb modify <suid> <cir|mir> <kbps>  #  set mir threshold <kbps>
 #  sudb modify <suid> <su2su> <group id,hex>  #  set rssitarget [<ism|unii> <dBm>]
 #  sudb view  #  set serviceradius [<ism | unii> <miles>]
 #  sulog [lastmins | sampleperiod <1..60>]  #  ssrssi <ch #> <h|v>
 #  sulog [<# of entry,1..18>]  #  su [<suid>|all]
 #  survey <ism|unii> <time, sec> <h|v>  #  su changechannel <all|suid> <ch#> <h|v>
 #  sw [<sw #> <on|off>]  #  su ipconfig <suid> <new ip> <new subnet> <new gateway>
 #  temp  #  su [live|poweroff|priority]
 #  tftpd [on|off]  #  su <ping|info|status> <suid>
 #  time  #  su powerleveling <all|suid>
 #  time <hour> <min> <sec>  #  su reboot <all|suid>
 #  save <mainimage|fpgaimage> <current chksum> <new chksum>  #  su restart <all|suid>
 #  save <systemsetting|sudb>  #  su testrflink <all|suid> [r]
 #  updateflash <mainimage|fpgaimage> <current chksum> <new chksum>  #  su testrflink <setlen> [64..1600]
 #  updateflash <systemsetting|sudb>  #  su testrflink <aptx> [20..100]
   #  su sw <suid|all> <sw #> <on|off>
 =pod  #  sudb [dload | view]
   #  sudb add <suid> pr <cir,kbps> <mir,kbps> <device id,hex>
 =head1 METHODS  #  sudb add <suid> reg <cir,kbps> <mir,kbps> <device id,hex>
   #  sudb delete <all|<suid>>
 =head2 ACCESSORS  #  sudb modify <suid> <cir|mir> <kbps>
   #  sudb modify <suid> <su2su> <group id,hex>
 =over  #  sudb view
   #  sulog [lastmins | sampleperiod <1..60>]
 =item Host  #  sulog [<# of entry,1..18>]
   #  survey <ism|unii> <time, sec> <h|v>
 returns the name of the host that you are accessing  #  sw [<sw #> <on|off>]
   #  temp
 =item firmware_version  #  tftpd [on|off]
   #  time
 returns the firmware version on the trango if available otherwise undef.    #  time <hour> <min> <sec>
 Available after a successful open()  #  save <mainimage|fpgaimage> <current chksum> <new chksum>
 This is usually only set internally  #  save <systemsetting|sudb>
   #  updateflash <mainimage|fpgaimage> <current chksum> <new chksum>
 =item host_type  #  updateflash <systemsetting|sudb>
   
 returns the type of host from the login banner for example M5830S or M5300S.    =pod
 Available after a successful open()  
 This is usually only set internally  =head1 ACCESSORS
   
 =item is_connected  These are usually only set internally.
   
 returns 1 after a successful open() otherwise undef  =head2 B<firmware_version> - returns the firmware version
 This is usually only set internally  
   Returns the firmware version if available, otherwise undef.
 =item logged_in  
   It 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<host_type> - 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 login_banner  
   Should be available after a successful open().
 returns the banner that is displayed when first connected at login.  Only set after a successful open()  
   =head2 B<is_connected> - Status of the connection to host.
 This is usually only set internally  
   returns 1 when connected, undef otherwise.
 =item last_lines  
   =head2 B<logged_in> - Status of being logged in to the host.
 returns the output from the last cmd() that was run as an array ref  
 This is usually only set internally  returns 1 after a successful login(), 0 if it failed and undef if
   login() was never called.
 =back  
   =head2 B<login_banner> - The banner when first connecting to the host.
 =head2 ALIASES  
   returns the banner that is displayed when first connected at login.
 =over  Only set after a successful open().
   
 =item bye  =head2 B<last_lines> - The last lines of output from the last cmd().
   
 alias of exit()  returns, as an array ref, the output from the last cmd() that was run.
   
 =item restart  =head2 B<last_error> - A text output of the last error that was encountered.
   
 alias of reboot()  returns the last error reported.  Probably contains the last entry in
   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.  =head2 B<save_systemsetting> - alias of save_ss()
   
 Also see enable_tftpd() and disable_tftpd() as those check for correct output  Does the same as save_ss()
   
 =item ver  =head1 COMMANDS
   
 Returns a hash ref of the decoded output from the command.  Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>,
   as such they accept the same options as C<cmd()>.
 =item sysinfo  Specifically they take a named paramater "args", for example:
   C<tftpd(args =E<gt> 'on')> would enable tftpd
 Returns a hash ref of the decoded output from the command.  
   =head2 B<tftpd> - The output from the tftpd command
 =item exit  
   Returns a hash ref of the decoded output from the
 exits the command session with the trango and closes the connection  command.
   
 =item reboot  Also see enable_tftpd() and disable_tftpd() as those check that it was
   successfully changed.
 reboots the trango and closes the connection  
   =head2 B<ver> - The output from the ver command
 =item sulog  
   Returns a hash ref of the decoded output from the
 returns an array ref of hashes containing each log line.  command.
   
 =item save_sudb  =head2 B<sysinfo> - The output from the sysinfo command
   
 returns true on success, undef on failure  Returns a hash ref of the decoded output from the
   command.
 =cut  
   =head2 B<exit> - Exits the connection
   
 my $success = 'Success.';  exits the command session with the Trango and closes
 my %COMMANDS = (  the connection
   tftpd       => { decode => 'all',   expect => $success },  
   ver         => { decode => 'all' },  =head2 B<reboot> - Sends a reboot command
   sysinfo     => { decode => 'all',   expect => $success },  
   updateflash => { decode => 'all',   expect => $success },  reboots the Trango and closes the connection
   sulog       => { decode => 'sulog', expect => $success },  
   'exit'      => { no_prompt => 1, cmd_disconnects => 1 },  ==head2 B<reset> <all|0..2> - Sends a reset command
   reboot      => { no_prompt => 1, cmd_disconnects => 1 },  
   save_sudb   => { String => "save sudb", expect => $success },  resets settings to default
   #su password???  
   #_bootloader  =head2 B<remarks> - Set or retrieve the remarks.
   #temp  
   #heater  Takes an optional argument, which sets the remarks.
 );  If there is no argument, returns the current remarks.
   
 my %ALIASES = (    my $old_remarks = $t->remarks();
   bye     => 'exit',    $t->remarks($new_remarks);
   restart => 'reboot',  
 );  =head2 B<sulog> - The output from the sulog command
   
 my %ACCESS = map { $_ => 1 } qw(  Returns an array ref of hashes containing each log
   firmware_version  line.
   host_type  
   Host  =head2 B<save_sudb> - saves the sudb
   is_connected  
   logged_in  Returns true on success, undef on failure
   login_banner  
   Timeout  =head2 B<syslog> - The output from the sulog command
   last_lines  
   last_vals  Returns a hashref of the output from the syslog command
 );  
   =head2 B<pipe> - the pipe command
 sub AUTOLOAD  
 {  Returns the output from the pipe command
   my $self = shift;  
   =head2 B<maclist> - retrieves the maclist
   my ($method) = (our $AUTOLOAD) =~ /^.*::(\w+)$/  
     or die "Weird: $AUTOLOAD";  Returns the output from the maclist command
   
   if (exists $ALIASES{$method}) {  =head2 B<maclist_reset> - resets the maclist.
     $method = $ALIASES{$method};  
     return $self->$method(@_);  No useful output.
   }  
   =head2 B<eth_link> - eth link command
   if (exists $COMMANDS{$method}) {  
     $method = shift if (@_ == 1);  Returns the output from the eth link command
     $COMMANDS{$method}{'String'} ||= $method;  
     return $self->cmd(%{ $COMMANDS{$method} }, @_);  This command seems to cause some weird issues.  It often will cause the
   }  command after it to appear to fail.  I am not sure why.
   
   if (exists $ACCESS{$method}) {  =head2 B<su_info> - gets the su info
     my $prev = $PRIVATE{$method};  
     ($PRIVATE{$method}) = @_ if @_;  Returns information about the SU.
     return $prev;  
   }  You need to pass in the $suid and it will return the info for that suid.
   
   $method = "SUPER::$method";    $t->su_info($suid);
   return $self->$method(@_);  
 }  =head2 B<su_testrflink> - tests the RF Link to an su
   
 =pod    $t->su_testrflink($suid|'all');
   
 =item open  =head2 B<save_ss> - saves the config.
   
 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()  Returns 1 on success, undef on failure.
   
 =cut  =head2 B<set_baseid> - sets baseid
   
 sub open      $t->set_baseid($baseid);
 {  
   my $self = shift;  =head2 B<set_suid> - sets baseid
   
   unless ( $self->SUPER::open(@_) ) {      $t->set_suid($baseid);
     #$! = "Couldn't connect to " . $self->Host . ":  $!";  
     return undef;  =head2 B<set_defaultopmode> - sets default opmode
   }  
       $t->set_defaultopmode(ap|su);
   ## Get to login prompt  
   unless ($self->waitfor(  =head2 B<opmode> - sets or returns the opmode
       -match => '/password: ?$/i',  
       -errmode => "return",      $t->opmode([ap y|su y]);
     ) ) {  
     #$! = "problem connecting to host (" . $self->Host . "): " .  =head2 B<freq> - sets or returns the freq
     #    $self->lastline;  
     return undef;      $channel = '11 v';
   }      $t->freq([$channel]);
   
   $self->parse_login_banner($self->lastline);  =head2 B<freq_writescan> - sets the freq writescan
   
   $self->is_connected(1);      $channels = '11 v 11 h 12 v 12 h';
       $t->freq_writescan($channels);
   return $self->is_connected;  
 }  =head2 B<freq_scantable> - returns the freq scantable
   
 =pod      $channels = $t->freq_scantable();
       # now $channels eq '11 v 11 h 12 v 12 h';
 =item login  
   
 Calls open() if not already connected, then sends the password and sets logged_in() if successful  =cut
   
 =cut  my $success  = 'Success\\.';
   my %COMMANDS = (
 sub login      _clear      => { String    => "\n" },
 {      tftpd       => { decode    => 'all', expect => $success },
   my $self = shift;      ver         => { decode    => 'all' },
       sysinfo     => { decode    => 'all', expect => $success },
   unless ($self->is_connected) {      updateflash => { decode    => 'all', expect => $success },
     $self->open or return undef;      sulog       => { decode    => 'sulog', expect => $success },
   }      'exit'      => { no_prompt => 1, cmd_disconnects => 1 },
       reboot      => { no_prompt => 1, cmd_disconnects => 1 },
   my $password = shift;      'reset'   => {},
       remarks   => { decode => 'all', expect => $success },
   $self->print($password);      save_sudb => { String => 'save sudb', expect => $success },
   unless ($self->waitfor(      syslog  => { expect => $success },
     -match => $self->prompt,      'pipe'  => {},      # XXX needs a special decode
     -errmode => "return",      maclist => { decode => 'maclist' },
   ) ) {      maclist_reset => { String => 'maclist reset', expect => 'done' },
     #$! = "login ($self->Host) failed: " . $self->lastline;      eth_link      => { String => 'eth link',      expect => $success },
     return undef;      su_info => { String => 'su info', decode => 'all', expect => $success },
   }      su_testrflink =>
           { String => 'su testrflink', decode => 'each', expect => $success },
   $self->logged_in(1);      save_ss    => { String => 'save ss', expect => $success },
       set_baseid => {
   return $self->logged_in;          String => 'set baseid',
 }          decode => 'all',
           expect => $success
 =pod      },
       set_suid => {
 =item parse_login_banner          String => 'set suid',
           decode => 'all',
 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()          expect => $success
       },
 =cut      set_defaultopmode => {
           String => 'set defaultopmode',
 sub parse_login_banner          decode => 'all',
 {          expect => $success
   my $self = shift;      },
       opmode => { decode => 'all',  expect => $success },
   if (@_) {      freq   => { decode => 'freq', expect => $success },
     $self->login_banner(@_);      freq_writescan =>
   }          { String => 'freq writescan', decode => 'all', expect => $success },
       freq_scantable =>
   my $banner = $self->login_banner;          { String => 'freq scantable', decode => 'all', expect => $success },
       arq => { decode => 'all' },
   my ($type, $ver) = $banner =~  );
     /Welcome to Trango Broadband Wireless (\S+)[\s-]+(.+)$/i;  
   my %ALIASES = (
   $self->login_banner($banner);      bye               => 'exit',
   $self->host_type($type);      restart           => 'reboot',
   $self->firmware_version($ver);      Host              => 'host',
       save_systemseting => 'save_ss',
   return 1;  );
 }  
   my %ACCESS = map { $_ => 1 } qw(
 =pod      firmware_version
       host_type
 =item su_password      is_connected
       logged_in
 C<su_password('all'|suid, 'new_password')>      login_banner
       Timeout
 =cut      last_lines
       last_vals
 sub su_password      last_error
 {      Decode
   my $self     = shift;  );
   my $su       = shift || '!';  
   my $new_pass = shift || '';  sub AUTOLOAD {
       my $self = shift;
   unless (defined $su) {  
     warn "No su passed!"      my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/
     #return undef;          or die "Weird: $AUTOLOAD";
   }  
       if ( exists $ALIASES{$method} ) {
   unless (defined $new_pass) {          $method = $ALIASES{$method};
     warn "No new password!"            return $self->$method(@_);
     #return undef;      }
   }  
       if ( exists $COMMANDS{$method} ) {
   return $self->cmd(String => 'su password ' .          my %cmd;
                      $su . ' ' .          foreach my $k ( keys %{ $COMMANDS{$method} } ) {
                      $new_pass . ' ' .              $cmd{$k} = $COMMANDS{$method}{$k};
                      $new_pass,          }
                      expect => $success,          $cmd{'String'} ||= $method;
                     );          $cmd{'args'} .= $SPACE . shift if ( @_ == 1 );
 }          return $self->cmd( %cmd, @_ );
       }
   
 =pod      if ( exists $ACCESS{$method} ) {
           my $s    = *$self->{net_telnet_trango};
 =item sudb_view          my $prev = $s->{$method};
           ( $s->{$method} ) = @_ if @_;
 returns a reference to an array of hashes each containing:          return $prev;
       }
   suid  
   type      $method = "SUPER::$method";
   cir      return $self->$method(@_);
   mir  }
   mac  
   =pod
 =cut  
   =head2 B<open> - Open a connection to a Trango AP.
 sub sudb_view  
 {  Calls Net::Telnet::open() then makes sure you get a password prompt so
   my $self = shift;  you are ready to login() and parses the login banner so you can get
   host_type() and firmware_version()
   my @lines = $self->cmd( String => 'sudb view', expect => $success );  
   =cut
   return undef unless @lines;  
   sub open {
   my @sus;      my $self = shift;
   foreach (@lines) {  
     if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) {      unless ( $self->SUPER::open(@_) ) {
       my %s = (          $self->last_error( "Couldn't connect to " . $self->host . ":  $!" );
         suid => $1,          return;
         type => $2,      }
         cir  => $3,  
         mir  => $4,      ## Get to login prompt
         mac  => $5,      unless (
       );          $self->waitfor(
               -match   => '/password: ?$/i',
           $s{'mac'} =~ s/\s//g;              -errmode => "return",
           $s{'mac'} = uc($s{'mac'});          )
           )
       push @sus, \%s;      {
     }          $self->last_error( "problem connecting to host ("
   }                  . $self->host . "): "
                   . $self->lastline );
   return \@sus;          return;
 }      }
   
 =pod      $self->parse_login_banner( $self->lastline );
   
 =item sudb_add      $self->is_connected(1);
   
 Takes the following paramaters      return $self->is_connected;
   }
         suid : numeric,  
         type : (reg|pr)  =pod
         cir  : numeric,  
         mir  : numeric,  =head2 B<login> - Login to the AP.
         mac  : Almost any format, it will be reformatted,  
   Calls open() if not already connected, then sends the password and sets
 and returns true on success or undef otherwise.  logged_in() if successful
   
 You should save_sudb() after calling this, or your changes  will be lost  =cut
 when the AP is rebooted.  
   sub login {
 =cut      my $self = shift;
   
 sub sudb_add      unless ( $self->is_connected ) {
 {          $self->open or return;
         my $self = shift;      }
         my $suid = shift;  
         my $type = shift;      my $password = shift;
         my $cir  = shift;  
         my $mir  = shift;      $self->print($password);
         my $mac  = shift;      unless (
           $self->waitfor(
         if ($suid =~ /\D/) {              -match   => $self->prompt,
                 return undef;              -errmode => "return",
         }          )
           )
         unless (lc($type) eq 'reg' || lc($type) eq 'pr') {      {
                 warn "Invalid type '$type'!";          $self->last_error( "login ($self->host) failed: " . $self->lastline );
                 return undef;          return;
         }      }
   
         if ($cir =~ /\D/) {      $self->logged_in(1);
                 warn "Invalid CIR '$cir'!";  
                 return undef;      return $self->logged_in;
         }  }
   
         if ($mir =~ /\D/) {  =pod
                 warn "Invalid MIR '$mir'!";  
                 return undef;  =head2 B<parse_login_banner> - Converts the login_banner to something useful.
         }  
   Takes a login banner (what you get when you first connect to the Trango)
         my $new_mac = $mac;  or reads what is already in login_banner() then parses it and sets
         $new_mac =~ s/[^0-9A-Fa-f]//;  host_type() and firmware_version() as well as login_banner()
         unless (length $new_mac == 12) {  
                 warn "Invalid MAC '$mac'!";  =cut
                 return undef;  
         }  sub parse_login_banner {
         $new_mac = join ' ', $new_mac =~ /../g;      my $self = shift;
   
         my $string = 'sudb add ' .      if (@_) {
                 $suid . ' ' .          $self->login_banner(@_);
                 $type . ' ' .      }
                 $cir  . ' ' .  
                 $mir  . ' ' .      my $banner = $self->login_banner;
                 $new_mac;  
       my ( $type, $sep1, $subtype, $sep2, $ver )
           = $banner
         return $self->cmd( String => $string, expect => $success );          =~ /Welcome to Trango Broadband Wireless,? (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i;
 }  
       $type .= $sep1 . $subtype;
 =pod      $ver = $subtype . $sep2 . $ver;
   
 =item sudb_delete      $self->login_banner($banner);
       $self->host_type($type);
 Takes either 'all' or the  suid of the su to delete      $self->firmware_version($ver);
 and returns true on success or undef otherwise.  
       return 1;
 You should save_sudb() after calling this, or your changes  will be lost  }
 when the AP is rebooted.  
   =pod
 =cut  
   =head2 B<linktest> - Link test to SU
 sub sudb_delete  
 {  linktest('suid'[, 'pkt len, bytes'[, '# of pkts'[, '# of cycles']]]);
         my $self = shift;  
         my $suid = shift;  Returns a hash reference to the results of the test
   
         if (lc($suid) ne 'all' || $suid =~ /\D/) {  =cut
                 return undef;  
         }  sub linktest {
       my $self = shift;
         return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );      my $suid = shift;
 }  
       # These numbers are what I found as defaults when running the command
       my $pkt_len = shift || 1600;
 =pod      my $pkt_cnt = shift || 500;
       my $cycles  = shift || 10;
 =item sudb_modify  
       my %config = @_;
 Takes either the  suid of the su to delete  
 as well as what you are changing, either "cir, mir or su2su"      # * 2, one for the FromAP, one FromSU.  Then / 1000 to get to ms.
 and returns true on success or undef otherwise.      # XXX This might need to be changed, this makes the default timeout the
       # same as $pkt_len, and that might not be enough at slower speeds.
 cir and mir also take a value to set the cir/mir to.      $config{Timeout} ||= int( ( $pkt_len * $pkt_cnt * $cycles * 2 ) / 1000 );
   
 su2su takes a group id parameter that is in hex.      my $string = join $SPACE, 'linktest', $suid, $pkt_len, $pkt_cnt, $cycles;
       return $self->cmd(
 You should save_sudb() after calling this, or your changes  will be lost          %config,
 when the AP is rebooted.          String => $string,
           decode => 'linktest',
 =cut      );
   
 sub sudb_modify  }
 {  
         my $self  = shift;  =pod
         my $suid  = shift;  
         my $opt   = shift;  =head2 B<su_password> - Set the password on SUs connected to the AP.
         my $value = shift;  
   su_password('new_password'[, 'suid']) If no suid is specified,
         if ($suid =~ /\D/) {  the default is "all".
                 return undef;  
         }    $t->su_password('good_pass', 5);
   
         if (lc($opt) eq 'cir' or lc($opt) eq 'mir') {  =cut
                 if ($value =~ /\D/) {  
                         return undef;  sub su_password {
                 }      my $self     = shift;
         } elsif (lc($opt) eq 'su2su') {      my $new_pass = shift || $EMPTY;
                 if ($value =~ /[^0-9A-Za-f]/) {      my $su       = shift || 'all';
                         return undef;  
                 }      unless ( defined $new_pass ) {
         } else {          $self->last_error("No new password");
                 return undef;  
         }          #return;
       }
         my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value;  
       return $self->cmd(
         return $self->cmd( String => $string, expect => $success );          String => 'su password '
 }              . $su
               . $SPACE
 =pod              . $new_pass
               . $SPACE
 =item enable_tftpd              . $new_pass,
           expect => $success,
 runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing      );
   }
 =cut  
   =pod
 sub enable_tftpd  
 {  =head2 B<ipconfig> - Change IP configuration
   my $self = shift;  
   ipconfig( 'new_ip', 'new_subnet', 'new_gateway' )
   my $vals = $self->tftpd( args => 'on' );  
     $t->ipconfig( '10.0.1.5', '255.255.255.0', '10.0.1.1' );
   if ($vals->{'Tftpd'} eq 'listen') {  
     return $vals;  =cut
   } else {  
     return undef;  sub ipconfig {
   }      my $self = shift;
 }  
       my $string = join $SPACE, 'ipconfig', @_;
 =pod  
       if ( @_ == 3 ) {
 =item disable_tftpd          $self->print($string);
           my @lines = $self->waitfor( Match => '/save\s+and\s+activate/', );
 runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'          $self->print('y');
   
 =cut          $self->logged_in(0);
           $self->is_connected(0);
 sub disable_tftpd  
 {          foreach my $line (@lines) {
   my $self = shift;              if ( $line =~ s/New \s configuration:\s+//xms ) {
                   return _decode_lines($line);
   my $vals = $self->tftpd( args => 'off' );              }
           }
   if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled') {  
     return $vals;          return {};
   } else {      }
     return undef;  
   }      # ipconfig [ <new ip> <new subnet> <new gateway> ]
 }      return $self->cmd( String => $string, expect => $success );
   }
 =pod  
   =pod
 =item cmd  
   =head2 B<su_ipconfig> - Change IP configuration on SUs connected to the AP.
 This does most of the work.  At the heart, it calls Net::Telnet::cmd() but it also does some special stuff for Trango.  
   su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )
 Normally returns the last lines from from the command  
     $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );
 Also accepts these options:  
   =cut
 I<decode>  
 - if this is true, then it will send the output lines to _decode_lines() and then returns the decoded output  sub su_ipconfig {
       my $self = shift;
 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      my $suid        = shift;
       my $new_ip      = shift;
 I<expect>      my $new_subnet  = shift;
 - if this is set (usually to 'Success.') it will check for that in the last line of output and if it does not, will return undef because the command probably failed      my $new_gateway = shift;
   
 I<args>      if ( $suid =~ /\D/ ) {
 - a string containing the command line options that are passed to the command          $self->last_error("Invalid suid '$suid'");
           return;
 =cut      }
       unless ($new_ip) {
 sub cmd          $self->last_error("no new_ip passed");
 {          return;
   my $self = shift;      }
       unless ($new_subnet) {
   my @valid_net_telnet_opts = qw(          $self->last_error("no new_subnet passed");
     String          return;
     Output      }
     Cmd_remove_mode      unless ($new_gateway) {
     Errmode          $self->last_error("no new_gateway passed");
     Input_record_separator          return;
     Ors      }
     Output_record_separator  
     Prompt      # su ipconfig <suid> <new ip> <new subnet> <new gateway>
     Rs      return $self->cmd(
     Timeout          String => 'su ipconfig '
   );              . $suid
               . $SPACE
   my %cfg;              . $new_ip
   if (@_ == 2) {              . $SPACE
     $cfg{'String'} = shift;              . $new_subnet
   } elsif (@_ > 2) {              . $SPACE
     %cfg = @_;              . $new_gateway,
   }          expect => $success,
       );
   $cfg{'Timeout'} ||= $self->Timeout;  }
   
   unless ($cfg{'String'}) {  =pod
     #$! = "No command passed";  
     #warn "No command passed\n";  =head2 B<sudb_view> - Returns the output from the sudb view command
     return undef;  
   }  returns a reference to an array of hashes each containing these keys
   'suid', 'su2su', 'type', 'cir', 'mir' and 'mac'
   unless ($self->is_connected) {  
     #$! = "Not connected";  =cut
     #warn "Not connected\n";  
     return undef;  sub sudb_view {
   }      my $self = shift;
   
   unless ($self->logged_in) {      my $lines = $self->cmd( String => 'sudb view', expect => $success ) || [];
     #$! = "Not logged in";  
     #warn "Not logged in\n";      return unless @{$lines};
     return undef;  
   }      my $s = *$self->{net_telnet_trango};
       return $lines if !$s->{'Decode'};
   
   my %cmd;      my @sus;
   foreach (@valid_net_telnet_opts) {      foreach ( @{$lines} ) {
     if (exists $cfg{$_}) {          next unless $_;
       $cmd{$_} = $cfg{$_};          if (/^
     }              \[(\d+)\]
   }              \s+
   if ($cfg{'args'}) {              [[:xdigit:]]{2}
     $cmd{'String'} .= ' ' . $cfg{'args'};              ([[:xdigit:]])
   }              ([[:xdigit:]])
   my @lines;              \s+
   unless ($cfg{'no_prompt'}) {              (\d+)
     @lines = $self->SUPER::cmd(%cmd);              \s+
   } else {              (\d+)
     $self->print($cmd{'String'});              \s+
     @lines = $self->lastline;              ([[:xdigit:]\s]+)
   }          $/ixms
               )
   $self->last_lines(\@lines);          {
               my %s = (
   my $vals = 1;                  suid  => $1,
   if ($cfg{'decode'}) {                  su2su => $2 ? $2 : undef,
     if ($cfg{'decode'} eq 'each') {                  type  => $3 == 1 ? 'reg' : $3 == 5 ? 'pri' : $3,
       $vals = _decode_each_line(@lines);                  cir   => $4,
     } elsif ($cfg{'decode'} eq 'sulog') {                  mir   => $5,
       $vals = _decode_sulog(@lines);                  mac   => $6,
     } else {              );
       $vals = _decode_lines(@lines);  
     }              $s{'mac'} =~ s/\s//gxms;
   }              $s{'mac'} = uc( $s{'mac'} );
   
   $self->last_vals($vals);              push @sus, \%s;
           }
       }
   my $last = $self->lastline;  
       return \@sus;
   if ((not $cfg{'expect'}) || $last =~ /$cfg{'expect'}$/) {  }
     if ($cfg{'cmd_disconnects'}) {  
       $self->logged_in(0);  =pod
       $self->close;  
       $self->is_connected(0);  =head2 B<sudb_add> - Adds an su to the sudb
     }  
   Takes the following paramaters
     if ($cfg{'decode'}) {  
       return $vals;      suid : numeric,
     } else {      type : (reg|pr)
       return @lines;      cir  : numeric,
     }      mir  : numeric,
   } else {      mac  : Almost any format, it will be reformatted,
     #$! = "Error with command ($cfg{'string'}): $last";  
     return undef;  and returns true on success or undef otherwise.
   }  
 }    $t->sudb_add($suid, 'reg', $cir, $mir, $mac);
   
 #=item _decode_lines  You should save_sudb() after calling this, or your changes  will be lost
   when the AP is rebooted.
 sub _decode_lines  
 {  =cut
   my @lines = @_;  
   sub sudb_add {
   my %conf;      my $self = shift;
       my $suid = shift;
   my $key = '';      my $type = shift;
   my $val = '';      my $cir  = shift;
   my $in_key = 0;      my $mir  = shift;
   my $in_val = 0;      my $mac  = shift;
   
   foreach my $line (@lines) {      if ( $suid =~ /\D/ ) {
     next if $line =~ /$success$/;          $self->last_error("Invalid suid '$suid'");
           return;
     my @chars = split //, $line;      }
   
     my $last_key = '';      unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) {
     foreach my $c (@chars) {          $self->last_error("Invalid type '$type'");
           return;
       if ($c eq '[' || $c eq "\r" || $c eq "\n") {      }
         if ($c eq '[') {  
           $in_key = 1;      if ( $cir =~ /\D/ ) {
           $in_val = 0;          $self->last_error("Invalid CIR '$cir'");
         } else {          return;
           $in_key = 0;      }
           $in_val = 0;  
         }      if ( $mir =~ /\D/ ) {
           $self->last_error("Invalid MIR '$mir'");
         if ($key) {          return;
           $key =~ s/^\s+//;      }
           $key =~ s/\s+$//;  
       my $new_mac = $mac;
           $val =~ s/^\s+//;      $new_mac =~ s/[^0-9A-Fa-f]//g;
           $val =~ s/\s+$//;      unless ( length $new_mac == 12 ) {
           $self->last_error("Invalid MAC '$mac'");
           if ($key eq 'Checksum' && $last_key) {          return;
             # Special case for these bastids.      }
             my $new = $last_key;      $new_mac = join $SPACE, $new_mac =~ /../g;
             $new =~ s/\s+\S+$//;  
             $key = $new . " " . $key;      my $string
           }          = 'sudb add '
           . $suid
           $last_key = $key;          . $SPACE
           $conf{$key} = $val;          . $type
           $key = '';          . $SPACE
           $val = '';          . $cir
         }          . $SPACE
           . $mir
       } elsif ($c eq ']') {          . $SPACE
         $in_val = 1;          . $new_mac;
         $in_key = 0;  
         $c = shift @chars;      return $self->cmd( String => $string, expect => $success );
   }
       } elsif ($in_key) {  
         $key .= $c;  =pod
   
       } elsif ($in_val) {  =head2 B<sudb_delete> - removes an su from the sudb
         $val .= $c;  
       }  Takes either 'all' or the  suid of the su to delete
     }  and returns true on success or undef otherwise.
   }  
     $t->sudb_delete($suid);
   if (%conf) {  
     return \%conf;  You should save_sudb() after calling this, or your changes  will be lost
   } else {  when the AP is rebooted.
     return undef;  
   }  =cut
 }  
   sub sudb_delete {
 #=item _decode_each_line      my $self = shift;
       my $suid = shift;
 sub _decode_each_line  
 {      #if (lc($suid) ne 'all' || $suid =~ /\D/) {
   my @lines = @_;      if ( $suid =~ /\D/ ) {
   my @decoded;          $self->last_error("Invalid suid '$suid'");
   foreach my $line (@lines) {          return;
     my $decoded = _decode_lines($line);      }
     push @decoded, $decoded if defined $decoded;  
   }      return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );
   return \@decoded;  }
 }  
   =pod
 #=item _decode_sulog  
   =head2 B<sudb_modify> - changes the su information in the sudb
 sub _decode_sulog  
 {  Takes either the  suid of the su to change
   my @lines = @_;  as well as what you are changing, either "cir, mir or su2su"
   my @decoded;  and returns true on success or undef otherwise.
   my $last_tm;  
   foreach my $line (@lines) {  cir and mir also take a value to set the cir/mir to.
     my $decoded = _decode_lines($line);  
   su2su takes a group id parameter that is in hex.
     if (defined $decoded) {  
       if ($decoded->{'tm'}) {    $t->sudb_modify($suid, 'cir', 512);
         $last_tm = $decoded->{'tm'};  
         next;  You should save_sudb() after calling this, or your changes  will be lost
       } else {  when the AP is rebooted.
         $decoded->{'tm'} = $last_tm;  
       }  =cut
       next unless $last_tm;  
   sub sudb_modify {
       push @decoded, $decoded if defined $decoded;      my $self  = shift;
     }      my $suid  = shift;
   }      my $opt   = shift;
   return \@decoded;      my $value = shift;
 }  
       if ( $suid =~ /\D/ ) {
 1;          $self->last_error("Invalid suid '$suid'");
 __END__          return;
       }
 =back  
       if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {
 =head1 SEE ALSO          if ( $value =~ /\D/ ) {
               $self->last_error("Invalid $opt '$value'");
 Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm              return;
           }
 L<Net::Telnet>      }
       elsif ( lc($opt) eq 'su2su' ) {
 =head1 TODO          if ( $value =~ /[^0-9A-Za-f]/ ) {
               $self->last_error("Invalid MAC '$value'");
 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.              return;
           }
 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.      }
       else {
 =head1 AUTHOR          $self->last_error("Invalid option '$opt'");
           return;
 Andrew Fresh E<lt>andrew@rraz.netE<gt>      }
   
 =head1 COPYRIGHT AND LICENSE      my $string = 'sudb modify ' . $suid . $SPACE . $opt . $SPACE . $value;
   
 Copyright (C) 2005 by Andrew Fresh      return $self->cmd( String => $string, expect => $success );
   }
 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,  =pod
 at your option, any later version of Perl 5 you may have available.  
   =head2 B<enable_tftpd> - enable the TFTP server
   
 =cut  runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing
   
   =cut
   
   sub enable_tftpd {
       my $self = shift;
   
       my $vals = $self->tftpd( args => 'on' );
   
       if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) {
           return $vals;
       }
       else {
           return;
       }
   }
   
   =pod
   
   =head2 B<disable_tftpd> - disable the TFTP server
   
   runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'
   
   =cut
   
   sub disable_tftpd {
       my $self = shift;
   
       my $vals = $self->tftpd( args => 'off' );
   
       if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) {
           return $vals;
       }
       else {
           return;
       }
   }
   
   =pod
   
   =head2 B<cmd> - runs a command on the AP.
   
   This does most of the work.  At the heart, it calls Net::Telnet::cmd()
   but it also does some special stuff for Trango.
   
   Normally returns the last lines from from the command
   
   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.
   
   In addition to the Net::Telnet::cmd() options, it also accepts these:
   
   I<decode>
   - if this is true, then it will send the output lines to _decode_lines()
   and then returns the decoded output
   
   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.
   
   I<cmd_disconnects>
   - if this is true, it then sets logged_in() to false, then it will
   close() the connection and set is_connected() to false
   
   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
   
   I<args>
   - a string containing the command line options that are passed to the
   command
   
       $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );
   
   =cut
   
   sub cmd {
       my $self = shift;
       my $s    = *$self->{net_telnet_trango};
   
       my @valid_net_telnet_opts = qw(
           String
           Output
           Cmd_remove_mode
           Errmode
           Input_record_separator
           Ors
           Output_record_separator
           Prompt
           Rs
           Timeout
       );
   
       my %cfg;
       if ( @_ == 1 ) {
           $cfg{'String'} = shift;
       }
       elsif ( @_ > 1 ) {
           %cfg = @_;
       }
   
       $cfg{'Timeout'} ||= $self->Timeout;
   
       unless ( $cfg{'String'} ) {
           $self->last_error("No command passed");
           return;
       }
   
       unless ( $self->is_connected ) {
           $self->last_error("Not connected");
           return;
       }
   
       unless ( $self->logged_in ) {
           $self->last_error("Not logged in");
           return;
       }
   
       my %cmd;
       foreach (@valid_net_telnet_opts) {
           if ( exists $cfg{$_} ) {
               $cmd{$_} = $cfg{$_};
           }
       }
       if ( $cfg{'args'} ) {
           $cmd{'String'} .= $SPACE . $cfg{'args'};
       }
   
       #print "Running cmd $cmd{String}\n";
       my @lines;
       if ( $cfg{'no_prompt'} ) {
           $self->print( $cmd{'String'} );
           @lines = $self->lastline;
       }
       else {
           @lines = $self->SUPER::cmd(%cmd);
       }
   
       $self->last_lines( \@lines );
   
       my $last   = $self->lastline;
       my $prompt = $self->prompt;
       $prompt =~ s{^/}{}xms;
       $prompt =~ s{/[gixms]*$}{}xms;
       while ( @lines && $last =~ qr($prompt) ) {
           pop @lines;
           $last = $lines[-1];
       }
       $self->last_error($EMPTY);
   
       my $vals = 1;
       if ( $s->{'Decode'} && $cfg{'decode'} ) {
           if ( $cfg{'decode'} eq 'each' ) {
               $vals = _decode_each_line(@lines);
           }
           elsif ( $cfg{'decode'} eq 'sulog' ) {
               $vals = _decode_sulog(@lines);
           }
           elsif ( $cfg{'decode'} eq 'maclist' ) {
               $vals = _decode_maclist(@lines);
               if ( !$vals ) {
                   $self->last_error("Error decoding maclist");
               }
           }
           elsif ( $cfg{'decode'} eq 'linktest' ) {
               $vals = _decode_linktest(@lines);
               if ( !$vals ) {
                   $self->last_error("Error decoding linktest");
               }
           }
           elsif ( $cfg{'decode'} eq 'freq' ) {
               $vals = _decode_freq(@lines);
           }
           else {
               $vals = _decode_lines(@lines);
           }
       }
       if ( ref $vals eq 'HASH' ) {
           $vals->{_raw} = join q{}, @lines;
       }
       $self->last_vals($vals);
   
       if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) {
           if ( $cfg{'cmd_disconnects'} ) {
               $self->logged_in(0);
               $self->close;
               $self->is_connected(0);
           }
   
           if ( $s->{'Decode'} && $cfg{'decode'} ) {
               return $vals;
           }
           else {
               return \@lines;
           }
       }
       else {
           my $err;
           if ( grep {/\[ERR\]/} @lines ) {
               $err = _decode_lines(@lines);
           }
   
           if ( ref $err eq 'HASH' && $err->{ERR} ) {
               $self->last_error( $err->{ERR} );
           }
           else {
               $self->last_error("Error with command ($cmd{'String'}): $last");
           }
           return;
       }
   }
   
   #=item _decode_lines
   
   sub _decode_lines {
       my @lines = @_;
   
       my %conf;
   
       my $key = $EMPTY;
       my $val = undef;
       my @vals;
       my $in_key = 0;
       my $in_val = 1;
   
   LINE: while ( my $line = shift @lines ) {
           next LINE if $line =~ /$success\Z/;
           next LINE if $line =~ /^ \*+ \s+ \d+ \s+ \*+ \Z/xms;
   
           # Special decode for sysinfo on a TrangoLink 45
           if ( $line =~ /^(.* Channel \s+ Table):\s*(.*)\Z/xms ) {
               my $key  = $1;
               my $note = $2;
   
               my %vals;
               while ( $line = shift @lines ) {
                   if ( $line =~ /^\Z/ ) {
                       $conf{$key} = \%vals;
                       $conf{$key}{note} = $note;
                       next LINE;
                   }
   
                   my $decoded = _decode_lines($line);
                   if ($decoded) {
                       %vals = ( %vals, %{$decoded} );
                   }
               }
           }
   
           # Another special decode for the TrangoLink
           elsif (
               $line =~ /^
               RF \s Band \s \#
               (\d+) \s+
               \( ([^\)]+) \) \s*
               (.*)$
           /xms
               )
           {
               my $num   = $1;
               my $band  = $2;
               my $extra = $3;
   
               if ( $extra =~ /\[/ ) {
                   my $decoded = _decode_lines($extra);
                   $conf{'RF Band'}{$num} = $decoded;
               }
               else {
                   $conf{'RF Band'}{$num}{$extra} = 1;
               }
               next LINE;
           }
   
           my @chars = split //, $line;
   
           my $last_key = $EMPTY;
           foreach my $c (@chars) {
   
               if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {
                   if ( $c eq '[' ) {
                       $in_key = 1;
                       $in_val = 0;
                   }
                   else {
                       $in_key = 0;
                       $in_val = 1;
                   }
   
                   if ($key) {
                       $key =~ s/^\s+//;
                       $key =~ s/\s+$//;
   
                       if ($val) {
                           $val =~ s/^\s+//;
                           $val =~ s/\s+\.*$//;
                       }
   
                       if ( $key eq 'Checksum' && $last_key ) {
   
                           # Special case for these bastids.
                           my $new = $last_key;
                           $new =~ s/\s+\S+$//;
                           $key = $new . $SPACE . $key;
                       }
   
                       $conf{$key} = $val;
                       $last_key   = $key;
                       $key        = $EMPTY;
                   }
                   elsif ($val) {
                       push @vals, $val;
                   }
                   $val = $EMPTY;
   
               }
               elsif ( $c eq ']' ) {
                   $in_val = 1;
                   $in_key = 0;
                   $c      = shift @chars;
   
               }
               elsif ($in_key) {
                   $key .= $c;
   
               }
               elsif ($in_val) {
                   $val .= $c;
               }
           }
       }
   
       unless ($key) {
           push @vals, $val;
       }
   
       foreach my $val (@vals) {
           if ( defined $val && length $val ) {
               $val =~ s/^\s+//;
               $val =~ s/\s+\.*$//;
           }
       }
   
       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 && length $decoded;
       }
       return \@decoded;
   }
   
   #=item _decode_linktest
   
   sub _decode_linktest {
       my @lines = @_;
       my %decoded;
       foreach my $line (@lines) {
   
           if ( $line =~ s/^(\d+) \s+ //xms ) {
               my $line_id = $1;
               my ( $tm, $rt );
               if ( $line =~ s/\s+ (\d+ \s+ \w+) \s* $//xms ) {
                   $rt = $1;
               }
               if ( $line =~ s/\s+ (\d+ \s+ \w+) \s* $//xms ) {
                   $tm = $1;
               }
   
               my $d = _decode_lines( $line . "\n" );
               $decoded{tests}[$line_id]         = $d;
               $decoded{tests}[$line_id]{'time'} = $tm;
               $decoded{tests}[$line_id]{rate}   = $rt;
           }
   
           else {
               my $d = _decode_lines( $line . "\n" );
               if ($d) {
                   while ( my ( $k, $v ) = each %{$d} ) {
                       $decoded{$k} = $v;
                   }
               }
           }
   
       }
       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 {
           return;
       }
   }
   
   #=item _decode_freq
   
   sub _decode_freq {
       my @lines   = @_;
       my $decoded = _decode_lines(@lines);
   
       if ( $decoded && $decoded->{ERR} ) {
           return $decoded;
       }
   
   LINE: foreach my $line (@lines) {
           if (my ( $channel, $polarity, $freq )
               = $line =~ /
               Ch \s+ \#(\d+)
               \s+
               (\w+)
               \s+
               \[ (\d+) \s+ MHz\]
           /ixms
               )
           {
               $decoded = {
                   channel   => $channel,
                   polarity  => $polarity,
                   frequency => $freq,
               };
               last LINE;
           }
       }
       return $decoded;
   }
   
   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.8  
changed lines
  Added in v.1.59

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