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

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

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

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