MSV FM

[email protected]: ~ $
Path : /scripts/
File Upload :
Current < : //scripts/userdata_wildcard_cleanup

#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/userdata_wildcard_cleanup       Copyright 2022 cPanel, L.L.C.
#                                                           All rights reserved.
# [email protected]                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package scripts::userdata_wildcard_cleanup;

use strict;

use Cpanel                              ();
use Cpanel::Config::userdata::Constants ();
use Cpanel::Config::userdata::Guard     ();
use Cpanel::FileUtils::TouchFile        ();
use Cpanel::SafeRun::Errors             ();
use Cpanel::ServerTasks                 ();
use Cpanel::WildcardDomain              ();
use Cpanel::WildcardDomain::Tiny        ();

use File::Basename ();

BEGIN { unshift @INC, '/usr/local/cpanel'; }

my @ssl_userdata_parts = qw(
  sslcertificatefile
  sslcertificatekeyfile
  sslcacertificatefile
);

our $TOUCH_FILE = '/var/cpanel/ssl/wildcard_cleanup_complete';

__PACKAGE__->script(@ARGV) unless caller();

########################################################################
# This script was created to fix an issue documented in case 67341
########################################################################

sub script {
    my ( $class, @argv ) = @_;

    my ( $rebuild_apache, $forced );
    for my $arg (@argv) {
        if ( $arg eq '--rebuildapache' ) {
            $rebuild_apache = 1;
        }
        if ( $arg eq '--force' ) {
            $forced = 1;
        }
    }

    return if -e $TOUCH_FILE && !$forced;

    my ( $httpd_conf_rebuild_needed, @migrated_servernames, @migrated_nobody_domains );

    @migrated_servernames      = _migrate_wildcard_encoded_userdata_files();
    @migrated_nobody_domains   = _migrate_nobody_userdata_files();
    $httpd_conf_rebuild_needed = 1 if @migrated_servernames || @migrated_nobody_domains;

    #Rebuild apache because previous rebuilds might have accidentally
    #deleted the wildcard SSL vhosts from being unable to find their
    #userdata files.
    if ($httpd_conf_rebuild_needed) {
        if ($rebuild_apache) {
            print "Rebuilding Apache\n";
            my $output = Cpanel::SafeRun::Errors::saferunallerrors("$Cpanel::root/bin/build_apache_conf");
            if ( $output !~ /OK$/ ) {
                warn "Error rebuilding the apache configuration: $output\n";
            }
            Cpanel::ServerTasks::queue_task( ['ApacheTasks'], 'apache_restart' );
        }
        else {
            print "Skipping Apache Rebuild\n";
        }
    }

    Cpanel::FileUtils::TouchFile::touchfile($TOUCH_FILE);

    return;
}

sub _migrate_nobody_userdata_files {
    my $userDir = $Cpanel::Config::userdata::Constants::USERDATA_DIR . "/nobody";
    if ( !-e $userDir ) {
        return;
    }
    my @domains_processed = ();

    {
        my $main_guard = Cpanel::Config::userdata::Guard->new( 'nobody', 'main' );
        my $maindata   = $main_guard->data();
        for my $domain ( $maindata->{'main_domain'}, @{ $maindata->{'sub_domains'} } ) {
            if ( !$domain || !Cpanel::WildcardDomain::Tiny::is_wildcard_domain($domain) || !-e $userDir . "/${domain}_SSL" ) {
                next;
            }

            my $guard    = Cpanel::Config::userdata::Guard->new( 'nobody', $domain . '_SSL' );
            my $userdata = $guard->data();

            _fix_userdata($userdata);

            push @domains_processed, $userdata->{'servername'};

            $guard->save();
        }

        $main_guard->abort();
    }

    return;
}

sub _migrate_wildcard_encoded_userdata_files {
    my @migrated_servernames            = ();
    my @wildcard_encoded_userdata_files = glob("$Cpanel::Config::userdata::Constants::USERDATA_DIR/*/_wildcard_*");

    for my $old_file (@wildcard_encoded_userdata_files) {
        next if !-f $old_file;

        if ( $old_file =~ m{\.cache\z} ) {
            unlink $old_file;
            next;
        }

        my ( $ok, %ret ) = _migrate_userdata_file($old_file);
        next if $ret{'deleted'};

        my $new_file = $old_file;

        #We *shouldn't* need the fussiness of anchoring this substitution
        #with / and \z, but just in case.
        $new_file =~ s{/_wildcard_([^/]+)\z}{/*$1};

        if ( !-f $new_file ) {
            if ( !rename( $old_file, $new_file ) ) {
                warn "The system failed to rename $old_file to $new_file because of an error: $!";
                next;
            }
            push @migrated_servernames, $ret{'servername'};
        }
    }

    return @migrated_servernames;
}

sub _migrate_userdata_file {
    my ($file) = @_;

    my ( $filename, $path, undef ) = File::Basename::fileparse($file);
    my $user        = File::Basename::basename($path);
    my %return_data = ();

    {
        my $guard    = Cpanel::Config::userdata::Guard->new( $user, $filename );
        my $userdata = $guard->data();
        if ( exists $userdata->{'servername'} ) {
            for my $ssl_part (@ssl_userdata_parts) {
                next if !$userdata->{$ssl_part};

                if ( !-e $userdata->{$ssl_part} ) {
                    $guard->abort();
                    unlink $file;
                    return ( 1, 'deleted' => 1 );
                }
            }

            _fix_userdata($userdata);

            $return_data{'servername'} = $userdata->{'servername'};

            $guard->save();
        }
        else {
            $guard->abort();
        }
    }

    return ( 1, %return_data );
}

sub _fix_userdata {
    my ($userdata) = @_;

    # Decodes wildcard encoded domains
    $userdata->{'servername'} = Cpanel::WildcardDomain::decode_wildcard_domain( $userdata->{'servername'} );
    $userdata->{'serveradmin'} =~ s{(\@)_wildcard_\.}{$1};
    $userdata->{'serveralias'} = $userdata->{'servername'};

    return;
}

1;
Bethany
Bethany
0%

THE FINEST HOTEL NEAR LAKE KIVU

The Perfect Base For You

Required fields are followed by *





EC1A68011

About Us

Delicious Interior With The Pinch Of Everything

Bethany Investment group is Presbyterian church in Rwanda(EPR) company that manage Hotel and Guest house in Karongi (Bethany Hotel), ISANO branch in GIKONDO(Kigali), Kiyovu branch(Kigali), AMIZERO branch(Nyagatare-East) and Gisenyi Branch(Rubavu).

Accomodation

Get a Comfortable Room
Feel The Comfort

Get a comfortable room and feel our hotel’s comfort. Bethany Hotel features a variety of fully furnished rooms with extra space, Executive rooms, Deluxe rooms with a beautiful lake view and garden space, Deluxe rooms, comfort rooms, family rooms and standard rooms at your service.

Standard Single

Services

We Provide Top Class Facility
Especially For You

Beach BBQ Party

Kick back on the beach& and enjoy our berbecue from our masterchef

Breakfast

Kick back at our hotels& enjoy our breakfast from our masterchef

Conference Hall

Kick back at our hotels& enjoy our conference halls from all bethany branches

Enjoy with your partner

Honeymoon Package

80%

Get In Touch

Don’t Miss Any Update

    +

    Search your Room

    Required fields are followed by *