rendered paste body#!/usr/bin/perl
use strict;
#use warnings;
### Globals
my $version = "0.0.1";
my %matched;
my $lineout;
my $php_ini = shift or die usage();
### Main
open( INFILE, "<$php_ini" )
or die "Cannot open $php_ini or file does not exist.\n\n" . usage();
open( OUTFILE, ">>./php.ini.tmp" );
`cp -f $php_ini $php_ini.old`;
my $ln = 0;
foreach (<INFILE>) {
chomp;
$ln++;
my $line = replace($_);
if ($line) {
$_ =~ s/^;//;
$_ =~ s/(.*?)\s*;.*$/$1/;
print "$ln: $_ -> $line\n";
$lineout = $line;
}
else {
$lineout = $_;
}
chomp($lineout);
print OUTFILE "$lineout\n";
}
close INFILE;
close OUTFILE;
print "Do you wish to write this file out? (y/n) : ";
while (1) {
chomp( my $reply = <STDIN> );
if ( $reply eq "y" ) {
`mv ./php.ini.tmp $php_ini`;
last;
}
elsif ( $reply eq "n" ) {
last;
}
print "please answer (y/n) : ";
}
## Subroutines
sub replace {
my $current = shift;
if ( $current =~ m/^\s*(post_max_size)\s+/ ) {
return "$1 = 100M";
}
elsif ( $current =~ m/^\s*(upload_max_filesize)\s+/ ) {
return "$1 = 100M";
}
elsif ( $current =~ m/^\s*(max_execution_time)\s+/ ) {
return "$1 = 6000";
}
elsif ( $current =~ m/^\s*;{0,1}(include_path)\s+/ && $matched{$1} == 0) {
$matched{$1}++;
return "$1"
. ' = ".:/usr/share/php:/share/php:/usr/share/php/smarty"' . "\n";
}
elsif ( $current =~ m/^\s*(display_errors)\s+/ ) {
my $reply;
print
"Do you wish to turn display_errors off? Leave this on for test installations. (y or n) : ";
while (1) {
chomp( $reply = <STDIN> );
if ( $reply eq "y" or "n" ) { last; }
print "(please answer y or n) : ";
}
if ( $reply eq "y" ) {
return "$1 = Off";
}
elsif ( $reply eq "n" ) {
return "$1 = On";
}
}
elsif ( $current =~ m/^\s*(log_errors)\s+/ ) {
return "$1 = On";
}
elsif ( $current =~ m/^\s*(auto_detect_line_endings)\s+/ ) {
return "$1 = On";
}
}
sub usage {
return <<USAGE
$0 $version -- (robf)
Usage: $0 <location of php.ini>
eg. $0 /etc/php/cli-php5/php.ini
A backup of the original will be made <location of php.ini>.old
USAGE
}