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/proc/self/root/scripts.20110531.215904.25158/restartsrv_exim
#!/usr/bin/perl
# cpanel - restartsrv_exim                        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', '/scripts'; }

use strict;
use RestartSrv;
use Cpanel::FileUtils::TouchFile ();
use Cpanel::OSSys                ();

require '/scripts/checkexim.pl';

eval {
    local $SIG{'__DIE__'};
    require Cpanel::Rlimit;
    Cpanel::Rlimit::set_rlimit_to_infinity();
};

setuppath();

my ( $system, $nodename, $release, $version, $machine ) = Cpanel::OSSys::uname();
my ( $restart, $check, $status ) = parseargv();

my $eximscript         = '';
my $antirelaydscript   = '';
my $eximdisabled       = 0;
my $antirelayddisabled = 0;

if ( -e '/etc/eximdisable' ) {
    $eximdisabled = 1;
}

checkeximlogs();

if ($restart) {
    my $lock_file = '/var/run/restartsrv_exim.lock';
    lock_file($lock_file);

    if ( $system !~ /freebsd/i ) {
        $eximscript = getinitfile( 'exim', $system );
    }

    if ( !$eximdisabled ) {
        Cpanel::FileUtils::TouchFile::touchfile('/etc/relayhosts');
        if ($eximscript) {
            nooutputsystem( $eximscript, 'stop' );
            doomedprocess('exim');
            if ( $restart != -1 ) {
                system( $eximscript, 'start' );
            }
        }
        else {
            doomedprocess('exim');
            doomedprocess('sendmail');
            if ( $restart != -1 ) {
                my $eximbin = &geteximbin();
                system( $eximbin, '-bd', '-q30m' );
                my $exim_other_port = exim_other_port() ;
                my $has_built_in_tls_on_connect=0;
                my $has_built_in_other_port=0;
                open(my $exim_cf,'<','/etc/exim.conf');
                while(readline($exim_cf)) {
                    if (/^\s*daemon_smtp_port.*465/) {
                        $has_built_in_tls_on_connect=1;
                    }
#no elsif on purpose
                    if (/^\s*daemon_smtp_port.*$exim_other_port/) {
                        $has_built_in_other_port=1;
                    }
                }
                close($exim_cf);
                if (!$has_built_in_tls_on_connect) {
                    system( $eximbin, '-tls-on-connect', '-bd', '-oX', '465' );
                }   
                if ( !$has_built_in_other_port && $exim_other_port ) {
                    system( $eximbin, '-bd', '-oX', $exim_other_port );
                }
            }
        }
    }

    my $antirelaydscript = getinitfile( 'antirelayd', $system );
    if ($antirelaydscript) {
        nooutputsystem( $antirelaydscript, 'stop' );
    }
    doomedprocess('antirelayd');

    unlink $lock_file if -e $lock_file;

}
elsif ($status) {

    #--status (show ps)
    if ($eximdisabled) {
        print "exim is disabled\n";
    }
    else {
        print check_service( 'service' => 'exim', 'user' => 'mailnull' );
    }
}
elsif ($check) {
    if ( !$eximdisabled && check_service( 'regex' => '\bexim[\s]?', 'service' => 'exim', 'user' => 'mailnull' ) eq '' ) {
        print "Exim is not running\n";
    }
}

sub exim_other_port {

    # Locate exim running on non-default port
    my $chksrvddir = '/etc/chkserv.d';
    my $entry      = '';
    opendir DH, $chksrvddir or die "Cannot open $chksrvddir";
    while ( $entry = readdir DH ) {
        next if $entry =~ /^\./;    #skip over dot files
        if ( $entry =~ /^exim-(\d+)$/ ) {
            return $1;
        }
    }
    return undef;
    closedir(DH);
}

sub geteximbin {
    my $eximbin;
    if ( -x '/usr/local/sbin/exim' ) {
        $eximbin = '/usr/local/sbin/exim';
    }
    elsif ( -x '/usr/sbin/exim' ) {
        $eximbin = '/usr/sbin/exim';
    }
    return $eximbin;
}