????

Your IP : 18.191.162.21


Current Path : /proc/322915/root/scripts/
Upload File :
Current File : //proc/322915/root/scripts/suphpup

#!/usr/local/cpanel/3rdparty/bin/perl
# cpanel - suphpup                                   Copyright 2011 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, '/var/cpanel/perl/easy'; }

use strict;
use Cpanel::DataStore ();
use Cpanel::Version   ();
use 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 = 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') ? ('/usr/local/cpanel/scripts/cpanel_easy_sanity_check') : ( '/usr/local/cpanel/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;
    {
        no warnings 'once';
        ($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( /usr/local/cpanel/scripts/easyapache --build --only=Cpanel::Easy::Apache::PHPAsUser), "--profile=$last_ok_file";    #issafe
}