[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.7 and 1.60

version 1.7, 2006/06/28 23:33:18 version 1.60, 2009/07/31 22:46:07
Line 1 
Line 1 
 package Net::Telnet::Trango;  package Net::Telnet::Trango;
 # $RedRiver: Trango.pm,v 1.6 2006/06/28 22:00:15 andrew Exp $  
 use strict;  # $RedRiver: Trango.pm,v 1.59 2009/07/31 21:44:33 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.
   
 =cut  =head2 B<sysinfo> - The output from the sysinfo command
   
   Returns a hash ref of the decoded output from the
 my $success = 'Success.';  command.
 my %COMMANDS = (  
   tftpd       => { decode => 'all',   expect => $success },  =head2 B<exit> - Exits the connection
   ver         => { decode => 'all' },  
   sysinfo     => { decode => 'all',   expect => $success },  exits the command session with the Trango and closes
   updateflash => { decode => 'all',   expect => $success },  the connection
   sulog       => { decode => 'sulog', expect => $success },  
   'exit'      => { no_prompt => 1, cmd_disconnects => 1 },  =head2 B<reboot> - Sends a reboot command
   reboot      => { no_prompt => 1, cmd_disconnects => 1 },  
   sudb_save   => { String => "sudb save", expect => $success },  reboots the Trango and closes the connection
   #su password???  
   #_bootloader  =head2 B<reset> <all|0..2> - Sends a reset command
   #temp  
   #heater  resets settings to default
 );  
   =head2 B<remarks> - Set or retrieve the remarks.
 my %ALIASES = (  
   bye     => 'exit',  Takes an optional argument, which sets the remarks.
   restart => 'reboot',  If there is no argument, returns the current remarks.
 );  
     my $old_remarks = $t->remarks();
 my %ACCESS = map { $_ => 1 } qw(    $t->remarks($new_remarks);
   firmware_version  
   host_type  =head2 B<sulog> - The output from the sulog command
   Host  
   is_connected  Returns an array ref of hashes containing each log
   logged_in  line.
   login_banner  
   Timeout  =head2 B<save_sudb> - saves the sudb
   last_lines  
   last_vals  Returns true on success, undef on failure
 );  
   =head2 B<syslog> - The output from the sulog command
 sub AUTOLOAD  
 {  Returns a hashref of the output from the syslog command
   my $self = shift;  
   =head2 B<pipe> - the pipe command
   my ($method) = (our $AUTOLOAD) =~ /^.*::(\w+)$/  
     or die "Weird: $AUTOLOAD";  Returns the output from the pipe command
   
   if (exists $ALIASES{$method}) {  =head2 B<maclist> - retrieves the maclist
     $method = $ALIASES{$method};  
     return $self->$method(@_);  Returns the output from the maclist command
   }  
   =head2 B<maclist_reset> - resets the maclist.
   if (exists $COMMANDS{$method}) {  
     $method = shift if (@_ == 1);  No useful output.
     $COMMANDS{$method}{'String'} ||= $method;  
     return $self->cmd(%{ $COMMANDS{$method} }, @_);  =head2 B<eth_link> - eth link command
   }  
   Returns the output from the eth link command
   if (exists $ACCESS{$method}) {  
     my $prev = $PRIVATE{$method};  This command seems to cause some weird issues.  It often will cause the
     ($PRIVATE{$method}) = @_ if @_;  command after it to appear to fail.  I am not sure why.
     return $prev;  
   }  =head2 B<su_info> - gets the su info
   
   $method = "SUPER::$method";  Returns information about the SU.
   return $self->$method(@_);  
 }  You need to pass in the $suid and it will return the info for that suid.
   
 =pod    $t->su_info($suid);
   
 =item open  =head2 B<su_testrflink> - tests the RF Link to an su
   
 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()    $t->su_testrflink($suid|'all');
   
 =cut  =head2 B<save_ss> - saves the config.
   
 sub open  Returns 1 on success, undef on failure.
 {  
   my $self = shift;  =head2 B<set_baseid> - sets baseid
   
   unless ( $self->SUPER::open(@_) ) {      $t->set_baseid($baseid);
     #$! = "Couldn't connect to " . $self->Host . ":  $!";  
     return undef;  =head2 B<set_suid> - sets baseid
   }  
       $t->set_suid($baseid);
   ## Get to login prompt  
   unless ($self->waitfor(  =head2 B<set_defaultopmode> - sets default opmode
       -match => '/password: ?$/i',  
       -errmode => "return",      $t->set_defaultopmode(ap|su);
     ) ) {  
     #$! = "problem connecting to host (" . $self->Host . "): " .  =head2 B<opmode> - sets or returns the opmode
     #    $self->lastline;  
     return undef;      $t->opmode([ap y|su y]);
   }  
   =head2 B<freq> - sets or returns the freq
   $self->parse_login_banner($self->lastline);  
       $channel = '11 v';
   $self->is_connected(1);      $t->freq([$channel]);
   
   return $self->is_connected;  =head2 B<freq_writescan> - sets the freq writescan
 }  
       $channels = '11 v 11 h 12 v 12 h';
 =pod      $t->freq_writescan($channels);
   
 =item login  =head2 B<freq_scantable> - returns the freq scantable
   
 Calls open() if not already connected, then sends the password and sets logged_in() if successful      $channels = $t->freq_scantable();
       # now $channels eq '11 v 11 h 12 v 12 h';
 =cut  
   
 sub login  =cut
 {  
   my $self = shift;  my $success  = 'Success\\.';
   my %COMMANDS = (
   unless ($self->is_connected) {      _clear      => { String    => "\n" },
     $self->open or return undef;      tftpd       => { decode    => 'all', expect => $success },
   }      ver         => { decode    => 'all' },
       sysinfo     => { decode    => 'all', expect => $success },
   my $password = shift;      updateflash => { decode    => 'all', expect => $success },
       sulog       => { decode    => 'sulog', expect => $success },
   $self->print($password);      'exit'      => { no_prompt => 1, cmd_disconnects => 1 },
   unless ($self->waitfor(      reboot      => { no_prompt => 1, cmd_disconnects => 1 },
     -match => $self->prompt,      'reset'   => {},
     -errmode => "return",      remarks   => { decode => 'all', expect => $success },
   ) ) {      save_sudb => { String => 'save sudb', expect => $success },
     #$! = "login ($self->Host) failed: " . $self->lastline;      syslog  => { expect => $success },
     return undef;      'pipe'  => {},      # XXX needs a special decode
   }      maclist => { decode => 'maclist' },
       maclist_reset => { String => 'maclist reset', expect => 'done' },
   $self->logged_in(1);      eth_link      => { String => 'eth link',      expect => $success },
       su_info => { String => 'su info', decode => 'all', expect => $success },
   return $self->logged_in;      su_testrflink =>
 }          { String => 'su testrflink', decode => 'each', expect => $success },
       save_ss    => { String => 'save ss', expect => $success },
 =pod      set_baseid => {
           String => 'set baseid',
 =item parse_login_banner          decode => 'all',
           expect => $success
 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()      },
       set_suid => {
 =cut          String => 'set suid',
           decode => 'all',
 sub parse_login_banner          expect => $success
 {      },
   my $self = shift;      set_defaultopmode => {
           String => 'set defaultopmode',
   if (@_) {          decode => 'all',
     $self->login_banner(@_);          expect => $success
   }      },
       opmode => { decode => 'all',  expect => $success },
   my $banner = $self->login_banner;      freq   => { decode => 'freq', expect => $success },
       freq_writescan =>
   my ($type, $ver) = $banner =~          { String => 'freq writescan', decode => 'all', expect => $success },
     /Welcome to Trango Broadband Wireless (\S+)[\s-]+(.+)$/i;      freq_scantable =>
           { String => 'freq scantable', decode => 'all', expect => $success },
   $self->login_banner($banner);      arq => { decode => 'all' },
   $self->host_type($type);  );
   $self->firmware_version($ver);  
   my %ALIASES = (
   return 1;      bye               => 'exit',
 }      restart           => 'reboot',
       Host              => 'host',
 =pod      save_systemseting => 'save_ss',
   );
 =item su_password  
   my %ACCESS = map { $_ => 1 } qw(
 C<su_password('all'|suid, 'new_password')>      firmware_version
       host_type
 =cut      is_connected
       logged_in
 sub su_password      login_banner
 {      Timeout
   my $self     = shift;      last_lines
   my $su       = shift || '!';      last_vals
   my $new_pass = shift || '';      last_error
       Decode
   unless (defined $su) {  );
     warn "No su passed!"  
     #return undef;  sub AUTOLOAD {
   }      my $self = shift;
   
   unless (defined $new_pass) {      my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/
     warn "No new password!"            or die "Weird: $AUTOLOAD";
     #return undef;  
   }      if ( exists $ALIASES{$method} ) {
           $method = $ALIASES{$method};
   return $self->cmd(String => 'su password ' .          return $self->$method(@_);
                      $su . ' ' .      }
                      $new_pass . ' ' .  
                      $new_pass,      if ( exists $COMMANDS{$method} ) {
                      expect => $success,          my %cmd;
                     );          foreach my $k ( keys %{ $COMMANDS{$method} } ) {
 }              $cmd{$k} = $COMMANDS{$method}{$k};
           }
           $cmd{'String'} ||= $method;
 =pod          $cmd{'args'} .= $SPACE . shift if ( @_ == 1 );
           return $self->cmd( %cmd, @_ );
 =item sudb_view      }
   
 returns a reference to an array of hashes each containing:      if ( exists $ACCESS{$method} ) {
           my $s    = *$self->{net_telnet_trango};
   suid          my $prev = $s->{$method};
   type          ( $s->{$method} ) = @_ if @_;
   cir          return $prev;
   mir      }
   mac  
       $method = "SUPER::$method";
 =cut      return $self->$method(@_);
   }
 sub sudb_view  
 {  =pod
   my $self = shift;  
   =head2 B<open> - Open a connection to a Trango AP.
   my @lines = $self->cmd( String => 'sudb view', expect => $success );  
   Calls Net::Telnet::open() then makes sure you get a password prompt so
   return undef unless @lines;  you are ready to login() and parses the login banner so you can get
   host_type() and firmware_version()
   my @sus;  
   foreach (@lines) {  =cut
     if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) {  
       my %s = (  sub open {
         suid => $1,      my $self = shift;
         type => $2,  
         cir  => $3,      unless ( $self->SUPER::open(@_) ) {
         mir  => $4,          $self->last_error( "Couldn't connect to " . $self->host . ":  $!" );
         mac  => $5,          return;
       );      }
   
           $s{'mac'} =~ s/\s//g;      ## Get to login prompt
           $s{'mac'} = uc($s{'mac'});      unless (
           $self->waitfor(
       push @sus, \%s;              -match   => '/password: ?$/i',
     }              -errmode => "return",
   }          )
           )
   return \@sus;      {
 }          $self->last_error( "problem connecting to host ("
                   . $self->host . "): "
 =pod                  . $self->lastline );
           return;
 =item sudb_add      }
   
 Takes the following paramaters      $self->parse_login_banner( $self->lastline );
   
         suid : numeric,      $self->is_connected(1);
         type : (reg|pr)  
         cir  : numeric,      return $self->is_connected;
         mir  : numeric,  }
         mac  : Almost any format, it will be reformatted,  
   =pod
 and returns true on success or undef otherwise.  
   =head2 B<login> - Login to the AP.
 You should sudb_save() after calling this, or your changes  will be lost  
 when the AP is rebooted.  Calls open() if not already connected, then sends the password and sets
   logged_in() if successful
 =cut  
   =cut
 sub sudb_add  
 {  sub login {
         my $self = shift;      my $self = shift;
         my $suid = shift;  
         my $type = shift;      unless ( $self->is_connected ) {
         my $cir  = shift;          $self->open or return;
         my $mir  = shift;      }
         my $mac  = shift;  
       my $password = shift;
         if ($suid =~ /\D/) {  
                 return undef;      $self->print($password);
         }      unless (
           $self->waitfor(
         unless (lc($type) eq 'reg' || lc($type) eq 'pr') {              -match   => $self->prompt,
                 warn "Invalid type '$type'!";              -errmode => "return",
                 return undef;          )
         }          )
       {
         if ($cir =~ /\D/) {          $self->last_error( "login ($self->host) failed: " . $self->lastline );
                 warn "Invalid CIR '$cir'!";          return;
                 return undef;      }
         }  
       $self->logged_in(1);
         if ($mir =~ /\D/) {  
                 warn "Invalid MIR '$mir'!";      return $self->logged_in;
                 return undef;  }
         }  
   =pod
         my $new_mac = $mac;  
         $new_mac =~ s/[^0-9A-Fa-f]//;  =head2 B<parse_login_banner> - Converts the login_banner to something useful.
         unless (length $new_mac == 12) {  
                 warn "Invalid MAC '$mac'!";  Takes a login banner (what you get when you first connect to the Trango)
                 return undef;  or reads what is already in login_banner() then parses it and sets
         }  host_type() and firmware_version() as well as login_banner()
         $new_mac = join ' ', $new_mac =~ /../g;  
   =cut
         my $string = 'sudb add ' .  
                 $suid . ' ' .  sub parse_login_banner {
                 $type . ' ' .      my $self = shift;
                 $cir  . ' ' .  
                 $mir  . ' ' .      if (@_) {
                 $new_mac;          $self->login_banner(@_);
       }
   
         return $self->cmd( String => $string, expect => $success );      my $banner = $self->login_banner;
 }  
       my ( $type, $sep1, $subtype, $sep2, $ver )
 =pod          = $banner
           =~ /Welcome to Trango Broadband Wireless,? (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i;
 =item sudb_delete  
       $type .= $sep1 . $subtype;
 Takes either 'all' or the  suid of the su to delete      $ver = $subtype . $sep2 . $ver;
 and returns true on success or undef otherwise.  
       $self->login_banner($banner);
 You should sudb_save() after calling this, or your changes  will be lost      $self->host_type($type);
 when the AP is rebooted.      $self->firmware_version($ver);
   
 =cut      return 1;
   }
 sub sudb_delete  
 {  =pod
         my $self = shift;  
         my $suid = shift;  =head2 B<linktest> - Link test to SU
   
         if (lc($suid) ne 'all' || $suid =~ /\D/) {  linktest('suid'[, 'pkt len, bytes'[, '# of pkts'[, '# of cycles']]]);
                 return undef;  
         }  Returns a hash reference to the results of the test
   
         return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );  =cut
 }  
   sub linktest {
       my $self = shift;
 =pod      my $suid = shift;
   
 =item sudb_modify      # These numbers are what I found as defaults when running the command
       my $pkt_len = shift || 1600;
 Takes either the  suid of the su to delete      my $pkt_cnt = shift || 500;
 as well as what you are changing, either "cir, mir or su2su"      my $cycles  = shift || 10;
 and returns true on success or undef otherwise.  
       my %config = @_;
 cir and mir also take a value to set the cir/mir to.  
       # * 2, one for the FromAP, one FromSU.  Then / 1000 to get to ms.
 su2su takes a group id parameter that is in hex.      # 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.
 You should sudb_save() after calling this, or your changes  will be lost      $config{Timeout} ||= int( ( $pkt_len * $pkt_cnt * $cycles * 2 ) / 1000 );
 when the AP is rebooted.  
       my $string = join $SPACE, 'linktest', $suid, $pkt_len, $pkt_cnt, $cycles;
 =cut      return $self->cmd(
           %config,
 sub sudb_modify          String => $string,
 {          decode => 'linktest',
         my $self  = shift;      );
         my $suid  = shift;  
         my $opt   = shift;  }
         my $value = shift;  
   =pod
         if ($suid =~ /\D/) {  
                 return undef;  =head2 B<su_password> - Set the password on SUs connected to the AP.
         }  
   su_password('new_password'[, 'suid']) If no suid is specified,
         if (lc($opt) eq 'cir' or lc($opt) eq 'mir') {  the default is "all".
                 if ($value =~ /\D/) {  
                         return undef;    $t->su_password('good_pass', 5);
                 }  
         } elsif (lc($opt) eq 'su2su') {  =cut
                 if ($value =~ /[^0-9A-Za-f]/) {  
                         return undef;  sub su_password {
                 }      my $self     = shift;
         } else {      my $new_pass = shift || $EMPTY;
                 return undef;      my $su       = shift || 'all';
         }  
       unless ( defined $new_pass ) {
         my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value;          $self->last_error("No new password");
   
         return $self->cmd( String => $string, expect => $success );          #return;
 }      }
   
 =pod      return $self->cmd(
           String => 'su password '
 =item enable_tftpd              . $su
               . $SPACE
 runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing              . $new_pass
               . $SPACE
 =cut              . $new_pass,
           expect => $success,
 sub enable_tftpd      );
 {  }
   my $self = shift;  
   =pod
   my $vals = $self->tftpd( args => 'on' );  
   =head2 B<ipconfig> - Change IP configuration
   if ($vals->{'Tftpd'} eq 'listen') {  
     return $vals;  ipconfig( 'new_ip', 'new_subnet', 'new_gateway' )
   } else {  
     return undef;    $t->ipconfig( '10.0.1.5', '255.255.255.0', '10.0.1.1' );
   }  
 }  =cut
   
 =pod  sub ipconfig {
       my $self = shift;
 =item disable_tftpd  
       my $string = join $SPACE, 'ipconfig', @_;
 runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'  
       if ( @_ == 3 ) {
 =cut          $self->print($string);
           my @lines = $self->waitfor( Match => '/save\s+and\s+activate/', );
 sub disable_tftpd          $self->print('y');
 {  
   my $self = shift;          $self->logged_in(0);
           $self->is_connected(0);
   my $vals = $self->tftpd( args => 'off' );  
           foreach my $line (@lines) {
   if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled') {              if ( $line =~ s/New \s configuration:\s+//xms ) {
     return $vals;                  return _decode_lines($line);
   } else {              }
     return undef;          }
   }  
 }          return {};
       }
 =pod  
       # ipconfig [ <new ip> <new subnet> <new gateway> ]
 =item cmd      return $self->cmd( String => $string, expect => $success );
   }
 This does most of the work.  At the heart, it calls Net::Telnet::cmd() but it also does some special stuff for Trango.  
   =pod
 Normally returns the last lines from from the command  
   =head2 B<su_ipconfig> - Change IP configuration on SUs connected to the AP.
 Also accepts these options:  
   su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )
 I<decode>  
 - if this is true, then it will send the output lines to _decode_lines() and then returns the decoded output    $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );
   
 I<cmd_disconnects>  =cut
 - if this is true, it then sets logged_in() to false, then it will close() the connection and then sets is_connected() to false  
   sub su_ipconfig {
 I<expect>      my $self = 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 $suid        = shift;
 I<args>      my $new_ip      = shift;
 - a string containing the command line options that are passed to the command      my $new_subnet  = shift;
       my $new_gateway = shift;
 =cut  
       if ( $suid =~ /\D/ ) {
 sub cmd          $self->last_error("Invalid suid '$suid'");
 {          return;
   my $self = shift;      }
       unless ($new_ip) {
   my @valid_net_telnet_opts = qw(          $self->last_error("no new_ip passed");
     String          return;
     Output      }
     Cmd_remove_mode      unless ($new_subnet) {
     Errmode          $self->last_error("no new_subnet passed");
     Input_record_separator          return;
     Ors      }
     Output_record_separator      unless ($new_gateway) {
     Prompt          $self->last_error("no new_gateway passed");
     Rs          return;
     Timeout      }
   );  
       # su ipconfig <suid> <new ip> <new subnet> <new gateway>
   my %cfg;      return $self->cmd(
   if (@_ == 2) {          String => 'su ipconfig '
     $cfg{'String'} = shift;              . $suid
   } elsif (@_ > 2) {              . $SPACE
     %cfg = @_;              . $new_ip
   }              . $SPACE
               . $new_subnet
   $cfg{'Timeout'} ||= $self->Timeout;              . $SPACE
               . $new_gateway,
   unless ($cfg{'String'}) {          expect => $success,
     #$! = "No command passed";      );
     #warn "No command passed\n";  }
     return undef;  
   }  =pod
   
   unless ($self->is_connected) {  =head2 B<sudb_view> - Returns the output from the sudb view command
     #$! = "Not connected";  
     #warn "Not connected\n";  returns a reference to an array of hashes each containing these keys
     return undef;  'suid', 'su2su', 'type', 'cir', 'mir' and 'mac'
   }  
   =cut
   unless ($self->logged_in) {  
     #$! = "Not logged in";  sub sudb_view {
     #warn "Not logged in\n";      my $self = shift;
     return undef;  
   }      my $lines = $self->cmd( String => 'sudb view', expect => $success ) || [];
   
       return unless @{$lines};
   my %cmd;  
   foreach (@valid_net_telnet_opts) {      my $s = *$self->{net_telnet_trango};
     if (exists $cfg{$_}) {      return $lines if !$s->{'Decode'};
       $cmd{$_} = $cfg{$_};  
     }      my @sus;
   }      foreach ( @{$lines} ) {
   if ($cfg{'args'}) {          next unless $_;
     $cmd{'String'} .= ' ' . $cfg{'args'};          if (/^
   }              \[(\d+)\]
   my @lines;              \s+
   unless ($cfg{'no_prompt'}) {              [[:xdigit:]]{2}
     @lines = $self->SUPER::cmd(%cmd);              ([[:xdigit:]])
   } else {              ([[:xdigit:]])
     $self->print($cmd{'String'});              \s+
     @lines = $self->lastline;              (\d+)
   }              \s+
               (\d+)
   $self->last_lines(\@lines);              \s+
               ([[:xdigit:]\s]+)
   my $vals = 1;          $/ixms
   if ($cfg{'decode'}) {              )
     if ($cfg{'decode'} eq 'each') {          {
       $vals = _decode_each_line(@lines);              my %s = (
     } elsif ($cfg{'decode'} eq 'sulog') {                  suid  => $1,
       $vals = _decode_sulog(@lines);                  su2su => $2 ? $2 : undef,
     } else {                  type  => $3 == 1 ? 'reg' : $3 == 5 ? 'pri' : $3,
       $vals = _decode_lines(@lines);                  cir   => $4,
     }                  mir   => $5,
   }                  mac   => $6,
               );
   $self->last_vals($vals);  
               $s{'mac'} =~ s/\s//gxms;
               $s{'mac'} = uc( $s{'mac'} );
   my $last = $self->lastline;  
               push @sus, \%s;
   if ((not $cfg{'expect'}) || $last =~ /$cfg{'expect'}$/) {          }
     if ($cfg{'cmd_disconnects'}) {      }
       $self->logged_in(0);  
       $self->close;      return \@sus;
       $self->is_connected(0);  }
     }  
   =pod
     if ($cfg{'decode'}) {  
       return $vals;  =head2 B<sudb_add> - Adds an su to the sudb
     } else {  
       return @lines;  Takes the following paramaters
     }  
   } else {      suid : numeric,
     #$! = "Error with command ($cfg{'string'}): $last";      type : (reg|pr)
     return undef;      cir  : numeric,
   }      mir  : numeric,
 }      mac  : Almost any format, it will be reformatted,
   
 #=item _decode_lines  and returns true on success or undef otherwise.
   
 sub _decode_lines    $t->sudb_add($suid, 'reg', $cir, $mir, $mac);
 {  
   my @lines = @_;  You should save_sudb() after calling this, or your changes  will be lost
   when the AP is rebooted.
   my %conf;  
   =cut
   my $key = '';  
   my $val = '';  sub sudb_add {
   my $in_key = 0;      my $self = shift;
   my $in_val = 0;      my $suid = shift;
       my $type = shift;
   foreach my $line (@lines) {      my $cir  = shift;
     next if $line =~ /$success$/;      my $mir  = shift;
       my $mac  = shift;
     my @chars = split //, $line;  
       if ( $suid =~ /\D/ ) {
     my $last_key = '';          $self->last_error("Invalid suid '$suid'");
     foreach my $c (@chars) {          return;
       }
       if ($c eq '[' || $c eq "\r" || $c eq "\n") {  
         if ($c eq '[') {      unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) {
           $in_key = 1;          $self->last_error("Invalid type '$type'");
           $in_val = 0;          return;
         } else {      }
           $in_key = 0;  
           $in_val = 0;      if ( $cir =~ /\D/ ) {
         }          $self->last_error("Invalid CIR '$cir'");
           return;
         if ($key) {      }
           $key =~ s/^\s+//;  
           $key =~ s/\s+$//;      if ( $mir =~ /\D/ ) {
           $self->last_error("Invalid MIR '$mir'");
           $val =~ s/^\s+//;          return;
           $val =~ s/\s+$//;      }
   
           if ($key eq 'Checksum' && $last_key) {      my $new_mac = $mac;
             # Special case for these bastids.      $new_mac =~ s/[^0-9A-Fa-f]//g;
             my $new = $last_key;      unless ( length $new_mac == 12 ) {
             $new =~ s/\s+\S+$//;          $self->last_error("Invalid MAC '$mac'");
             $key = $new . " " . $key;          return;
           }      }
       $new_mac = join $SPACE, $new_mac =~ /../g;
           $last_key = $key;  
           $conf{$key} = $val;      my $string
           $key = '';          = 'sudb add '
           $val = '';          . $suid
         }          . $SPACE
           . $type
       } elsif ($c eq ']') {          . $SPACE
         $in_val = 1;          . $cir
         $in_key = 0;          . $SPACE
         $c = shift @chars;          . $mir
           . $SPACE
       } elsif ($in_key) {          . $new_mac;
         $key .= $c;  
       return $self->cmd( String => $string, expect => $success );
       } elsif ($in_val) {  }
         $val .= $c;  
       }  =pod
     }  
   }  =head2 B<sudb_delete> - removes an su from the sudb
   
   if (%conf) {  Takes either 'all' or the  suid of the su to delete
     return \%conf;  and returns true on success or undef otherwise.
   } else {  
     return undef;    $t->sudb_delete($suid);
   }  
 }  You should save_sudb() after calling this, or your changes  will be lost
   when the AP is rebooted.
 #=item _decode_each_line  
   =cut
 sub _decode_each_line  
 {  sub sudb_delete {
   my @lines = @_;      my $self = shift;
   my @decoded;      my $suid = shift;
   foreach my $line (@lines) {  
     my $decoded = _decode_lines($line);      #if (lc($suid) ne 'all' || $suid =~ /\D/) {
     push @decoded, $decoded if defined $decoded;      if ( $suid =~ /\D/ ) {
   }          $self->last_error("Invalid suid '$suid'");
   return \@decoded;          return;
 }      }
   
 #=item _decode_sulog      return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );
   }
 sub _decode_sulog  
 {  =pod
   my @lines = @_;  
   my @decoded;  =head2 B<sudb_modify> - changes the su information in the sudb
   my $last_tm;  
   foreach my $line (@lines) {  Takes either the  suid of the su to change
     my $decoded = _decode_lines($line);  as well as what you are changing, either "cir, mir or su2su"
   and returns true on success or undef otherwise.
     if (defined $decoded) {  
       if ($decoded->{'tm'}) {  cir and mir also take a value to set the cir/mir to.
         $last_tm = $decoded->{'tm'};  
         next;  su2su takes a group id parameter that is in hex.
       } else {  
         $decoded->{'tm'} = $last_tm;    $t->sudb_modify($suid, 'cir', 512);
       }  
       next unless $last_tm;  You should save_sudb() after calling this, or your changes  will be lost
   when the AP is rebooted.
       push @decoded, $decoded if defined $decoded;  
     }  =cut
   }  
   return \@decoded;  sub sudb_modify {
 }      my $self  = shift;
       my $suid  = shift;
 1;      my $opt   = shift;
 __END__      my $value = shift;
   
 =back      if ( $suid =~ /\D/ ) {
           $self->last_error("Invalid suid '$suid'");
 =head1 SEE ALSO          return;
       }
 Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm  
       if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {
 L<Net::Telnet>          if ( $value =~ /\D/ ) {
               $self->last_error("Invalid $opt '$value'");
 =head1 TODO              return;
           }
 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.      }
       elsif ( lc($opt) eq 'su2su' ) {
 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.          if ( $value =~ /[^0-9A-Za-f]/ ) {
               $self->last_error("Invalid MAC '$value'");
 =head1 AUTHOR              return;
           }
 Andrew Fresh E<lt>andrew@rraz.netE<gt>      }
       else {
 =head1 COPYRIGHT AND LICENSE          $self->last_error("Invalid option '$opt'");
           return;
 Copyright (C) 2005 by Andrew Fresh      }
   
 This library is free software; you can redistribute it and/or modify      my $string = 'sudb modify ' . $suid . $SPACE . $opt . $SPACE . $value;
 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.      return $self->cmd( String => $string, expect => $success );
   }
   
 =cut  =pod
   
   =head2 B<enable_tftpd> - enable the TFTP server
   
   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.7  
changed lines
  Added in v.1.60

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