????
Current Path : /proc/328295/root/scripts/ |
Current File : //proc/328295/root/scripts/cpanel_easy_sanity_check |
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - cpanel_easy_sanity_check Copyright 2015 cPanel, Inc. # All rights Reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited use strict; use warnings; use Cpanel::Config::Sources (); use Cpanel::Encoder::Tiny (); use Cpanel::SafeDir::MK (); use Cpanel::SafeRun::Dynamic (); use Getopt::Param (); use Cpanel::FileUtils (); use Cpanel::Config::Httpd::EA4 (); if ( Cpanel::Config::Httpd::EA4::is_ea4() ) { die "EasyApache3 is not available when EasyApache4 is in effect.\n"; } my $param = Getopt::Param->new(); my $loud = $param->param('quiet') ? 0 : 1; my $html = $param->param('as-html') ? 1 : 0; my $need_build = $param->param('build') ? 1 : 0; my $httpupdate_uri = $param->param('tier') || 'easy'; # 1. Ensure proper --tier usage # 2. Easyapache builds are written to easy-$version on update server. However, # for backwards compatibility, the latest customer build now links to 'easy' # e.g. easy, easy-x.y.z, or easy-project-x.y.z die "Incorrect 'tier' argument" unless $httpupdate_uri =~ /^easy(?:\-(?:\w+\-)?\d+\.\d+\.\d+)?$/; # Case 59284: abort esayapache when passed bad profile name. # if $need_build is 1, validate profile. if ($need_build) { my $profile_full_name = $param->param('profile') || ''; # validate profile only if the arg contains a file name or a path. if ( ( length($profile_full_name) > 0 ) && !( lc($profile_full_name) eq '--profile' ) ) { my $cust_path = '/var/cpanel/easy/apache/profile/custom'; # if arg is just a file name, put it in the dir. if ( $profile_full_name !~ m{/} ) { $profile_full_name = $cust_path . '/' . $profile_full_name; } $profile_full_name = Cpanel::FileUtils::cleanpath($profile_full_name); # ensure .yaml extension. $profile_full_name =~ s/(\.yaml$)//i; $profile_full_name .= '.yaml'; if ( !-e $profile_full_name ) { die "Specified profile \"" . $profile_full_name . "\" does not exist\n"; } elsif ( -s $profile_full_name <= 0 ) { die "Specified profile \"" . $profile_full_name . "\" has zero size\n"; } } } if ( -e '/var/cpanel/easy_skip_cpanelsync' ) { print "/var/cpanel/easy_skip_cpanelsync exists. Skipping update of EasyApache\n"; exit; } my $opt_mod_dir = '/var/cpanel/perl/easy'; if ( defined $param->param('test-branch') ) { print "The '--test-branch' command line flag is obsolete. Ignoring.\n"; } else { my $test_branch_path = '/var/cpanel/use_easy_test_branch'; if ( -e $test_branch_path ) { my $msg = "Use of $test_branch_path is obsolete. I will now delete that file.... "; unlink $test_branch_path; $msg .= -e $test_branch_path ? 'Not deleted' : 'Deleted'; print $msg . "\n"; } } if ( !-d $opt_mod_dir ) { Cpanel::SafeDir::MK::safemkdir($opt_mod_dir) or die "Could not create opt mod directory: $!"; } my $action = $param->param('action') || ''; my $skip = $action eq '_pre_cpanel_sync_screen' || $param->param('help') || $param->param('skip-cpanelsync') ? 1 : 0; exit if $skip; my %CPSRC = Cpanel::Config::Sources::loadcpsources(); my $easources_host = get_easources_host( \%CPSRC ); my $cpanelsync = "$opt_mod_dir/.cpanelsync"; ## audit case 45000: leaving cpanelsync invocations as is, as they operate over httpupdate's "easy/" directory if ( -x '/usr/local/cpanel/scripts/cpanelsync' ) { my $orig = -e $cpanelsync ? _hash_file($cpanelsync) : 0; for my $run ( [ "/cpanelsync/$httpupdate_uri/Cpanel", "$opt_mod_dir/Cpanel" ], [ "/cpanelsync/$httpupdate_uri/profiles", '/var/cpanel/' ], ) { $|++; Cpanel::SafeRun::Dynamic::livesaferun( 'prog' => [ '/usr/local/cpanel/scripts/cpanelsync', '--signed=1', '--quiet=1', $easources_host, @{$run} ], 'formatter' => sub { my ($line) = @_; if ($html) { chomp $line; $line = Cpanel::Encoder::Tiny::safe_html_encode_str($line); $line .= "<br />\n"; } return $line if $loud; if ( $line =~ /The update server is currently updating its files/i || $line =~ /It may take up to 30 minutes before access can be obtained/i || $line =~ /Waiting 30 seconds for access to the update server/i || $line =~ /Checking again/i ) { return $line; } return ''; # empty string to stay quiet && avoid uninit value warnings }, ); } my $crnt = -e $cpanelsync ? _hash_file($cpanelsync) : 0; unlink '/var/cpanel/easy/apache/state.yaml' if !$orig || !$crnt || $orig ne $crnt; } else { die '/usr/local/cpanel/scripts/cpanelsync must exist and be executable'; } sub get_easources_host { my $sources_hr = shift; # First look for EA-specific, else fall back on the generic httpupdate host for my $name (qw[ EASOURCES HTTPUPDATE ]) { my $host = $sources_hr->{$name}; return $host if $host; } # We'll never arrive here; Cpanel::Config::Sources always sets a suitable default return; } sub _hash_file { my ($file) = @_; return Digest::SHA->new(512)->addfile($file)->hexdigest; }