‰PNG  IHDR @ @ ªiqÞ pHYs   šœ —tEXtComment package CpanelConfig; # cpanel - CpanelConfig.pm Copyright 2021 cPanel, L.L.C. # 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 Common (); # read_config use CpanelLogger; my %TIER_CACHE; sub signatures_enabled { my $config = read_config('/var/cpanel/cpanel.config'); my $is_enabled = ( defined $config->{'signature_validation'} && $config->{'signature_validation'} eq 'Off' ) ? 0 : 1; return $is_enabled; } sub get_lts_version { my ($cpanel_version) = @_; defined $cpanel_version && length $cpanel_version || die; my ( undef, $lts_version ) = split( qr/\./, $cpanel_version ); $lts_version or FATAL("The system could not determine the LTS version for $cpanel_version"); return $lts_version; } sub get_cpanel_version { my $tier = get_cpanel_tier(); my $version = guess_version_from_tier($tier); $version or FATAL("The system could not determine the target version from your tier: $tier"); return $version; } sub get_staging_dir { return read_config('/etc/cpupdate.conf')->{'STAGING_DIR'} // ''; } sub get_cpanel_tier { # Pull in cpupdate.conf settings. my $cpupdate_conf = read_config('/etc/cpupdate.conf'); # Determine tier or assume defaults. my $tier = $cpupdate_conf->{'CPANEL'} || 'release'; # version numbers without 11. if ( $tier =~ /^[0-9]+/ && $tier !~ /^11\./ ) { $tier = '11.' . $tier; } return $tier; } sub get_update_source { my $source_file = '/etc/cpsources.conf'; my $conf = read_config($source_file); my $update_source = $conf->{'HTTPUPDATE'} // 'httpupdate.cpanel.net'; if ( !$update_source ) { FATAL("HTTPUPDATE is unset in the $source_file file."); } return $update_source; } sub read_config { my ($file) = @_; ( $file && length $file ) or die 'No file passed to read_config'; my $config = {}; open( my $fh, "<", $file ) or return $config; while ( my $line = readline $fh ) { chomp $line; if ( $line =~ m/^\s*([^=]+?)\s*$/ ) { my $key = $1 or next; # Skip loading the key if it's undef or 0 $config->{$key} = undef; } elsif ( $line =~ m/^\s*([^=]+?)\s*=\s*(.*?)\s*$/ ) { my $key = $1 or next; # Skip loading the key if it's undef or 0 $config->{$key} = $2; } } return $config; } sub guess_version_from_tier { my ($tier) = @_; $tier ||= 'release'; if ( defined( $TIER_CACHE{$tier} ) ) { return $TIER_CACHE{$tier}; } # Support version numbers as tiers. if ( $tier =~ /^\s*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s*$/ ) { $TIER_CACHE{$tier} = $tier; return $tier; } # Download the file. Common::cpfetch('/cpanelsync/TIERS'); -e 'TIERS' or FATAL('The installation process could not fetch the /cpanelsync/TIERS file from the httpupdate server.'); # Parse the downloaded TIERS data for our tier. (Stolen from Cpanel::Update) open( my $fh, '<', 'TIERS' ) or FATAL("The system could not read the downloaded TIERS file."); while ( my $tier_definition = <$fh> ) { chomp $tier_definition; next if ( $tier_definition =~ m/^\s*#/ ); # Skip commented lines. ## e.g. edge:11.29.0 (requires two dots) next if ( $tier_definition !~ m/^\s*([^:\s]+)\s*:\s*(\S+)/ ); my ( $remote_tier, $remote_version ) = ( $1, $2 ); $TIER_CACHE{$remote_tier} = $remote_version; } close $fh; # Set any disabled tiers to install-fallback if possible. foreach my $key ( keys %TIER_CACHE ) { next if $key eq 'install-fallback'; if ( $TIER_CACHE{$key} && $TIER_CACHE{'install-fallback'} && $TIER_CACHE{$key} eq 'disabled' ) { $TIER_CACHE{$key} = $TIER_CACHE{'install-fallback'}; } } # Fail if the tier is not present. if ( !$TIER_CACHE{$tier} ) { FATAL("The specified tier ('$tier') in the /etc/cpupdate.conf file is not a valid cPanel & WHM tier."); } # Fail if the tier is still disabled. if ( $TIER_CACHE{$tier} eq 'disabled' ) { FATAL("cPanel has temporarily disabled updates on the central httpupdate servers. Please try again later."); } return $TIER_CACHE{$tier}; } 1;