[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.33 and 1.34

version 1.33, 2007/02/02 21:26:56 version 1.34, 2007/02/05 21:02:07
Line 1 
Line 1 
 package Net::Telnet::Trango;  package Net::Telnet::Trango;
 # $RedRiver: Trango.pm,v 1.32 2007/02/02 18:59:50 andrew Exp $  
 use strict;  # $RedRiver: Trango.pm,v 1.33 2007/02/02 21:26:56 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  => { String => 'su info',  decode => 'all', expect => $success },
   sulog       => { decode => 'sulog', expect => $success },      su_testrflink =>
   'exit'      => { no_prompt => 1, cmd_disconnects => 1 },        { String => 'su testrflink', decode => 'each', expect => $success },
   reboot      => { no_prompt => 1, cmd_disconnects => 1 },      save_ss => { String => 'save ss', expect => $success },
   remarks     => { decode => 'all', expect => $success },      opmode  => { decode => 'all',     expect => $success },
   save_sudb   => { String => 'save sudb', expect => $success },  
   syslog      => { expect => $success },      # eth r, w and reset???
   'pipe'      => { }, # XXX needs a special decode      #su password???
   maclist     => { decode => 'maclist' },      #_bootloader
   maclist_reset => { String => 'maclist reset', expect => 'done' },      #temp
   eth_link    => { String => 'eth link', expect => $success },      #heater
   su_info     => { String => 'su info', decode => 'all', expect => $success },  );
   su_testrflink => { String => 'su testrflink', decode => 'each', expect => $success },  
   save_ss     => { String => 'save ss', expect => $success },  my %ALIASES = (
   opmode      => { decode => 'all',   expect => $success },      bye     => 'exit',
   # eth r, w and reset???      restart => 'reboot',
   #su password???      Host    => 'host',
   #_bootloader  );
   #temp  
   #heater  my %ACCESS = map { $_ => 1 } qw(
 );    firmware_version
     host_type
 my %ALIASES = (    is_connected
   bye     => 'exit',    logged_in
   restart => 'reboot',    login_banner
   Host    => 'host',    Timeout
 );    last_lines
     last_vals
 my %ACCESS = map { $_ => 1 } qw(    last_error
   firmware_version    Decode
   host_type  );
   is_connected  
   logged_in  sub AUTOLOAD {
   login_banner      my $self = shift;
   Timeout  
   last_lines      my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/
   last_vals        or die "Weird: $AUTOLOAD";
   last_error  
   Decode      if ( exists $ALIASES{$method} ) {
 );          $method = $ALIASES{$method};
           return $self->$method(@_);
 sub AUTOLOAD      }
 {  
   my $self = shift;      if ( exists $COMMANDS{$method} ) {
           my %cmd;
   my ($method) = (our $AUTOLOAD) =~ /^.*::(\w+)$/          foreach my $k ( keys %{ $COMMANDS{$method} } ) {
     or die "Weird: $AUTOLOAD";              $cmd{$k} = $COMMANDS{$method}{$k};
           }
   if (exists $ALIASES{$method}) {          $cmd{'String'} ||= $method;
     $method = $ALIASES{$method};          $cmd{'args'} .= ' ' . shift if ( @_ == 1 );
     return $self->$method(@_);          return $self->cmd( %cmd, @_ );
   }      }
   
   if (exists $COMMANDS{$method}) {      if ( exists $ACCESS{$method} ) {
     my %cmd;          my $prev = $PRIVATE{$method};
     foreach my $k (keys %{ $COMMANDS{$method} }) {          ( $PRIVATE{$method} ) = @_ if @_;
       $cmd{$k} = $COMMANDS{$method}{$k};          return $prev;
     }      }
     $cmd{'String'} ||= $method;  
     $cmd{'args'}   .= ' ' . shift if (@_ == 1);      $method = "SUPER::$method";
     return $self->cmd(%cmd, @_);      return $self->$method(@_);
   }  }
   
   if (exists $ACCESS{$method}) {  =pod
     my $prev = $PRIVATE{$method};  
     ($PRIVATE{$method}) = @_ if @_;  =head2 B<open>
     return $prev;  - Open a connection to a Trango AP.
   }  
   Calls Net::Telnet::open() then makes sure you get a password prompt so
   $method = "SUPER::$method";  you are ready to login() and parses the login banner so you can get
   return $self->$method(@_);  host_type() and firmware_version()
 }  
   =cut
 =pod  
   sub open {
 =item B<open>      my $self = shift;
   
 - Open a connection to a Trango AP.      unless ( $self->SUPER::open(@_) ) {
           $self->last_error( "Couldn't connect to " . $self->host . ":  $!" );
 Calls Net::Telnet::open() then makes sure you get a password prompt so          return;
 you are ready to login() and parses the login banner so you can get      }
 host_type() and firmware_version()  
       ## Get to login prompt
 =cut      unless (
           $self->waitfor(
 sub open              -match   => '/password: ?$/i',
 {              -errmode => "return",
   my $self = shift;          )
         )
   unless ( $self->SUPER::open(@_) ) {      {
     $self->last_error("Couldn't connect to " . $self->host . ":  $!");          $self->last_error( "problem connecting to host ("
     return;                . $self->host . "): "
   }                . $self->lastline );
           return;
   ## Get to login prompt      }
   unless ($self->waitfor(  
       -match => '/password: ?$/i',      $self->parse_login_banner( $self->lastline );
       -errmode => "return",  
     ) ) {      $self->is_connected(1);
     $self->last_error("problem connecting to host (" . $self->host . "): " .  
         $self->lastline);      return $self->is_connected;
     return;  }
   }  
   =pod
   $self->parse_login_banner($self->lastline);  
   =head2 B<login>
   $self->is_connected(1);  - Login to the AP.
   
   return $self->is_connected;  Calls open() if not already connected, then sends the password and sets
 }  logged_in() if successful
   
 =pod  =cut
   
 =item B<login>  sub login {
       my $self = shift;
 - Login to the AP.  
       unless ( $self->is_connected ) {
 Calls open() if not already connected, then sends the password and sets          $self->open or return;
 logged_in() if successful      }
   
 =cut      my $password = shift;
   
 sub login      $self->print($password);
 {      unless (
   my $self = shift;          $self->waitfor(
               -match   => $self->prompt,
   unless ($self->is_connected) {              -errmode => "return",
     $self->open or return;          )
   }        )
       {
   my $password = shift;          $self->last_error( "login ($self->host) failed: " . $self->lastline );
           return;
   $self->print($password);      }
   unless ($self->waitfor(  
     -match => $self->prompt,      $self->logged_in(1);
     -errmode => "return",  
   ) ) {      return $self->logged_in;
     $self->last_error("login ($self->host) failed: " . $self->lastline);  }
     return;  
   }  =pod
   
   $self->logged_in(1);  =head2 B<parse_login_banner>
   - Converts the login_banner to some useful
   return $self->logged_in;  variables.
 }  
   Takes a login banner (what you get when you first connect to the Trango)
 =pod  or reads what is already in login_banner() then parses it and sets
   host_type() and firmware_version() as well as login_banner()
 =item B<parse_login_banner>  
   =cut
 - Converts the login_banner to some useful  
 variables.  sub parse_login_banner {
       my $self = shift;
 Takes a login banner (what you get when you first connect to the Trango)  
 or reads what is already in login_banner() then parses it and sets      if (@_) {
 host_type() and firmware_version() as well as login_banner()          $self->login_banner(@_);
       }
 =cut  
       my $banner = $self->login_banner;
 sub parse_login_banner  
 {      my ( $type, $sep1, $subtype, $sep2, $ver ) =
   my $self = shift;        $banner =~
         /Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i;
   if (@_) {  
     $self->login_banner(@_);      $type .= $sep1 . $subtype;
   }      $ver = $subtype . $sep2 . $ver;
   
   my $banner = $self->login_banner;      $self->login_banner($banner);
       $self->host_type($type);
   my ($type, $sep1, $subtype, $sep2, $ver) = $banner =~      $self->firmware_version($ver);
     /Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i;  
       return 1;
   $type .= $sep1 . $subtype;  }
   $ver = $subtype . $sep2 . $ver;  
   =pod
   $self->login_banner($banner);  
   $self->host_type($type);  =head2 B<su_password>
   $self->firmware_version($ver);  - Set the password on SUs connected to the AP.
   
   return 1;  su_password('new_password'[, 'suid']) If no suid is specified,
 }  the default is "all".
   
 =pod    $t->su_password('good_pass', 5);
   
 =item B<su_password>  =cut
   
 - Set the password on SUs connected to the AP.  sub su_password {
       my $self     = shift;
 su_password('new_password'[, 'suid']) If no suid is specified,      my $new_pass = shift || '';
 the default is "all".      my $su       = shift || 'all';
   
   $t->su_password('good_pass', 5);      unless ( defined $new_pass ) {
           $self->last_error("No new password");
 =cut  
           #return;
 sub su_password      }
 {  
   my $self     = shift;      return $self->cmd(
   my $new_pass = shift || '';          String => 'su password ' . $su . ' ' . $new_pass . ' ' . $new_pass,
   my $su       = shift || 'all';          expect => $success,
       );
   unless (defined $new_pass) {  }
     $self->last_error("No new password");  
     #return;  =pod
   }  
   =head2 B<su_ipconfig>
   return $self->cmd(String => 'su password ' .  - Change IP configuration on SUs connected to
                      $su . ' ' .  the AP.
                      $new_pass . ' ' .  
                      $new_pass,  su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )
                      expect => $success,  
                     );    $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );
 }  
   =cut
 =pod  
   sub su_ipconfig {
 =item B<su_ipconfig>      my $self = shift;
   
 - Change IP configuration on SUs connected to      my $suid        = shift;
 the AP.      my $new_ip      = shift;
       my $new_subnet  = shift;
 su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )      my $new_gateway = shift;
   
   $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );      if ( $suid =~ /\D/ ) {
           $self->last_error("Invalid suid '$suid'");
 =cut          return;
       }
 sub su_ipconfig      unless ($new_ip) {
 {          $self->last_error("no new_ip passed");
         my $self        = shift;          return;
       }
         my $suid        = shift;      unless ($new_subnet) {
         my $new_ip      = shift;          $self->last_error("no new_subnet passed");
         my $new_subnet  = shift;          return;
         my $new_gateway = shift;      }
       unless ($new_gateway) {
         if ($suid =~ /\D/) {          $self->last_error("no new_gateway passed");
                 $self->last_error("Invalid suid '$suid'");          return;
                 return;      }
         }  
         unless ($new_ip) {      # su ipconfig <suid> <new ip> <new subnet> <new gateway>
                 $self->last_error("no new_ip passed");      return $self->cmd(
                 return;          String => 'su ipconfig ' . $suid . ' ' . $new_ip . ' '
         }            . $new_subnet . ' '
         unless ($new_subnet) {            . $new_gateway,
                 $self->last_error("no new_subnet passed");          expect => $success,
                 return;      );
         }  }
         unless ($new_gateway) {  
                 $self->last_error("no new_gateway passed");  =pod
                 return;  
         }  =head2 B<sudb_view>
   - Returns the output from the sudb view command
         # su ipconfig <suid> <new ip> <new subnet> <new gateway>  
         return $self->cmd(String => 'su ipconfig ' .  returns a reference to an array of hashes each containing these keys
                      $suid       . ' ' .  'suid', 'type', 'cir', 'mir' and 'mac'
                      $new_ip     . ' ' .  
                      $new_subnet . ' ' .  =cut
                      $new_gateway,  
                      expect => $success,  sub sudb_view {
                     );      my $self = shift;
 }  
       my $lines = $self->cmd( String => 'sudb view', expect => $success ) || [];
 =pod  
       return unless @{$lines};
 =item B<sudb_view>  
       unless ( $PRIVATE{'Decode'} ) {
 - Returns the output from the sudb view command          return $lines;
       }
 returns a reference to an array of hashes each containing these keys  
 'suid', 'type', 'cir', 'mir' and 'mac'      my @sus;
       foreach ( @{$lines} ) {
 =cut          next unless $_;
           if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) {
 sub sudb_view              my %s = (
 {                  suid => $1,
   my $self = shift;                  type => $2,
                   cir  => $3,
   my $lines = $self->cmd( String => 'sudb view', expect => $success ) || [];                  mir  => $4,
                   mac  => $5,
   return unless @{ $lines };              );
   
   unless ($PRIVATE{'Decode'}) {              $s{'mac'} =~ s/\s//g;
     return $lines;              $s{'mac'} = uc( $s{'mac'} );
   }  
               push @sus, \%s;
   my @sus;          }
   foreach (@{ $lines }) {      }
     next unless $_;  
     if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) {      return \@sus;
       my %s = (  }
         suid => $1,  
         type => $2,  =pod
         cir  => $3,  
         mir  => $4,  =head2 B<sudb_add>
         mac  => $5,  
       );  Takes the following paramaters
   
           $s{'mac'} =~ s/\s//g;          suid : numeric,
           $s{'mac'} = uc($s{'mac'});          type : (reg|pr)
           cir  : numeric,
       push @sus, \%s;          mir  : numeric,
     }          mac  : Almost any format, it will be reformatted,
   }  
   and returns true on success or undef otherwise.
   return \@sus;  
 }    $t->sudb_add($suid, 'reg', $cir, $mir, $mac);
   
 =pod  You should save_sudb() after calling this, or your changes  will be lost
   when the AP is rebooted.
 =item B<sudb_add>  
   =cut
 Takes the following paramaters  
   sub sudb_add {
         suid : numeric,      my $self = shift;
         type : (reg|pr)      my $suid = shift;
         cir  : numeric,      my $type = shift;
         mir  : numeric,      my $cir  = shift;
         mac  : Almost any format, it will be reformatted,      my $mir  = shift;
       my $mac  = shift;
 and returns true on success or undef otherwise.  
       if ( $suid =~ /\D/ ) {
   $t->sudb_add($suid, 'reg', $cir, $mir, $mac);          $self->last_error("Invalid suid '$suid'");
           return;
 You should save_sudb() after calling this, or your changes  will be lost      }
 when the AP is rebooted.  
       unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) {
 =cut          $self->last_error("Invalid type '$type'");
           return;
 sub sudb_add      }
 {  
         my $self = shift;      if ( $cir =~ /\D/ ) {
         my $suid = shift;          $self->last_error("Invalid CIR '$cir'");
         my $type = shift;          return;
         my $cir  = shift;      }
         my $mir  = shift;  
         my $mac  = shift;      if ( $mir =~ /\D/ ) {
           $self->last_error("Invalid MIR '$mir'");
         if ($suid =~ /\D/) {          return;
                 $self->last_error("Invalid suid '$suid'");      }
                 return;  
         }      my $new_mac = $mac;
       $new_mac =~ s/[^0-9A-Fa-f]//;
         unless (lc($type) eq 'reg' || lc($type) eq 'pr') {      unless ( length $new_mac == 12 ) {
                 $self->last_error("Invalid type '$type'");          $self->last_error("Invalid MAC '$mac'");
                 return;          return;
         }      }
       $new_mac = join ' ', $new_mac =~ /../g;
         if ($cir =~ /\D/) {  
                 $self->last_error("Invalid CIR '$cir'");      my $string =
                 return;        'sudb add ' . $suid . ' ' . $type . ' ' . $cir . ' ' . $mir . ' '
         }        . $new_mac;
   
         if ($mir =~ /\D/) {      return $self->cmd( String => $string, expect => $success );
                 $self->last_error("Invalid MIR '$mir'");  }
                 return;  
         }  =pod
   
         my $new_mac = $mac;  =head2 B<sudb_delete>
         $new_mac =~ s/[^0-9A-Fa-f]//;  
         unless (length $new_mac == 12) {  Takes either 'all' or the  suid of the su to delete
                 $self->last_error("Invalid MAC '$mac'");  and returns true on success or undef otherwise.
                 return;  
         }    $t->sudb_delete($suid);
         $new_mac = join ' ', $new_mac =~ /../g;  
   You should save_sudb() after calling this, or your changes  will be lost
         my $string = 'sudb add ' .  when the AP is rebooted.
                 $suid . ' ' .  
                 $type . ' ' .  =cut
                 $cir  . ' ' .  
                 $mir  . ' ' .  sub sudb_delete {
                 $new_mac;      my $self = shift;
       my $suid = shift;
   
         return $self->cmd( String => $string, expect => $success );      #if (lc($suid) ne 'all' || $suid =~ /\D/) {
 }      if ( $suid =~ /\D/ ) {
           $self->last_error("Invalid suid '$suid'");
 =pod          return;
       }
 =item B<sudb_delete>  
       return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );
 Takes either 'all' or the  suid of the su to delete  }
 and returns true on success or undef otherwise.  
   =pod
   $t->sudb_delete($suid);  
   =head2 B<sudb_modify>
 You should save_sudb() after calling this, or your changes  will be lost  
 when the AP is rebooted.  Takes either the  suid of the su to change
   as well as what you are changing, either "cir, mir or su2su"
 =cut  and returns true on success or undef otherwise.
   
 sub sudb_delete  cir and mir also take a value to set the cir/mir to.
 {  
         my $self = shift;  su2su takes a group id parameter that is in hex.
         my $suid = shift;  
     $t->sudb_modify($suid, 'cir', 512);
         #if (lc($suid) ne 'all' || $suid =~ /\D/) {  
         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
   
         return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );  sub sudb_modify {
 }      my $self  = shift;
       my $suid  = shift;
 =pod      my $opt   = shift;
       my $value = shift;
 =item B<sudb_modify>  
       if ( $suid =~ /\D/ ) {
 Takes either the  suid of the su to change          $self->last_error("Invalid suid '$suid'");
 as well as what you are changing, either "cir, mir or su2su"          return;
 and returns true on success or undef otherwise.      }
   
 cir and mir also take a value to set the cir/mir to.      if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {
           if ( $value =~ /\D/ ) {
 su2su takes a group id parameter that is in hex.              $self->last_error("Invalid $opt '$value'");
               return;
   $t->sudb_modify($suid, 'cir', 512);          }
       }
 You should save_sudb() after calling this, or your changes  will be lost      elsif ( lc($opt) eq 'su2su' ) {
 when the AP is rebooted.          if ( $value =~ /[^0-9A-Za-f]/ ) {
               $self->last_error("Invalid MAC '$value'");
 =cut              return;
           }
 sub sudb_modify      }
 {      else {
         my $self  = shift;          $self->last_error("Invalid option '$opt'");
         my $suid  = shift;          return;
         my $opt   = shift;      }
         my $value = shift;  
       my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value;
         if ($suid =~ /\D/) {  
                 $self->last_error("Invalid suid '$suid'");      return $self->cmd( String => $string, expect => $success );
                 return;  }
         }  
   =pod
         if (lc($opt) eq 'cir' or lc($opt) eq 'mir') {  
                 if ($value =~ /\D/) {  =head2 B<enable_tftpd>
                         $self->last_error("Invalid $opt '$value'");  - enable the TFTP server
                         return;  
                 }  runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing
         } elsif (lc($opt) eq 'su2su') {  
                 if ($value =~ /[^0-9A-Za-f]/) {  =cut
                         $self->last_error("Invalid MAC '$value'");  
                         return;  sub enable_tftpd {
                 }      my $self = shift;
         } else {  
                 $self->last_error("Invalid option '$opt'");      my $vals = $self->tftpd( args => 'on' );
                 return;  
         }      if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) {
           return $vals;
         my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value;      }
       else {
         return $self->cmd( String => $string, expect => $success );          return;
 }      }
   }
 =pod  
   =pod
 =item B<enable_tftpd>  
   =head2 B<disable_tftpd>
 - enable the TFTP server  - disable the TFTP server
   
 runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing  runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'
   
 =cut  =cut
   
 sub enable_tftpd  sub disable_tftpd {
 {      my $self = shift;
   my $self = shift;  
       my $vals = $self->tftpd( args => 'off' );
   my $vals = $self->tftpd( args => 'on' );  
       if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) {
   if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen') {          return $vals;
     return $vals;      }
   } else {      else {
     return;          return;
   }      }
 }  }
   
 =pod  =pod
   
 =item B<disable_tftpd>  =head2 B<cmd> - runs a command on the AP.
   
 - disable the TFTP server  This does most of the work.  At the heart, it calls Net::Telnet::cmd()
   but it also does some special stuff for Trango.
 runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'  
   Normally returns the last lines from from the command
 =cut  
   If you are using this, rather than one of the "easy" methods above,
 sub disable_tftpd  you probably want to read through the source of this module to see how
 {  some of the other commands are called.
   my $self = shift;  
   In addition to the Net::Telnet::cmd() options, it also accepts these:
   my $vals = $self->tftpd( args => 'off' );  
   I<decode>
   if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled') {  - if this is true, then it will send the output lines to _decode_lines()
     return $vals;  and then returns the decoded output
   } else {  
     return;  I<no_prompt>
   }  - if this is true, it does not wait for a prompt, so you are not stuck
 }  waiting for something that will never happen.
   
 =pod  I<cmd_disconnects>
   - if this is true, it then sets logged_in() to false, then it will
 =item B<cmd>  close() the connection and set is_connected() to false
   
 - runs a command on the AP.  I<expect>
   - if this is set (usually to 'Success.') it will check for that in the
 This does most of the work.  At the heart, it calls Net::Telnet::cmd()  last line of output and if it does not, will return undef because the
 but it also does some special stuff for Trango.  command probably failed
   
 Normally returns the last lines from from the command  I<args>
   - a string containing the command line options that are passed to the
 If you are using this, rather than one of the "easy" methods above,  command
 you probably want to read through the source of this module to see how  
 some of the other commands are called.          $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );
   
 In addition to the Net::Telnet::cmd() options, it also accepts these:  =cut
   
 I<decode>  sub cmd {
       my $self = shift;
 - if this is true, then it will send the output lines to _decode_lines()  
 and then returns the decoded output      my @valid_net_telnet_opts = qw(
         String
 I<no_prompt>        Output
         Cmd_remove_mode
 - if this is true, it does not wait for a prompt, so you are not stuck        Errmode
 waiting for something that will never happen.        Input_record_separator
         Ors
 I<cmd_disconnects>        Output_record_separator
         Prompt
 - if this is true, it then sets logged_in() to false, then it will        Rs
 close() the connection and set is_connected() to false        Timeout
       );
 I<expect>  
       my %cfg;
 - if this is set (usually to 'Success.') it will check for that in the      if ( @_ == 1 ) {
 last line of output and if it does not, will return undef because the          $cfg{'String'} = shift;
 command probably failed      }
       elsif ( @_ > 1 ) {
 I<args>          %cfg = @_;
       }
 - a string containing the command line options that are passed to the  
 command      $cfg{'Timeout'} ||= $self->Timeout;
   
         $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );      unless ( $cfg{'String'} ) {
           $self->last_error("No command passed");
 =cut          return;
       }
 sub cmd  
 {      unless ( $self->is_connected ) {
   my $self = shift;          $self->last_error("Not connected");
           return;
   my @valid_net_telnet_opts = qw(      }
     String  
     Output      unless ( $self->logged_in ) {
     Cmd_remove_mode          $self->last_error("Not logged in");
     Errmode          return;
     Input_record_separator      }
     Ors  
     Output_record_separator      my %cmd;
     Prompt      foreach (@valid_net_telnet_opts) {
     Rs          if ( exists $cfg{$_} ) {
     Timeout              $cmd{$_} = $cfg{$_};
   );          }
       }
   my %cfg;      if ( $cfg{'args'} ) {
   if (@_ == 1) {          $cmd{'String'} .= ' ' . $cfg{'args'};
     $cfg{'String'} = shift;      }
   } elsif (@_ > 1) {  
     %cfg = @_;      my @lines;
   }      if ( $cfg{'no_prompt'} ) {
           $self->print( $cmd{'String'} );
   $cfg{'Timeout'} ||= $self->Timeout;          @lines = $self->lastline;
       }
   unless ($cfg{'String'}) {      else {
     $self->last_error("No command passed");          @lines = $self->SUPER::cmd(%cmd);
     return;      }
   }  
       $self->last_lines( \@lines );
   unless ($self->is_connected) {  
     $self->last_error("Not connected");      my $vals = 1;
     return;      if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {
   }          if ( $cfg{'decode'} eq 'each' ) {
               $vals = _decode_each_line(@lines);
   unless ($self->logged_in) {          }
     $self->last_error("Not logged in");          elsif ( $cfg{'decode'} eq 'sulog' ) {
     return;              $vals = _decode_sulog(@lines);
   }          }
           elsif ( $cfg{'decode'} eq 'maclist' ) {
               $vals = _decode_maclist(@lines);
   my %cmd;          }
   foreach (@valid_net_telnet_opts) {          else {
     if (exists $cfg{$_}) {              $vals = _decode_lines(@lines);
       $cmd{$_} = $cfg{$_};          }
     }      }
   }  
   if ($cfg{'args'}) {      $self->last_vals($vals);
     $cmd{'String'} .= ' ' . $cfg{'args'};  
   }      my $last = $self->lastline;
   
   my @lines;      if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) {
   if ($cfg{'no_prompt'}) {          if ( $cfg{'cmd_disconnects'} ) {
     $self->print($cmd{'String'});              $self->logged_in(0);
     @lines = $self->lastline;              $self->close;
   } else {              $self->is_connected(0);
     @lines = $self->SUPER::cmd(%cmd);          }
   }  
           if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) {
   $self->last_lines(\@lines);              return $vals;
           }
   my $vals = 1;          else {
   if ($PRIVATE{'Decode'} && $cfg{'decode'}) {              return \@lines;
     if ($cfg{'decode'} eq 'each') {          }
       $vals = _decode_each_line(@lines);      }
     } elsif ($cfg{'decode'} eq 'sulog') {      else {
       $vals = _decode_sulog(@lines);          $self->last_error("Error with command ($cfg{'String'}): $last");
     } elsif ($cfg{'decode'} eq 'maclist') {          return;
       $vals = _decode_maclist(@lines);      }
     } else {  }
       $vals = _decode_lines(@lines);  
     }  #=item _decode_lines
   }  
   sub _decode_lines {
   $self->last_vals($vals);      my @lines = @_;
   
       my %conf;
   my $last = $self->lastline;  
       my $key = '';
   if ((not $cfg{'expect'}) || $last =~ /$cfg{'expect'}$/) {      my $val = undef;
     if ($cfg{'cmd_disconnects'}) {      my @vals;
       $self->logged_in(0);      my $in_key = 0;
       $self->close;      my $in_val = 1;
       $self->is_connected(0);  
     }      foreach my $line (@lines) {
           next if $line =~ /$success$/;
     if ($PRIVATE{'Decode'} && $cfg{'decode'}) {  
       return $vals;          my @chars = split //, $line;
     } else {  
       return \@lines;          my $last_key = '';
     }          foreach my $c (@chars) {
   } else {  
     $self->last_error("Error with command ($cfg{'String'}): $last");              if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {
     return;                  if ( $c eq '[' ) {
   }                      $in_key = 1;
 }                      $in_val = 0;
                   }
 #=item _decode_lines                  else {
                       $in_key = 0;
 sub _decode_lines                      $in_val = 1;
 {                  }
   my @lines = @_;  
                   if ($key) {
   my %conf;                      $key =~ s/^\s+//;
                       $key =~ s/\s+$//;
   my $key = '';  
   my $val = undef;                      if ($val) {
   my @vals;                          $val =~ s/^\s+//;
   my $in_key = 0;                          $val =~ s/\s+$//;
   my $in_val = 1;                      }
   
   foreach my $line (@lines) {                      if ( $key eq 'Checksum' && $last_key ) {
     next if $line =~ /$success$/;  
                           # Special case for these bastids.
     my @chars = split //, $line;                          my $new = $last_key;
                           $new =~ s/\s+\S+$//;
     my $last_key = '';                          $key = $new . " " . $key;
     foreach my $c (@chars) {                      }
   
       if ($c eq '[' || $c eq "\r" || $c eq "\n") {                      $conf{$key} = $val;
         if ($c eq '[') {                      $last_key   = $key;
           $in_key = 1;                      $key        = '';
           $in_val = 0;                  }
         } else {                  elsif ($val) {
           $in_key = 0;                      push @vals, $val;
           $in_val = 1;                  }
         }                  $val = '';
   
         if ($key) {              }
           $key =~ s/^\s+//;              elsif ( $c eq ']' ) {
           $key =~ s/\s+$//;                  $in_val = 1;
                   $in_key = 0;
           if ($val) {                  $c      = shift @chars;
             $val =~ s/^\s+//;  
             $val =~ s/\s+$//;              }
           }              elsif ($in_key) {
                   $key .= $c;
           if ($key eq 'Checksum' && $last_key) {  
             # Special case for these bastids.              }
             my $new = $last_key;              elsif ($in_val) {
             $new =~ s/\s+\S+$//;                  $val .= $c;
             $key = $new . " " . $key;              }
           }          }
       }
           $conf{$key} = $val;  
           $last_key = $key;      unless ($key) {
           $key = '';          push @vals, $val;
         } elsif ($val) {      }
                         push @vals, $val;  
                 }      if ( @vals == 1 ) {
         $val = '';          $val = $vals[0];
       }
       } elsif ($c eq ']') {      elsif (@vals) {
         $in_val = 1;          $val = \@vals;
         $in_key = 0;      }
         $c = shift @chars;      else {
           $val = undef;
       } elsif ($in_key) {      }
         $key .= $c;  
       if (%conf) {
       } elsif ($in_val) {          $conf{_pre} = $val if $val;
         $val .= $c;          return \%conf;
       }      }
     }      else {
   }          return $val;
       }
   unless ($key) {  }
     push @vals, $val;  
   }  #=item _decode_each_line
   
   if (@vals == 1) {  sub _decode_each_line {
     $val = $vals[0];      my @lines = @_;
   } elsif (@vals) {      my @decoded;
     $val= \@vals;      foreach my $line (@lines) {
   } else {          my $decoded = _decode_lines($line);
     $val = undef;          push @decoded, $decoded if defined $decoded;
   }      }
       return \@decoded;
   if (%conf) {  }
     $conf{_pre} = $val if $val;  
     return \%conf;  #=item _decode_sulog
   } else {  
     return $val;  sub _decode_sulog {
   }      my @lines = @_;
 }      my @decoded;
       my $last_tm;
 #=item _decode_each_line      foreach my $line (@lines) {
           my $decoded = _decode_lines($line);
 sub _decode_each_line  
 {          if ( defined $decoded ) {
   my @lines = @_;              if ( $decoded->{'tm'} ) {
   my @decoded;                  $last_tm = $decoded->{'tm'};
   foreach my $line (@lines) {                  next;
     my $decoded = _decode_lines($line);              }
     push @decoded, $decoded if defined $decoded;              else {
   }                  $decoded->{'tm'} = $last_tm;
   return \@decoded;              }
 }              next unless $last_tm;
   
 #=item _decode_sulog              push @decoded, $decoded if defined $decoded;
           }
 sub _decode_sulog      }
 {      return \@decoded;
   my @lines = @_;  }
   my @decoded;  
   my $last_tm;  #=item _decode_maclist
   foreach my $line (@lines) {  
     my $decoded = _decode_lines($line);  sub _decode_maclist {
       my @lines = @_;
     if (defined $decoded) {      my @decoded;
       if ($decoded->{'tm'}) {      my $total_entries = 0;
         $last_tm = $decoded->{'tm'};      my $current_tm    = 0;
         next;      foreach my $line (@lines) {
       } else {          $line =~ s/\r?\n$//;
         $decoded->{'tm'} = $last_tm;          my ( $mac, $loc, $tm ) = $line =~ /
       }                          ([0-9a-fA-F ]{17})\s+
       next unless $last_tm;                          (.*)\s+
                           tm\s+
       push @decoded, $decoded if defined $decoded;                          (\d+)
     }                  /x;
   }  
   return \@decoded;          if ($mac) {
 }              $mac =~ s/\s+//g;
               $loc =~ s/^\s+//;
 #=item _decode_maclist              $loc =~ s/\s+$//;
   
 sub _decode_maclist              my $suid = undef;
 {              if ( $loc =~ /suid\s+=\s+(\d+)/ ) {
         my @lines = @_;                  $suid = $1;
         my @decoded;                  $loc  = undef;
         my $total_entries = 0;              }
         my $current_tm = 0;  
         foreach my $line (@lines) {              push @decoded,
                 $line =~ s/\r?\n$//;                {
                 my ($mac, $loc, $tm) = $line =~ /                  mac  => $mac,
                         ([0-9a-fA-F ]{17})\s+                  loc  => $loc,
                         (.*)\s+                  tm   => $tm,
                         tm\s+                  suid => $suid,
                         (\d+)                };
                 /x;          }
           elsif ( $line =~ /(\d+)\s+entries/ ) {
                 if ($mac) {              $total_entries = $1;
                         $mac =~ s/\s+//g;          }
                         $loc =~ s/^\s+//;          elsif ( $line =~ /current tm = (\d+)\s+sec/ ) {
                         $loc =~ s/\s+$//;              $current_tm = $1;
           }
                         my $suid = undef;      }
                         if ($loc =~ /suid\s+=\s+(\d+)/) {  
                                 $suid = $1;      map { $_->{'cur_tm'} = $current_tm } @decoded;
                                 $loc = undef;  
                         }      if ( scalar @decoded == $total_entries ) {
           return \@decoded;
                         push @decoded, {      }
                                 mac  => $mac,      else {
                                 loc  => $loc,  
                                 tm   => $tm,          # XXX we should have a way to set last error, not sure why we don't
                                 suid => $suid,          return;
                         };      }
                 } elsif ($line =~ /(\d+)\s+entries/) {  }
                         $total_entries = $1;  
                 } elsif ($line =~ /current tm = (\d+)\s+sec/) {  1;    # End of Net::Telnet::Trango
                         $current_tm = $1  __END__
                 }  
         }  =head1 SEE ALSO
   
         map { $_->{'cur_tm'} = $current_tm } @decoded;  Trango Documentation -
   L<http://www.trangobroadband.com/support/product_docs.htm>
         if (scalar @decoded == $total_entries) {  
                 return \@decoded;  L<Net::Telnet>
         } else {  
                 # XXX we should have a way to set last error, not sure why we don't  =head1 TODO
                 return;  
         }  There are still a lot of commands that are not accessed directly.  If
 }  you call them (as cmd("command + args") or whatever) and it works,
   please send me examples that work and I will try to get it incorporated
 1;  into the next version of the script.
 __END__  
   I also want to be able to parse the different types of output from
 =back  commands like su, sudb all and anything else that would be better
   available as a perl datastructure.
 =head1 SEE ALSO  
   =head1 AUTHOR
 Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm  
   Andrew Fresh E<lt>andrew@rraz.netE<gt>
 L<Net::Telnet>  
   =head1 SUPPORT
 =head1 TODO  
   You can find documentation for this module with the perldoc command.
 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,      perldoc Net::Telnet::Trango
 please send me examples that work and I will try to get it incorporated  
 into the next version of the script.  You can also look for information at:
   
 I also want to be able to parse the different types of output from  =over 4
 commands like su, sudb all and anything else that would be better  
 available as a perl datastructure.  =item * AnnoCPAN: Annotated CPAN documentation
   
 =head1 AUTHOR  L<http://annocpan.org/dist/Net-Telnet-Trango>
   
 Andrew Fresh E<lt>andrew@rraz.netE<gt>  =item * CPAN Ratings
   
 =head1 COPYRIGHT AND LICENSE  L<http://cpanratings.perl.org/d/Net-Telnet-Trango>
   
 Copyright (C) 2005,2006,2007 by Andrew Fresh  =item * RT: CPAN's request tracker
   
 This library is free software; you can redistribute it and/or modify  L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Telnet-Trango>
 it under the same terms as Perl itself, either Perl version 5.8.7 or,  
 at your option, any later version of Perl 5 you may have available.  =item * Search CPAN
   
 =cut  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.33  
changed lines
  Added in v.1.34

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