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

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

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

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