File: //scripts.20110531.215904.25158/modgzipconfmods
#!/usr/bin/perl
# cpanel - modgzipconfmods 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::EditHttpdconf ();
use Cpanel::Logger ();
my $logger = Cpanel::Logger->new();
my $t_file = ( grep( s/^--apache-conf=(\S+).*/$1/, @ARGV ) )[0];
my $apache_conf = $t_file && -e $t_file ? $t_file : '/usr/local/apache/conf/httpd.conf';
if ( defined $ARGV[0] && $ARGV[0] eq '--force' ) {
system '/scripts/strip_apache_directive', '--apache-conf=' . $apache_conf, '--no-restart', '<IfModule mod_gzip.c>';
}
else {
local $ENV{'exit-with-message'} = '';
Cpanel::EditHttpdconf::edit_httpdconf(
sub {
my ( $rw_fh, $safe_replace_content_coderef ) = @_;
LINE:
while ( my $line = readline($rw_fh) ) {
next LINE if (/^\s*#/);
if ( $line =~ /^\s*mod_gzip_on/ ) {
$ENV{'exit-with-message'} = "mod gzip directives appear to already be setup,\nuse --force to force their removal and re-addition";
return;
}
}
},
$apache_conf
);
if ( $ENV{'exit-with-message'} ) {
print $ENV{'exit-with-message'} . "\n";
exit;
}
}
my $httplock = Cpanel::SafeFile::safeopen( \*HTTPC, '>>', $apache_conf );
if ( !$httplock ) {
$logger->die("Could not write to $apache_conf");
}
print HTTPC<<EOM;
<IfModule mod_gzip.c>
mod_gzip_on yes
mod_gzip_send_vary yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_temp_dir /tmp
mod_gzip_minimum_file_size 1002
mod_gzip_maximum_file_size 0
mod_gzip_maximum_inmem_size 1000000
mod_gzip_item_include file "\\.htm\$"
mod_gzip_item_include file "\\.html\$"
mod_gzip_item_include mime "text/.*"
mod_gzip_item_include file "\\.php\$"
mod_gzip_item_include mime "jserv-servlet"
mod_gzip_item_include handler "jserv-servlet"
mod_gzip_item_include mime "application/x-httpd-php.*"
mod_gzip_item_include mime "httpd/unix-directory"
mod_gzip_item_exclude file "\\.css\$"
mod_gzip_item_exclude file "\\.js\$"
mod_gzip_item_exclude file "\\.wml\$"
</IfModule>
EOM
Cpanel::SafeFile::safeclose( \*HTTPC, $httplock );
if ( $apache_conf = '/usr/local/apache/conf/httpd.conf' ) {
Cpanel::RcsRecord::rcsrecord( '/usr/local/apache/conf/httpd.conf', "mod_gzip via $0" );
}