This file is indexed.

/usr/share/perl5/ClamTk/Schedule.pm is in clamtk 5.20-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
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
# ClamTk, copyright (C) 2004-2015 Dave M
#
# This file is part of ClamTk (http://code.google.com/p/clamtk/).
#
# ClamTk is free software; you can redistribute it and/or modify it
# under the terms of either:
#
# a) the GNU General Public License as published by the Free Software
# Foundation; either version 1, or (at your option) any later version, or
#
# b) the "Artistic License".
package ClamTk::Schedule;

# I haven't found a cross-distro Perl module for
# scheduling, so we have call crontab as a system command.

# use strict;
# use warnings;
$| = 1;

use POSIX 'locale_h';
use Locale::gettext;

use Glib 'TRUE', 'FALSE';

use open ':encoding(utf8)';

# This should be under /usr/bin, but we'll check anyway.
my $cmd
    = ( -e '/usr/bin/crontab' ) ? '/usr/bin/crontab'
    : ( -e '/usr/local/bin/crontab' ) ? '/usr/local/bin/crontab'
    : ( -e '/bin/crontab' )           ? '/bin/crontab'
    :                                   '';
chomp( $cmd );

my ( $scan_status_label, $defs_status_label );

my ( $hour_spin_av,   $min_spin_av );
my ( $hour_spin_scan, $min_spin_scan );
my ( $hour_spin_defs, $min_spin_defs );
my ( $scan_apply_btn, $scan_remove_btn );
my ( $defs_apply_btn, $defs_remove_btn );

sub show_window {
    my $dialog
        = Gtk2::Dialog->new( _( 'Schedule' ), undef, 'destroy-with-parent' );
    $dialog->signal_connect( close   => sub { $dialog->destroy } );
    $dialog->signal_connect( destroy => sub { Gtk2->main_quit } );

    my $ebox = Gtk2::EventBox->new;
    #$ebox->modify_bg( 'normal',
    #    Gtk2::Gdk::Color->new( 0xFFFF, 0xFFFF, 0xFFFF ) );
    $dialog->get_content_area->add( $ebox );
    $dialog->set_position( 'mouse' );

    my $vbox = Gtk2::VBox->new( FALSE, 5 );
    $ebox->add( $vbox );

    ################
    # scan options #
    ################

    my $scan_frame = Gtk2::Frame->new( _( 'Scan' ) );
    $vbox->pack_start( $scan_frame, FALSE, FALSE, 5 );
    my $scan_box = Gtk2::VBox->new( FALSE, 5 );
    $scan_frame->add( $scan_box );

    my $label = Gtk2::Label->new(
        _( 'Select a time to scan your home directory' ) );
    $scan_box->pack_start( $label, FALSE, FALSE, 5 );

    $label
        = Gtk2::Label->new( _( 'Set the scan time using a 24 hour clock' ) );
    $scan_box->pack_start( $label, FALSE, FALSE, 5 );

    my $time_hbox = Gtk2::HBox->new;
    $scan_box->pack_start( $time_hbox, FALSE, FALSE, 0 );

    $hour_spin_scan = Gtk2::SpinButton->new_with_range( 0, 23, 1 );
    $time_hbox->pack_start( $hour_spin_scan, TRUE, TRUE, 5 );
    $hour_spin_scan->set_wrap( TRUE );
    $hour_spin_scan->set_tooltip_text(
        _( 'Set the hour using a 24 hour clock' ) );
    my $hour_label = Gtk2::Label->new( _( 'Hour' ) );
    $hour_label->set_alignment( 0.0, 0.5 );
    $time_hbox->pack_start( $hour_label, FALSE, TRUE, 5 );

    $min_spin_scan = Gtk2::SpinButton->new_with_range( 0, 59, 1 );
    $min_spin_scan->set_wrap( TRUE );
    $time_hbox->pack_start( $min_spin_scan, TRUE, TRUE, 5 );
    my $min_label = Gtk2::Label->new( _( 'Minute' ) );
    $min_label->set_alignment( 0.0, 0.5 );
    $time_hbox->pack_start( $min_label, FALSE, TRUE, 5 );

    my $time_bar = Gtk2::Toolbar->new;
    $scan_box->pack_start( $time_bar, FALSE, FALSE, 0 );
    $time_bar->set_style( 'icons' );

    my $dsep = Gtk2::SeparatorToolItem->new;
    $dsep->set_draw( FALSE );
    $dsep->set_expand( TRUE );
    $time_bar->insert( $dsep, -1 );

    $scan_apply_btn = Gtk2::ToolButton->new_from_stock( 'gtk-add' );
    $time_bar->insert( $scan_apply_btn, -1 );
    $scan_apply_btn->signal_connect( 'clicked' => \&apply_scan );

    $time_bar->insert( Gtk2::SeparatorToolItem->new, -1 );

    $scan_remove_btn = Gtk2::ToolButton->new_from_stock( 'gtk-remove' );
    $time_bar->insert( $scan_remove_btn, -1 );
    $scan_remove_btn->signal_connect(
        'clicked' => sub {
            remove( 'clamtk-scan' );
        }
    );

    ###############################
    # antivirus signature options #
    ###############################

    my $defs_frame = Gtk2::Frame->new( _( 'Antivirus signatures' ) );
    $vbox->pack_start( $defs_frame, FALSE, FALSE, 5 );

    my $defs_vbox = Gtk2::VBox->new;
    $defs_frame->add( $defs_vbox );

    $label
        = Gtk2::Label->new( _( 'Select a time to update your signatures' ) );
    $defs_vbox->pack_start( $label, FALSE, FALSE, 5 );

    my $defs_hbox = Gtk2::HBox->new;
    $defs_vbox->pack_start( $defs_hbox, FALSE, FALSE, 0 );

    $hour_spin_defs = Gtk2::SpinButton->new_with_range( 0, 23, 1 );
    $defs_hbox->pack_start( $hour_spin_defs, TRUE, TRUE, 5 );
    $hour_spin_defs->set_wrap( TRUE );
    $hour_spin_defs->set_tooltip_text(
        _( 'Set the hour using a 24 hour clock' ) );
    $label = Gtk2::Label->new( _( 'Hour' ) );
    $defs_hbox->pack_start( $label, FALSE, TRUE, 5 );

    $min_spin_defs = Gtk2::SpinButton->new_with_range( 0, 59, 1 );
    $min_spin_defs->set_wrap( TRUE );
    $defs_hbox->pack_start( $min_spin_defs, TRUE, TRUE, 5 );
    $label = Gtk2::Label->new( _( 'Minute' ) );
    $defs_hbox->pack_start( $label, FALSE, TRUE, 5 );

    my $defs_hbb = Gtk2::HButtonBox->new;
    $defs_vbox->pack_start( $defs_hbb, FALSE, FALSE, 0 );
    $defs_hbb->set_layout( 'end' );

    my $defs_bar = Gtk2::Toolbar->new;
    $defs_vbox->pack_start( $defs_bar, FALSE, FALSE, 0 );
    $defs_bar->set_style( 'icons' );

    $dsep = Gtk2::SeparatorToolItem->new;
    $dsep->set_draw( FALSE );
    $dsep->set_expand( TRUE );
    $defs_bar->insert( $dsep, -1 );

    my $can_update
        = ( ClamTk::Prefs->get_preference( 'Update' ) eq 'shared' )
        ? FALSE
        : TRUE;

    $defs_apply_btn = Gtk2::ToolButton->new_from_stock( 'gtk-add' );
    if ( $can_update ) {
        $defs_bar->insert( $defs_apply_btn, -1 );
        $defs_apply_btn->signal_connect( 'clicked' => \&apply_defs );
    }

    $defs_bar->insert( Gtk2::SeparatorToolItem->new, -1 );

    $defs_remove_btn = Gtk2::ToolButton->new_from_stock( 'gtk-remove' );
    $defs_bar->insert( $defs_remove_btn, -1 );
    $defs_remove_btn->signal_connect(
        'clicked' => sub {
            remove( 'clamtk-defs' );
        }
    );

    ##########
    # status #
    ##########

    my $status_frame = Gtk2::Frame->new( _( 'Status' ) );
    $vbox->pack_start( $status_frame, FALSE, FALSE, 5 );

    my $status_box = Gtk2::VBox->new( TRUE, 5 );
    $status_frame->add( $status_box );

    # By default, put the label in; helps with spacing and what not
    $scan_status_label = Gtk2::Label->new;
    $status_box->pack_start( $scan_status_label, FALSE, FALSE, 0 );
    $scan_status_label->set_text( _( 'A daily scan is scheduled' ) );

    $defs_status_label = Gtk2::Label->new;
    $status_box->pack_start( $defs_status_label, FALSE, FALSE, 0 );
    $defs_status_label->set_text(
        _( 'A daily definitions update is scheduled' ) );

    my $end_bar = Gtk2::Toolbar->new;
    $vbox->pack_start( $end_bar, FALSE, FALSE, 0 );
    $end_bar->set_style( 'both-horiz' );

    $dsep = Gtk2::SeparatorToolItem->new;
    $dsep->set_draw( FALSE );
    $dsep->set_expand( TRUE );
    $end_bar->insert( $dsep, -1 );

    my $btn = Gtk2::ToolButton->new_from_stock( 'gtk-close' );
    $btn->set_is_important( TRUE );
    $end_bar->insert( $btn, -1 );
    $btn->signal_connect( 'clicked' => sub { $dialog->destroy } );

    $dialog->show_all;

    is_enabled();
    Gtk2->main();
}

sub is_enabled {
    my ( $scan, $scan_hour, $scan_minute, $updates, $updates_hour,
        $updates_minute )
        = ( 0 ) x 6;
    my $excludes = 0;     # guess if user is ignoring whitelist or not
    my $target   = '';    # guess if scan involves Home or System

    open( my $L, '-|', $cmd, '-l' )
        or warn "problem checking crontab listing in is_enabled\n";

    while ( <$L> ) {
        Gtk2->main_iteration while ( Gtk2->events_pending );
        next if /^#/;
        next if /^\s*$/;
        chomp;
        my ( $min, $hour ) = split( /\s+/ );
        if ( /# clamtk-scan/ ) {
            $scan        = 1;
            $scan_hour   = $hour;
            $scan_minute = $min;
            $excludes++ while /--exclude/g;
            $target = 'home';
        } elsif ( /# clamtk-defs/ ) {
            $updates        = 1;
            $updates_hour   = $hour;
            $updates_minute = $min;
        }
    }
    close( $L );

    if ( $scan ) {
        $hour_spin_scan->set_value( $scan_hour );
        $min_spin_scan->set_value( $scan_minute );
        $scan_apply_btn->set_sensitive( FALSE );
        $scan_remove_btn->set_sensitive( TRUE );
        $scan_status_label->set_text( _( 'A daily scan is scheduled' ) );
    } else {
        $scan_apply_btn->set_sensitive( TRUE );
        $scan_remove_btn->set_sensitive( FALSE );
        $scan_status_label->set_text( _( 'A daily scan is not scheduled' ) );
    }

    if ( $updates ) {
        $hour_spin_defs->set_value( $updates_hour );
        $min_spin_defs->set_value( $updates_minute );
        $defs_apply_btn->set_sensitive( FALSE );
        $defs_remove_btn->set_sensitive( TRUE );
        $defs_status_label->set_text(
            _( 'A daily definitions update is scheduled' ) );
    } else {
        $defs_apply_btn->set_sensitive( TRUE );
        $defs_remove_btn->set_sensitive( FALSE );
        $defs_status_label->set_text(
            _( 'A daily definitions update is not scheduled' ) );
    }

    my $can_update
        = ( ClamTk::Prefs->get_preference( 'Update' ) eq 'shared' )
        ? FALSE
        : TRUE;
    if ( !$can_update ) {
        $defs_status_label->set_text(
            _( 'You are set to automatically receive updates' ) );
    }
    return;
}

sub apply_scan {
    my $hour = $hour_spin_scan->get_value;
    my $min  = $min_spin_scan->get_value;

    my $paths = ClamTk::App->get_path( 'all' );

    # This probably isn't necessary;
    # ensure old task is removed
    remove( '# clamtk-scan' );

    my $tmp_file = "$paths->{clamtk}" . "/" . "cron";
    open( my $T, '>', $tmp_file )
        or do {
        warn "Error opening temporary file in apply_scan: $!\n";
        return;
        };

    open( my $L, '-|', $cmd, '-l' )
        or do {
        warn "Error opening crontab command in apply_scan: $!\n";
        return;
        };

    while ( <$L> ) {
        Gtk2->main_iteration while ( Gtk2->events_pending );
        print $T $_;
    }
    close( $L );
    close( $T );

    my $full_cmd = $paths->{ clamscan };
    $full_cmd =~ s/(.*?clamscan)\s.*/$1/;

    # We don't scan the quarantine directory
    $full_cmd .= ' --exclude-dir=' . $paths->{ viruses };

    # Directories set as whitelisted in preferences
    for ( split /;/, ClamTk::Prefs->get_preference( 'Whitelist' ) ) {
        $full_cmd .= ' --exclude-dir=' . quotemeta( $_ );
    }

    # By default, we ignore .gvfs directories.
    for my $m ( 'smb4k', "/run/user/$ENV{USER}/gvfs", "$ENV{HOME}/.gvfs" ) {
        $full_cmd .= " --exclude-dir=$m";
    }

    # Ignore mail directories until we can parse stuff
    for my $not_parse (
        qw| .thunderbird        .mozilla-thunderbird
        .evolution      Mail    kmail |
        )
    {
        $full_cmd .= ' --exclude-dir=' . $not_parse;
    }

    # Use the appropriate signatures
    if ( ClamTk::Prefs->get_preference( 'Update' ) eq 'single' ) {
        $full_cmd .= " --database=$paths->{db}";
    }

    # Only report "infected" (-i)
    $full_cmd .= " -i ";

    # Does the user want PUA reporting?
    if ( ClamTk::Prefs->get_preference( 'Thorough' ) ) {
        $full_cmd .= " --detect-pua ";
    }

    # Home directory will be scanned
    $full_cmd .= "-r " . $paths->{ directory };

    # Add the (ugly) logging
    $full_cmd .= ' --log="$HOME/.clamtk/history/$(date +\%b-\%d-\%Y).log"'
        . ' 2>/dev/null';

    # Temporary file used for crontab
    open( $T, '>>', $tmp_file ) or do {
        warn "Error opening temporary file in apply_scan: $!\n";
        return;
    };
    print $T "$min $hour * * * $full_cmd # clamtk-scan\n";
    close( $T );

    # reload crontab
    system( $cmd, $tmp_file ) == 0
        or do {
        warn 'Error reloading cron file';
        unlink( $tmp_file )
            or warn "Unable to delete tmp_file $tmp_file: $!\n";
        return;
        };
    is_enabled();
    return;
}

sub apply_defs {
    my $hour = $hour_spin_defs->get_value;
    my $min  = $min_spin_defs->get_value;

    my $paths = ClamTk::App->get_path( 'all' );

    # this probably isn't necessary;
    # ensure old task is removed
    remove( '# clamtk-defs' );

    my $tmp_file = $paths->{ clamtk } . "/" . "cron";
    open( my $T, '>', $tmp_file )
        or do {
        warn "Error opening temporary file in apply_defs: $!\n";
        return;
        };

    open( my $L, '-|', $cmd, '-l' )
        or do {
        warn "Error opening crontab command in apply_defs: $!\n";
        return;
        };

    while ( <$L> ) {
        Gtk2->main_iteration while ( Gtk2->events_pending );
        print $T $_;
    }
    close( $L );
    close( $T );

    my $full_cmd = $paths->{ freshclam };

    if (ClamTk::Prefs->get_preference( 'Update' ) eq 'single'
        # The following is necessary if the user is not root, as
        # the update attempt will fail due to lack of permissions.
        # It's still not a good fix since the user might not realize it...
        # But with the ability to rerun the AV choice, it should work.
        || $> != 0
        )
    {
        $full_cmd
            .= " --datadir=$paths->{db} --log=$paths->{db}/freshclam.log";
    }

    # Add config file if user has configured a proxy
    if ( ClamTk::Prefs->get_preference( 'HTTPProxy' ) ) {
        if ( ClamTk::Prefs->get_preference( 'HTTPProxy' ) == 2 ) {
            if ( -e "$paths->{db}/local.conf" ) {
                $full_cmd .= " --config-file=$paths->{db}/local.conf";
            }
        }
    }

    open( $T, '>>', $tmp_file ) or do {
        warn "Error opening temporary file in apply_defs: $!";
        return;
    };

    print $T "$min $hour * * * $full_cmd # clamtk-defs\n";
    close( $T );

    # reload crontab

    system( $cmd, $tmp_file ) == 0
        or do {
        warn "Error reloading cron file: $!\n";
        };
    unlink( $tmp_file )
        or warn "Unable to delete tmp_file $tmp_file: $!\n";
    is_enabled();
    return;
}

sub remove {
    # $which = 'clamtk-scan' or 'clamtk-defs'
    my ( $which ) = shift;

    my $paths = ClamTk::App->get_path( 'clamtk' );

    my $tmp_file = "$paths/cron";
    open( my $T, '>', $tmp_file )
        or do {
        warn "Error opening temporary file in remove: $!\n";
        return;
        };
    open( my $L, '-|', $cmd, '-l' )
        or do {
        warn "Error opening crontab in remove: $!\n";
        return;
        };

    while ( <$L> ) {
        Gtk2->main_iteration while ( Gtk2->events_pending );
        print $T $_ unless ( /$which/ );
    }
    close( $L );

    # reload crontab
    system( $cmd, $tmp_file ) == 0
        or do {
        warn "Error reloading cron file in remove: $!\n";
        };
    unlink( $tmp_file )
        or warn "Unable to delete tmp_file $tmp_file: $!\n";

    if ( $which eq 'clamtk-scan' ) {
        $hour_spin_scan->set_value( '00' );
        $min_spin_scan->set_value( '00' );
    } elsif ( $which eq 'clamtk-defs' ) {
        $hour_spin_defs->set_value( '00' );
        $min_spin_defs->set_value( '00' );
    }
    is_enabled();
    return;
}

1;