version 1.37, 2007/02/05 23:09:59 |
version 1.38, 2007/02/06 16:22:46 |
|
|
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';
|
|
|
|
|
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,
|
|
|
|
|
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)>,
|
|
|
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(
|
|
|
$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, @_ );
|
}
|
}
|
|
|
|
|
|
|
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 ) {
|
|
|
}
|
}
|
|
|
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,
|
);
|
);
|
}
|
}
|
|
|
|
|
# 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,
|
);
|
);
|
|
|
$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 );
|
|
|
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 );
|
}
|
}
|
|
|
}
|
}
|
}
|
}
|
if ( $cfg{'args'} ) {
|
if ( $cfg{'args'} ) {
|
$cmd{'String'} .= ' ' . $cfg{'args'};
|
$cmd{'String'} .= $SPACE . $cfg{'args'};
|
}
|
}
|
|
|
my @lines;
|
my @lines;
|
|
|
}
|
}
|
}
|
}
|
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;
|
}
|
}
|
}
|
}
|
|
|
|
|
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;
|
|
|
|
|
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" ) {
|
|
|
# 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 ']' ) {
|