#!/bin/sh
eval 'if [ -x /usr/local/cpanel/3rdparty/bin/perl ]; then exec /usr/local/cpanel/3rdparty/bin/perl -x -- $0 ${1+"$@"}; else exec /usr/bin/perl -x $0 ${1+"$@"}; fi;'
  if 0;

#!/usr/bin/perl

# cpanel - remservlets                            Copyright(c) 2016 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';    #issafe
}

use Cpanel::HttpUtils     ();             #issafe
use Getopt::Param         ();             #issafe
use Cpanel::EditHttpdconf ();             #issafe
use Cpanel::SafeDir       ();

if ( !-e '/usr/local/jakarta' ) {
    print 'Sorry you must install mod_jk from easyapache';
    exit;
}

my $help_cr = sub {
    print <<"END_HELP";
Remove JkMount entries to a vhost

$0 --help  (this screen)
$0 --domain=domain-you-want-to-remove-jsp-and-servlets.com

END_HELP
    exit;
};

my $prm = Getopt::Param->new(
    {    #issafe
        'help_coderef' => $help_cr,
    }
);

my @list = $prm->list_params();
$help_cr->() if @list == 0;

my $domain = $prm->get_param('domain');
$domain =~ s{ \A www [.] }{}xms;
die 'Please specify a domain' if !$prm->get_param('domain') || $prm->get_param('domain') eq '--domain';

my $removedhost = Cpanel::EditHttpdconf::del_vhost_include(
    {    #issafe
        'domain'         => $prm->get_param('domain'),
        'file'           => 'cp_jkmount.conf',
        'restart_apache' => 1,
    }
);

if ($removedhost) {
    print "Deleting cache directory for $domain: /usr/local/jakarta/work/Catalina/$domain\n";
    Cpanel::SafeDir::safermdir("/usr/local/jakarta/tomcat/work/Catalina/$domain");
    system '/usr/local/cpanel/scripts/gentomcatlist2';
    Cpanel::HttpUtils::safeaprestart();    #issafe
    print "Done: .jsp support removed for $domain\n";
}
else {
    print "Error: .jsp support could not be removed for $domain\n";
}
