Files
resatennis_tyroltenn/IDrive/.config/createManualJob.php

218 lines
6.8 KiB
PHP
Executable File

<?php
include_once 'path.php';
$startManualTaskButtonPressed = false;
$cancelManualTaskButtonPressed = false;
if(!isset($_SESSION['validUser']) || $_SESSION['validUser'] !== true)
exit(header("Location:../index.php"));
if(empty($_POST)){
$resp = array(false,null, "Unknown error.");
echo json_encode($resp);
exit;
}
$jobType = trim($_POST['jobTypeManualTask']);
$jobNameDir = "+ManualTask";
if(isset($_POST['trash']))
$jobNameDir = "+TrashManualTask";
$jobTypePath = Scheduler::$user_dir."$jobType";
$jobNameDirPath = "$jobTypePath/$jobNameDir";
//For Two-tier: Checking whether scheduled job is running or not
if(isset($_POST["startManualTaskButton"]) && $_POST["startManualTaskButton"]=='Yes'){
$oldJobName = str_replace_first($jobType.'_','',$_POST['oldJobName']);
$jobstatus = isScheduledJobRunning($jobType,$oldJobName);
if($jobstatus == true){
$jobType = strtolower($jobType);
$resp[] = false;
$resp[] = 1;
$resp[] = "Unable to start $jobType. Scheduled $jobType is in progress.";
echo json_encode($resp);
exit;
}
}
if(strpos($jobType, "Restore")>=0){
//Update restore location
if(isset($_POST['restoreLocation']) && $_POST['restoreLocation']){
$restoreLocation = phpRealEscapeString($_POST['restoreLocation']);
file_put_contents($drlFile,$restoreLocation);
@chmod($drlFile, $permissionVal);
}
//Update local backup location to restore items
if(isset($_POST['sourcePath'])){
$localmpc = phpRealEscapeString($_POST['sourcePath']);
if($jobType=="LocalRestore"){
$dedupBucket = '';
if(isset($_POST['dedupBucket']) && $_POST['dedupBucket']){
$dedupBucket = $_POST['dedupBucket'];
}
$path = json_encode(array('hostName'=>$localmpc,'deviceID'=>$dedupBucket));
file_put_contents($localMPCfile,$path);
@chmod($localMPCfile, $permissionVal);
} else if($_SESSION['dedup']) {
file_put_contents($dedupRestoreDeviceID,$localmpc);
@chmod($dedupRestoreDeviceID, $permissionVal);
}
}
} else {
//Update local backup location
if(isset($_POST['localBackupLocation']) && $_POST['localBackupLocation']){
$localmpc = phpRealEscapeString($_POST['localBackupLocation']);
$dedupBucket = '';
if(isset($_POST['dedupBucket']) && $_POST['dedupBucket']){
$dedupBucket = $_POST['dedupBucket'];
}
$path = json_encode(array('hostName'=>$localmpc,'deviceID'=>$dedupBucket));
file_put_contents($localMPCfile,$path);
@chmod($localMPCfile, $permissionVal);
}
//Update Cloud backup location
else if($_POST['backupLocation'])
update_mpc($_POST['backupLocation']);
}
if(isset($_POST["startManualTaskButton"]) && $_POST["startManualTaskButton"]=='Yes'){
$startManualTaskButtonPressed = true;
}
else if(isset($_POST["cancelManualTaskButton"]) && $_POST["cancelManualTaskButton"]=='Yes'){
$cancelManualTaskButtonPressed = true;
}
if($startManualTaskButtonPressed == true){
unset($_SESSION['dirPathsManualTask']);
if (isset($_POST['chk_group'])){
if (isset($_POST['vrn']) && !empty($_POST['vrn'])) {
if (count($_POST['chk_group']) > 1) {
$resp[] = false;
$resp[] = null;
$resp[] = "More than one file are not allowed.";
echo json_encode($resp);
exit;
}
$_POST['chk_group'][0] = ($_POST['chk_group'][0] . "_IBVER" . trim($_POST['vrn']));
$optionArray = $_POST['chk_group'];
}
else {
$optionArray = $_POST['chk_group'];
}
}
$oldMask = umask(0);
if(!file_exists($jobTypePath)) {
if(!mkdir($jobTypePath, $permissionVal)) {
//$_SESSION['validUser'] = true; #<Deepak>
$resp = array(false,null, "Failed to create Directory $jobTypePath : ".customErrorMsg());
echo json_encode($resp);
exit;
}
@chmod($jobTypePath, $permissionVal);
}
if(!file_exists($jobNameDirPath)){
if(!mkdir($jobNameDirPath, $permissionVal)){
restartSession(); //Restart session
$resp = array(false,null, "Failed to create Directory $jobNameDirPath : ".customErrorMsg());
echo json_encode($resp);
exit;
}
@chmod($jobNameDirPath, $permissionVal);
}
umask($oldMask);
if(($fHandle = fopen("$jobNameDirPath/$startPid", "w+"))){
if (isset($_POST['vrn'])) {
$versionData = array();
$versionData['version'] = $_POST['vrn'];
$versionData['file'] = preg_replace('/_IBVER(\d)+$/', '', $_POST['chk_group'][0]);
$versionData['size'] = $_POST['vrs'];
$versionData['modifiedon'] = $_POST['vrm'];
fwrite($fHandle, serialize($versionData));
}
fclose($fHandle);
}
@chmod("$jobNameDirPath/$startPid", $permissionVal);
if(strcmp($jobType, "Backup") === 0 || strcmp($jobType, "LocalBackup") === 0)
$displayFile = "$jobNameDirPath/".BACKUPSETFILEDISPLAY;
else
$displayFile = "$jobNameDirPath/".RESTORESETFILEDISPLAY;
$displayFileHandle = fopen($displayFile, "w+");
$selectedItemsCount = count($optionArray);
if($selectedItemsCount > 0){
$itemType = $_POST['itemType'];
$itemSize = $_POST['itemSize'];
$itemLModf = $_POST['itemLModf'];
for($i = 0; $i < $selectedItemsCount; $i++){
$itemName = phpRealEscapeString($optionArray[$i]);
if($itemName !== "")
{
$itemLModfVal = $itemLModf[$i];
if($itemLModfVal != "undefined")
{
$date = strtotime($itemLModfVal);
$itemLModfVal = date("D M j H:i:s Y",$date);
}
fwrite($displayFileHandle, $itemName."\n".$itemType[$i]."\n".$itemSize[$i]."\n".$itemLModfVal."\n");
}
}
}
fclose($displayFileHandle);
@chmod($displayFile, $permissionVal);
if(strcmp($jobType, "Backup") === 0){
$_SESSION['currentBackupJob'] = $_POST['oldJobName'];
} else if(strcmp($jobType, "LocalBackup") === 0){
$jobType = "Backup";
$_SESSION['currentLocalBackupJob'] = $_POST['oldJobName'];
} else if(strcmp($jobType, "LocalRestore") === 0){
$jobType = "Restore";
$_SESSION['currentLocalRestoreJob'] = $_POST['oldJobName'];
} else{
$_SESSION['currentRestoreJob'] = $_POST['oldJobName'];
}
$cmd = phpScriptExecution($jobType."_Script_IDrive.php", $jobNameDirPath, 0);
try {
pclose(popen("$cmd 1>/tmp/out.txt 2>/tmp/error.txt &","r"));
}
catch (customException $e) {
unlink("$jobNameDirPath/$startPid");
//display custom message
}
$resp = array(true, MANUAL_TASK_STARTED);
echo json_encode($resp);
}
else if($cancelManualTaskButtonPressed){
if(($fHandle = fopen("$jobNameDirPath/".CANCEL_PATH, "w"))) {
fclose($fHandle);
@chmod("$jobNameDirPath/".CANCEL_PATH, $permissionVal);
}
$fullPathJobName = $jobNameDirPath;
$jobTerminationStatus = phpScriptExecution(JOBTERMINATE, $fullPathJobName);
scheduler::Log('Canceling the job');
if(strcmp($jobType, "Backup") === 0){
$_SESSION['currentBackupJob'] = '';
} else if(strcmp($jobType, "LocalBackup") === 0){
$_SESSION['currentLocalBackupJob'] = '';
} else if(strcmp($jobType, "LocalRestore") === 0){
$jobType = "Restore";
$_SESSION['currentLocalRestoreJob'] = $_POST['oldJobName'];
} else{
$_SESSION['currentRestoreJob'] = '';
}
$resp = array(false, MANUAL_TASK_STOPPED);
echo json_encode($resp);
}
?>