Viewing File: /usr/local/cpanel/3rdparty/bin/clamav_setupcrontab

#!/bin/sh
eval 'if [ -x /usr/local/cpanel/3rdparty/bin/perl ]; then exec /usr/local/cpanel/3rdparty/bin/perl -x -- $0 ${1+"$@"}; else exec /usr/bin/perl -x $0 ${1+"$@"}; fi;'
  if 0;

#!/usr/bin/perl
# cpanel - setupcrontab                           Copyright(c) 2011 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

my $match   = 'freshclam';
my $command = '/usr/local/cpanel/3rdparty/bin/freshclam --quiet --no-warnings';

my $enable = 1;
if ( @ARGV && $ARGV[0] =~ m/^off$/i ) {
    $enable = 0;
}

setupcrontab();

sub setupcrontab {
    my $has_match = 0;
    my @crontab = split( /\n/, `crontab -l` );
    foreach my $line (@crontab) {
        next if $line =~ m/^#/;
        if ( $line =~ m/$match/ ) {
            $has_match = 1;
            last;
        }
    }

    umask 077;    # See SEC-408.

    if ($enable) {
        if ( !$has_match ) {
            my $rt   = int( rand(2.9999999) );
            my $hour = int( rand(6) );
            if ( $rt == 0 ) {
                $hour = ( 24 - int( rand(4) ) );
            }
            if ( $hour == 24 ) {
                $hour = 0;
            }
            push @crontab, int( rand(60) ) . ' ' . $hour . ' * * * ' . $command;
            if ( open my $cron_in, '>', '/scripts/.crontab' ) {
                foreach my $line (@crontab) {
                    print {$cron_in} $line . "\n";
                }
                close $cron_in;
                system 'crontab', '/scripts/.crontab';
                unlink '/scripts/.crontab';
                return 1;
            }
            return;
        }
        else {
            return 1;
        }
    }
    else {
        if ($has_match) {
            @crontab = grep( !/$match/, @crontab );
            if ( open my $cron_in, '>', '/scripts/.crontab' ) {
                foreach my $line (@crontab) {
                    print {$cron_in} $line . "\n";
                }
                close $cron_in;
                system 'crontab', '/scripts/.crontab';
                unlink '/scripts/.crontab';
                return 1;
            }
            return;
        }
        return 1;
    }
    return 1;
}
Back to Directory File Manager