<?php
include("/usr/local/cpanel/php/cpanel.php");
$cpanel = new CPANEL();
print $cpanel->header( "PrivateJVM Domain Map Tool" );
?>

<?php
$cpUser = $cpanel->cpanelprint('$user');
$cpHomeDir = $cpanel->cpanelprint('$homedir');
$domain1 = $_GET['domain'];
$jvmdb = "$cpHomeDir/.cpanel/jvm.db";
$setstatus=$_GET['setstatus'];

$get_userdata = $cpanel->uapi(
        'DomainInfo', 'single_domain_data',
        array(
            'domain'    => $domain1,
            'return_https_redirect_status' => '1'
        )
    );

$domain=$get_userdata['cpanelresult']['result']['data']['servername'];

if(!file_exists($jvmdb)){
        die("Error: JVM database is missing, please contact technical support.");
}
$std_file="/etc/apache2/conf.d/userdata/std/2_4/$cpUser/$domain/cp_jvm.conf";
$ssl_file="/etc/apache2/conf.d/userdata/ssl/2_4/$cpUser/$domain/cp_jvm.conf";

$std_file1="/usr/local/apache/conf/userdata/std/2/$cpUser/$domain/cp_jvm.conf";

if($setstatus == "map"){
$my_variable = $cpanel->api2(
    'CustomModuleJVM', 'do_MyJvm_stuff',
    array(
        'map'      => $domain,
    )
 );
} elseif($setstatus == "unmap"){
$my_variable = $cpanel->api2(
    'CustomModuleJVM', 'do_MyJvm_stuff',
    array(
        'unmap'      => $domain,
    )
 );
} else {
        $setstatus = null;
}



if(file_exists($std_file) || file_exists($std_file1)){
        echo "<div class=\"container\">";
        echo "<div class=\"panel panel-default\">";
        echo "<div class=\"panel-heading\">Domain $domain1</div>";
        echo "<div class=\"panel-body\"><h4>Domain status: <font color=green>JVM is enabled</font> </h4><hr> <a href=\"?domain=$domain&setstatus=unmap\" class=\"btn btn-danger\" role=\"button\">Disble JVM</a></div>";
        echo "</div>";
        echo "</div>";

}

else{
        echo "<div class=\"container\">";
        echo "<div class=\"panel panel-default\">";
        echo "<div class=\"panel-heading\">Domain $domain1</div>";
        echo "<div class=\"panel-body\"><h4>Domain status: <font color=red>JVM is disabled</font> </h4><hr> <a href=\"?domain=$domain&setstatus=map\" class=\"btn btn-success\" role=\"button\">Enable JVM</a></div>";
        echo "</div>";
        echo "</div>";
}


?>

<hr>
<a href="index.html">Back</a>
<?php
print $cpanel->footer();
$cpanel->end();
?>
