This file is indexed.

/usr/share/perl5/TWatch/Config.pm is in libtwatch-perl 0.0.7-1.

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
package TWatch::Config;

=head1 NAME

TWatch::Config - Load project configuretion

=cut

use strict;
use warnings;
use utf8;

use File::Basename qw(dirname);
use File::Path qw(make_path);
use POSIX qw(strftime);

use base qw(Exporter);
our @EXPORT=qw(config notify DieDumper Dumper);

###############################################################################
# This section contains some paths for use in this program
# Edit this for some OS
# I think no any place to change. If it`s wrong, please inform me.
# (Except config file)
################################################################################
use constant TWATCH_SYSTEM_CONFIG_PATH  => '/etc/twatch/twatch.conf';
use constant TWATCH_CONFIG_PATH         => '~/.twatch/twatch.conf';
use constant TWATCH_LOG_PATH            => '~/.twatch/twatch.log';
###############################################################################

# Colors for highlight console output
use constant COLOR_RED      => "\e[1;31m";
use constant COLOR_GREEN    => "\e[1;32m";
use constant COLOR_YELLOW   => "\e[1;33m";
use constant COLOR_CLEAR    => "\e[0m";

=head1 CONSTRUCTOR

=cut

=head2 config

Load and cache configuratuon.
Use this funtction for access configuration params.

=cut

sub config
{
    our $config;
    return $config if $config;

    $config = TWatch::Config->new;
    return $config;
}

=head2 new

Load and return configuration object

=cut

sub new
{
    my ($class, %opts) = @_;
    my %config = (dir => {}, param => {});

    # Версии конфигов
    $config{dir}{config} = [
        TWATCH_SYSTEM_CONFIG_PATH,
        TWATCH_CONFIG_PATH,
    ];

    my $self = bless \%config ,$class;

    # Load config
    $self->load;

    # Check configuration
#    $self->check;

    # Create dirs (if not exists)
    $self->create_dir;

    # Open log file and print data
    my $path = TWATCH_LOG_PATH;
    $path =~ s/^~/$ENV{HOME}/;# glob $path;
    $self->set('Log', $path);
    open my $h, '+>>:encoding(UTF-8)', $path or die 'Can`t open log file: '.$!;
    printf $h "*** %s ***\n",
        POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime(time));
    $self->set('hLog', $h);

    return $self;
}

sub DESTROY
{
    my ($self) = @_;

    # Close log file
    if( $self->get('hLog') )
    {
        close $self->get('hLog')
            or die 'Can`t close log file: '.$!;
    }
}

################################################################################

=head1 METHODS

=cut

=head2 load

Load current config

=cut

sub load
{
    my ($self) = @_;

    # Flag successful loaded
    my $loaded = 'no';

    # Loading: first default config, next over users config
    for my $config ( @{$self->{dir}{config}} )
    {
        # Get abcoulete path
        ($config) = glob $config;

        # Next if file not exists
        next unless -f $config;

        # Open config file
        open my $file, '<', $config
            or warn sprintf('Can`t read config file %s : %s', $config, $!);
        next unless $file;

        # Read and parse file. Next hash write over previus configuration hash
        %{ $self->{param} } = (
            %{ $self->{param} },
            (
                map{ split m/\s*=\s*/, $_, 2 }
                grep m/=/,
                map { s/#\s.*//; s/^\s*#.*//; s/\s+$//; s/^\s+//; $_ } <$file>
            )
        );

        # Close file and mark successful loaded
        close $file;
        $loaded = 'yes';
    }

    # Exit if no one config exists
    die 'Config file not exists' unless $loaded eq 'yes';

    # Save original because it can be edit by user (twatch-gtk)
    %{ $self->{orig} } = %{ $self->{param} };

    # Transform some parameters for comfort usage
    $self->{param}{EmailLevel} = [ split ',', $self->{param}{EmailLevel} ];
    s/^\s*//, s/\s*$// for @{ $self->{param}{EmailLevel} };

    $self->{param}{NoProxy} =
        ($self->{param}{NoProxy} =~ m/^(1|yes|true|on)$/i) ?1 :0;

    return 1;
}

=head2 get $name

Get parameter by $name.

=cut

sub get
{
    my ($self, $name) = @_;
    return $self->{param}{$name};
}

=head2 get_orig $name

Get original (as in config file) parameter by $name.

=cut

sub get_orig
{
    my ($self, $name) = @_;
    return $self->{orig}{$name};
}

=head2 set $name, $value

Set new $value for parameter by $name.

=cut

sub set
{
    my ($self, $name, $value) = @_;
    $self->{param}{$name} = $value;
}

################################################################################

=head1 NOTIFICATIONS METHODS

=cut

=head2 notify $message, $level,  $wait

Send $message to standart output.
Param $level ( good|warn|bad ) highlight the message.
The $wait indicate print or not \n in the end of message.

=cut

sub notify
{
    my ($message, $level, $wait) = @_;

    # Skip unless message
    return unless $message;

    # Format message by module
    $message = ((' ') x 2) . $message if caller eq 'TWatch';
    $message = ((' ') x 4) . $message if caller eq 'TWatch::Project';
    $message = ((' ') x 6) . $message if caller eq 'TWatch::Watch';

    # Unless waiting flag print \n
    $message .= "\n" unless $wait;

    # Print to log file
    my $h = config->get('hLog');
    print $h $message;

    # Skip if output disabled
    return unless config->get('verbose');

    # Highlight message
    $level = lc $level || '';
    if( $level eq 'good' )
        { $message = COLOR_GREEN    . $message . COLOR_CLEAR  }
    elsif( $level eq 'warn' )
        { $message = COLOR_YELLOW   . $message . COLOR_CLEAR  }
    elsif( $level eq 'bad' )
        { $message = COLOR_RED      . $message . COLOR_CLEAR  }

    print $message;
}

################################################################################

=head1 MORE FUNCTIONS

=cut

=head2 create_dir

Create directories in user home path if it is not exists.

=cut

sub create_dir
{
    my ($self) = @_;

    # Create list of directories
    for my $param ('Save', 'Project', 'Complete')
    {
        # Get path
        my $path = $self->get($param);
        # Get absoulete path
        $path =~ s/^~/$ENV{HOME}/;# glob $path;
        # Set new absoulete path in configuration
        $self->set($param, $path);

        # Get dirs from params (It can consist mask and etc.)
        # (Save is a directory)
        my $dir = $path;
        $dir = dirname( $dir ) unless $param eq 'Save';
        # Next if directory exists
        next if -d $dir;
        # Create one
        eval{ make_path $dir; };
        die sprintf("Can`t create store directory: %s, %s\n", $dir, $@) if $@;
    }
}

################################################################################

=head1 DEBUG METHODS

=cut

=head2 DieDumper

Print all params and die

=cut

sub DieDumper
{
    require Data::Dumper;
    $Data::Dumper::Indent = 1;
    $Data::Dumper::Terse = 1;
    $Data::Dumper::Useqq = 1;
    $Data::Dumper::Deepcopy = 1;
    $Data::Dumper::Maxdepth = 0;
    my $dump = Data::Dumper->Dump([@_]);
    # юникодные символы преобразуем в них самих
    # вметсто \x{уродство}
    $dump=~s/(\\x\{[\da-fA-F]+\})/eval "qq{$1}"/eg;
    die $dump;
}

=head2 Dumper

Get all params description

=cut

sub Dumper
{
    require Data::Dumper;
    $Data::Dumper::Indent = 1;
    $Data::Dumper::Terse = 1;
    $Data::Dumper::Useqq = 1;
    $Data::Dumper::Deepcopy = 1;
    $Data::Dumper::Maxdepth = 0;
    my $dump = Data::Dumper->Dump([@_]);

    return $dump;
}

1;

=head1 REQUESTS & BUGS

Roman V. Nikolaev <rshadow@rambler.ru>

=head1 AUTHORS

Copyright (C) 2008 Roman V. Nikolaev <rshadow@rambler.ru>

=head1 LICENSE

This program is free software: you can redistribute  it  and/or  modify  it
under the terms of the GNU General Public License as published by the  Free
Software Foundation, either version 3 of the License, or (at  your  option)
any later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even  the  implied  warranty  of  MERCHANTABILITY  or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public  License  for
more details.

You should have received a copy of the GNU  General  Public  License  along
with this program.  If not, see <http://www.gnu.org/licenses/>.

=cut