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

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

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