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

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

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.34

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