File: //proc/self/root/scripts.20110531.215904.25158/checkallowoverride
#!/usr/bin/perl
# cpanel - checkallowoverride 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::RcsRecord ();
use Cpanel::HttpUtils::ApRestart ();
use Cpanel::Logger ();
my $logger = Cpanel::Logger->new();
my $httpdconf = '/usr/local/apache/conf/httpd.conf';
my $restart = @ARGV && grep( /^--no-restart$/, @ARGV ) ? 0 : 1;
my $verbose = @ARGV && grep( /^--verbose$/, @ARGV ) ? 1 : 0;
my $hlock = Cpanel::SafeFile::safeopen( \*HTTPC, '<', $httpdconf );
if ( !$hlock ) {
$logger->die("Could not read from $httpdconf");
}
my $inslashdir;
my $needs_update;
while (<HTTPC>) {
if ($inslashdir) {
if ( m/^\s*AllowOverride\s+none/i || m/^\s*Order\s+/i || m/^\s*Deny\s+/i ) {
$needs_update = 1;
}
}
if (m/^\s*<Directory\s+"?\/"?>/i) {
$inslashdir = 1;
}
elsif (m/^\s*<\/Directory/i) {
$inslashdir = 0;
}
}
Cpanel::SafeFile::safeclose( \*HTTPC, $hlock );
exit if !$needs_update;
print "Updating Apache configuration\n";
$inslashdir = 0;
$hlock = '';
Cpanel::RcsRecord::rcsrecord( $httpdconf, 'checkallowoverride BEGIN' );
$hlock = Cpanel::SafeFile::safeopen( \*HTTPC, '+<', $httpdconf );
if ( !$hlock ) {
$logger->die("Could not edit $httpdconf");
}
while (<HTTPC>) {
push @CFILE, $_;
}
seek( HTTPC, 0, 0 );
foreach (@CFILE) {
if ($inslashdir) {
if (m/^(\s*)AllowOverride\s+none/i) {
print "Updating AllowOverride to All\n" if $verbose;
print HTTPC $1 . "AllowOverride All\n";
}
elsif (m/^(\s*)Options\s+(?:none|follow)/i) {
print "Updating Options to All\n" if $verbose;
print HTTPC $1 . "Options All\n";
}
elsif ( m/^\s*Order\s+/ || m/^\s*Deny\s+/ ) {
print "Removing $_" if $verbose;
next;
}
else {
print HTTPC;
}
}
else {
print HTTPC;
}
if (m/^\s*<Directory\s+"?\/"?>/i) {
$inslashdir = 1;
}
if (m/^\s*<\/Directory/i) {
$inslashdir = 0;
}
}
truncate( HTTPC, tell(HTTPC) );
Cpanel::SafeFile::safeclose( \*HTTPC, $hlock );
Cpanel::RcsRecord::rcsrecord( $httpdconf, 'checkallowoverride END' );
if ($restart) {
Cpanel::HttpUtils::ApRestart::safeaprestart();
}
exit;