403Webshell
Server IP : 103.119.228.120  /  Your IP : 18.116.15.22
Web Server : Apache
System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User : nobody ( 99)
PHP Version : 5.6.40
Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime
MySQL : ON |  cURL : ON |  WGET : ON |  Perl : ON |  Python : ON |  Sudo : ON |  Pkexec : ON
Directory :  /scripts/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /scripts/maildir_converter
#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/maildir_converter               Copyright 2022 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 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;
}

Youez - 2016 - github.com/yon3zu
LinuXploit