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

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

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