????
Current Path : /proc/325305/root/proc/325304/root/scripts/ |
Current File : //proc/325305/root/proc/325304/root/scripts/checkerrorlogsafe |
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - scripts/checkerrorlogsafe Copyright 2014 cPanel, Inc. # All rights Reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited use Cpanel::SafeFile (); use Cpanel::ConfigFiles::Apache (); use Cpanel::HttpUtils::ApRestart::BgSafe (); use Cpanel::Logger (); my $apacheconf = Cpanel::ConfigFiles::Apache->new(); my $logger = Cpanel::Logger->new(); my $errblk = <<EOM; <Files ~ "^error_log\$"> Order allow,deny Deny from all Satisfy All </Files> EOM my $httpconf = $apacheconf->file_conf(); 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'); undef $hlock; $hlock = Cpanel::SafeFile::safeopen( \*HTTPC, '+<', $httpconf ); if ( !$hlock ) { $logger->die("Could not edit $httpconf"); } my @CFILE; 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::HttpUtils::ApRestart::BgSafe::restart();