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/suphpup
#!/usr/bin/perl
# cpanel - suphpup                                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/easy'; }

use strict;
use Cpanel::DataStore         ();
use Cpanel::Version           ();
use Cpanel::CPAN::Getopt::Param ();

my $last_ok_file = '/var/cpanel/easy/apache/profile/_last_success.yaml';    # case 3928 #issafe

if ( !-e $last_ok_file ) {
    print "You will need to successfully build PHP via EasyApache before you can use this tool.\n";
    exit;
}

my $prm = Cpanel::CPAN::Getopt::Param->new(
    {
        'help_coderef' => sub {
            print <<"END_HELP";
$0 - update suPHP to the latest
   --help          - this screen
   --force         - rebuild suPHP even if its already the latest
   --dryrun        - don't actually do anything just report what would be done
   --verbose       - don't hide any output
   --version       - show version info and exit

END_HELP

            exit;
        },
    }
);

my $last_ok_profile_hr = Cpanel::DataStore::load_ref( $last_ok_file, {} ) or exit;    # load_ref() reports the error

if ( !$last_ok_profile_hr->{'Apache'}{'optmods'}{'PHPAsUser'} ) {                       #issafe
    print "Your last EasyApache build did not have suPHP selected\n";
}
else {
    print "Updating suPHP...\n" if !$prm->param('version');

    my @cmd = $prm->param('verbose') ? ('/scripts/cpanel_easy_sanity_check') : ( '/scripts/cpanel_easy_sanity_check', '--quiet' );
    if ( system(@cmd) != 0 ) {
        die 'Could not sync easyapache source';
    }

    require Cpanel::Easy::Apache::PHPAsUser;                                            #issafe
    my ($latest_suphp_version) = $Cpanel::Easy::Apache::PHPAsUser::easyconfig->{'src_cd2'} =~ m{suphp-(\d+\.\d+\.\d+)};    #issafe

    # think its convoluted? try running it in your shell (piping to less to see if you can capture it)
    # without either the STDERR redirect and/or pipe to cat - its doing some sort of file descriptor voodod
    my ($server_suphp_version) = `/opt/suphp/sbin/suphp 2>&1 | cat` =~ m{suPHP version (\d+\.\d+\.\d+)};

    print "Current suPHP is v$server_suphp_version\n" if $prm->param('verbose') || $prm->param('version');
    print "Latest suPHP is v$latest_suphp_version\n"  if $prm->param('verbose') || $prm->param('version');
    exit                                              if $prm->param('version');

    if ( Cpanel::Version::compare( $server_suphp_version, '==', $latest_suphp_version ) ) {
        if ( $prm->param('force') ) {
            print "Rebuilding suPHP as per --force even though suPHP is already the latest (v$latest_suphp_version).\n";
        }
        else {
            print "suPHP is already the latest (v$latest_suphp_version). Use --force to make it rebuild anyway\n";
            exit;
        }
    }

    print "Building suPHP v$latest_suphp_version\n";
    if ( $prm->param('dryrun') ) {
        print "Not actually running anything as per the 'dryrun' flag\n";
        exit;
    }

    # PHPAsUser.pm sees that its in the only flag and Apache is not also in only and changes it's behavior
    system qw( /scripts/easyapache --build --only=Cpanel::Easy::Apache::PHPAsUser), "--profile=$last_ok_file";    #issafe
}