This file is indexed.

/usr/share/perl5/App/ClusterSSH/Config.pm is in clusterssh 4.08-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
package App::ClusterSSH::Config;

use strict;
use warnings;

use version;
our $VERSION = version->new('0.02');

use Carp;
use Try::Tiny;

use FindBin qw($Script);
use File::Copy;

use base qw/ App::ClusterSSH::Base /;
use App::ClusterSSH::Cluster;

my $clusters;
my %old_clusters;
my @app_specific = (qw/ command title comms method parent /);

# list of config items to not write out when writing the default config
my @ignore_default_config = (qw/ user /);

my %default_config = (
    terminal                   => "xterm",
    terminal_args              => "",
    terminal_title_opt         => "-T",
    terminal_colorize          => 1,
    terminal_bg_style          => 'dark',
    terminal_allow_send_events => "-xrm '*.VT100.allowSendEvents:true'",
    terminal_font              => "6x13",
    terminal_size              => "80x24",

    use_hotkeys             => "yes",
    key_quit                => "Alt-q",
    key_addhost             => "Control-Shift-plus",
    key_clientname          => "Alt-n",
    key_history             => "Alt-h",
    key_localname           => "Alt-l",
    key_retilehosts         => "Alt-r",
    key_macros_enable       => "Alt-p",
    key_paste               => "Control-v",
    key_username            => "Alt-u",
    mouse_paste             => "Button-2",
    auto_quit               => "yes",
    auto_close              => 5,
    use_natural_sort        => 0,
    window_tiling           => "yes",
    window_tiling_direction => "right",
    console_position        => "",

    screen_reserve_top    => 0,
    screen_reserve_bottom => 60,
    screen_reserve_left   => 0,
    screen_reserve_right  => 0,

    terminal_reserve_top    => 5,
    terminal_reserve_bottom => 0,
    terminal_reserve_left   => 5,
    terminal_reserve_right  => 0,

    terminal_decoration_height => 10,
    terminal_decoration_width  => 8,

    console      => 'console',
    console_args => '',
    rsh          => 'rsh',
    rsh_args     => "",
    telnet       => 'telnet',
    telnet_args  => "",
    ssh          => 'ssh',
    ssh_args     => "",
    sftp         => 'sftp',
    sftp_args    => "",

    extra_tag_file           => '',
    extra_cluster_file       => '',
    external_cluster_command => '',

    unmap_on_redraw => "no",    # Debian #329440

    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 => '',
);

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;
}

sub parse_config_file {
    my ( $self, $config_file ) = @_;

    $self->debug( 2, 'Loading in config file: ', $config_file );

    #    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'
                ),
            );
        }
    }

    return if ( -f "$ENV{HOME}/.clusterssh/config" );

    if ( !-d "$ENV{HOME}/.clusterssh" ) {
        if ( !mkdir("$ENV{HOME}/.clusterssh") ) {
            croak(
                App::ClusterSSH::Exception::Config->throw(
                    error => $self->loc(
                        'Unable to create directory [_1]: [_2]' . $/,
                        '$HOME/.clusterssh', $!
                    ),
                ),
            );

        }
    }

    # Debian #673507 - migrate clusters prior to writing ~/.clusterssh/config
    # in order to update the extra_cluster_file property
    if (%old_clusters) {
        if ( open( my $fh, ">", "$ENV{HOME}/.clusterssh/clusters" ) ) {
            print $fh '# '
                . $self->loc('Tag definitions moved from old .csshrc file'),
                $/;
            foreach ( sort( keys(%old_clusters) ) ) {
                print $fh $_, ' ', join( ' ', $old_clusters{$_} ), $/;
            }
            close($fh);
        }
        else {
            croak(
                App::ClusterSSH::Exception::Config->throw(
                    error => $self->loc(
                        'Unable to write [_1]: [_2]' . $/,
                        '$HOME/.clusterssh/clusters',
                        $!
                    ),
                ),
            );
        }
    }

    if ( open( CONFIG, ">", "$ENV{HOME}/.clusterssh/config" ) ) {
        foreach ( sort( keys(%$self) ) ) {
            my $comment = '';
            if ( grep /$_/, @ignore_default_config ) {
                $comment = '#';
            }
            print CONFIG ${comment}, $_, '=', $self->{$_}, $/;
        }
        close(CONFIG);
        warn(
            $self->loc(
                'Created new configuration file within [_1]' . $/,
                '$HOME/.clusterssh/'
            )
        );
    }
    else {
        croak(
            App::ClusterSSH::Exception::Config->throw(
                error => $self->loc(
                    'Unable to write default [_1]: [_2]' . $/,
                    '$HOME/.clusterssh/config', $!
                ),
            ),
        );
    }

    return $self;
}

# search given directories for the given file
sub search_dirs {
    my ( $self, $file, @directories ) = @_;

    my $path;

    foreach my $dir (@directories) {
        $self->debug( 3, "Looking for $file in $dir" );

        if ( -f $dir . '/' . $file && -x $dir . '/' . $file ) {
            $path = $dir . '/' . $file;
            $self->debug( 2, "Found at $path" );
            last;
        }
    }

    return $path;
}

# could use File::Which for some of this but we also search a few other places
# just in case $PATH isnt set up right
sub find_binary {
    my ( $self, $binary ) = @_;

    if ( !$binary ) {
        croak(
            App::ClusterSSH::Exception::Config->throw(
                error => $self->loc('argument not provided') . $/,
            ),
        );
    }

    $self->debug( 2, "Looking for $binary" );

    # if not found, strip the path and look again
    if ( $binary =~ m!^/! ) {
        if ( -f $binary ) {
            $self->debug( 2, "Already have full path to in $binary" );
            return $binary;
        }
        else {
            $self->debug( 2, "Full path for $binary incorrect; searching" );
            $binary =~ s!^.*/!!;
        }
    }

    my $path;
    if ( !-x $binary || substr( $binary, 0, 1 ) ne '/' ) {
        $path = $self->search_dirs( $binary, split( /:/, $ENV{PATH} ) );

        # if it is on $PATH then no need to qualitfy the path to it
        # keep it as it is
        if ($path) {
            return $binary;
        }
        else {
            $path = $self->search_dirs(
                $binary, qw!
                    /bin
                    /sbin
                    /usr/sbin
                    /usr/bin
                    /usr/local/bin
                    /usr/local/sbin
                    /opt/local/bin
                    /opt/local/sbin
                    !
            );
        }

    }
    else {
        $self->debug( 2, "Already configured OK" );
        $path = $binary;
    }
    if ( !$path || !-f $path || !-x $path ) {
        croak(
            App::ClusterSSH::Exception::Config->throw(
                error => $self->loc(
                    '"[_1]" binary not found - please amend $PATH or the cssh config file'
                        . $/,
                    $binary
                ),
            ),
        );
    }

    chomp($path);
    return $path;
}

sub dump {
    my ( $self, $no_exit, ) = @_;

    $self->debug( 3, 'Dumping config to STDOUT' );
    print( '# Configuration dump produced by "cssh -u"', $/ );

    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-2015 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;