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

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

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