shell bypass 403

UnknownSec Shell

: /scripts/ [ drwxr-xr-x ]

name : find_and_fix_rpm_issues
#!/usr/local/cpanel/3rdparty/bin/perl

#                                      Copyright 2024 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

package scripts::find_and_fix_rpm_issues;

use cPstrict;

use parent qw( Cpanel::HelpfulScript );

use Cpanel::Usage;

use Cpanel::Binaries::Rpm   ();
use Cpanel::OS              ();
use Cpanel::Pkgr            ();
use Cpanel::SafeRun::Simple ();
use Cpanel::Update::Logger  ();

our $RPM_DB_DIR = '/var/lib/rpm';

exit( __PACKAGE__->new(@ARGV)->run() // 0 ) unless caller;

=encoding utf-8

=head1 NAME

find_and_fix_rpm_issues

=head1 USAGE

scripts/find_and_fix_rpm_issues [--findonly] [--rebuildonly] [--help]

=head1 DESCRIPTION

Detects problems with the rpm database and will rebuild the database
if it detects problems. Exits 0 if RPM is working properly, or if
we were able to fix it by rebuilding its database.

This script also detects duplicate cPanel RPMs, removes, and then
re-installs them if necessary.

    --findonly - Detect and report problems. Do not make any changes.

    --rebuildonly - Unconditionally rebuild the RPM database.

=cut

sub _OPTIONS {
    return qw( findonly rebuildonly );
}

# NOTE: Return logic throughout the script is reversed so that $? is 0 for
# success or 1 for failure.
sub run {
    my ($self) = @_;

    my $logger = Cpanel::Update::Logger->new( { 'stdout' => 1, 'log_level' => 'debug', 'timestamp' => 0 } );

    # Bail on non-rpm based s
    if ( !Cpanel::OS::is_rpm_based() ) {
        $logger->warn( "find_and_fix_rpm_issues: Cannot be used on a non rpm based distro. Current distro is " . Cpanel::OS::display_name() . "\n" );
        return;
    }

    my $findonly       = $self->getopt('findonly');
    my $rebuildonly    = $self->getopt('rebuildonly');
    my $rpm_db_is_good = 1;

    if ( !$rebuildonly ) {

        my $status;
        ( $rpm_db_is_good, $status ) = Cpanel::Pkgr::verify_package_manager_can_install_packages($logger);

        if ($rpm_db_is_good) {
            my $rpm_db = _dump_rpm_db();

            fix_duplicate_cpanel_rpms( $logger, $rpm_db );

            $rpm_db_is_good = verify_no_duplicate_rpms( $logger, $rpm_db );
        }

        $logger->info("find_and_fix_rpm_issues: rpm issues have been found") if !$rpm_db_is_good;
    }

    $rpm_db_is_good = 0 if $rebuildonly;

    if ( !$findonly && !$rpm_db_is_good ) {
        $logger->info("find_and_fix_rpm_issues: Performing rpm rebuild");

        # A non-zero return from rebuild_rpm_database indicates failure. It just returns $?.
        rebuild_rpm_database($logger) && return 1;

    }

    remove_cpanel_obsoleted_rpms($logger);

    return 0;
}

sub rebuild_rpm_database {
    my ($logger) = @_;

    if ( opendir my $dh, $RPM_DB_DIR ) {
        while ( my $file = readdir $dh ) {
            next unless $file =~ m{^__db\.[0-9]+$} && -f "$RPM_DB_DIR/$file";
            unlink "$RPM_DB_DIR/$file" or do {
                $logger->info("find_and_fix_rpm_issues: Could not unlink $RPM_DB_DIR/$file: $!");
                return 1;
            };
        }
        closedir $dh;
    }

    my $rpm    = Cpanel::Binaries::Rpm->new;
    my $result = $rpm->cmd( '-vvv', '--rebuilddb' );

    my $exit_code = $result->{'status'} >> 8;
    if ($exit_code) {
        $logger->info("find_and_fix_rpm_issues: Rebuilding the rpm database failed with exit code $exit_code:");
        $logger->debug( $result->{'output'} );
        return 1;
    }
    else {
        return 0;
    }
}

sub _dump_rpm_db {
    my $rpm    = Cpanel::Binaries::Rpm->new;
    my $result = $rpm->cmd( qw { -qa --nodigest --nosignature --queryformat }, '%{INSTALLTIME}\t%{NAME}\t%{VERSION}\t%{RELEASE}\t%{ARCH}\t\n' );

    return [ split "\n", $result->{'output'} ];
}

sub fix_duplicate_cpanel_rpms {
    my ( $logger, $rpmdb_ar ) = @_;

    my %rpms;
    my %rpm_erase;
    foreach my $line (@$rpmdb_ar) {
        next if index( $line, '.cp' ) == -1;

        my ( $installtime, $name, $version, $release, $arch ) = split( m/\t/, $line );

        # Only fix cp11## rpms.
        next if ( $release !~ m/cp\d{4}$/ );

        if ( $rpms{$name} ) {
            $rpm_erase{ sprintf( "%s-%s-%s.%s", $name, $rpms{$name}[0], $rpms{$name}[1], $rpms{$name}[2] ) } = 1;
            $rpm_erase{ sprintf( "%s-%s-%s.%s", $name, $version,        $release,        $arch ) }           = 1;
        }
        else {

            # No duplicate found.
            $rpms{$name} = [ $version, $release, $arch ];

        }
    }

    return 0 if !%rpm_erase;

    $logger->info("Duplicate RPMs found.");

    my $rpm      = Cpanel::Binaries::Rpm->new;
    my @cmd_args = ( qw{-e --nodeps --justdb}, sort { $a cmp $b } keys %rpm_erase );

    $logger->info( "\$> rpm " . join( " ", @cmd_args ) . "\n" );
    my $result = $rpm->cmd(@cmd_args);
    $logger->info( $result->{'output'} );

    $logger->info("\$> /usr/local/cpanel/scripts/check_cpanel_pkgs --fix\n");
    $logger->info( Cpanel::SafeRun::Simple::saferunallerrors(qw{/usr/local/cpanel/scripts/check_cpanel_pkgs --fix --no-digest}) );

    return 0;
}

# if check_cpanel_pkgs or one of its child processes are killed during an rpm transaction, this can put the rpm
# database in an unstable state as far as what rpms should be installed. This cleans that mistake up after the fact.
#
# NEVER kill -9 an rpm command. Bad things can happen!

sub remove_cpanel_obsoleted_rpms ($logger) {
    my $obsoletes = Cpanel::Pkgr::installed_cpanel_obsoletes();
    return unless ref $obsoletes && @$obsoletes;    # Nothing is obsolete!

    $logger->info( "Removing obsoleted package(s): " . join( ", ", @$obsoletes ) );
    $logger->info( Cpanel::Pkgr::remove_packages_nodeps(@$obsoletes) );

    $logger->info("Attempting to fix the local install by running scripts/check_cpanel_pkgs --fix --no-digest");
    $logger->info( Cpanel::SafeRun::Simple::saferunallerrors(qw{/usr/local/cpanel/scripts/check_cpanel_pkgs --fix --no-digest}) );
}

# NOTE: The logic here may not be obvious.
# If the system has duplicate RPMs, this function will return 0, indicating a problem.
# Otherwise, it will return 1, indicating that it did not detect a problem.
#
# (That doesn't mean there isn't a problem; it just means we didn't find one.)
sub verify_no_duplicate_rpms {
    my ( $logger, $rpmdb_ar ) = @_;
    my %rpm_hash;
    $rpm_hash{ substr( $_, index( $_, "\t" ) + 1 ) }++ for @$rpmdb_ar;

    # Multiple kernel packages are ok
    delete @rpm_hash{ grep { index( $_, "kernel" ) == 0 } keys %rpm_hash };

    if ( grep { $_ > 1 } values %rpm_hash ) {
        foreach my $line ( grep { $rpm_hash{$_} > 1 } keys %rpm_hash ) {
            my ( $name, $version, $release, $arch ) = split( m/\t/, $line );
            my $dupe_count = $rpm_hash{$line} - 1;
            $logger->info( "The “$name” package has “$dupe_count” duplicate package" . ( $dupe_count > 1 ? 's' : '' ) . " installed." );
        }
        return 0;
    }
    return 1;
}

1;

© 2025 UnknownSec
Display on the page Footer | Anyleson - Learning Platform
INR (₹)
India Rupee
$
United States Dollar

Display on the page Footer

Privacy Policy

Effective Date: 24 August , 2024

At Anyleson, we are committed to protecting your privacy and ensuring that your personal information is handled securely and responsibly. This Privacy Policy outlines how we collect, use, and safeguard your data when you use our platform.


Information We Collect


  1. Personal Information:

    • Name, email address, phone number, and billing details.

    • Account login credentials (username and password).



  2. Course Usage Data:

    • Progress and activity within courses.

    • Feedback and reviews submitted for courses.



  3. Technical Information:

    • IP address, browser type, device information, and cookies for improving website functionality.



  4. Communication Data:

    • Information from your interactions with our customer support.




How We Use Your Information


  1. To Provide Services:

    • Process course purchases, registrations, and access to content.



  2. To Improve User Experience:

    • Analyze user behavior to enhance course offerings and platform features.



  3. To Communicate:

    • Send updates, notifications, and promotional offers (only if you’ve opted in).



  4. For Legal Compliance:

    • Meet legal or regulatory requirements and prevent fraud.




How We Protect Your Information


  1. Data Encryption: All sensitive data is encrypted during transmission using SSL.

  2. Access Control: Only authorized personnel have access to personal information.

  3. Secure Storage: Data is stored on secure servers with regular security updates.


Sharing Your Information

We do not sell, rent, or trade your personal data. However, we may share your information with:


  1. Service Providers:

    • Payment processors and hosting services that assist in delivering our platform.



  2. Legal Authorities:

    • When required by law or to protect our legal rights.




Your Rights


  1. Access and Update: You can view and update your personal information in your account settings.

  2. Request Deletion: You have the right to request deletion of your data by contacting us.

  3. Opt-Out: You can opt out of receiving promotional emails by clicking the “unsubscribe” link in our emails.


Cookies Policy

We use cookies to enhance your experience by:


  • Remembering your preferences.

  • Analyzing website traffic.
    You can manage your cookie preferences through your browser settings.


Third-Party Links

Our platform may contain links to third-party websites. We are not responsible for their privacy practices and recommend reviewing their privacy policies.


Policy Updates

We may update this Privacy Policy from time to time. Changes will be posted on this page, and the "Effective Date" will be updated. Please review the policy periodically.


Contact Us

If you have any questions or concerns about our Privacy Policy or how your data is handled, please contact us at:

Email: support@anyleson.comThank you for trusting Anyleson with your learning journey!