107 lines
2.8 KiB
PHP
Executable File
107 lines
2.8 KiB
PHP
Executable File
<?php
|
|
include 'path.php';
|
|
if(!isset($_SESSION['validUser']) || $_SESSION['validUser'] !== true)
|
|
exit(header("Location:../index.php"));
|
|
|
|
if($_POST)
|
|
{
|
|
$pageSubmitted = true;
|
|
if(isset($_POST["newJobName"]) && trim($_POST["newJobName"]) != "")
|
|
$newJobName = trim($_POST["newJobName"]);
|
|
|
|
$newJobNameEmpty = false;
|
|
$jobType = ucfirst($_POST['jobType']);
|
|
|
|
$jobs = Scheduler::ReadJobs();
|
|
$jobName = $jobType."_".$newJobName;
|
|
|
|
if(@count($jobs[$jobName])>0){
|
|
$resp[] = false;
|
|
$resp[] = $jobType=='Backup'?DUPLICATE_BACKUP_JOB:DUPLICATE_RESTORE_JOB;
|
|
echo json_encode($resp);
|
|
exit;
|
|
}
|
|
|
|
if(strcmp($_POST['jobType'], "Backup") === 0)
|
|
{
|
|
$countOfJobs = getTotalCountOfJobs();
|
|
if($countOfJobs >= 5){
|
|
$resp[] = false;
|
|
$resp[] = "You are not allowed to create more than 5 Backup sets";
|
|
Scheduler::Log("Failed to open backup set file " . $jobNameDirPath . " : Crossed Total Count Of Jobs Limit" );
|
|
echo json_encode($resp);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$data = array();
|
|
$jobNameDirPath = Scheduler::$user_dir."$jobType/$newJobName";
|
|
if(!is_dir($jobNameDirPath)){
|
|
if(!mkdir($jobNameDirPath, $permissionVal)){
|
|
$resp[] = false;
|
|
$resp[] = "Failed to create Directory $jobNameDirPath : ".customErrorMsg();
|
|
echo json_encode($resp);
|
|
exit;
|
|
}
|
|
@chmod($jobNameDirPath, $permissionVal);
|
|
}
|
|
|
|
$job_type_val = strcmp($_POST['jobType'], "Backup");
|
|
if(strcmp($_POST['jobType'], "Backup") === 0)
|
|
{
|
|
$displayFile = "$jobNameDirPath/".BACKUPSETFILEDISPLAY;
|
|
}
|
|
else
|
|
{
|
|
$displayFile = "$jobNameDirPath/".RESTORESETFILEDISPLAY;
|
|
}
|
|
|
|
if(file_exists($displayFile)){
|
|
unlink($displayFile);
|
|
}
|
|
|
|
$displayFileHandle = fopen($displayFile, "w+");
|
|
|
|
if(!$displayFileHandle){
|
|
$resp[] = false;
|
|
$resp[] = "Failed to create $jobNameDirPath. Please try again.";
|
|
Scheduler::Log("Failed to open backup set file " . $jobNameDirPath . " : " . customErrorMsg());
|
|
echo json_encode($resp);
|
|
exit;
|
|
}
|
|
|
|
if(count($_POST['chk_group'])>0){
|
|
$itemType = $_POST['itemType'];
|
|
$itemSize = $_POST['itemSize'];
|
|
$itemLModf = $_POST['itemLModf'];
|
|
$cnt =0;
|
|
|
|
foreach($_POST['chk_group'] as $dirPath){
|
|
$dirPath = phpRealEscapeString($dirPath);
|
|
$itemLModfVal = $itemLModf[$cnt];
|
|
if($job_type_val != 0)
|
|
{
|
|
if($itemLModfVal != "undefined")
|
|
{
|
|
$date = strtotime($itemLModfVal);
|
|
$itemLModfVal = date("D M j H:i:s Y",$date);
|
|
}
|
|
}
|
|
fwrite($displayFileHandle, $dirPath."\n".$itemType[$cnt]."\n".$itemSize[$cnt]."\n".$itemLModfVal."\n");
|
|
$cnt++;
|
|
}
|
|
}
|
|
|
|
fclose($displayFileHandle);
|
|
@chmod($displayFile, $permissionVal);
|
|
|
|
|
|
$data["job_type"] = $jobType;
|
|
Scheduler::AddJob($data, $jobType.'_'.$newJobName);
|
|
$message = "Successfully Created the " . $_POST['jobType'] . " Job";
|
|
Scheduler::Log($message);
|
|
|
|
$resp[] = true;
|
|
$resp[] = $message;
|
|
echo json_encode($resp);
|
|
} |