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: //scripts.20110531.215904.25158/fixperlscript
#!/usr/bin/perl
# cpanel - fixperlscript                          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'; }

use strict;
use Cpanel::AccessIds::SetUids ();

my $script = $ARGV[0];

if ( !defined $script || $script eq '' || !-f $script ) {
    print "You must specify a perl script to check.\n";
    print "Example: $0 /home/user/public_html/testscript.cgi\n";
    exit;
}

my ( $uid, $gid ) = ( stat($script) )[ 4, 5 ];
die "Undefined UID" if !defined $uid;

my %seen;

my $need_mod = 1;
MOD_CHECK:
while ($need_mod) {
    my $childpid = open( my $rdr_fh, '-|' );
    if ($childpid) {
        my $perl_c_had_missing = 0;
        while ( my $line = readline($rdr_fh) ) {
            line_handler( $line, \$perl_c_had_missing, \%seen ) or last MOD_CHECK;
        }
        $need_mod = $perl_c_had_missing;
        close($rdr_fh);
    }
    else {
        if ( $uid != $> ) {
            Cpanel::AccessIds::SetUids::setuids( $uid, $gid ) || die "Could not setuid()";
        }

        open( STDERR, ">&STDOUT" );
        exec 'perl', '-c', $script;
        exit(1);
    }

    if ( keys %seen ) {
        print "\nThe following modules were installed for $script:\n";
        print map { $seen{$_} eq 'failed' ? "\t$_ (failed)\n" : "\t$_\n" } sort keys %seen;
    }
    else {
        print "$script has no missing modules\n";
    }
}
#### functions ####

sub line_handler {
    my ( $line, $perl_c_had_missing_sr, $seen_hr ) = @_;

    if ( $line =~ /Can\'t locate (\S+)/ ) {
        my $module = $1;
        $module =~ s/\//::/g;
        $module =~ s/\.pm$//g;

        ${$perl_c_had_missing_sr}++;

        if ( !exists $seen_hr->{$module} ) {
            print "\n-- Missing $module. Starting installation -- \n\n";
            $seen_hr->{$module}++;
            system '/scripts/perlinstaller', $module;
        }
        else {
            $seen_hr->{$module} = 'failed';
            print "\n!! We have already tried to install $module. Please manually troubleshoot the installation of $module !!\n";
            return;
        }
    }
    return 1;
}