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();