MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //proc/self/root/scripts.20110531.215904.25158/convert2maildir
#!/usr/bin/perl
# cpanel - convert2maildir                        Copyright(c) 2010 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cpanel license. Unauthorized copying is prohibited

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

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

use strict;
use Cpanel::Config::LoadCpConf ();
use Cpanel::Config::Backup     ();
use Cpanel::HttpRequest        ();
use Cpanel::MailDir            ();

my %BACKCONF = Cpanel::Config::Backup::load();

mainMenu();

sub mainMenu {
    my %CPCONF = Cpanel::Config::LoadCpConf::loadcpconf();

    if ( open my $logo_fh, '<', '/scripts/logo.dat' ) {
        while (<$logo_fh>) {
            s{%x%}{Mail Directory (maildir) Conversion System}g;
            print;
        }
        close $logo_fh;
    }

    print qq{NOTE: For users using POP accounts, converted messages will appear as new and will download twice. Users should re-download their messages after the conversion completes.\n\n};

    my $option;
    if ( $CPCONF{'maildir'} ne '1' ) {
        print "maildir is not active, this system is using mbox\n\n";
        print "1) Backup all mail folders on this server\n";
        print "2) Restore a mail backup\n";
        print "3) Start maildir conversion process with Courier mail server\n";
        print "4) Start maildir conversion process with Dovecot mail server\n";
        print "*) Exit\n";
        print "Enter Selection---] ";
        chomp( $option = <STDIN> );
        if    ( $option =~ /^1/ ) { backup(); }
        elsif ( $option =~ /^2/ ) { restore(); }
        elsif ( $option =~ /^3/ ) { convert('courier'); }
        elsif ( $option =~ /^4/ ) { convert('dovecot'); }
        else                      { exit(); }
    }
    else {
        print "maildir is enabled\n\n";
        print "1) Restore system to mbox (non-maildir) state.\n";
        print "2) Convert partially converted mail accounts\n";
        print "3) Attempt to finish a failed conversion\n";
        print "*) Exit\n";
        print "Enter Selection---] ";
        chomp( $option = <STDIN> );
        if    ( $option =~ /^1/ ) { restoreAll(); }
        elsif ( $option =~ /^2/ ) { convert(); }
        elsif ( $option =~ /^3/ ) { checkconvertfail(); }
        else                      { exit(); }
    }
    mainMenu();
}

sub restore {
    Cpanel::MailDir::checksources( $BACKCONF{'BACKUPDIR'} );
    my $option;
    print "Are you sure you wish to overwrite the current system with the backups? ";
    chomp( $option = <STDIN> );
    if ( $option =~ /^y/i ) {
        Cpanel::MailDir::restoreMbox( $BACKCONF{'BACKUPDIR'} );
    }
}

sub restoreAll {
    my $option;

    print "Do you wish to restore the mail backup as well (mailboxes will revert back to their contents before the conversion)? ";
    chomp( $option = <STDIN> );
    if ( $option =~ /^y/i ) {
        Cpanel::MailDir::restoreMbox( $BACKCONF{'BACKUPDIR'} );
    }
    Cpanel::MailDir::restoreMboxConfig();
}

sub backup {
    Cpanel::MailDir::checksources( $BACKCONF{'BACKUPDIR'} );

    my $option;
    print "Are you sure you wish to backup (this will overwrite any previous backups done from this utility)? ";
    chomp( $option = <STDIN> );
    return if ( $option !~ /^y/i );
    Cpanel::MailDir::backupMbox( $BACKCONF{'BACKUPDIR'} );
}

sub convert {
    my $mailserver_type = shift;
    print "Conversion in progress.....this can take 5 minutes - 24 hours depending on the number of accounts, and the system hardware.\n";
    print "\t.....DO NOT CANCEL THE PROCESS OR YOU MAY BE LEFT WITH A BROKEN MAIL SYSTEM....\n";
    print "\t.....DO NOT CANCEL THE PROCESS OR YOU MAY BE LEFT WITH A BROKEN MAIL SYSTEM....\n";
    print "\t.....DO NOT CANCEL THE PROCESS OR YOU MAY BE LEFT WITH A BROKEN MAIL SYSTEM....\n";
    print "Conversion Started!\n";
    my @cmd = ('/usr/local/cpanel/bin/maildirconversion');
    push @cmd, $mailserver_type if $mailserver_type;
    system(@cmd);

    print qq{
        If you wish to watch the progress of the conversion, we recommend tailing the log file
by running 'tail -f' on the log. \n};
    exit(0);
}

sub unfreezeexim {
    unlink("/usr/local/cpanel/etc/exim/cf/fail_remote_domains");
    system("/scripts/buildeximconf");
    system( "/scripts/restartsrv", "exim" );
}

sub checkconvertfail {
    if ( -e "/usr/local/cpanel/etc/exim/cf/fail_remote_domains" ) {
        print "It appears that a previous conversion failed.\n";
        print "Attempted to finish the conversion....";
        unfreezeexim();
        print "Done\n";
    }
    else {
        print "Could not find a failed conversion!\n";
    }
}