App-ClusterSSH
view release on metacpan or search on metacpan
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
show_history => 0,
history_width => 40,
history_height => 10,
command => q{},
hide_menu => 0,
max_host_menu_items => 30,
macros_enabled => 'yes',
macro_servername => '%s',
macro_hostname => '%h',
macro_username => '%u',
macro_newline => '%n',
macro_version => '%v',
max_addhost_menu_cluster_items => 6,
menu_send_autotearoff => 0,
menu_host_autotearoff => 0,
unique_servers => 0,
use_all_a_records => 0,
send_menu_xml_file => $ENV{HOME} . '/.clusterssh/send_menu',
auto_wm_decoration_offsets => "no", # Debian #842965
# don't set username here as takes precendence over ssh config
user => '',
rows => -1,
cols => -1,
fillscreen => "no",
);
sub new {
my ( $class, %args ) = @_;
my $self = $class->SUPER::new(%default_config);
( my $comms = $Script ) =~ s/^c//;
$comms = 'telnet' if ( $comms eq 'tel' );
$comms = 'console' if ( $comms eq 'con' );
$comms = 'ssh' if ( $comms eq 'lusterssh' );
$comms = 'sftp' if ( $comms eq 'sftp' );
# list of allowed comms methods
if ( 'ssh rsh telnet sftp console' !~ m/\b$comms\b/ ) {
$self->{comms} = 'ssh';
}
else {
$self->{comms} = $comms;
}
$self->{title} = uc($Script);
$clusters = App::ClusterSSH::Cluster->new();
return $self->validate_args(%args);
}
sub validate_args {
my ( $self, %args ) = @_;
my @unknown_config = ();
foreach my $config ( sort( keys(%args) ) ) {
if ( grep /$config/, @app_specific ) {
# $self->{$config} ||= 'unknown';
next;
}
if ( exists $self->{$config} ) {
$self->{$config} = $args{$config};
}
else {
push( @unknown_config, $config );
}
}
if (@unknown_config) {
croak(
App::ClusterSSH::Exception::Config->throw(
unknown_config => \@unknown_config,
error => $self->loc(
'Unknown configuration parameters: [_1]' . $/,
join( ',', @unknown_config )
)
)
);
}
if ( !$self->{comms} ) {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc( 'Invalid variable: comms' . $/ ),
),
);
}
if ( !$self->{ $self->{comms} } ) {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc(
'Invalid variable: [_1]' . $/,
$self->{comms}
),
),
);
}
# check the terminal has been found correctly
# looking for the terminal should not be fatal
if ( !-e $self->{terminal} ) {
eval { $self->{terminal} = $self->find_binary( $self->{terminal} ); };
if ($@) {
warn $@->message;
}
}
return $self;
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
# if ( !-e $config_file || !-r $config_file ) {
# croak(
# App::ClusterSSH::Exception::Config->throw(
# error => $self->loc(
# 'File [_1] does not exist or cannot be read' . $/,
# $config_file
# ),
# ),
# );
# }
#
# open( CFG, $config_file ) or die("Couldnt open $config_file: $!");
# my $l;
# my %read_config;
# while ( defined( $l = <CFG> ) ) {
# next
# if ( $l =~ /^\s*$/ || $l =~ /^#/ )
# ; # ignore blank lines & commented lines
# $l =~ s/#.*//; # remove comments from remaining lines
# $l =~ s/\s*$//; # remove trailing whitespace
#
# # look for continuation lines
# chomp $l;
# if ( $l =~ s/\\\s*$// ) {
# $l .= <CFG>;
# redo unless eof(CFG);
# }
#
# next unless $l =~ m/\s*(\S+)\s*=\s*(.*)\s*/;
# my ( $key, $value ) = ( $1, $2 );
# if ( defined $key && defined $value ) {
# $read_config{$key} = $value;
# $self->debug( 3, "$key=$value" );
# }
# }
# close(CFG);
my %read_config;
%read_config
= $self->load_file( type => 'config', filename => $config_file );
# grab any clusters from the config before validating it
if ( $read_config{clusters} ) {
$self->debug( 3, "Picked up clusters defined in $config_file" );
foreach my $cluster ( sort split / /, $read_config{clusters} ) {
if ( $read_config{$cluster} ) {
$clusters->register_tag( $cluster,
split( / /, $read_config{$cluster} ) );
$old_clusters{$cluster} = $read_config{$cluster};
delete( $read_config{$cluster} );
}
}
delete( $read_config{clusters} );
}
# tidy up entries, just in case
$read_config{terminal_font} =~ s/['"]//g
if ( $read_config{terminal_font} );
$self->validate_args(%read_config);
}
sub load_configs {
my ( $self, @configs ) = @_;
for my $config (
'/etc/csshrc',
$ENV{HOME} . '/.csshrc',
$ENV{HOME} . '/.clusterssh/config',
)
{
$self->parse_config_file($config) if ( -e $config );
}
# write out default config file if necesasry
try {
$self->write_user_config_file();
}
catch {
warn $_, $/;
};
# Attempt to load in provided config files. Also look for anything
# relative to config directory
for my $config (@configs) {
next unless ($config); # can be null when passed from Getopt::Long
$self->parse_config_file($config) if ( -e $config );
my $file = $ENV{HOME} . '/.clusterssh/config_' . $config;
$self->parse_config_file($file) if ( -e $file );
}
return $self;
}
sub write_user_config_file {
my ($self) = @_;
# attempt to move the old config file to one side
if ( -f "$ENV{HOME}/.csshrc" ) {
eval { move( "$ENV{HOME}/.csshrc", "$ENV{HOME}/.csshrc.DISABLED" ) };
if ($@) {
croak(
App::ClusterSSH::Exception::Config->throw(
error => $self->loc(
'Unable to move [_1] to [_2]: [_3]' . $/,
'$HOME/.csshrc', '$HOME/.csshrc.DISABLED', $@
),
)
);
}
else {
warn(
$self->loc(
'Moved [_1] to [_2]' . $/, '$HOME/.csshrc',
'$HOME/.csshrc.DISABLED'
),
);
}
lib/App/ClusterSSH/Config.pm view on Meta::CPAN
}
chomp($path);
return $path;
}
sub dump {
my ( $self, $no_exit, ) = @_;
$self->debug( 3, 'Dumping config to STDOUT' );
print( '# Configuration dump produced by "cssh -d"', $/ );
foreach my $key ( sort keys %$self ) {
my $comment = '';
if ( grep /$key/, @app_specific ) {
next;
}
if ( grep /$key/, @ignore_default_config ) {
$comment = '#';
}
print $comment, $key, '=', $self->{$key}, $/;
}
$self->exit if ( !$no_exit );
}
#use overload (
# q{""} => sub {
# my ($self) = @_;
# return $self->{hostname};
# },
# fallback => 1,
#);
1;
=pod
=head1 NAME
ClusterSSH::Config - Object representing application configuration
=head1 SYNOPSIS
=head1 DESCRIPTION
Object representing application configuration
=head1 METHODS
=over 4
=item $host=ClusterSSH::Config->new ({ })
Create a new configuration object.
=item $config->parse_config_file('<filename>');
Read in configuration from given filename
=item $config->validate_args();
Validate and apply all configuration loaded at this point
=item $path = $config->search_dirs('<name>', @seaarch_directories);
Search the given directories for the name given. Return undef if not found.
=item $path = $config->find_binary('<name>');
Locate the binary <name> and return the full path. Doesn't just search
$PATH in case the environment isn't set up correctly
=item $config->load_configs(@extra);
Load up configuration from known locations (warn if .csshrc file found) and
load in option files as necessary.
=item $config->write_user_config_file();
Write out default $HOME/.clusterssh/config file (before option config files
are loaded).
=item $config->dump()
Write currently defined configuration to STDOUT
=back
=head1 AUTHOR
Duncan Ferguson, C<< <duncan_j_ferguson at yahoo.co.uk> >>
=head1 LICENSE AND COPYRIGHT
Copyright 1999-2016 Duncan Ferguson.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1;
( run in 0.409 second using v1.01-cache-2.11-cpan-140bd7fdf52 )