MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //proc/self/root/scripts.20110531.215904.25158/check_cpscripts
#!/usr/bin/perl
# cpanel - check_cpscripts                        Copyright(c) 2010 cPanel, Inc.
#                                                           All Rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

BEGIN {
    unshift @INC, '/usr/local/cpanel', '/var/cpanel/perl';
    pop(@INC) if ( $INC[$#INC] eq '.' );
    $ENV{'LANG'} = 'C';
}

use Carp ();
use Cpanel::Usage;
use Cpanel::Hostname ();

my $force    = 0;
my $no_email = 0;
my $has_cp   = 0;

eval 'use Cpanel::SafeRun::Errors (); use Cpanel::Notify (); $has_cp=1;';

Cpanel::Usage::wrap_options( \@ARGV, \&usage, { 'force' => \$force, 'noemail' => \$no_email, } );

my $hostname = Cpanel::Hostname::gethostname();

if ( !$force && $hostname !~ m/\.cpanel\.(?:com|net)$/ ) {
    exit;
}

my @BIN_CHECK_LIST = ('/usr/local/cpanel/3rdparty/bin/php');
my @CHECK_LIST = ( '/usr/local/cpanel/Whostmgr/TweakSettings.pm', '/usr/local/cpanel/Whostmgr/TweakSettings/Mail.pm' );

foreach my $cdir ( '/scripts', '/usr/local/cpanel/bin' ) {
    if ( opendir my $cpdir_fh, $cdir ) {
      PERL:
        while ( my $script = readdir($cpdir_fh) ) {
            next PERL if ( !-e $cdir . '/' . $script || -B _ || $script =~ m/^\./ || $script =~ m/\~/ || $script =~ m/\.(?:bak|orig)$/i );    # -e excludes broken symlinks
            if ( open my $script_fh, '<', $cdir . '/' . $script ) {
                my $int = readline $script_fh;
                if ( $int =~ m/\/perl/ ) {
                    push @CHECK_LIST, $cdir . '/' . $script;
                }
                close $script_fh;
            }
            else {
                print "Unable to read $cdir/$script: $!";
            }
        }
        closedir $cpdir_fh;
    }
    else {
        print "Unable to read directory $cdir: $!";
    }
}

if ($has_cp) {
    foreach my $script (@BIN_CHECK_LIST) {
        my $ldd = Cpanel::SafeRun::Errors::saferunallerrors( 'ldd', $script );
        if ( $ldd =~ /not found/i ) {
            if ( !$no_email ) {
                Cpanel::Notify::notification(
                    'application' => 'checkcpscripts',
                    'status'      => 'brokenbinary',
                    'priority'    => 1,
                    'interval'    => 1,
                    'subject'     => qq{[check_cpscripts] broken binary: $script: $!},
                    'message'     => $ldd
                );
            }
            else {
                print "BROKEN BINARY $script: $!\n";
            }
        }
    }
}

foreach my $script ( sort @CHECK_LIST ) {
    if ( $script =~ /linktest/ ) {
        system( 'perl', '-c', $script, '--system' );
    }
    else {
        system( 'perl', '-I/usr/local/cpanel', '-c', $script );
    }
    if ( $? != 0 && $? != 1 ) {
        if ($has_cp) {
            if ( !$no_email ) {
                Cpanel::Notify::notification(
                    'application' => 'checkcpscripts',
                    'status'      => 'brokenscript',
                    'priority'    => 1,
                    'interval'    => 1,
                    'subject'     => qq{[check_cpscripts] broken script: $script: $!},
                    'message'     => Cpanel::SafeRun::Errors::saferunallerrors( 'perl', '-I/usr/local/cpanel', '-c', $script )
                );
            }
            else {
                print "BROKEN PERL SCRIPT: $!\n";
            }
        }
        else {
            Carp::cluck("[check_cpscripts] : $script: $!");
        }
    }
}

sub usage {
    $p = $0;
    $p =~ s@^.+/(.+)$@$1@;
    print <<EOF;
Usage: $p [--help | --usage | --noemail | --force]
    Normally runs without args. It is similar to build-tools/buildcpscripts
    in that it compiles all the perl code base and is seemingly more dynamic
    in that it does readdirs and checks for perl shbang lines, so whatever
    it finds it will compile!
    - The "noemail" flag prevents notification system messages from being sent.
    - The "force" flag bypasses the hostname check and allows execution on any host.
EOF
    exit;
}    # end of usage