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: //scripts.20110531.215904.25158/checkerrorlogsafe
#!/usr/bin/perl
# cpanel - checkerrorlogsafe                      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'; }

use Cpanel::SafeFile             ();
use Cpanel::ConfigFiles          ();
use Cpanel::HttpUtils::ApRestart ();
use Cpanel::RcsRecord            ();
use Cpanel::Logger               ();

my $logger = Cpanel::Logger->new();

my $errblk = <<EOM;

<Files ~ "^error_log\$">
    Order allow,deny
    Deny from all
    Satisfy All
</Files>

EOM

my $httpconf = Cpanel::ConfigFiles::find_httpconf();
my $hlock = Cpanel::SafeFile::safeopen( \*HTTPC, $httpconf );
if ( !$hlock ) {
    $logger->die("Could not read from $httpconf");
}

my $haserrlog = 0;
while (<HTTPC>) {
    if (/<files.*error_log/i) {
        $haserrlog = 1;
    }
}
Cpanel::SafeFile::safeclose( \*HTTPC, $hlock );

exit if $haserrlog;

$logger->info('Adding error_log exclusion to Apache configuration');

Cpanel::RcsRecord::rcsrecord( $httpconf, 'checkerrorlogsafe BEGIN' );

undef $hlock;
$hlock = Cpanel::SafeFile::safeopen( \*HTTPC, '+<', $httpconf );
if ( !$hlock ) {
    $logger->die("Could not edit $httpconf");
}

while (<HTTPC>) {
    push @CFILE, $_;
}

seek( HTTPC, 0, 0 );

foreach my $line (@CFILE) {
    if ($line =~ m/^\s*<files.*\.ht/i) {
        print HTTPC $errblk;
    }
    print HTTPC $line;

}
truncate( HTTPC, tell(HTTPC) );
Cpanel::SafeFile::safeclose( \*HTTPC, $hlock );

Cpanel::RcsRecord::rcsrecord( $httpconf, 'checkerrorlogsafe END' );

Cpanel::HttpUtils::ApRestart::safeaprestart();