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

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

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