[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.17 and 1.36

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

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