$line){ if(empty($line)) continue; if(0 === $isOpened){ usleep(1000); ++$pageCount; if($searchFileHandle) @fclose($searchFileHandle); if(!$searchFileHandle = fopen("$searchDir/page$pageCount","w")){ traceLog("Unable to open $searchDir/page$pageCount"); userCancelCleanup(); } chmod("$searchDir/page$pageCount",PERMISSIONVAL); $isOpened = 1; } $type = ""; # Stat output: # 7 => total size of file, in bytes # 9 => last modify time in seconds since the epoch. $statRes = stat($line); if(count($statRes)-1) { if(is_link($line)) continue; if (is_file($line)) $type = "F"; elseif (is_dir($line)) $type = "D"; if(!empty($type)){ list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($statRes[9]); $year += 1900; $mon += 1; $mday = (($mday < 10)? "0" . $mday : $mday); $mon = (($mon < 10)? "0" . $mon : $mon); $dateTime = "$year/$mon/$mday $hour:$min:$sec"; if($statRes[7] < 0) $statRes[7] = customFileSize($line); $size = convertFileSize($statRes[7]); fwrite($searchFileHandle, $line."\n".$size."\n".$dateTime."\n".$type."\n"); ++$count; if(0 === $count % NO_OF_LINES) $isOpened = 0; } } if(!($countChk % 10) and !file_exists($pidPath)) userCancelCleanup(); ++$countChk; } if(1 === $flag) break; } userCancelCleanup(); } while(count($searchChilds) > 0) { foreach($searchChilds as $key => $pid) { $res = pcntl_waitpid($pid, $status, WNOHANG); // If the process has already exited if($res == -1 || $res > 0) unset($searchChilds[$key]); } sleep(1); } exit; #**************************************************************************************************** # Subroutine Name : userCancelCleanup # Objective : This function completes the user cancel cleanup # Added By : Pooja Havaldar #*****************************************************************************************************/ function traceChildPIDs($pid) { GLOBAL $childpidfile; file_put_contents($childpidfile, "{$pid}\n", FILE_APPEND); } #**************************************************************************************************** # Subroutine Name : userCancelCleanup # Objective : This function completes the user cancel cleanup # Added By : Pooja Havaldar # Modified By : Sabin Cheruvattil #*****************************************************************************************************/ function userCancelCleanup() { GLOBAL $searchFileHandle, $outputFileHandle, $pidPath, $searchDir, $searchPath, $outputFilePath, $childpidfile; @fclose($searchFileHandle); @fclose($outputFileHandle); if(file_exists($childpidfile)) { $cpids = file($childpidfile); foreach($cpids as $cpid) { $cpid = trim($cpid); if($cpid != '' && (int)$cpid > 0) { `kill $cpid`; } } @unlink($childpidfile); } if(file_exists($pidPath)){ unlink($pidPath); unlink($searchPath); unlink($outputFilePath); unlink($searchDir.PATHSEPARATOR.ERRORFILE); } else{ $searchDir = str_replace("'","'\''",$searchDir); $searchDir = "'".$searchDir."'"; if($searchDir!="/") removeItems($searchDir); } exit; } #**************************************************************************************************** # Subroutine Name : getSearchResult # Objective : This function search the pattern provided in full NAS machine and returns # the output. # Added By : Deepak Chaurasia #*****************************************************************************************************/ function getSearchResult($searcharray,$searchDir) { GLOBAL $webDir,$machine; $searchItem = trim($searcharray[0],LINEFEED); $searchItem = phpQuoteMeta($searchItem); $searchItem = str_replace("'","'\''",$searchItem); $OnlySearch = "'".$searchItem."'"; $excludePath = getWebDirPath(); $searchHiddenItem = ""; if(preg_match("/^\\./m",$searchItem )) $searchHiddenItem = "'"."$searchItem"."*'"; else $searchHiddenItem = "'."."$searchItem"."*'"; $searchDir = str_replace("'","'\''",$searchDir); $searchDir = "'".$searchDir."'"; $searchItem = "'*"."$searchItem"."*'"; $searcharray_size = count($searcharray); if((SYNOLOGY === $machine) or (NETGEAR === $machine) or (ASUSTOR === $machine)){ $pattern = "-type d \\( -path $excludePath/".APPDIR." -o -path $excludePath/".SERVICE." \\) -prune -o -iname $searchItem -print -o -iname $searchHiddenItem -print -o -iname $OnlySearch -print >> ".$searchDir.PATHSEPARATOR.OUTPUTFILE." 2>>".$searchDir.PATHSEPARATOR.ERRORFILE.";"; $find = "find "; for($i=1 ; $i<$searcharray_size ; $i++){ $searcharray[$i] = trim($searcharray[$i],LINEFEED); $find .= "'$searcharray[$i]' "; if($i%SHARED_FOLDER_COUNT_FOR_SEARCH === 0){ $cmd = $find.$pattern; if(file_exists(PIDFILE)) exec($cmd); else break; $find = "find "; } } if($find !== "find "){ $cmd = $find.$pattern; if(file_exists(PIDFILE)) exec($cmd); } } elseif(QNAP == $machine){ $pattern1 = "-name $searchItem >> ".$searchDir.PATHSEPARATOR.OUTPUTFILE." 2>>".$searchDir.PATHSEPARATOR.ERRORFILE; $pattern2 = "-name $searchHiddenItem >> ".$searchDir.PATHSEPARATOR.OUTPUTFILE." 2>>".$searchDir.PATHSEPARATOR.ERRORFILE; $find = "find "; for($i=1 ; $i<$searcharray_size ; $i++){ $searcharray[$i] = trim($searcharray[$i],LINEFEED); $find .= "'$searcharray[$i]' "; if($i%SHARED_FOLDER_COUNT_FOR_SEARCH === 0){ $cmd1 = $find.$pattern1; if(file_exists(PIDFILE)) exec($cmd1); else break; $cmd2 = $find.$pattern2; if(file_exists(PIDFILE)) exec($cmd2); else break; $find = "find "; } } if($find !== "find "){ $cmd1 = $find.$pattern1; if(file_exists(PIDFILE)) exec($cmd1); $cmd2 = $find.$pattern2; if(file_exists(PIDFILE)) exec($cmd2); } } }