199 lines
6.6 KiB
PHP
Executable File
199 lines
6.6 KiB
PHP
Executable File
<?php
|
|
include_once 'path.php';
|
|
session_write_close();
|
|
if(!isset($_SESSION['validUser']) || $_SESSION['validUser'] !== true) {
|
|
exit(header("Location:../index.php"));
|
|
}
|
|
|
|
if($_SESSION['validUser'] === true) {
|
|
$fullPath = isset($_GET['fullPath'])? $_GET['fullPath'] : '';
|
|
$pageid = (isset($_GET['pageid']))? $_GET['pageid'] : '0';
|
|
$getList = (isset($_GET['getList']))? $_GET['getList'] : '0';
|
|
|
|
if(isset($_SESSION['dedup']) && $_SESSION['dedup']) {
|
|
$_SESSION['selectedRestoreDeviceID'] = isset($_GET['deviceID'])?$_GET['deviceID']:$_SESSION['deviceID'];
|
|
}
|
|
if(strpos($fullPath, "/") !== FALSE) {
|
|
$fullPath = rtrim($fullPath, "/");
|
|
}
|
|
|
|
$fullPath = phpRealEscapeString($fullPath);
|
|
$rListPath = constructRestoreFileName($fullPath, $pageid);
|
|
$restoreDirPath = createFullRestoreDir($fullPath);
|
|
$pidFile = $restoreDirPath.'/'.PID_FILE;
|
|
$OutErrorFilePath = $restoreDirPath.'/'.ERROR_FILE;
|
|
$retryCount = 0;
|
|
$dirFiles = NULL;
|
|
|
|
while(1) {
|
|
if($getList == '1') {
|
|
# make sure remote list process is not running already
|
|
if(file_exists($pidFile)) {
|
|
$handle = fopen($pidFile, 'w');
|
|
if(!flock($handle, LOCK_EX|LOCK_NB)) {
|
|
# Scheduler::Log('Remote list process already running. Terminating the duplicate request!');
|
|
exit;
|
|
}
|
|
|
|
unlink($pidFile);
|
|
}
|
|
|
|
remoteList("$fullPath");
|
|
if(file_exists($pidFile)) {
|
|
unlink($pidFile);
|
|
}
|
|
|
|
exit;
|
|
} else if(file_exists($rListPath) && customFileSize($rListPath)) {
|
|
$dirFiles = file_get_contents($rListPath);
|
|
$dirArrayDefault = json_decode($dirFiles,true);
|
|
$dirArrayDefault1 = json_decode($dirFiles);
|
|
ksort($dirArrayDefault);
|
|
$countDir = count($dirArrayDefault);
|
|
if($countDir <= 0 and !file_exists($pidFile)){
|
|
if(@file_exists($OutErrorFilePath) && customFileSize($OutErrorFilePath)){
|
|
$outError = file_get_contents($OutErrorFilePath);
|
|
checkErrorAndReason($outError);
|
|
if(stristr($outError,"encryption verification failed")){
|
|
exit(header("Location: ./logout.php"));
|
|
}
|
|
if(isset($_SESSION['dedup']) && $_SESSION['dedup']){
|
|
if(strpos($outError, 'failed to get the device information') !== false){
|
|
exit(header("Location: ./logout.php"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
else if(file_exists($pidFile))
|
|
{
|
|
if($retryCount <= 20) {
|
|
++$retryCount;
|
|
sleep(1);
|
|
}
|
|
else{
|
|
$response = array();
|
|
$response[] = false;
|
|
$response['retry'] = true;
|
|
echo json_encode($response);
|
|
exit;
|
|
}
|
|
}
|
|
else{
|
|
if(@file_exists($OutErrorFilePath) && customFileSize($OutErrorFilePath)){
|
|
$outError = file_get_contents($OutErrorFilePath);
|
|
checkErrorAndReason($outError);
|
|
if(stristr($outError,"encryption verification failed")){
|
|
exit(header("Location: ./logout.php"));
|
|
}
|
|
if(isset($_SESSION['dedup']) && $_SESSION['dedup']){
|
|
if(strpos($outError, 'failed to get the device information') !== false){
|
|
exit(header("Location: ./logout.php"));
|
|
}
|
|
}
|
|
}
|
|
|
|
$response = array();
|
|
$response[] = false;
|
|
$response['retry'] = false;
|
|
echo json_encode($response);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$resStatus = true;
|
|
$resHtml = '';
|
|
if($countDir > 0){
|
|
$fullPath = $fullPath!="/"?"$fullPath/":"$fullPath";
|
|
if(isset($_GET['newRestoreSet'])){
|
|
$fileMenuList = '';
|
|
} else {
|
|
$fileMenuList = '<td class="file_menu_list"></td>';
|
|
}
|
|
$index=0;
|
|
foreach($dirArrayDefault as $dir=>$property) {
|
|
$dirName = $dir;
|
|
$dir = str_replace('&','&',$dir);
|
|
$dirSize = humanReadableSize($property['size']);
|
|
$expDate = explode(' ',trim($property['datetime']));
|
|
$dirDate = $expDate[0]." ".ampmTimeFormat($expDate[1]);
|
|
|
|
/*$size[] = $dirSize;
|
|
$date[] = $dirDate;*/
|
|
$size[] = $property['size'];
|
|
$date[] = $property['datetime'];
|
|
#$fullPathHTML = htmlentities($fullPath.$dirName, ENT_QUOTES);
|
|
$fullPathHTML = $fullPath.$dirName;
|
|
$dirName = str_replace('&','&',$dir);
|
|
#$dirNameHTML = htmlentities($dirName, ENT_QUOTES);
|
|
$dirNameHTML = $dirName;
|
|
|
|
if($property['type'] == "D") {
|
|
$resHtml .= '<tr class="row_list">';
|
|
$resHtml .= '<td class="file_check">';
|
|
$resHtml .= '<input type="checkbox" id="chk_elements['.$index.']" name="chk_elements['.$index.']" value="'.$fullPathHTML.'">';
|
|
$resHtml .= '<label >folder</label> </td>';
|
|
$resHtml .= '<td class="cont_heading" title="'.$dirNameHTML.'">';
|
|
$resHtml .= '<a class="getDirList" href="javascript:void(0);" alt="'.$fullPathHTML.'/"><img src="include/images/idq_ico_folder.png"></a>';
|
|
$resHtml .= '<a class="getDirList" href="javascript:void(0);" alt="'.$fullPathHTML.'/"><span>';
|
|
$resHtml .= str_replace(' ',' ',$dirNameHTML);
|
|
$resHtml .= '</span></a>';
|
|
$resHtml .= '</td>';
|
|
$resHtml .= '<td class="file_size">'.$dirSize.'</td><td class="file_date">'.$dirDate.'</td>';
|
|
$resHtml .= $fileMenuList;
|
|
$resHtml .= '</tr>';
|
|
|
|
$type[] = 'folder';
|
|
|
|
} else {
|
|
$fileMenuList1 = ($machine=='twotier')?'<td class=""></td>':$fileMenuList;
|
|
$resHtml .= '<tr class="row_list">';
|
|
$resHtml .= '<td class="file_check">';
|
|
$resHtml .= '<input type="checkbox" id="chk_elements['.$index.']" name="chk_elements['.$index.']" value="'.$fullPathHTML.'">';
|
|
$resHtml .= '<label >file</label></td>';
|
|
$resHtml .= '<td class="cont_heading" title="'.$dirNameHTML.'"><img src="include/images/idq_ico_file.png" >';
|
|
$resHtml .= '<span>'.str_replace(' ',' ',$dirNameHTML).'</span></td>';
|
|
$resHtml .= '<td class="file_size" value="'.$property['size'].'" >'.$dirSize.'</td><td class="file_date" value="'.$property['datetime'].'" >'.$dirDate.'</td>';
|
|
$resHtml .= $fileMenuList1;
|
|
$resHtml .= '</tr>';
|
|
|
|
$type[] = 'file';
|
|
}
|
|
$index++;
|
|
$dirArray[] = $fullPath.$dir;
|
|
}
|
|
}
|
|
else {
|
|
$fullPath = $fullPath!="/"?"$fullPath/":"$fullPath";
|
|
|
|
$resStatus = false;
|
|
$resHtml = '<div class="nfiles" style="display:block;">'.NO_FILES.'</div>';
|
|
}
|
|
|
|
if(isset($_GET['fullPath'])) {
|
|
$resArr[]=$resStatus;
|
|
$resArr[]=$resHtml;
|
|
|
|
if(!isset($dirArray))
|
|
$dirArray = array();
|
|
|
|
if(!isset($type)) {
|
|
$type = array();
|
|
$size = array();
|
|
$date = array();
|
|
}
|
|
if(isset($_SESSION['selectedRestoreDeviceID']) && isset($_SESSION['dedup']) && $_SESSION['dedup'])
|
|
$fullPath = $_SESSION['selectedRestoreDeviceID'].$fullPath;
|
|
|
|
$resArr[]= array('url'=>$fullPath,'dir'=>$dirArray,'type'=>$type,'size'=>$size,'date'=>$date);
|
|
//$resArr[]= array('url'=>$fullPath,'dir'=>$dirArray,'type'=>$type,'size'=>$size,'date'=>$date, 'orgiSize'=>$orgiSize,'orgiDate'=>$orgiDate );
|
|
echo json_encode($resArr);
|
|
exit;
|
|
}
|
|
else {
|
|
echo $resHtml;
|
|
}
|
|
}
|
|
?>
|