public function filterFile($fileName, $hiddenTest = false)
 {
     $pathParts = pathinfo($fileName);
     if ($hiddenTest) {
         $showHiddenFiles = $this->getFilteredOption("SHOW_HIDDEN_FILES", $this->repository->getId());
         if (AJXP_Utils::isHidden($pathParts["basename"]) && !$showHiddenFiles) {
             return true;
         }
     }
     $hiddenFileNames = $this->getFilteredOption("HIDE_FILENAMES", $this->repository->getId());
     $hiddenExtensions = $this->getFilteredOption("HIDE_EXTENSIONS", $this->repository->getId());
     if (!empty($hiddenFileNames)) {
         if (!is_array($hiddenFileNames)) {
             $hiddenFileNames = explode(",", $hiddenFileNames);
         }
         foreach ($hiddenFileNames as $search) {
             if (strcasecmp($search, $pathParts["basename"]) == 0) {
                 return true;
             }
         }
     }
     if (!empty($hiddenExtensions)) {
         if (!is_array($hiddenExtensions)) {
             $hiddenExtensions = explode(",", $hiddenExtensions);
         }
         foreach ($hiddenExtensions as $search) {
             if (strcasecmp($search, $pathParts["extension"]) == 0) {
                 return true;
             }
         }
     }
     return false;
 }
 public function postProcess($action, $httpVars, $postProcessData)
 {
     if (isset($httpVars["simple_uploader"]) || isset($httpVars["xhr_uploader"])) {
         return;
     }
     /* If set resumeFileId and resumePartitionIndex, cross-session resume is requested. */
     if (isset($httpVars["resumeFileId"]) && isset($httpVars["resumePartitionIndex"])) {
         header("HTTP/1.1 200 OK");
         print "fileId: " . $httpVars["resumeFileId"] . "\n";
         print "partitionIndex: " . $httpVars["resumePartitionIndex"];
         return;
     }
     /*if (self::$skipDecoding) {
     
             }*/
     if (isset($postProcessData["processor_result"]["ERROR"])) {
         if (isset($httpVars["lastPartition"]) && isset($httpVars["partitionCount"])) {
             /* we get the stream url (where all the partitions have been uploaded so far) */
             $repository = ConfService::getRepository();
             $dir = AJXP_Utils::decodeSecureMagic($httpVars["dir"]);
             $plugin = AJXP_PluginsService::findPlugin("access", $repository->getAccessType());
             $streamData = $plugin->detectStreamWrapper(true);
             $destStreamURL = $streamData["protocol"] . "://" . $repository->getId() . $dir . "/";
             if ($httpVars["partitionCount"] > 1) {
                 /* we fetch the information that help us to construct the temp files name */
                 $fileId = $httpVars["fileId"];
                 $fileHash = md5($httpVars["fileName"]);
                 /* deletion of all the partitions that have been uploaded */
                 for ($i = 0; $i < $httpVars["partitionCount"]; $i++) {
                     if (file_exists($destStreamURL . "{$fileHash}.{$fileId}.{$i}")) {
                         unlink($destStreamURL . "{$fileHash}.{$fileId}.{$i}");
                     }
                 }
             } else {
                 $fileName = $httpVars["fileName"];
                 unlink($destStreamURL . $fileName);
             }
         }
         echo "Error: " . $postProcessData["processor_result"]["ERROR"]["MESSAGE"];
         return;
     }
     if (!isset($httpVars["partitionRealName"]) && !isset($httpVars["lastPartition"])) {
         return;
     }
     $repository = ConfService::getRepository();
     $driver = ConfService::loadDriverForRepository($repository);
     if (!$repository->detectStreamWrapper(false)) {
         return false;
     }
     if ($httpVars["lastPartition"]) {
         $plugin = AJXP_PluginsService::findPlugin("access", $repository->getAccessType());
         $streamData = $plugin->detectStreamWrapper(true);
         $dir = AJXP_Utils::decodeSecureMagic($httpVars["dir"]);
         $destStreamURL = $streamData["protocol"] . "://" . $repository->getId() . $dir . "/";
         /* we check if the current file has a relative path (aka we want to upload an entire directory) */
         $this->logDebug("Now dispatching relativePath dest:", $httpVars["relativePath"]);
         $subs = explode("/", $httpVars["relativePath"]);
         $userfile_name = array_pop($subs);
         $folderForbidden = false;
         $all_in_place = true;
         $partitions_length = 0;
         $fileId = $httpVars["fileId"];
         $fileHash = md5($userfile_name);
         $partitionCount = $httpVars["partitionCount"];
         $fileLength = $_POST["fileLength"];
         /*
          *
          * Now, we supposed that access driver has already saved uploaded file in to
          * folderServer with file name is md5 relativePath value.
          * We try to copy this file to right location in recovery his name.
          *
          */
         $userfile_name = md5($httpVars["relativePath"]);
         if (self::$remote) {
             $partitions = array();
             $newPartitions = array();
             $index_first_partition = -1;
             $i = 0;
             do {
                 $currentFileName = $driver->getFileNameToCopy();
                 $partitions[] = $driver->getNextFileToCopy();
                 if ($index_first_partition < 0 && strstr($currentFileName, $fileHash) != false) {
                     $index_first_partition = $i;
                 } else {
                     if ($index_first_partition < 0) {
                         $newPartitions[] = array_pop($partitions);
                     }
                 }
             } while ($driver->hasFilesToCopy());
         }
         /* if partitionned */
         if ($partitionCount > 1) {
             if (self::$remote) {
                 for ($i = 0; $all_in_place && $i < $partitionCount; $i++) {
                     $partition_file = "{$fileHash}.{$fileId}.{$i}";
                     if (strstr($partitions[$i]["name"], $partition_file) != false) {
                         $partitions_length += filesize($partitions[$i]["tmp_name"]);
                     } else {
                         $all_in_place = false;
                     }
                 }
             } else {
                 for ($i = 0; $all_in_place && $i < $partitionCount; $i++) {
                     $partition_file = $destStreamURL . "{$fileHash}.{$fileId}.{$i}";
                     if (file_exists($partition_file)) {
                         $partitions_length += filesize($partition_file);
                     } else {
                         $all_in_place = false;
                     }
                 }
             }
         } else {
             if (self::$remote) {
                 if (strstr($newPartitions[count($newPartitions) - 1]["name"], $userfile_name) != false) {
                     $partitions_length += filesize($newPartitions[count($newPartitions) - 1]["tmp_name"]);
                 }
             } else {
                 if (file_exists($destStreamURL . $userfile_name)) {
                     $partitions_length += filesize($destStreamURL . $userfile_name);
                 }
             }
         }
         if (!$all_in_place || $partitions_length != floatval($fileLength)) {
             echo "Error: Upload validation error!";
             /* we delete all the uploaded partitions */
             if ($httpVars["partitionCount"] > 1) {
                 for ($i = 0; $i < $partitionCount; $i++) {
                     if (file_exists($destStreamURL . "{$fileHash}.{$fileId}.{$i}")) {
                         unlink($destStreamURL . "{$fileHash}.{$fileId}.{$i}");
                     }
                 }
             } else {
                 $fileName = $httpVars["partitionRealName"];
                 unlink($destStreamURL . $fileName);
             }
             return;
         }
         if (count($subs) > 0 && !self::$remote) {
             $curDir = "";
             if (substr($curDir, -1) == "/") {
                 $curDir = substr($curDir, 0, -1);
             }
             // Create the folder tree as necessary
             foreach ($subs as $key => $spath) {
                 $messtmp = "";
                 $dirname = AJXP_Utils::decodeSecureMagic($spath, AJXP_SANITIZE_FILENAME);
                 $dirname = substr($dirname, 0, ConfService::getCoreConf("NODENAME_MAX_LENGTH"));
                 //$this->filterUserSelectionToHidden(array($dirname));
                 if (AJXP_Utils::isHidden($dirname)) {
                     $folderForbidden = true;
                     break;
                 }
                 if (file_exists($destStreamURL . "{$curDir}/{$dirname}")) {
                     // if the folder exists, traverse
                     $this->logDebug("{$curDir}/{$dirname} existing, traversing for {$userfile_name} out of", $httpVars["relativePath"]);
                     $curDir .= "/" . $dirname;
                     continue;
                 }
                 $this->logDebug($destStreamURL . $curDir);
                 $dirMode = 0775;
                 $chmodValue = $repository->getOption("CHMOD_VALUE");
                 if (isset($chmodValue) && $chmodValue != "") {
                     $dirMode = octdec(ltrim($chmodValue, "0"));
                     if ($dirMode & 0400) {
                         $dirMode |= 0100;
                     }
                     // Owner is allowed to read, allow to list the directory
                     if ($dirMode & 040) {
                         $dirMode |= 010;
                     }
                     // Group is allowed to read, allow to list the directory
                     if ($dirMode & 04) {
                         $dirMode |= 01;
                     }
                     // Other are allowed to read, allow to list the directory
                 }
                 $url = $destStreamURL . $curDir . "/" . $dirname;
                 $old = umask(0);
                 mkdir($url, $dirMode);
                 umask($old);
                 AJXP_Controller::applyHook("node.change", array(null, new AJXP_Node($url), false));
                 $curDir .= "/" . $dirname;
             }
         }
         if (!$folderForbidden) {
             $fileId = $httpVars["fileId"];
             $this->logDebug("Should now rebuild file!", $httpVars);
             // Now move the final file to the right folder
             // Currently the file is at the base of the current
             $this->logDebug("PartitionRealName", $destStreamURL . $httpVars["partitionRealName"]);
             // Get file by name (md5 value)
             $relPath_md5 = AJXP_Utils::decodeSecureMagic(md5($httpVars["relativePath"]));
             // original file name
             $relPath = AJXP_Utils::decodeSecureMagic($httpVars["relativePath"]);
             $target = $destStreamURL;
             $target .= self::$remote ? basename($relPath) : $relPath;
             /*
              *   $current is uploaded file with md5 value as his name
              *   we copy to $relPath and delete md5 file
              */
             $current = $destStreamURL . basename($relPath_md5);
             if ($httpVars["partitionCount"] > 1) {
                 if (self::$remote) {
                     $test = AJXP_Utils::getAjxpTmpDir() . "/" . $httpVars["partitionRealName"];
                     $newDest = fopen(AJXP_Utils::getAjxpTmpDir() . "/" . $httpVars["partitionRealName"], "w");
                     $newFile = array();
                     $length = 0;
                     for ($i = 0, $count = count($partitions); $i < $count; $i++) {
                         $currentFile = $partitions[$i];
                         $currentFileName = $currentFile["tmp_name"];
                         $part = fopen($currentFileName, "r");
                         while (!feof($part)) {
                             $length += fwrite($newDest, fread($part, 4096));
                         }
                         fclose($part);
                         unlink($currentFileName);
                     }
                     $newFile["type"] = $partitions[0]["type"];
                     $newFile["name"] = $httpVars["partitionRealName"];
                     $newFile["error"] = 0;
                     $newFile["size"] = $length;
                     $newFile["tmp_name"] = AJXP_Utils::getAjxpTmpDir() . "/" . $httpVars["partitionRealName"];
                     $newFile["destination"] = $partitions[0]["destination"];
                     $newPartitions[] = $newFile;
                 } else {
                     $newDest = fopen($destStreamURL . $httpVars["partitionRealName"], "w");
                     $fileHash = md5($httpVars["partitionRealName"]);
                     for ($i = 0; $i < $httpVars["partitionCount"]; $i++) {
                         $part = fopen($destStreamURL . "{$fileHash}.{$fileId}.{$i}", "r");
                         while (!feof($part)) {
                             fwrite($newDest, fread($part, 4096));
                         }
                         fclose($part);
                         unlink($destStreamURL . "{$fileHash}.{$fileId}.{$i}");
                     }
                 }
                 fclose($newDest);
             }
             if (!self::$remote && (!self::$wrapperIsRemote || $relPath != $httpVars["partitionRealName"])) {
                 $err = copy($current, $target);
             } else {
                 for ($i = 0, $count = count($newPartitions); $i < $count; $i++) {
                     $driver->storeFileToCopy($newPartitions[$i]);
                 }
             }
             if ($err !== false) {
                 if (!self::$remote) {
                     unlink($current);
                 }
                 AJXP_Controller::applyHook("node.change", array(null, new AJXP_Node($target), false));
             } else {
                 if ($current == $target) {
                     AJXP_Controller::applyHook("node.change", array(null, new AJXP_Node($target), false));
                 }
             }
         } else {
             // Remove the file, as it should not have been uploaded!
             //if(!self::$remote) unlink($current);
         }
     }
 }
 function countFiles($dirName, $foldersOnly = false, $nonEmptyCheckOnly = false)
 {
     $handle = opendir($dirName);
     $count = 0;
     while (strlen($file = readdir($handle)) > 0) {
         if ($file != "." && $file != ".." && !(AJXP_Utils::isHidden($file) && !$this->driverConf["SHOW_HIDDEN_FILES"]) && !($foldersOnly && is_file($dirName . "/" . $file))) {
             $count++;
             if ($nonEmptyCheckOnly) {
                 return 1;
             }
         }
     }
     closedir($handle);
     return $count;
 }
 public function recursivePurge($dirName, $hardPurgeTime, $softPurgeTime = 0)
 {
     $handle = opendir($dirName);
     while (false !== ($entry = readdir($handle))) {
         if ($entry == "" || $entry == ".." || AJXP_Utils::isHidden($entry)) {
             continue;
         }
         $fileName = $dirName . "/" . $entry;
         if (is_file($fileName)) {
             $docAge = time() - filemtime($fileName);
             if ($hardPurgeTime > 0 && $docAge > $hardPurgeTime) {
                 $this->purge($fileName);
             } elseif ($softPurgeTime > 0 && $docAge > $softPurgeTime) {
                 if (!ShareCenter::isShared(new AJXP_Node($fileName))) {
                     $this->purge($fileName);
                 }
             }
         } else {
             $this->recursivePurge($fileName, $hardPurgeTime, $softPurgeTime);
         }
     }
     closedir($handle);
 }
 public function recursivePurge($dirName, $hardPurgeTime, $softPurgeTime = 0)
 {
     $handle = opendir($dirName);
     $shareCenter = false;
     if (class_exists("ShareCenter")) {
         $shareCenter = ShareCenter::getShareCenter("action.share");
     }
     if ($handle === false) {
         $this->logError(__FUNCTION__, "Cannot open folder " . $dirName);
         return;
     }
     while (false !== ($entry = readdir($handle))) {
         if ($entry == "" || $entry == ".." || AJXP_Utils::isHidden($entry)) {
             continue;
         }
         $fileName = $dirName . "/" . $entry;
         if (is_file($fileName)) {
             $docAge = time() - filemtime($fileName);
             if ($hardPurgeTime > 0 && $docAge > $hardPurgeTime) {
                 $this->purge($fileName);
             } elseif ($softPurgeTime > 0 && $docAge > $softPurgeTime) {
                 if ($shareCenter !== false && $shareCenter->isShared(new AJXP_Node($fileName))) {
                     $this->purge($fileName);
                 }
             }
         } else {
             $this->recursivePurge($fileName, $hardPurgeTime, $softPurgeTime);
         }
     }
     closedir($handle);
 }
 /**
  * Returns an array with all the child nodes
  *
  * @return Sabre\DAV\INode[]
  */
 public function getChildren()
 {
     if (isset($this->children)) {
         return $this->children;
     }
     $contents = array();
     $errors = array();
     $nodes = scandir($this->getUrl());
     foreach ($nodes as $file) {
         if ($file == "." || $file == "..") {
             continue;
         }
         if (!$this->repository->getOption("SHOW_HIDDEN_FILES") && AJXP_Utils::isHidden($file)) {
             continue;
         }
         if (is_dir($this->getUrl() . "/" . $file)) {
             // Add collection without any children
             $contents[] = new AJXP_Sabre_Collection($this->path . "/" . $file, $this->repository, $this->getAccessDriver());
         } else {
             // Add files without content
             $contents[] = new AJXP_Sabre_NodeLeaf($this->path . "/" . $file, $this->repository, $this->getAccessDriver());
         }
     }
     $this->children = $contents;
     $ajxpNode = new AJXP_Node($this->getUrl());
     AJXP_Controller::applyHook("node.read", array(&$ajxpNode));
     return $contents;
 }
 /**
  * Returns members of collection.
  *
  * Returns an array with the members of the collection identified by $path.
  * The returned array can contain {@link ezcWebdavCollection}, and {@link
  * ezcWebdavResource} instances and might also be empty, if the collection
  * has no members.
  * 
  * @param string $path 
  * @return array(ezcWebdavResource|ezcWebdavCollection)
  */
 protected function getCollectionMembers($path)
 {
     $path = $this->fixPath($path);
     $url = $this->getAccessDriver()->getRessourceUrl($path);
     $contents = array();
     $errors = array();
     $nodes = scandir($url);
     AJXP_Logger::debug("getCollectionMembers " . $path);
     foreach ($nodes as $file) {
         if (isset($this->options->hideDotFiles) && $this->options->hideDotFiles !== false && AJXP_Utils::isHidden($file)) {
             continue;
         }
         if (is_dir($url . "/" . $file)) {
             // Add collection without any children
             $contents[] = new ezcWebdavCollection($this->urlEncodePath(SystemTextEncoding::toUTF8($path, true) . ($path == "/" ? "" : "/") . SystemTextEncoding::toUTF8($file, true)));
         } else {
             // Add files without content
             $contents[] = new ezcWebdavResource($this->urlEncodePath(SystemTextEncoding::toUTF8($path, true) . ($path == "/" ? "" : "/") . SystemTextEncoding::toUTF8($file, true)));
         }
     }
     return $contents;
 }
 function recursivePurge($dirName, $purgeTime)
 {
     $handle = opendir($dirName);
     $count = 0;
     while (strlen($file = readdir($handle)) > 0) {
         if ($file == "" || $file == ".." || AJXP_Utils::isHidden($file)) {
             continue;
         }
         if (is_file($dirName . "/" . $file)) {
             $time = filemtime($dirName . "/" . $file);
             $docAge = time() - $time;
             if ($docAge > $purgeTime) {
                 $node = new AJXP_Node($dirName . "/" . $file);
                 AJXP_Controller::applyHook("node.before_change", array($node));
                 unlink($dirName . "/" . $file);
                 AJXP_Controller::applyHook("node.change", array($node));
                 AJXP_Logger::logAction("Purge", array("file" => $dirName . "/" . $file));
                 print " - Purging document : " . $dirName . "/" . $file . "\n";
             }
         } else {
             $this->recursivePurge($dirName . "/" . $file, $purgeTime);
         }
     }
     closedir($handle);
 }
 public function postProcess($action, $httpVars, $postProcessData)
 {
     if (isset($httpVars["simple_uploader"]) || isset($httpVars["xhr_uploader"])) {
         return;
     }
     if (self::$skipDecoding) {
     }
     if (!isset($httpVars["partitionRealName"]) && !isset($httpVars["checkRelativePath"])) {
         return;
     }
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(false)) {
         return false;
     }
     $plugin = AJXP_PluginsService::findPlugin("access", $repository->getAccessType());
     $streamData = $plugin->detectStreamWrapper(true);
     $dir = AJXP_Utils::decodeSecureMagic($httpVars["dir"]);
     $destStreamURL = $streamData["protocol"] . "://" . $repository->getId() . $dir . "/";
     if (isset($httpVars["partitionRealName"])) {
         $count = intval($httpVars["partitionCount"]);
         $index = intval($httpVars["partitionIndex"]);
         $fileId = $httpVars["fileId"];
         $clientId = $httpVars["ajxp_sessid"];
         AJXP_Logger::debug("Should now rebuild file!", $httpVars);
         $newDest = fopen($destStreamURL . $httpVars["partitionRealName"], "w");
         AJXP_LOGGER::debug("PartitionRealName", $destStreamURL . $httpVars["partitionRealName"]);
         for ($i = 0; $i < $count; $i++) {
             $part = fopen($destStreamURL . "{$clientId}.{$fileId}.{$i}", "r");
             while (!feof($part)) {
                 fwrite($newDest, fread($part, 4096));
             }
             fclose($part);
             unlink($destStreamURL . "{$clientId}.{$fileId}.{$i}");
         }
         fclose($newDest);
     }
     if (isset($httpVars["checkRelativePath"])) {
         AJXP_LOGGER::debug("Now dispatching relativePath dest:", $httpVars["relativePath"]);
         $subs = explode("/", $httpVars["relativePath"]);
         $userfile_name = array_pop($subs);
         $subpath = "";
         $curDir = "";
         // remove trailing slash from current dir if we've got subdirs
         if (count($subs) > 0) {
             if (substr($curDir, -1) == "/") {
                 $curDir = substr($curDir, 0, -1);
             }
             $folderForbidden = false;
             // Create the folder tree as necessary
             foreach ($subs as $key => $spath) {
                 $messtmp = "";
                 $dirname = AJXP_Utils::decodeSecureMagic($spath, AJXP_SANITIZE_HTML_STRICT);
                 $dirname = substr($dirname, 0, ConfService::getCoreConf("NODENAME_MAX_LENGTH"));
                 //$this->filterUserSelectionToHidden(array($dirname));
                 if (AJXP_Utils::isHidden($dirname)) {
                     $folderForbidden = true;
                     break;
                 }
                 if (file_exists($destStreamURL . "{$curDir}/{$dirname}")) {
                     // if the folder exists, traverse
                     AJXP_Logger::debug("{$curDir}/{$dirname} existing, traversing for {$userfile_name} out of", $httpVars["relativePath"]);
                     $curDir .= "/" . $dirname;
                     continue;
                 }
                 AJXP_Logger::debug($destStreamURL . $curDir);
                 $dirMode = 0775;
                 $chmodValue = $repository->getOption("CHMOD_VALUE");
                 if (isset($chmodValue) && $chmodValue != "") {
                     $dirMode = octdec(ltrim($chmodValue, "0"));
                     if ($dirMode & 0400) {
                         $dirMode |= 0100;
                     }
                     // User is allowed to read, allow to list the directory
                     if ($dirMode & 040) {
                         $dirMode |= 010;
                     }
                     // Group is allowed to read, allow to list the directory
                     if ($dirMode & 04) {
                         $dirMode |= 01;
                     }
                     // Other are allowed to read, allow to list the directory
                 }
                 $old = umask(0);
                 mkdir($destStreamURL . $curDir . "/" . $dirname, $dirMode);
                 umask($old);
                 $curDir .= "/" . $dirname;
             }
             // Now move the final file to the right folder
             // Currently the file is at the base of the current
             $relPath = AJXP_Utils::decodeSecureMagic($httpVars["relativePath"]);
             $current = $destStreamURL . basename($relPath);
             $target = $destStreamURL . $relPath;
             if (!$folderForbidden) {
                 $err = copy($current, $target);
                 if ($err !== false) {
                     unlink($current);
                 }
             } else {
                 // Remove the file, as it should not have been uploaded!
                 unlink($current);
             }
         }
     }
 }