1?$exp[1]:$exp[0]; $startPidPath = Scheduler::$user_dir.$data["job_type"]."/".$jobname."/$startPid"; if(file_exists($startPidPath)){ $arr["msg"] = "Job is already in progress. Please try again later"; break; } else if($machine=='twotier'){ $startPidfilePath = Scheduler::$backup_dir."+ManualTask/$startPid"; //if(isJobRunning($startPidfilePath)){ if(file_exists($startPidfilePath)){ $arr["msg"] = "Manual backup is in progress. Please try again later"; break; } } Scheduler::Log('Starting ' . $data["job_type"] . ' Job: ' . $jobname); $path = Scheduler::$user_dir.$data["job_type"]."/".$jobname."/".ucfirst($data['job_type'])."setDisplayFile.txt"; if(customFileSize($path)>0){ Scheduler::StartJobImmediately($job, $data["job_type"]); $exp = explode($data['job_type'],$job,2); if(count($exp)<=1){ $job = $data['job_type'].'_'.$job; } $updated_job = Scheduler::UpdateJobData($job, $data, $weekday_selection); $arr["msg"] = "Job started successfully"; $arr["jobs"] = $updated_job; Scheduler::Log(ucfirst($data["job_type"]) . 'Job Started Successfully: ' . $jobname); } else { $arr["msg"] = "Failed to start ".$jobname.". Please add content to ".lcfirst($data['job_type'])." set and try again"; Scheduler::Log('Failed to start ' . $data['job_type'] . ' job: ' . $jobname); } } else { $exp = explode($data['job_type'],$job,2); if(count($exp)<=1){ $job = $data['job_type'].'_'.$job; } $updated_job = Scheduler::UpdateJobData($job, $data, $weekday_selection); $arr["msg"] = "Job updated successfully."; $arr["jobs"] = $updated_job; Scheduler::Log($data['job_type'] . 'Job: ' . $job . ' updated successfully.'); } } catch (Exception $e) { $arr["msg"] = "Error in updating job"; } break; case "delete_job": try { $job = isset($_REQUEST["job"]) ? $_REQUEST["job"] : ""; $updated_job = Scheduler::DeleteJob($job); $arr["msg"] = "Job deleted successfully."; $arr["jobs"] = $updated_job; Scheduler::Log('Job: ' . $job. ' deleted successfully.'); } catch(Exception $e) { $arr["msg"] = "Error in deleting job"; } break; case "cancel_job": try { $job = isset($_REQUEST["job"]) ? $_REQUEST["job"] : ""; $cancel_job = Scheduler::CancelJob($job); $arr["msg"] = "Job cancelled successfully."; Scheduler::Log('Job: ' . $job. ' cancelled successfully.'); } catch (Exception $e) { $arr["msg"] = "Error in cancelling job"; } break; case "run_job_immediately": try { $job = isset($_REQUEST["job"]) ? $_REQUEST["job"] : ""; $job_type = isset($_REQUEST["job_type"]) ? $_REQUEST["job_type"] : ""; Scheduler::StartJobImmediately($job, $job_type); $arr["msg"] = "Job Run successfully."; Scheduler::Log('Job: ' . $job. ' Run successfully.'); } catch (Exception $e) { $arr["msg"] = "Error in running job"; } break; case "cront_test": try { Scheduler::debug_Log("cront_test"); } catch (Exception $e) { $arr["msg"] = "Error in cront_test"; } break; case "watch_logs": $updated_logs = Log::WatchLogs(); $arr = $updated_logs; break; case "scheduler_list_table": $jobs = Scheduler::ReadJobs(); $selected_job = isset($_REQUEST["selected_job"]) ? $_REQUEST["selected_job"] : ""; ?> $job) { $job_type = $job["job_type"]; $scheduler_selection = isset($job["scheduler"]["scheduler_selection"]) ? ucfirst($job["scheduler"]["scheduler_selection"]) : ""; if(isset($job["scheduler"]["weekday_selection"])) { $weekday_selection = json_decode($job["scheduler"]["weekday_selection"], true); if(($scheduler_selection == "Daily" || $scheduler_selection == "") && count($weekday_selection) < 7 && count($weekday_selection) > 0) { $scheduler_selection = "Weekly"; } $weekday_selection = @implode(",", $weekday_selection); $weekday_selection = " - ".$weekday_selection; }else { $weekday_selection = ""; } if(isset($job["scheduler"]["start_hour"])) { $time = $job["scheduler"]["start_hour"].":".str_pad($job["scheduler"]["start_minute"], 2, '0', STR_PAD_LEFT)." ".strtoupper($job["scheduler"]["start_meridian"]); } else { $time = ""; } if($scheduler_selection == "Hourly") { $time = "00:".str_pad($job["scheduler"]["start_minute"], 2, '0', STR_PAD_LEFT); } if($scheduler_selection == "Daily") { $weekday_selection = ""; } if($scheduler_selection == 'Monthly'){ $weekday_selection = " - ".$job["scheduler"]["day_of_month"].ordinal_suffix($job["scheduler"]["day_of_month"])." day"; } if(isset($job["scheduler"]["start_immediately"])) { $scheduler_selection = ""; $time = ""; } $jobName = substr($k,(strlen($job["job_type"])+1)); $selected_job = $selected_job==''?$k:$selected_job; ?> bgcolor="#EFF9FF" bgcolor="#FFFFFF" >
class="">Stop Job Delete Job
>

'.$itemName.'

Home'.$sharedPath.'
'; } } $sharefiles .= ''; $arr['sharePath'] = $sharefiles; break; case "sendShareEmail": $mailcontent = rawurldecode($_REQUEST['mailcontent']); $emailAddress = $_REQUEST['emailAddress']; $sharedFiles=''; $itemPath = $_REQUEST['itemPath']; if(!empty($_SESSION['userName'])){ $userName = $_SESSION['userName']; $password = base64_decode($_SESSION['password']); $deviceID = isset($_GET['deviceID']) ? urlencode(rawurldecode($_GET['deviceID'])) : ''; $dedupAcc = ''; if($_SESSION['dedup']){ $dedupAcc = "&DEDUP=YES"; if($deviceID) $deviceID = substr($deviceID, 4, -4); } $itemPathArray = explode("\n",$itemPath); foreach($itemPathArray as $path){ if(trim($path)!=''){ $sharedFiles .= "&PATHS=".urlencode($deviceID.$path); } } $shareURLData = 'USERNAME='.urlencode($userName).'&PASSWORD='.urlencode($password); $shareURLData .= '&rec_email='.urlencode($emailAddress).'&description='.urlencode($mailcontent); $shareURLData .= $sharedFiles."&NEW=YES&json=yes".$dedupAcc; $shareOutputArr = getCurlOutput(getHash("02"), $shareURLData); if($shareOutputArr['status'] == true){ $shareOutput = json_decode($shareOutputArr['output']); $result = $shareOutput->res; if(trim($result)=="SUCCESS") $arr[] = true; else $arr[] = false; } else { $arr[] = false; Scheduler::Log("Share CGI: "." Output: ".$shareOutputArr['output']. " Error: ".$shareOutputArr['error']); } } else $arr[] = false; break; case "getVersionDetails" : $trash_Search = 0; if(isset($_REQUEST['trash'])) $trash_Search = 1; $itemName = $_REQUEST['itemName']; $isLocalFile = FALSE; if(isset($_REQUEST['deviceID'])) { $isLocalFile = TRUE; $_SESSION['selectedRestoreDeviceID'] = rawurldecode($_REQUEST['deviceID']); } $arr = getVersionInfo($itemName, $isLocalFile); $arr[] = $itemName; break; case "getDetail": $itemName = $_REQUEST['itemName']; $page = $_REQUEST["page"]; $devicePath = phpRealEscapeString($_REQUEST["deviceID"]); $dedupBucket = phpRealEscapeString($_REQUEST["dedupBucket"]); $itemName = phpRealEscapeString($itemName); if($page=='Restore') $arr = getProperties($itemName); else $arr = getDirDetail($itemName, $devicePath, $dedupBucket); $explode = explode("/",$itemName); $itemName = array_pop($explode); $arr[] = $itemName; $arr[] = "Home".implode("/",$explode)."/"; break; case "createDir"; $newDirName = rawurldecode($_REQUEST['newDirName']); $newDirPath = rawurldecode($_REQUEST['newDirPath']); $newDirName = phpRealEscapeString($newDirName); $newDirPath = phpRealEscapeString($newDirPath); $out = createDir($newDirName, $newDirPath, $_SESSION['encType']); $arr[] = $out[0]; if(strpos($out[1],'folder exists')) $arr[] = 'Folder name already exists'; else if(!$out[0]) $arr[] = 'Could not create folder'; else { $arr[]= "Folder $newDirName has been created successfully"; Scheduler::Log('Directory ' . $newDirName . ' has been created successfully'); updateNewDirInRestoreList($newDirPath,$newDirName); $remoteSearchDir = Scheduler::$user_dir."Restore/.+searchList/"; systemCmdExecutionViaPhp("rm -r $remoteSearchDir"); } $arr[] = date('Y/m/d h:i:s A'); //2014/09/23 05:54:40 PM break; case "startLocalSearch": if(isset($_SESSION['localPatternPath'])){ unset($_SESSION['localPatternPath']); unset($_SESSION['currentLocalSearchPath']); } $searchKeyword = searchKeyword(rawurldecode($_REQUEST['searchKeyword'])); //Constructing keyword $searchKeyword = phpRealEscapeString($searchKeyword); $searchKeyword = trim($searchKeyword,'/'); $searchPath = rawurldecode($_REQUEST['searchPath']); $searchPath = phpRealEscapeString($searchPath); $localSearchPath = Scheduler::$user_dir."Backup/.+searchList"; if(!is_dir($localSearchPath)){ /* Creating the directory ".+searchList" if not exist */ if(!mkdir($searchDirLocal, $permissionVal)) $arr[] = "Failed to create Directory $searchDirLocal"; @chmod($searchDirLocal, $permissionVal); } $searchKeyword = getSearchPattern($searchKeyword); $localPatternPath = createSearchDir($searchPath.$searchKeyword,$localSearchPath); if(file_exists($localPatternPath."/page1")){ $_SESSION['localPatternPath'] = $localPatternPath; $_SESSION['currentLocalSearchPath'] = $localPatternPath."/"; $arr[] = false; break; } createLocalSearchTxt($localPatternPath,$searchKeyword,$searchPath); if(customFileSize("$localPatternPath/".SEARCH_FILE)>0) { if(!($handle = fopen("$localPatternPath/".PID_FILE, "w"))){ Scheduler::Log("Failed to create $localPatternPath/" . PID_FILE); exit; } else @chmod("$localPatternPath/".PID_FILE, $permissionVal); $exec = phpScriptExecution("localSearch.php","$localPatternPath",0); pclose(popen("$exec &","r")); Scheduler::Log("Local search started:$searchKeyword"); $_SESSION['localPatternPath'] = $localPatternPath; $_SESSION['currentLocalSearchPath'] = $localPatternPath."/"; $arr[] = true; } break; case "getSearchRes": $trashFlag = $_REQUEST['trash']; if($trashFlag) $currPage = isset($_REQUEST['page'])?"trash_page".$_REQUEST['page']:"trash_page1"; else $currPage = isset($_REQUEST['page'])?"page".$_REQUEST['page']:"page1"; $type = $_REQUEST['type']; $Resultcount = $_REQUEST['count']; $isflag = 0; if($type=='backup'){ $localPatternPath = $_SESSION['localPatternPath']; if($_REQUEST['page']==1){ $count = 0; $isflag = 1; while(!is_dir($localPatternPath)){ sleep(2); $count++; if($count >= 60){ $isflag = 0; break; } } $path = $localPatternPath."/"; } else { $path = $_SESSION['currentLocalSearchPath']; $isflag = 1; } if($isflag==1){ $page = $path.$currPage; $arr = getSearchResult($page,$path.PID_FILE,$Resultcount); } } else if($type=='restore'){ if($trashFlag) $path = $_SESSION['currentRemoteTrashSearchPath']; else $path = $_SESSION['currentRemoteSearchPath']; $page = $path.$currPage; $arr = getSearchResult($page,$path.PID_FILE,$Resultcount); } break; case "stopSearch": if($_REQUEST['type'] == 'backup' and !empty($_SESSION['currentLocalSearchPath'])) { $cmd = phpScriptExecution(JOBTERMINATE, $_SESSION['currentLocalSearchPath'], 0); pclose(popen("$cmd &","r")); } else if($_REQUEST['type']=='restore' and !empty($_SESSION['currentRemoteSearchPath'])){ $cmd = phpScriptExecution(JOBTERMINATE,$_SESSION['currentRemoteSearchPath'],0, FALSE, TRUE); pclose(popen("$cmd &","r")); } else if($_REQUEST['type']=='trash' and !empty($_SESSION['currentRemoteTrashSearchPath'])){ $cmd = phpScriptExecution(JOBTERMINATE,$_SESSION['currentRemoteTrashSearchPath'],0, FALSE, TRUE); popen("$cmd","r"); } else if($_REQUEST['type']=='archive'){ //Modified by Sajana for Archive Cleanup job termination... $_SESSION["progress_stat"] = 1; $archive_dir = Scheduler::$archiveclean_dir.$_SESSION['manual_backupset']."/"; $cmd = phpScriptExecution(JOBTERMINATE,$archive_dir,0); pclose(popen("$cmd &","r")); $resultfile = $archive_dir.ARCHIVERESULT; $countfile = $archive_dir.ARCHIVECOUNT; $filesOnly = $archive_dir.FILESONLY; $cleanupStatusFile = $archive_dir.CLEANUP_STATUS; $temp = $archive_dir."temp/"; if(is_dir($temp)) removeItems($temp); @unlink($resultfile); @unlink($countfile); @unlink($filesOnly); @unlink($cleanupStatusFile); } else if($_REQUEST['type']=='removeArchivePid'){ $archive_dir = Scheduler::$archiveclean_dir.$_SESSION['manual_backupset']."/"; $archivePid = $archive_dir.PID_FILE; $resultfile = $archive_dir.ARCHIVERESULT; $countfile = $archive_dir.ARCHIVECOUNT; @unlink($archivePid); @unlink($resultfile); @unlink($countfile); $temp = $archive_dir."temp/"; if(is_dir($temp)){ removeItems($temp); } } else $res = "is not running"; $arr[] = true; $arr[] = "Execution Terminated"; break; case "startRemoteSearch": if(isset($_SESSION['currentRemoteSearchPath'])) unset($_SESSION['currentRemoteSearchPath']); if(isset($_SESSION['currentRemoteTrashSearchPath'])) unset($_SESSION['currentRemoteTrashSearchPath']); $trashSearch = 0; if(isset($_REQUEST['trash'])) $trashSearch = 1; $searchKeyword = strtolower(rawurldecode($_REQUEST['searchKeyword'])); $searchKeyword = getSearchPattern($searchKeyword); $searchPath = rawurldecode($_REQUEST['searchPath']); if($searchKeyword == "*" && $trashSearch == 1){ GLOBAL $searchDirTrashRemote; GLOBAL $searchDirRemote,$empty_trash; $trash_Search = 1; $empty_trash = 0; $searchDirRemote = $searchDirTrashRemote; $arr[] = remoteInitialSearch($searchKeyword,$searchPath,$searchDirTrashRemote); } else{ GLOBAL $searchDirRemote; $trash_Search = 0; $arr[] = remoteSearch($searchKeyword,$searchPath,$trashSearch); } break; case "emptyTrash": GLOBAL $searchDirTrashRemote,$searchDirRemote,$trash_Search; $empty_trash = 1; $trash_Search = 1; $trashDirExists = true; //$cmd = perlScriptExecution(JOBTERMINATE,$searchDirTrashRemote,0); $cmd = phpScriptExecution(JOBTERMINATE,$searchDirTrashRemote,0); pclose(popen("$cmd &","r")); $searchDirRemote = $searchDirTrashRemote."/EmptyTrash"; if(!is_dir($searchDirTrashRemote."/EmptyTrash/")){ if(!is_dir($searchDirTrashRemote)){ if(!mkdir($searchDirTrashRemote, $permissionVal)){ $trashDirExists = false; } @chmod($searchDirTrashRemote,$permissionVal); } if(!is_dir($searchDirTrashRemote."/EmptyTrash/")){ if(!mkdir($searchDirTrashRemote."/EmptyTrash/", $permissionVal)){ $trashDirExists = false; } @chmod($searchDirTrashRemote."/EmptyTrash/",$permissionVal); } } if($trashDirExists){ if(isset($_REQUEST['deviceID'])){ $_SESSION['selectedRestoreDeviceID'] = rawurldecode($_REQUEST['deviceID']); chdir("$searchDirRemote/"); file_put_contents($searchDirRemote."/trash_page1",'/'); @chmod($searchDirRemote."/trash_page1",$permissionVal); $outputArray = deleteItems(REMOVE_FROM_TRASHOP,$searchDirRemote."/trash_page1",""); } else { $outputArray = remoteInitialSearch("*","/",$searchDirRemote); } if($outputArray['DELETEOP']['CONSIDERED'] == 0 || $outputArray['DELETEOP']['HAPPENED'] == 0) $outputArray['STATUS'] = DELETEOP_FAILED; else if($outputArray['DELETEOP']['CONSIDERED'] > 1) { $outputArray['REMOVE_JS_ARRAY'] = 1; if($OP != REMOVE_FROM_TRASHOP && $restoreListFolderPath!='/' && $searchDir!='/') systemCmdExecution("rm -rf '$restoreListFolderPath' '$searchDir' "); $outputArray['STATUS'] = DELETEOP_SUCCESSFUL; } else if($outputArray['DELETEOP']['CONSIDERED'] == 1) { $outputArray['REMOVE_JS_ARRAY'] = 0; $singleItemDelete = $itemsForDelete[0]; $removeFolder = $restoreListFolderPath.$singleItemDelete; $singleItemDeleteParentFolder = substr($removeFolder, 0, strrpos($removeFolder, "/")); $listTxt = $singleItemDeleteParentFolder."/list.txt"; if($OP != REMOVE_FROM_TRASHOP && $searchDir!='/' && $removeFolder!='/') systemCmdExecution("rm -rf '$searchDir' '$removeFolder' '$listTxt' "); $outputArray['STATUS'] = DELETEOP_SUCCESSFUL; } } header("Content-type:application/json"); echo json_encode($outputArray); exit; case "emptyTrashChk": $outputArray = emptyTrashSearch(); if($outputArray['DELETEOP']['CONSIDERED'] == 0 || $outputArray['DELETEOP']['HAPPENED'] == 0) $outputArray['STATUS'] = DELETEOP_FAILED; else if($outputArray['DELETEOP']['CONSIDERED'] > 1) { $outputArray['REMOVE_JS_ARRAY'] = 1; $outputArray['STATUS'] = DELETEOP_SUCCESSFUL; } else if($outputArray['DELETEOP']['CONSIDERED'] == 1) { $outputArray['REMOVE_JS_ARRAY'] = 0; $outputArray['STATUS'] = DELETEOP_SUCCESSFUL; } if($outputArray['SIZE'] > 0 && $searchDirTrashRemote!='/') systemCmdExecution("rm -rf '$searchDirTrashRemote'"); header("Content-type:application/json"); echo json_encode($outputArray); exit; case "setEncryption": $encType = ucfirst($_POST['encryptionKey']); $passwrd = base64_decode($_SESSION['password']); $pvtKey =''; if($encType != 'Default') $pvtKey = rawurldecode($_POST['pvtKey']); encodePathWrapper($passwrd, $encType, $pvtKey); $confXmlArray = confAccount($encType, $pvtKey); $result = (string)$confXmlArray['message']; if($result == "SUCCESS") { $dir = getNAShostname(); $dirOutput = createDir($dir, "", $encType); $_SESSION['configVerified'] = true; $_SESSION['encType'] = $encType; $arr = array(TRUE); } else { Scheduler::Log("Error in encryption key setup : " . $confXmlArray['desc']); $arr = array(FALSE, $confXmlArray['desc']); } break; case "validateEncryption": $encType = 'Private'; $passwrd = base64_decode($_SESSION['password']); //$pvtKey = rawurldecode($_POST['encryptKey']); $pvtKey = $_POST['encryptKey']; encodePathWrapper($passwrd, $encType, $pvtKey); $serverOutput = getEVSServerAddr(); //Getting & Assigning EVS server address to session variable if($serverOutput != ''){ if($_SESSION['dedup']) $dirOutput = getDedupDeviceList(); else { $dir =''; if(file_exists($mpc)) $dir = file_get_contents($mpc); if(empty($dir)) $dir = getNAShostname(); $dirOutput = createDir($dir, "", $encType); } if($dirOutput[0] == false && strpos($dirOutput[1], "encryption verification failed") !== false){ $encPvtkeyPath = Scheduler::$user_dir."IDPVT"; $result = "FAIL"; unlink($encPvtkeyPath); $arr[] = false; $arr[] = INVALID_PRIVATE_KEY; } else if($dirOutput[0] == false && strpos($dirOutput[1], "Proxy Authentication Required") !== false){ $encPvtkeyPath = Scheduler::$user_dir."IDPVT"; $result = "FAIL"; unlink($encPvtkeyPath); $arr[] = false; $arr[] = INVALID_PROXY; } else if(strpos($dirOutput[1], "private encryption key must be between") !== false){ $encPvtkeyPath = Scheduler::$user_dir."IDPVT"; $result = "FAIL"; unlink($encPvtkeyPath); $arr = array(FALSE, INVALID_PRIVATE_KEY_LENGTH); } else { $_SESSION['configVerified'] = true; $_SESSION['encType'] = $encType; $arr[] = true; } } else { $arr[] = false; $arr[] = NO_EVS_SERVER; } break; case "addToExcludeList": //Added by sajana and modified by Deepak for addToExcludeList option... $itemName = rtrim(rawurldecode(trim($_REQUEST['itemName'],"\n")),'/'); $itemType = trim($_REQUEST['itemType']); $itemName = phpRealEscapeString($itemName); $exludeStatus = addToExcludeList($itemName, $itemType, $excludeFullFile); $_SESSION['fullEntry'] = file($excludeFullFile, FILE_IGNORE_NEW_LINES); $arr = array($exludeStatus[0], $exludeStatus[1]); break; case "getSharedList"; getSharedList(); break; case "createDefaultBackupSet"; createDefaultBackupSet(); break; case "deleteArchive" : // archive cleanup delete call. $selected_backupset = $_SESSION['manual_backupset']; $deleteFile = Scheduler::$archiveclean_dir.$selected_backupset."/".ARCHIVERESULT; $countFile = Scheduler::$archiveclean_dir.$selected_backupset."/".ARCHIVECOUNT; $not_exit_count = 0; if(file_exists($countFile)) { $_SESSION['totalFileToDelete'] = 0; $_SESSION['countDeleted'] = 0; $values = file_get_contents($countFile); $tempval=explode("\n",$values); $total_count = isset($tempval[2])?$tempval[2]:0; $not_exit_count = isset($tempval[3])?$tempval[3]:0; } $delStatus = deleteItems(ARCHIVEOP,$deleteFile,"", $not_exit_count); if($delStatus == "") $arr[0]=true; else $arr[0]=$delStatus; unset($_SESSION['totalFileToDelete']); unset($_SESSION['countDeleted']); $arr[1] = $_SESSION['deleteCommand']; break; case "deletedArchiveStatus" : // archive cleanup delete call. $jobName = Scheduler::$manual_dir; $countFile = Scheduler::$archiveclean_dir.$jobName."/".ARCHIVECOUNT; $countDeleted = file_get_contents($countFile); if($countDeleted != '') $_SESSION['countDeleted'] = $countDeleted; if($_SESSION['totalFileToDelete'] == 0) $arr['response'] = 'Deleting...'; else $arr['response'] = "Deleting... (".$_SESSION['countDeleted']." of ".$_SESSION['totalFileToDelete'].")"; break; case "archiveStatus" : // archive cleanup file progress. $jobName = Scheduler::$manual_dir; $countFile = Scheduler::$archiveclean_dir.$jobName."/".ARCHIVECOUNT; $cleanupStatusFile = Scheduler::$archiveclean_dir.$jobName."/".CLEANUP_STATUS; $arr['operation_status'] = "scanning"; if(file_exists($cleanupStatusFile)){ $status = file_get_contents($cleanupStatusFile); $exp = explode("\n",trim($status)); foreach($exp as $line){ if($line=='progress_stat=1'){ $arr['operation_status'] = "completed"; @unlink($cleanupStatusFile); } elseif(strstr($line,'ERR=')){ $error = str_replace("ERR=","",$line); $arr['Error'] = trim($error); } } } $arr['total_count'] = 0; if(file_exists($countFile)){ $readCount = file_get_contents($countFile); $countValues = explode("\n", $readCount); if(count($countValues)>1){ $arr['files_scanned'] = trim($countValues[1]); $arr['total_count'] = trim($countValues[2]); } } break; case "archivePerc" : //archive percentage $countFile = Scheduler::$archiveclean_dir.$_SESSION['manual_backupset']."/".ARCHIVECOUNT; $readCount = file_get_contents($countFile); $countValues = explode("\n", $readCount); $arr['manualPerc'] = $_SESSION['manual_per']; $arr['total_count'] = $countValues[2]; $arr['total_del_count'] = $countValues[3]; break; case "deleteCancel": $archive_dir = Scheduler::$archiveclean_dir.$_SESSION['manual_backupset']."/"; Scheduler::debug_Log("perlScriptExecution--archivedir " . $archive_dir); $cmd = phpScriptExecution(JOBTERMINATE,$archive_dir,0); pclose(popen("$cmd &","r")); break; case "deleteAction": $outputArray = deleteAction(); header("Content-type:application/json"); echo json_encode($outputArray); exit; break; case "checkJobRunning": $archivePath = Scheduler::$archiveclean_dir; $jobstatus = checkIfJobRunning($archivePath); $arr['jobstatus'] = false; if($jobstatus == 1) $arr['jobstatus'] = true; break; case "deleteOpCancel": $delete_dir = Scheduler::$delete_dir; $cmd = phpScriptExecution(JOBTERMINATE,$delete_dir,0); pclose(popen("$cmd &","r")); break; case "startTrashList": $itemSelected = isset($_GET['fullPath']) ? $_GET['fullPath'] : ''; if(strpos($itemSelected, "/") !== FALSE) $itemSelected = rtrim($itemSelected, "/"); $fullPath = "$itemSelected/"; if(1 < strlen($fullPath)) $fullPath = substr($fullPath, 0, -1); if(substr($fullPath, -1)!= "/") $fullPath.="/"; GLOBAL $trashListPath; $trashListPath = constructRestoreFileName($fullPath,1); if(file_exists($trashListPath)) $trashListPathSize = customFileSize($trashListPath); if(!file_exists($rListPath) || $rListPathSize==0 ) { if(isset($_SESSION['currentRemoteSearchPath'])) unset($_SESSION['currentRemoteSearchPath']); $searchKeyword = rawurldecode($fullPath); $searchKeyword = getSearchPattern($searchKeyword); $arr[] = trashListing($searchKeyword); } else $arr['Trashlist'] = 1; break; case "getTrashRes" : $Resultcount = $_REQUEST['count']; $path = $_SESSION['currentRemoteSearchPath']; if($_REQUEST['path']) $path = $restoreListFolderPath.$_REQUEST['path']; $page = $path."Trashlist.txt"; $arr = getSearchResult($page,$path."pid.txt",$Resultcount); if($arr[0]===0) { if(file_exists($path."pid.txt")) { $arr[0]=0; $arr[1]=1; $arr[2]=$path; $arr[3]=$Resultcount; $arr[4]="Result file not found yet. Search script running"; } } break; case "checkWritePermission": $itemName = $_REQUEST['dirPath']; $itemName = phpRealEscapeString($itemName); file_put_contents($temp_file, ISWRITABLE."\n$itemName"); @chmod($temp_file,$permissionVal); $iswritable = phpScriptExecution(OPERATIONSFILE, scheduler::$user_dir, 1); if($iswritable == 'writable') $arr[] = true; else $arr[] = false; break; case "ScheduledTaskWatcher": $startPidPath = Scheduler::$backup_dir.DEFAULT_BACKUPSET."/".START_PID; $userCancelFile = Scheduler::$backup_dir.DEFAULT_BACKUPSET."/".CANCEL_PATH; $arr[] = file_exists($startPidPath)?true:false; $arr[] = file_exists($userCancelFile)?true:false; break; case "update": if($machine == 'twotier') { $output = updateIDriveApp(); header('Location: /' . CONFIG . '/logout.php'); } else if($machine == SYNOLOGY_LOCAL) { addAppUpdateLockFile(); $output = updateIDriveApp(); # wait a second for the perl to get the execution handle sleep(5); while(!clearAppUpdateLock()) { sleep(1); } header('Location: ./logout.php'); } exit(0); break; case "getProxySettings": $output = getProxySettings(); if(count($output)>0){ $ipAddress = trim($output[0]); $port = trim($output[1]); $username = trim($output[2]); $password = base64_encode(rawurlencode(trim($output[3]))); $arr[] = true; $arr[] = array('ipAddress'=>$ipAddress,'port'=>$port,'username'=>$username,'password'=>$password); $arr[] = PROXY_DETECTED; $_SESSION['proxy_option'] = 'autodetect'; $_SESSION['ipAddress'] = $ipAddress; $_SESSION['port'] = $port; $_SESSION['proxyUserName'] = $username; $_SESSION['proxyPassword'] = $password; } else { $arr[] = false; $arr[] = NO_PROXY; unsetProxySessions(); } break; case "refresh": $dirName = rawurldecode($_REQUEST['dirName']); $type = $_REQUEST['type']; if($type=='restore'){ $rListPath = Scheduler::$restore_list_dir."/$dirName"; if(is_dir($rListPath) && $rListPath!='/'){ removeItems($rListPath); } if(file_exists($searchDirRemote) && $searchDirRemote!='/'){ removeItems($searchDirRemote); } } else if($type=='backup' || $type=='localBackup'){ getSharedList(); if(file_exists($searchDirLocal) && $searchDirLocal!='/'){ removeItems($searchDirLocal); } killSizeFd(); unlink(Scheduler::$nasUser_dir."$username/".SIZEOUTPUT); autoUpdateBackupset(); } break; case "removeArchivePid": $archive_dir = Scheduler::$archiveclean_dir.$_SESSION['manual_backupset']."/"; $pid = $archive_dir."pid.txt"; @unlink($pid); $temp = $archive_dir."temp/"; if(is_dir($temp)){ removeItems($temp); } break; case "readErrorInfo": # Sabin Cheruvattil - log file check here and warn user when they click the send button $log_rel_path = '.trace/' . LOG_FILE; $trace_rel_path = '.trace/' . TRACE_LOG_FILE; $logSendWarning = ''; if($_SESSION['userName'] != '') { $logSize = file_exists(Scheduler::$user_dir . $log_rel_path)? customFileSize(Scheduler::$user_dir . $log_rel_path):0; $traceLogSize = file_exists(Scheduler::$user_dir . $trace_rel_path)?customFileSize(Scheduler::$user_dir . $trace_rel_path):0; $errorInfoPath = Scheduler::$user_dir . 'sendErrorInfo.txt'; if((($logSize + $traceLogSize) / (1024 * 1024)) >= SEND_ERROR_LOG_WARN_SIZE) { $logSendWarning = 'It may take a while to prepare your error report. Please wait...'; } } $arr = array(); if($errorInfoPath != '' && file_exists($errorInfoPath)) { $arr = file_get_contents($errorInfoPath); $arr = json_decode($arr, TRUE); } else { $arr['username'] = $_SESSION['userName']; } $arr['logSendWarning'] = $logSendWarning; echo json_encode($arr); break; case 'getNextScheduledTask': echo json_encode(getNextScheduledTask()); break; case "validateRestoreFileChk": $jobPath = $_POST['jobPath']; echo validateRestoreFileChk($jobPath); break; case "putbackTrashSetItems": GLOBAL $empty_trash; $empty_trash = 0; if(isset($_REQUEST["items"]))$itemsForPutBack = $_REQUEST["items"]; if(!$itemsForPutBack) { $outputArray['STATUS'] = NO_ITEMS_FOR_DELETE; header("Content-type:application/json"); echo json_encode($outputArray); exit; } chdir(Scheduler::$delete_dir); $deleteFileContent = implode("\n",$itemsForPutBack); if(!file_put_contents("put_back.txt",$deleteFileContent."\n")) { $outputArray['STATUS'] = DELETEOP_FAILED; header("Content-type:application/json"); echo json_encode($outputArray); exit; } @chmod("put_back.txt", $permissionVal); $outputArray = deleteItems(PUT_BACKOP,"put_back.txt"); if($outputArray['PUT_BACKOP']['HAPPENED'] > 0 && $outputArray['PUT_BACKOP']['HAPPENED'] == $outputArray['PUT_BACKOP']['CONSIDERED'] ){ $outputArray['STATUS'] = DELETEOP_SUCCESSFUL; header("Content-type:application/json"); echo json_encode($outputArray); exit; }else if($outputArray['PUT_BACKOP']['HAPPENED'] > 0 && $outputArray['PUT_BACKOP']['HAPPENED'] != $outputArray['PUT_BACKOP']['CONSIDERED']){ $outputArray['STATUS'] = "partial"; header("Content-type:application/json"); echo json_encode($outputArray); exit; } break; case "getSize": $item = rawurldecode($_REQUEST['item']); $errorFile = Scheduler::$user_dir."sizeError.txt"; $outputFile = Scheduler::$user_dir.SIZEOUTPUT; #Scheduler::Log("","Calculating size for $item\n--------------------------------------------------------"); file_put_contents($temp_file, GETFILEFOLDERSIZE."\n$item"); @chmod($temp_file,$permissionVal); #$cmd = phpScriptExecution(OPERATIONSFILE." ".GETFILEFOLDERSIZE, Scheduler::$user_dir,0); $cmd = phpScriptExecution(OPERATIONSFILE, Scheduler::$user_dir,0); pclose(popen("$cmd &","r")); $arr['retry'] = true; break; case "getSizeResult": $outputFile = Scheduler::$user_dir.SIZEOUTPUT; //$errorFile = Scheduler::$user_dir."sizeError.txt"; if(isset($_REQUEST['item']) && file_exists($outputFile)){ $lines = file($outputFile); //$errorContent = file_exists($errorFile)?file_get_contents($errorFile):''; $i=0; $item = $_REQUEST['item']; // What to look for $item = rawurldecode($item); $search = "\t$item\n"; $search1 = "\t$item"; // Read from file foreach($lines as $line) { // Check if the line contains the string we're looking for, and print if it does if(strpos($line, $search) !== false || strpos($line, $search1) !== false){ $exp = explode("\t",$line); $arr[$i]['size'] = $exp[0]!=''?$exp[0]:0; $arr[$i]['name'] = rtrim($exp[1],"\n"); $arr[$i]['retry'] = false; $i++; break; } } } else{ $fileSizeRequest = Scheduler::$user_dir."sizepid.txt"; if(!file_exists($fileSizeRequest)){ $arr['retry'] = false; break; } } if(count($arr) == 0) $arr['retry'] = true; break; case "updateLocalMPC": $hostName = rawurldecode($_REQUEST['path']); $dedupBucket = rawurldecode($_REQUEST['dedupBucket']); $path = json_encode(array('hostName'=>$hostName,'deviceID'=>$dedupBucket)); file_put_contents($localMPCfile,$path); @chmod($localMPCfile,$permissionVal); break; case 'getUsedSize': $path = rawurldecode($_REQUEST['path']); $size = 0; $arr = array(FALSE); if($_SESSION['dedup']) { if(file_exists($dedupDetailFile)) { $deviceJSON = file_get_contents($dedupDetailFile); $deviceArray = json_decode($deviceJSON, true); $dedupDeviceID = preg_replace("/^5c0b/", '', trim($deviceArray['deviceID']), 1); $dedupDeviceID = preg_replace("/4b5z$/", '', $dedupDeviceID, 1); $dbAppPath = getExpressDBPath($path, $dedupDeviceID); $size = getUsedSpace($dbAppPath); } } else { $dbAppPath = getExpressDBPath($path); $size = getUsedSpace($dbAppPath); } if($size >= 0) { $_SESSION['usedSize'][$dbAppPath] = $size; $arr = array(TRUE, $size); } break; case "reIndex": $drive = getLocalBackupLocation(); $dedupBucket = ''; if($_SESSION['dedup'] && trim($_REQUEST['dedupBucket']) != '') { $dedupBucket = trim($_REQUEST['dedupBucket']); } $dedupServerRoot = ''; if(file_exists($dedupDetailFile)) { $dedupServerRoot = '/' . getServerRootByDeviceID($dedupBucket); } $dbDriveUserDir = "{$drive}/{$userName}{$dedupServerRoot}"; if(!file_exists($dbDriveUserDir)) { Scheduler::Log("ReIndex: {$dbDriveUserDir} not found"); $arr = array(FALSE); break; } if(isJobRunning("{$reIndexDirPath}/{$pidPath}")) { $arr = array(FALSE, REINDEX_INPROGRESS); break; } $localStartPidfilePath = Scheduler::$localbackup_dir . "+ManualTask/{$startPid}"; if(isJobRunning($localStartPidfilePath)) { $arr = array(FALSE, REINDEX_ERR); break; } if(!file_exists($reIndexDirPath)) { if(!mkdir($reIndexDirPath, $permissionVal)) { $arr = array(FALSE, "Failed to create Directory {$reIndexDirPath} : " . customErrorMsg()); break; } if($dedupBucket != '') { file_put_contents($reIndexDirPath . '/' . REINDEXBUCKET, $dedupBucket); @chmod($reIndexDirPath . '/' . REINDEXBUCKET, 0777); } @chmod($reIndexDirPath, $permissionVal); } $php = getPhpPath(); $phpPath = "{$appPath}/" . CONFIG; $cmd = "{$php} {$phpPath}/" . DB_REINDEX_FILE; $cmd = systemCmdExecution($cmd, 0, $reIndexDirPath); pclose(popen("{$cmd} &", 'r')); $arr = array(true); break; case "reIndexWatcher": $reIndexOutput = "$reIndexDirPath/$pidPath"; if(file_exists($reIndexOutput)) $arr[] = 'running'; else $arr[] = 'completed'; break; case "checkMountedDrives": $checkDrive = isset($_REQUEST['driveName'])?rawurldecode($_REQUEST['driveName']):''; $devicesArr = getMountedDevices(); if(empty($checkDrive)) { $arr[] = (empty($devicesArr)? FALSE : TRUE); } else { $IDriveLocal = '/IDriveLocal'; $checkDrive = str_replace($IDriveLocal, '', $checkDrive); $arr[] = in_array($checkDrive, $devicesArr); } break; case "logoff": # unset the username so that app won't be able to figureout the user unset($_SESSION['userName']); restartSession(); killSizeFd(); //Killing the getSize process $arr = array(true, LOGGED_OFF, GUEST_USER); break; case "displayArchiveResult": $resultFile = Scheduler::$archiveclean_dir.$_SESSION['manual_backupset']."/temp/result".$_SESSION['file_offset'].".txt"; if(file_exists($resultFile)){ $deleteFileList = file_get_contents($resultFile); $arr["data_status"] = "1"; if(count($deleteFileList) == 0) $arr["data_status"] = "0"; $_SESSION['file_offset'] = $_SESSION['file_offset'] + 1; $arr["result"] = nl2br($deleteFileList); }else $arr["data_status"] = "0"; break; case "checkActiveJobs": session_write_close(); if($_SESSION['dedup']){ if(!file_exists($dedupDetailFile)){ exit(header("Location:logout.php")); } } $arr = listOngoingJobs(Scheduler::$backup_dir,Scheduler::$restore_dir); break; case "watchManualTaskStatus": $job_type = $_GET['type']; $job_name = "+ManualTask"; if($_GET['trash'] == 1) $job_name = "+TrashManualTask"; echo chkJobInProgress($job_name, ucfirst($job_type)); break; case "getLocalRestoreSearchList": $searchStr = $_POST['search_str']; $searchPath = rawurldecode($_POST['search_path']); $dedupBucket = trim($_POST['dedupBucket']); $deviceID = trim($_POST['deviceID']); if($_POST['page'] > 0) { $page = $_POST['page'] - 1; } $arr = getLocalRestoreSearchList($searchStr, $searchPath, $page, $dedupBucket, $deviceID); break; case "bucket": $operation = isset($_REQUEST['operation'])?rawurldecode($_REQUEST['operation']):''; $deviceID = isset($_REQUEST['deviceID'])?rawurldecode($_REQUEST['deviceID']):''; $nickName = isset($_REQUEST['nickName'])?rawurldecode($_REQUEST['nickName']):''; $oldDeviceID = ''; if($operation=='create') $op = CREATEBUCKETOP; else if($operation=='link') { $op = LINKBUCKETOP; $dedupHostname = shell_exec("hostname"); $dedupHostname = trim($dedupHostname); $nickName = $dedupHostname; $oldDeviceID = $deviceID; } else if($operation=='update') $op = NICKNAMEUPDATEOP; $arr = bucketOperation($op,$nickName,$deviceID); if($arr[0] == true) { if($operation=='link' && isset($_SESSION['deviceList'][$deviceID]['D'])) unset($_SESSION['deviceList'][$deviceID]['D']); $deviceID = $_SESSION['deviceID']; $nickName = $_SESSION['nickName']; $serverRoot = $_SESSION['serverRoot']; $dedupDetail = json_encode(array('serverRoot' => $serverRoot, 'deviceID' => $deviceID, 'nick_name' => $nickName)); file_put_contents($dedupDetailFile,$dedupDetail); @chmod($dedupDetailFile, $permissionVal); file_put_contents($dedupRestoreDeviceID, $deviceID); @chmod($dedupRestoreDeviceID, $permissionVal); file_put_contents($mpc,$nickName); @chmod($mpc, $permissionVal); $listDevice = array(); if($nickName != '') { renameExpressNickNameOnBucketUpdate($nickName, $oldDeviceID); } $_SESSION['deviceList'][$deviceID]['D'] = $nickName; updateHostName(); resetLoglistXml(); } break; case "removeRestoreSetFiles": $manulRestoreSetFilePath = Scheduler::$restore_dir.Scheduler::$manual_dir."/".RESTORESETFILEDISPLAY; @unlink($manulRestoreSetFilePath); break; case "installationScript": executeInstallationScript(); break; case "checkAppUpdate": $output = checkAppUpdate(); $arr['response'] = $output; break; } $html_action = array("scheduler_list_table", "log_list_table", "readErrorInfo", 'getNextScheduledTask','watchManualTaskStatus'); if(!in_array($action, $html_action)) { echo json_encode($arr); } exit; ?>