Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > main-src > by-pkgid > f44114f08a89ac206daeca70b0c4364e > files > 6

apache-conf-1.3.23-4mdk.src.rpm

#!/usr/bin/perl
# advxdelmod
# Script to modify the Apache configuration file to remove a module
# (C) 2001 Jean-Michel Dault <jmdault@mandrakesoft.com> and Mandrakesoft
# You can use it under the Apache Licence

# See InstallModule for more info ;-)

$bakpath="/etc/httpd/conf/bak";

if ((!$ARGV[0]) || (!$ARGV[1]) || (!$ARGV[2]) || (!$ARGV[3])) {
    print "Usage: $0 <conffile> <mod_filename> <mod_name> \n";
    print "<name_module> [OPTIONS]\n";
    print "Options:\n";
    print " define=WHATEVER will remove module between <IfDefine WHATEVER>\n";
    print " addconf=CONFFILE removes 'Include CONFFILE' in httpd.conf\n";
    die "\n";
}

sub debug{
    if ($DEBUG) { foreach (@_) { print $_; } }
}

$_=$ARGV[1];
	s/^.*\///g;
	s/^mod_//g;
	s/^lib//g;
	s/\.so$//g;
$modso=$_;

$modc=$ARGV[2];
$name_mod=$ARGV[3];

@confparts=split(/\//,$ARGV[0]);

if ($#confparts==0) { 
#    debug "confparts=0\n";
    $confpath="/etc/httpd/conf"; 
    $conf="$ARGV[0]";
} else {
#    debug "confparts=$#confparts\n";
    $conf="$confparts[$#confparts]";
    $confpath=join('/',@confparts[0 .. $#confparts-1]);
}

system("mkdir -p $bakpath") ==0  
	or die "Can't create backup directory $bakpath\n";

#debug "Confpath: $confpath\n";
#debug "Conffile: $conf\n";
#debug "Backups: $bakpath\n";


foreach (@ARGV) {
    if (/define=(\w+)/i) {
	$opendef="<IfDefine $1>\n";
	$closedef="</IfDefine>\n";
	debug "##define=$1##\n";
    }
    if (/addconf=(\S+)/i) {
	$addconf=$1;
    }
}


$_=`date +%Y%m%d-%T`;chop;s/:/./g;$dat=$_;
$bak="$conf-$dat";
debug "$bak\n";


open(BAK,">$bakpath/$bak") or die "Can't create $bakpath/$bak\n";
open(CONFF,"$confpath/$conf") or die "Can't open $confpath/$conf\n";

while (<CONFF>) {
    print BAK $_;
    if (($opendef) && (/^$opendef/i)) { 
	debug "$opendef";
	$beginsection=$.;
	$mysection=1;
    }
    if (/^#*LoadModule\s+$name_mod\s+.*$modso/i) {
	$delline{$.}=1;
	debug "Deleting Loadmodule at line $.\n";
    }
    if (/^#*AddModule\s+$modc/i) {
	$delline{$.}=1;
	debug "Deleting Addmodule at line $.\n";
    }
    if (($addconf) &&(/^#*Include\s+$addconf/i)) {
	$delline{$.}=1;
	debug "Deleting Include at line $.";
    }
    if (($closedef) && (/^$closedef/) && ($mysection > 0)) {
	debug "$closedef";
        if ((($.-$beginsection) == 2) && ($delline{$.-1}==1)) {
	    debug "Removing entire section\n";
	    $delline{$beginsection}=$delline{$.}=1;
        }
	if (($.-$beginsection) ==1) {
	   debug "Empty section! Removing.\n";
	   $delline{$beginsection}=$delline{$.}=1;
        }
	if (($.-$beginsection) >2) {
	   debug "Section contain more than one directive...\n";
	   debug "Leaving it alone.\n";
        }
	$mysection=0;
    }
}

close(CONFF);
close(BAK);

debug "-----\n";
foreach (sort keys %delline) {
    debug "Delete line $_=";
    debug $delline{$_};
    debug "\n";
}
debug "-----\n";

open(BAK,"$bakpath/$bak") or die "Can't open $bakpath/$bak\n";
open(CONFF,">$confpath/$conf") or die "Can't create $confpath/$conf\n";

while (<BAK>) {
    if ($delline{$.}!=1) {
    print CONFF $_;
    }
}

close(CONFF);
close(BAK);