#!/usr/bin/perl

BEGIN {
        push(@INC,"/scripts");
}

use RcsRecord qw(rcsrecord);
use SafeFile;

$httplock = SafeFile::safeopen(\*HC,"+<","/usr/local/apache/conf/httpd.conf");
while(<HC>) {
        push(@CFILE,$_);
}
seek(HC,0,0);
foreach(@CFILE) {
    $line = $_;
    if (! ($line =~ /^#/) ) {
           if ($line =~ /^\s*RewriteMap\s*LeechProtect\s* /i) {
               next;
           }
           if ($line =~ /^\s*RewriteEngine\s*on\s* /i) {
               print <<EOM;
+-----------------------------------------------------+
| !! Currently mod_rewrite's RewriteEngine is on. !!  |
|This script will not turn it off, so you may want to |
|disable it in the apache configuration file manually.|
+-----------------------------------------------------+
EOM
           }
           print HC $line;
       }
}

truncate(HC,tell(HC));
SafeFile::safeclose(\*HC,$httplock);

rcsrecord("/usr/local/apache/conf/httpd.conf");

safeaprestart();


sub safeaprestart {
        if (-x "/usr/local/cpanel/bin/safeapacherestart") {
                system("/usr/local/cpanel/bin/safeapacherestart");
        } else {
                if (-x "/usr/bin/killall") {
                        system("/usr/bin/killall","-USR1","httpd");
                } elsif (-x "/usr/sbin/killall") {
                        system("/usr/sbin/killall","-USR1","httpd");
                } elsif (-x "/sbin/killall") {
                        system("/sbin/killall","-USR1","httpd");
                } elsif (-x "/bin/killall") {
                        system("/bin/killall","-USR1","httpd");
                } elsif (-x "/usr/local/bin/killall") {
                        system("/usr/local/bin/killall","-USR1","httpd");
                } elsif (-x "/usr/local/sbin/killall") {
                        system("/usr/local/sbin/killall","-USR1","httpd");
                }
        }
}
