[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.20 and 1.35

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

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