MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //scripts.20110531.215904.25158/killvhost
#!/usr/bin/perl
# cpanel - killvhost                              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 strict;
use Cpanel::ConfigFiles ();
use Cpanel::DomainTools ();
use Cpanel::Logger      ();
use Cpanel::RcsRecord   ();
use Cpanel::SafeFile;

my $logger = Cpanel::Logger->new();

my $httpconf = Cpanel::ConfigFiles::find_httpconf();

my $servername = $ARGV[0];
$servername =~ s/[\n\s]*//g;
exit if !$servername;
exit if length($servername) < 3;

my $domain = $servername;

# if domain is an IP, let it pass the domain check, needed for domainfwdip

if ( $domain !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ ) {
    $domain = Cpanel::DomainTools::normalize($domain);
    if ( !Cpanel::DomainTools::is_valid($domain) ) {
        print "Sorry, that's an invalid domain\n";
        exit;
    }
}

Cpanel::RcsRecord::rcsrecord( $httpconf, "Initial check-in: remove $domain" );

my $ivh      = 0;
my $hasip    = 1;
my $pln      = 1;
my $vh       = '';
my $httplock = Cpanel::SafeFile::safeopen( \*HTTPCONF, '+<', $httpconf );
if ( !$httplock ) {
    $logger->die("Could not edit $httpconf");
}
my @THTTPCONF = <HTTPCONF>;
seek( HTTPCONF, 0, 0 );
my $removed = 0;
my $lc      = 0;
foreach my $line (@THTTPCONF) {
    $lc++;
    if ( ( $domain =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ ) && ( $line =~ m/^\s*# WHM DOMAIN FORWARDING VHOST/ ) ) { next; }    # remove comment for domain forwarder if killing an IP (domainfwdip is the only ip based servername)
    if ($ivh) {
        if ( $line =~ /^\s*servername\s+(www\.)?\Q${domain}\E$/i ) {
            print "Removed $domain Server at line: $lc.\n";
            $pln     = 0;
            $removed = 1;
        }
    }
    if ( $line =~ /^\s*<virtualhost/i ) {
        $ivh = 1;
        $vh  = '';
        $pln = 1;
    }
    if ($ivh) { $vh .= $line; }
    if ( $ivh == 0 ) {
        print HTTPCONF $line;
    }
    if ( $line =~ /\s*<\/virtualhost/i ) {
        $ivh = 0;
        if ( $pln == 1 ) { print HTTPCONF $vh; }
        $vh = '';
    }
}
truncate( HTTPCONF, tell(HTTPCONF) );
Cpanel::SafeFile::safeclose( \*HTTPCONF, $httplock );
if ( !$removed ) {
    print "$domain not found in httpd.conf.\n";
}
else {
    print "Removed Entry from httpd.conf\n";
}

Cpanel::RcsRecord::rcsrecord( $httpconf, "Final check-in: remove $domain" );