[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.38

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

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

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