[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.25 and 1.34

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

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