Merge branch 'start_again'

This commit is contained in:
Duncan Ferguson 2010-06-18 23:50:11 +01:00
commit c300718131
7 changed files with 2405 additions and 2303 deletions

View file

@ -1,6 +1,9 @@
????-??-?? Duncan Ferguson <duncan_ferguson@user.sf.net> - v4.00_02
* Add in bugtracker and homepage resources to Build.PL file
* Bring new module App::ClusterSSH::Host into play for parsing host strings
* Patch to override font used on command line (Roland Rosenfeld)
* Put options in cssh pod into alphabetical order
2010-01-08 Duncan Ferguson <duncan_ferguson@user.sf.net> - v4.00_01

3
THANKS
View file

@ -33,5 +33,4 @@ Sami Kerola
Kristian Lyngstol
Mike Loseke
Ian Marsh
$Id$
Roland Rosenfeld

2232
bin/cssh

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -63,6 +63,7 @@ sub _translate {
sub loc {
my ( $self, @args ) = @_;
$_ ||= q{} foreach (@args);
return _translate(@args);
}

View file

@ -53,7 +53,7 @@ sub new {
sub get_givenname {
my ($self) = @_;
return $self->{givenname};
return $self->{hostname};
}
sub get_hostname {
@ -63,7 +63,7 @@ sub get_hostname {
sub get_username {
my ($self) = @_;
return $self->{username};
return $self->{username} || q{};
}
sub set_username {
@ -74,7 +74,7 @@ sub set_username {
sub get_port {
my ($self) = @_;
return $self->{port};
return $self->{port} || q{};
}
sub set_port {
@ -152,11 +152,11 @@ sub parse_host_string {
# Check for unbracketed IPv6 addresses as best we can...
# first, see if there is a username to grab
my $username;
my $username = q[];
if ( $host_string =~ s/\A(?:(.*)@)// ) {
# catch where @ is in host_string but no text before it
$username = $1 || undef;
$username = $1 || q{};
}
# use number of colons as a possible indicator
@ -170,11 +170,10 @@ sub parse_host_string {
parse_string => $parse_string,
username => $username,
hostname => $host_string,
port => undef,
port => q{},
type => 'ipv6',
);
}
if ( $colon_count > 1
&& $colon_count < 8
&& $host_string =~ m/:(\d+)$/xsm )
@ -184,16 +183,21 @@ sub parse_host_string {
$self->debug( 5, $self->loc( 'Ambiguous IPv6 u=[_1] h=[_2] p=[_3]', $username, $host_string, '' ) );
#warn "host_string=$host_string";
#warn "username=$username";
#warn $self->loc('some string to return');
#warn 'debug done, returning';
return __PACKAGE__->new(
parse_string => $parse_string,
username => $username,
hostname => $host_string,
port => undef,
port => q{},
type => 'ipv6',
);
}
else {
my $port;
my $port = q{};
if ( $host_string =~ s/:(\d+)$// ) {
$port = $1;
}
@ -281,10 +285,25 @@ Return specific details about the host
Set specific details about the host after its been created.
=item get_realname
If the server name provided is not an IP address (either IPv4 or IPv6)
attempt to resolve it and retun the discovered names.
=item get_givenname
Alias to get_hostname, for use when C< get_realname > might return something
different
=item parse_host_string
Given a host string, returns a host object. Parses hosts such as
=item check_ssh_hostname
Check the objects hostname to see whether or not it may be configured within
the users F< $HOME/.ssh/config > configuration file
=over 4
=item host

View file

@ -12,14 +12,18 @@ BEGIN { use_ok("App::ClusterSSH::Host") }
my $host;
eval { $host = App::ClusterSSH::Host->new(); };
like( $@, qr/hostname is undefined/, 'eval error - hostname is undefined (method)' );
like(
$@,
qr/hostname is undefined/,
'eval error - hostname is undefined (method)'
);
diag('Checking IPv4 type addresses') if ( $ENV{TEST_VERBOSE} );
$host = App::ClusterSSH::Host->new( hostname => 'hostname' );
is( $host, 'hostname', 'stringify works' );
is( $host->get_hostname, 'hostname', 'hostname set' );
is( $host->get_port, undef, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_port, q{}, 'checking set works' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, 'hostname', 'realname set' );
$host->set_port(2323);
@ -27,14 +31,14 @@ $host->set_port(2323);
is( $host, 'hostname', 'stringify works' );
is( $host->get_hostname, 'hostname', 'checking set works' );
is( $host->get_port, 2323, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, 'hostname', 'realname set' );
$host->set_username('username');
is( $host->get_hostname, 'hostname', 'checking set works' );
is( $host->get_port, 2323, 'checking set works' );
is( $host->get_username, 'username', 'username is undef' );
is( $host->get_username, 'username', 'username is unset' );
is( $host->get_realname, 'hostname', 'realname set' );
$host = undef;
@ -45,8 +49,8 @@ isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, 'hostname', 'stringify works' );
is( $host->get_hostname, 'hostname', 'hostname set' );
is( $host->get_port, undef, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_port, q{}, 'checking set works' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, 'hostname', 'realname set' );
$host->set_port(2323);
@ -54,14 +58,14 @@ $host->set_port(2323);
is( $host, 'hostname', 'stringify works' );
is( $host->get_hostname, 'hostname', 'checking set works' );
is( $host->get_port, 2323, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, 'hostname', 'realname set' );
$host->set_username('username');
is( $host->get_hostname, 'hostname', 'checking set works' );
is( $host->get_port, 2323, 'checking set works' );
is( $host->get_username, 'username', 'username is undef' );
is( $host->get_username, 'username', 'username is unset' );
is( $host->get_realname, 'hostname', 'realname set' );
$host = undef;
@ -76,14 +80,14 @@ isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, 'hostname', 'stringify works' );
is( $host->get_hostname, 'hostname', 'hostname set' );
is( $host->get_port, 2323, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, 'hostname', 'realname set' );
$host->set_username('username');
is( $host->get_hostname, 'hostname', 'checking set works' );
is( $host->get_port, 2323, 'checking set works' );
is( $host->get_username, 'username', 'username is undef' );
is( $host->get_username, 'username', 'username is unset' );
is( $host->get_realname, 'hostname', 'realname set' );
$host = undef;
@ -97,7 +101,7 @@ isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, 'hostname', 'stringify works' );
is( $host->get_hostname, 'hostname', 'hostname set' );
is( $host->get_port, undef, 'checking set works' );
is( $host->get_port, q{}, 'checking set works' );
is( $host->get_username, 'username', 'username is set' );
is( $host->get_realname, 'hostname', 'realname set' );
@ -134,16 +138,16 @@ $host = App::ClusterSSH::Host->parse_host_string('hostname');
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, 'hostname', 'stringify works' );
is( $host->get_hostname, 'hostname', 'checking set works' );
is( $host->get_port, undef, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_port, q{}, 'checking set works' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, 'hostname', 'realname set' );
$host = App::ClusterSSH::Host->parse_host_string('host%name');
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, 'host%name', 'stringify works' );
is( $host->get_hostname, 'host%name', 'checking set works' );
is( $host->get_port, undef, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_port, q{}, 'checking set works' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, 'host%name', 'realname set' );
$host = undef;
@ -154,7 +158,7 @@ isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, 'hostname', 'stringify works' );
is( $host->get_hostname, 'hostname', 'checking set works' );
is( $host->get_port, 2323, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, 'hostname', 'realname set' );
$host = App::ClusterSSH::Host->parse_host_string('host%name:2323');
@ -162,7 +166,7 @@ isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, 'host%name', 'stringify works' );
is( $host->get_hostname, 'host%name', 'checking set works' );
is( $host->get_port, 2323, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, 'host%name', 'realname set' );
$host = undef;
@ -191,7 +195,7 @@ $host = App::ClusterSSH::Host->parse_host_string('username@hostname');
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, 'hostname', 'stringify works' );
is( $host->get_hostname, 'hostname', 'checking set works' );
is( $host->get_port, undef, 'checking set works' );
is( $host->get_port, q{}, 'checking set works' );
is( $host->get_username, 'username', 'username is set' );
is( $host->get_realname, 'hostname', 'realname set' );
@ -199,7 +203,7 @@ $host = App::ClusterSSH::Host->parse_host_string('username@host%name');
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, 'host%name', 'stringify works' );
is( $host->get_hostname, 'host%name', 'checking set works' );
is( $host->get_port, undef, 'checking set works' );
is( $host->get_port, q{}, 'checking set works' );
is( $host->get_username, 'username', 'username is set' );
is( $host->get_realname, 'host%name', 'realname set' );
@ -209,8 +213,8 @@ $host = App::ClusterSSH::Host->parse_host_string('127.0.0.1');
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, '127.0.0.1', 'stringify works' );
is( $host->get_hostname, '127.0.0.1', 'checking set works' );
is( $host->get_port, undef, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_port, q{}, 'checking set works' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, '127.0.0.1', 'realname set' );
$host = undef;
@ -222,7 +226,7 @@ isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, '127.0.0.1', 'stringify works' );
is( $host->get_hostname, '127.0.0.1', 'checking set works' );
is( $host->get_port, 2323, 'checking set works' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, '127.0.0.1', 'realname set' );
$host = undef;
@ -244,7 +248,7 @@ isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, '127.0.0.1', 'stringify works' );
is( $host->get_hostname, '127.0.0.1', 'checking set works' );
is( $host->get_port, undef, 'checking set works' );
is( $host->get_port, q{}, 'checking set works' );
is( $host->get_username, 'username', 'username is set' );
is( $host->get_realname, '127.0.0.1', 'realname set' );
@ -257,8 +261,8 @@ $host = App::ClusterSSH::Host->parse_host_string('::1');
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, '::1', 'stringify works' );
is( $host->get_hostname, '::1', 'checking set works' );
is( $host->get_port, undef, 'port is undef' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_port, q{}, 'port is unset' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, '::1', 'realname set' );
$host = undef;
@ -268,9 +272,9 @@ $host = App::ClusterSSH::Host->parse_host_string('username@::1');
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, '::1', 'stringify works' );
is( $host->get_hostname, '::1', 'checking set works' );
is( $host->get_port, undef, 'port is undef' );
is( $host->get_port, q{}, 'port is unset' );
is( $host->get_username, 'username', 'username is set' );
is( $host->get_realname, '::1', 'realname set' );
is( $host->get_realname, '::1', 'realname set' );
$host = undef;
is( $host, undef, 'starting afresh' );
@ -279,8 +283,8 @@ $host = App::ClusterSSH::Host->parse_host_string('[::1]');
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, '::1', 'stringify works' );
is( $host->get_hostname, '::1', 'checking set works' );
is( $host->get_port, undef, 'port is undef' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_port, q{}, 'port is unset' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, '::1', 'realname set' );
$host = undef;
@ -290,9 +294,9 @@ $host = App::ClusterSSH::Host->parse_host_string('username@[::1]');
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, '::1', 'stringify works' );
is( $host->get_hostname, '::1', 'checking set works' );
is( $host->get_port, undef, 'port is undef' );
is( $host->get_port, q{}, 'port is unset' );
is( $host->get_username, 'username', 'username is set' );
is( $host->get_realname, '::1', 'realname set' );
is( $host->get_realname, '::1', 'realname set' );
$host = undef;
is( $host, undef, 'starting afresh' );
@ -302,7 +306,7 @@ isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, '::1', 'stringify works' );
is( $host->get_hostname, '::1', 'checking set works' );
is( $host->get_port, 22, 'checking port set' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, '::1', 'realname set' );
$host = undef;
@ -314,66 +318,96 @@ is( $host, '::1', 'stringify works' );
is( $host->get_hostname, '::1', 'checking set works' );
is( $host->get_port, 22, 'checking port set' );
is( $host->get_username, 'username', 'username is set' );
is( $host->get_realname, '::1', 'realname set' );
is( $host->get_realname, '::1', 'realname set' );
$host = undef;
is( $host, undef, 'starting afresh' );
$host = App::ClusterSSH::Host->parse_host_string('2001:0db8:85a3:0000:0000:8a2e:0370:7334');
$host = App::ClusterSSH::Host->parse_host_string(
'2001:0db8:85a3:0000:0000:8a2e:0370:7334');
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'stringify works' );
is( $host->get_hostname, '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'checking set works' );
is( $host->get_port, undef, 'port is undef' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_realname, '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'realname set' );
is( $host, '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'stringify works' );
is( $host->get_hostname,
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
'checking set works'
);
is( $host->get_port, q{}, 'port is unset' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
'realname set' );
$host = undef;
is( $host, undef, 'starting afresh' );
trap {
$host = App::ClusterSSH::Host->parse_host_string('2001:0db8:85a3::8a2e:0370:7334');
$host = App::ClusterSSH::Host->parse_host_string(
'2001:0db8:85a3::8a2e:0370:7334');
};
is( $trap->leaveby, 'return', 'returned ok' );
is( $trap->die, undef, 'returned ok' );
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, '2001:0db8:85a3::8a2e:0370:7334', 'stringify works' );
is( $trap->stdout, '', 'Expecting no STDOUT' );
is( $trap->stdout, q{}, 'Expecting no STDOUT' );
is( $trap->stderr =~ tr/\n//, 2, 'got correct number of print lines' );
like( $trap->stderr, qr/^Ambiguous host string: "2001:0db8:85a3::8a2e:0370:7334/, 'checking warning output' );
like( $trap->stderr, qr/Assuming you meant "\[2001:0db8:85a3::8a2e:0370:7334\]"?/, 'checking warning output' );
like(
$trap->stderr,
qr/^Ambiguous host string: "2001:0db8:85a3::8a2e:0370:7334/,
'checking warning output'
);
like(
$trap->stderr,
qr/Assuming you meant "\[2001:0db8:85a3::8a2e:0370:7334\]"?/,
'checking warning output'
);
is( $host->get_hostname, '2001:0db8:85a3::8a2e:0370:7334', 'checking set works' );
is( $host->get_port, undef, 'port is undef' );
is( $host->get_username, undef, 'username is undef' );
is( $host->get_hostname,
'2001:0db8:85a3::8a2e:0370:7334',
'checking set works'
);
is( $host->get_port, q{}, 'port is unset' );
is( $host->get_username, q{}, 'username is unset' );
is( $host->get_realname, '2001:0db8:85a3::8a2e:0370:7334', 'realname set' );
$host = undef;
is( $host, undef, 'starting afresh' );
trap {
$host = App::ClusterSSH::Host->new( hostname => 'ssh_test', ssh_config => $Bin . '/10host_ssh_config', );
$host = App::ClusterSSH::Host->new(
hostname => 'ssh_test',
ssh_config => $Bin . '/10host_ssh_config',
);
};
is( $trap->leaveby, 'return', 'returned ok' );
is( $trap->die, undef, 'returned ok' );
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, 'ssh_test', 'stringify works' );
is( $host->check_ssh_hostname, 0, 'check_ssh_hostname ok for ssh_test', );
is( $host, 'ssh_test', 'stringify works' );
is( $host->check_ssh_hostname, 0, 'check_ssh_hostname ok for ssh_test', );
for my $hostname ( 'server1', 'server2', 'server3', 'server4', 'server-5', 'server5.domain.name', 'server-6.domain.name' ) {
for my $hostname (
'server1', 'server2',
'server3', 'server4',
'server-5', 'server5.domain.name',
'server-6.domain.name'
)
{
$host = undef;
is( $host, undef, 'starting afresh for ssh hostname checks' );
trap {
$host = App::ClusterSSH::Host->new( hostname => $hostname, ssh_config => $Bin . '/10host_ssh_config', );
$host = App::ClusterSSH::Host->new(
hostname => $hostname,
ssh_config => $Bin . '/10host_ssh_config',
);
};
is( $trap->leaveby, 'return', 'returned ok' );
is( $trap->die, undef, 'returned ok' );
isa_ok( $host, "App::ClusterSSH::Host" );
is( $host, $hostname, 'stringify works' );
is( $host->check_ssh_hostname, 1, 'check_ssh_hostname ok for '. $hostname );
is( $host->get_realname, $hostname, 'realname set' );
is( $host, $hostname, 'stringify works' );
is( $host->check_ssh_hostname, 1,
'check_ssh_hostname ok for ' . $hostname );
is( $host->get_realname, $hostname, 'realname set' );
}