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

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

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.36

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