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/phpup
#!/usr/bin/perl
# cpanel - phpup                                  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::PHPConfig           ();
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 PHP to the latest
   --help          - this screen
   --force         - rebuild PHP even if its already the latest
   --dryrun        - don't actually do anything just report what would be done
   --only-do=[4|5] - only work with PHP 4 or PHP 5

END_HELP

            exit;
        },
    }
);

my @phpvers = ( 4, 5 );
if ( $prm->exists_param('only-do') ) {
    my @vers = $prm->get_param('only-do');
    if ( @vers > 1 || ( $vers[0] ne '4' && $vers[0] ne '5' ) ) {
        print "Invalid use of 'only-do' flag. See --help for more info.\n";
        exit;
    }
    else {
        @phpvers = ( $vers[0] );
        print "Only doing PHP $vers[0] as per 'only-do' flag.\n";
    }
}

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

if ( !$last_ok_profile_hr->{'Cpanel::Easy::PHP4'} && !$last_ok_profile_hr->{'Cpanel::Easy::PHP5'} ) {    #issafe
    print "Your last EasyApache build did not have any PHP selected\n";
}
else {
    print "Updating PHP...\n";
    my @only;
    my $phpv = Cpanel::PHPConfig::_check_installed_php_binaries();

    my $have_run_sanity = 0;

    if ( !$prm->get_param('force') ) {

      PHP_MAIN_VER:
        for my $v (@phpvers) {
            my $ns = "Cpanel::Easy::PHP$v";    #issafe

            next PHP_MAIN_VER if !$last_ok_profile_hr->{$ns};

            if ( eval qq{ require $ns; } ) {
                my ($ea3_latest) = reverse( $ns->versions() );
                $ea3_latest =~ s{\_}{\.}g;
                $ea3_latest = "$v\.$ea3_latest";

                my $system_has = '';

              PHP_SYS_VER:
                for my $key ( sort keys %{$phpv} ) {
                    next PHP_SYS_VER if $phpv->{$key}{'version'} ne $v;
                    $system_has = $phpv->{$key}{'long_version'};
                }

                if ( !$system_has ) {
                    print "Could not determine system version of PHP $v, skipping\n";
                    next PHP_MAIN_VER;
                }

                if ( $system_has eq $ea3_latest ) {
                    print "PHP $v is already the latest. Use --force to make it rebuild anyway\n";
                    next PHP_MAIN_VER;
                }

                print "Updating PHP $v to $ea3_latest from $system_has\n";
                push @only, "--only=Cpanel::Easy::PHP$v";    #issafe
            }
            else {
                print "Could not load $ns.\n";

                if ( !$have_run_sanity ) {
                    print "Getting EasyApache...\n";
                    $have_run_sanity++;
                    system '/scripts/cpanel_easy_sanity_check';    #issafe
                    redo PHP_MAIN_VER;
                }
                else {
                    print "Aborting since we already tried to fetch the module and its still missing.\n";
                    exit;
                }
            }
        }
    }
    else {
        my $string = join ' and/or ', @phpvers;
        print "Building PHP $string as per your last build\n";
        @only = map { "--only=Cpanel::Easy::PHP$_" } @phpvers;    #issafe
    }

    if ( $prm->get_param('force') || @only ) {
        if ( $prm->get_param('dryrun') ) {
            print "Not actually running anything as per the 'dryrun' flag\n";
        }
        else {
            system qw( /scripts/easyapache --always_do_the_latest_phps --build ), "--profile=$last_ok_file", @only;
        }
    }
}