MSV FM

[email protected]: ~ $
Path : /proc/self/root/scripts/
File Upload :
Current < : //proc/self/root/scripts/maildir_converter

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

# cpanel - scripts/maildir_converter               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

use strict;
use Cpanel::PwCache::PwEnt     ();
use Cpanel::AccessIds::SetUids ();
use Cpanel::Config::Users      ();
use Cpanel::Binaries           ();
use Cpanel::Usage              ();
use Cpanel::SafeRun::Errors    ();
use Cpanel::Sys::Setsid::Fast  ();

$| = 1;

my $do_conversion = 0;
my $to_dovecot    = 0;
my $to_courier    = 0;
my $overwrite     = 0;

# Argument processing
my %opts = (
    'forreal'    => \$do_conversion,
    'overwrite'  => \$overwrite,
    'to-dovecot' => \$to_dovecot,
    'to-courier' => \$to_courier,
);

Cpanel::Usage::wrap_options( \@ARGV, \&usage, \%opts );

if ( $to_dovecot && $to_courier ) {
    print "Can not convert to dovecot and to courier at the same time!\n";
    exit 1;
}

if ( $> != 0 ) {
    die "Conversion process must be performed as root";
}

@ARGV = ( grep( !/^--/, @ARGV ) );

my @users = Cpanel::Config::Users::getcpusers();
my %USERS = map { $_ => 1 } @users;

my @CARGS;
push @CARGS, '--convert'    if ($do_conversion);
push @CARGS, '--overwrite'  if ($overwrite);
push @CARGS, '--to-dovecot' if ($to_dovecot);
push @CARGS, '--to-courier' if ($to_courier);

my $convertuser = $ARGV[0];

my $now = time();

unless ( -d '/var/cpanel/logs' ) {
    mkdir '/var/cpanel/logs' || die "Couldn't create /var/cpanel/logs directory: $!";
    chmod oct(700), '/var/cpanel/logs' || die "Couldn't set permissions on /var/cpanel/logs directory: $!";
}

my $old_umask = umask(0077);    # Case 92381: Logs should not be world-readable.
open my $log_fh, '>', '/var/cpanel/logs/imap_conversion.log.' . $now;
umask($old_umask);

if ( !$log_fh ) {
    die "Couldn't open log file: $!";
}

my @conversion_failures;

$SIG{'INT'} = $SIG{'HUP'} = sub {
    print "maildir_converter Ignoring signal to avoid mail corruption\n";
    return;
};

my $quotaon_cmd  = Cpanel::Binaries::path('quotaon');
my $quotaoff_cmd = Cpanel::Binaries::path('quotaoff');

# Disable quotas
if ( -x $quotaoff_cmd ) {
    system $quotaoff_cmd, '-a';
}

Cpanel::PwCache::PwEnt::setpwent();
while ( my @PW = Cpanel::PwCache::PwEnt::getpwent() ) {
    my ( $user, $uid, $gid, $homedir ) = @PW[ 0, 2, 3, 7 ];
    next if ( $convertuser && $user ne $convertuser );
    next if ( !exists $USERS{$user} );

    $homedir =~ /(.*)/;    # Untaint
    $homedir = $1;

    if ( !-d $homedir ) { next; }
    my @maildirs = find_maildirs($homedir);
    foreach my $dir (@maildirs) {
        $dir =~ /(.*)/;
        $dir = $1;
        print "Converting $dir...";

        if ( my $pid = fork() ) {

            #parent
            waitpid( $pid, 0 );
            my $exitcode = $?;
            if ($exitcode) {
                print "failed\n";
                push @conversion_failures, $user . ':' . $dir . ':' . $now . "\n";
            }
            else {
                print "ok\n";
            }
        }
        else {
            Cpanel::Sys::Setsid::Fast::fast_setsid();
            Cpanel::AccessIds::SetUids::setuids( $uid, $gid );
            chdir $dir || exit 1;
            my $output = Cpanel::SafeRun::Errors::saferunallerrors( '/usr/local/cpanel/bin/maildir-migrate', @CARGS, '--recursive' );
            print $log_fh "\nDirectory: $dir\n";
            print $log_fh join( ' ', '/usr/local/cpanel/bin/maildir-migrate', @CARGS, '--recursive' ) . "\n";
            print $log_fh $output . "\n";
            my $exitcode = $?;
            exit $exitcode >> 8;
        }
    }
}
Cpanel::PwCache::PwEnt::endpwent();

close $log_fh;

# Restore quotas
if ( -x $quotaon_cmd ) {
    system $quotaon_cmd, '-a';
}

if ( scalar @conversion_failures ) {
    my $old_umask = umask(0077);    # Case 92381: Logs should not be world-readable.
    open my $failure_fh, '>>', '/var/cpanel/logs/imap_conversion_failures';
    umask($old_umask);

    if ( !$failure_fh ) {
        die "Couldn't open log file: $!";
    }

    print $failure_fh @conversion_failures;
    close $failure_fh;
    print "\nSome failures were encountered during maildir conversion process.\n";
    print "Full log available at: /var/cpanel/logs/imap_conversion.log.$now\n";
    exit 1;
}
exit 0;

sub find_maildirs {
    my $homedir = shift;
    my @maildirs;
    if ( -d $homedir . '/mail/cur' && -d $homedir . '/mail/new' ) {
        push @maildirs, $homedir . '/mail';
        if ( opendir( my $base_dh, $homedir . '/mail' ) ) {
            my @base_dirlist = readdir($base_dh);
            closedir $base_dh;
            foreach my $base_dir (@base_dirlist) {
                next if ( $base_dir =~ /^(?:\.|cur\Z|tmp\Z|new\Z)/ );
                next unless ( -d $homedir . '/mail/' . $base_dir );
                if ( opendir( my $sub_dh, $homedir . '/mail/' . $base_dir ) ) {
                    my @sub_dirlist = readdir($sub_dh);
                    closedir $sub_dh;
                    foreach my $sub_dir (@sub_dirlist) {
                        next if ( $sub_dir =~ /^\./ );
                        next unless ( -d $homedir . '/mail/' . $base_dir . '/' . $sub_dir . '/cur' && -d $homedir . '/mail/' . $base_dir . '/' . $sub_dir . '/new' );
                        push @maildirs, $homedir . '/mail/' . $base_dir . '/' . $sub_dir;
                    }
                }
            }
        }
    }
    return @maildirs;
}

sub usage {
    print "Usage: maildir_converter [options] [user]\n\n";
    print "Options:\n";
    print "    --forreal       Perform conversion\n";
    print "    --overwrite     Overwrite existing files\n";
    print "    --to-dovecot    Conversion is from Courier to Dovecot\n";
    print "    --to-courier    Conversion is from Dovecot to Courier\n";
    print "\n";
    print "If no user is specified, maildirs for all accounts will be converted.\n";
    print "\n";
    print "When direction over conversion (dovecot/courier) is not specified\n";
    print "maildir files will be updated based on relative timestamps.\n";

    exit 0;
}
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 *