[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.37 and 1.38

version 1.37, 2007/02/05 23:09:59 version 1.38, 2007/02/06 16:22:46
Line 1 
Line 1 
 package Net::Telnet::Trango;  package Net::Telnet::Trango;
   
 # $RedRiver: Trango.pm,v 1.36 2007/02/05 21:09:26 andrew Exp $  # $RedRiver: Trango.pm,v 1.37 2007/02/05 23:09:59 andrew Exp $
 use strict;  use strict;
 use warnings;  use warnings;
 use base 'Net::Telnet';  use base 'Net::Telnet';
Line 45 
Line 45 
   
 our $VERSION = '0.01';  our $VERSION = '0.01';
   
   my $EMPTY = q{};
   my $SPACE = q{ };
   
 my %PRIVATE = (  my %PRIVATE = (
     is_connected => 0,      is_connected => 0,
     logged_in    => 0,      logged_in    => 0,
Line 217 
Line 220 
   
 Does the same as reboot()  Does the same as reboot()
   
   =head2 B<save_systemsetting> - alias of save_ss()
   
   Does the same as save_ss()
   
 =head1 COMMANDS  =head1 COMMANDS
   
 Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>,  Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>,
Line 339 
Line 346 
     bye     => 'exit',      bye     => 'exit',
     restart => 'reboot',      restart => 'reboot',
     Host    => 'host',      Host    => 'host',
       save_systemseting => 'save_ss',
 );  );
   
 my %ACCESS = map { $_ => 1 } qw(  my %ACCESS = map { $_ => 1 } qw(
Line 371 
Line 379 
             $cmd{$k} = $COMMANDS{$method}{$k};              $cmd{$k} = $COMMANDS{$method}{$k};
         }          }
         $cmd{'String'} ||= $method;          $cmd{'String'} ||= $method;
         $cmd{'args'} .= ' ' . shift if ( @_ == 1 );          $cmd{'args'} .= $SPACE . shift if ( @_ == 1 );
         return $self->cmd( %cmd, @_ );          return $self->cmd( %cmd, @_ );
     }      }
   
Line 505 
Line 513 
   
 sub su_password {  sub su_password {
     my $self     = shift;      my $self     = shift;
     my $new_pass = shift || '';      my $new_pass = shift || $EMPTY;
     my $su       = shift || 'all';      my $su       = shift || 'all';
   
     unless ( defined $new_pass ) {      unless ( defined $new_pass ) {
Line 515 
Line 523 
     }      }
   
     return $self->cmd(      return $self->cmd(
         String => 'su password ' . $su . ' ' . $new_pass . ' ' . $new_pass,          String => 'su password ' . $su . $SPACE . $new_pass . $SPACE . $new_pass,
         expect => $success,          expect => $success,
     );      );
 }  }
Line 557 
Line 565 
   
     # su ipconfig <suid> <new ip> <new subnet> <new gateway>      # su ipconfig <suid> <new ip> <new subnet> <new gateway>
     return $self->cmd(      return $self->cmd(
         String => 'su ipconfig ' . $suid . ' ' . $new_ip . ' '          String => 'su ipconfig ' . $suid . $SPACE . $new_ip . $SPACE
           . $new_subnet . ' '            . $new_subnet . $SPACE
           . $new_gateway,            . $new_gateway,
         expect => $success,          expect => $success,
     );      );
Line 661 
Line 669 
         $self->last_error("Invalid MAC '$mac'");          $self->last_error("Invalid MAC '$mac'");
         return;          return;
     }      }
     $new_mac = join ' ', $new_mac =~ /../g;      $new_mac = join $SPACE, $new_mac =~ /../g;
   
     my $string =      my $string =
       'sudb add ' . $suid . ' ' . $type . ' ' . $cir . ' ' . $mir . ' '        'sudb add ' . $suid . $SPACE . $type . $SPACE . $cir . $SPACE . $mir . $SPACE
       . $new_mac;        . $new_mac;
   
     return $self->cmd( String => $string, expect => $success );      return $self->cmd( String => $string, expect => $success );
Line 744 
Line 752 
         return;          return;
     }      }
   
     my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value;      my $string = 'sudb modify ' . $suid . $SPACE . $opt . $SPACE . $value;
   
     return $self->cmd( String => $string, expect => $success );      return $self->cmd( String => $string, expect => $success );
 }  }
Line 879 
Line 887 
         }          }
     }      }
     if ( $cfg{'args'} ) {      if ( $cfg{'args'} ) {
         $cmd{'String'} .= ' ' . $cfg{'args'};          $cmd{'String'} .= $SPACE . $cfg{'args'};
     }      }
   
     my @lines;      my @lines;
Line 928 
Line 936 
         }          }
     }      }
     else {      else {
         $self->last_error("Error with command ($cfg{'String'}): $last");          my $err;
           if (grep { /\[ERR\]/ } @lines) {
               $err = _decode_lines(@lines);
           }
   
           if (ref $err eq 'HASH' && $err ->{ERR}) {
               $self->last_error($err->{ERR} );
           } else {
               $self->last_error("Error with command ($cfg{'String'}): $last");
           }
         return;          return;
     }      }
 }  }
Line 940 
Line 957 
   
     my %conf;      my %conf;
   
     my $key = '';      my $key = $EMPTY;
     my $val = undef;      my $val = undef;
     my @vals;      my @vals;
     my $in_key = 0;      my $in_key = 0;
Line 951 
Line 968 
   
         my @chars = split //, $line;          my @chars = split //, $line;
   
         my $last_key = '';          my $last_key = $EMPTY;
         foreach my $c (@chars) {          foreach my $c (@chars) {
   
             if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {              if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {
Line 978 
Line 995 
                         # Special case for these bastids.                          # Special case for these bastids.
                         my $new = $last_key;                          my $new = $last_key;
                         $new =~ s/\s+\S+$//;                          $new =~ s/\s+\S+$//;
                         $key = $new . " " . $key;                          $key = $new . $SPACE . $key;
                     }                      }
   
                     $conf{$key} = $val;                      $conf{$key} = $val;
                     $last_key   = $key;                      $last_key   = $key;
                     $key        = '';                      $key        = $EMPTY;
                 }                  }
                 elsif ($val) {                  elsif ($val) {
                     push @vals, $val;                      push @vals, $val;
                 }                  }
                 $val = '';                  $val = $EMPTY;
   
             }              }
             elsif ( $c eq ']' ) {              elsif ( $c eq ']' ) {

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.38

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