[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.36 and 1.45

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

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