File: //proc/self/root/proc/self/root/scripts.20110531.215904.25158/checkfcgid
#!/usr/bin/perl
# cpanel - checkfcgid 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::HttpUtils ();
use Cpanel::Logger ();
my $logger = Cpanel::Logger->new();
my $apache_base = '/usr/local/apache';
my $modules_dir = $apache_base . '/modules';
my $httpdconf = $apache_base . '/conf/httpd.conf';
my $restart = @ARGV && grep( /^--no-restart$/, @ARGV ) ? 0 : 1;
my $verbose = @ARGV && grep( /^--verbose$/, @ARGV ) ? 1 : 0;
if ( !-e $modules_dir . '/mod_fcgid.so' ) {
print "The current apache does not have FCGID support\n";
exit 1;
}
my $has_load_module;
my $needs_update;
my $last_load_module;
my $last_add_module;
my $hlock = Cpanel::SafeFile::safeopen( \*HTTPC, '+<', $httpdconf );
if ( !$hlock ) {
$logger->die("Could not edit $httpdconf");
}
my $line_count = 1;
my @httpdconf;
while ( my $line = <HTTPC> ) {
if ( $line =~ m/^\s*LoadModule\s+(.+)\s*(?:$|#)/ ) {
my $load_module = $1;
$load_module =~ s/(?:^\s+|\s+$)//g;
if ( $load_module =~ m/^fcgid_module\s+modules\/mod_fcgid\.so$/ ) {
$has_load_module = 1;
$line_count++;
push @httpdconf, $line;
}
else {
$line_count++;
push @httpdconf, $line;
$last_load_module = $line_count;
}
}
else {
$line_count++;
push @httpdconf, $line;
}
}
if ( !$needs_update && $has_load_module && !$has_add_module ) {
Cpanel::SafeFile::safeclose( \*HTTPC, $hlock );
exit;
}
print "Updating Apache configuration\n";
seek( HTTPC, 0, 0 );
my $new_line_count = 0;
foreach my $line (@httpdconf) {
$new_line_count++;
if ( $new_line_count == $last_load_module ) {
print HTTPC "LoadModule fcgid_module modules/mod_fcgid.so\n";
}
else {
print HTTPC $line;
}
}
truncate( HTTPC, tell(HTTPC) );
Cpanel::SafeFile::safeclose( \*HTTPC, $hlock );
if ($restart) {
Cpanel::HttpUtils::safeaprestart();
}
exit;