[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.31 and 1.36

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

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