コード例 #1
0
 public function switchActions($actionName, $httpVars, $fileVars)
 {
     //$urlBase = $this->accessDriver
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     if (!isset($this->pluginConf)) {
         $this->pluginConf = array("GENERATE_THUMBNAIL" => false);
     }
     $streamData = $repository->streamData;
     $this->streamData = $streamData;
     $destStreamURL = $streamData["protocol"] . "://" . $repository->getId();
     switch ($actionName) {
         case "filehasher_signature":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             if (!file_exists($destStreamURL . $file)) {
                 break;
             }
             $cacheItem = AJXP_Cache::getItem("signatures", $destStreamURL . $file, array($this, "generateSignature"));
             $data = $cacheItem->getData();
             header("Content-Type:application/octet-stream");
             header("Content-Length", strlen($data));
             echo $data;
             break;
         case "filehasher_delta":
         case "filehasher_patch":
             // HANDLE UPLOAD DATA
             if (!isset($fileVars) && !is_array($fileVars["userfile_0"])) {
                 throw new Exception("These action should find uploaded data");
             }
             $uploadedData = tempnam(AJXP_Utils::getAjxpTmpDir(), $actionName . "-sig");
             move_uploaded_file($fileVars["userfile_0"]["tmp_name"], $uploadedData);
             $fileUrl = $destStreamURL . AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $file = call_user_func(array($this->streamData["classname"], "getRealFSReference"), $fileUrl, true);
             if ($actionName == "filehasher_delta") {
                 $signatureFile = $uploadedData;
                 $deltaFile = tempnam(AJXP_Utils::getAjxpTmpDir(), $actionName . "-delta");
                 rsync_generate_delta($signatureFile, $file, $deltaFile);
                 header("Content-Type:application/octet-stream");
                 header("Content-Length:" . filesize($deltaFile));
                 readfile($deltaFile);
                 unlink($signatureFile);
                 unlink($deltaFile);
             } else {
                 $patched = $file . ".rdiff_patched";
                 $deltaFile = $uploadedData;
                 rsync_patch_file($file, $deltaFile, $patched);
                 rename($patched, $file);
                 header("Content-Type:text/plain");
                 unlink($deltaFile);
                 echo md5_file($file);
             }
             break;
     }
 }
コード例 #2
0
 public function switchActions($actionName, $httpVars, $fileVars)
 {
     //$urlBase = $this->accessDriver
     $repository = $this->accessDriver->repository;
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     $selection = new UserSelection($repository, $httpVars);
     switch ($actionName) {
         case "filehasher_signature":
             $file = $selection->getUniqueNode();
             if (!file_exists($file->getUrl())) {
                 break;
             }
             $cacheItem = AJXP_Cache::getItem("signatures", $file->getUrl(), array($this, "generateSignature"));
             $data = $cacheItem->getData();
             header("Content-Type:application/octet-stream");
             header("Content-Length", strlen($data));
             echo $data;
             break;
         case "filehasher_delta":
         case "filehasher_patch":
             // HANDLE UPLOAD DATA
             $this->logDebug("Received signature file, should compute delta now");
             if (!isset($fileVars) && !is_array($fileVars["userfile_0"])) {
                 throw new Exception("These action should find uploaded data");
             }
             $signature_delta_file = $fileVars["userfile_0"]["tmp_name"];
             $fileUrl = $selection->getUniqueNode()->getUrl();
             $file = AJXP_MetaStreamWrapper::getRealFSReference($fileUrl, true);
             if ($actionName == "filehasher_delta") {
                 $deltaFile = tempnam(AJXP_Utils::getAjxpTmpDir(), $actionName . "-delta");
                 $this->logDebug("Received signature file, should compute delta now");
                 rsync_generate_delta($signature_delta_file, $file, $deltaFile);
                 $this->logDebug("Computed delta file, size is " . filesize($deltaFile));
                 header("Content-Type:application/octet-stream");
                 header("Content-Length:" . filesize($deltaFile));
                 readfile($deltaFile);
                 unlink($deltaFile);
             } else {
                 $patched = $file . ".rdiff_patched";
                 rsync_patch_file($file, $signature_delta_file, $patched);
                 rename($patched, $file);
                 $node = $selection->getUniqueNode();
                 AJXP_Controller::applyHook("node.change", array($node, $node, false));
                 header("Content-Type:text/plain");
                 echo md5_file($file);
             }
             break;
         case "stat_hash":
             clearstatcache();
             header("Content-type:application/json");
             if ($selection->isUnique()) {
                 $node = $selection->getUniqueNode();
                 $stat = @stat($node->getUrl());
                 if (!$stat || !is_readable($node->getUrl())) {
                     print '{}';
                 } else {
                     if (is_file($node->getUrl())) {
                         if (isset($_SERVER["HTTP_RANGE"])) {
                             $fullSize = floatval($stat['size']);
                             $ranges = explode('=', $_SERVER["HTTP_RANGE"]);
                             $offsets = explode('-', $ranges[1]);
                             $offset = floatval($offsets[0]);
                             $length = floatval($offsets[1]) - $offset;
                             if (!$length) {
                                 $length = $fullSize - $offset;
                             }
                             if ($length + $offset > $fullSize || $length < 0) {
                                 $length = $fullSize - $offset;
                             }
                             $hash = $this->getPartialHash($node, $offset, $length);
                         } else {
                             $hash = $this->getFileHash($selection->getUniqueNode());
                         }
                     } else {
                         $hash = 'directory';
                     }
                     $stat[13] = $stat["hash"] = $hash;
                     print json_encode($stat);
                 }
             } else {
                 $files = $selection->getFiles();
                 print '{';
                 foreach ($files as $index => $path) {
                     $node = new AJXP_Node($selection->currentBaseUrl() . $path);
                     $stat = @stat($selection->currentBaseUrl() . $path);
                     if (!$stat || !is_readable($node->getUrl())) {
                         $stat = '{}';
                     } else {
                         if (!is_dir($node->getUrl())) {
                             $hash = $this->getFileHash($node);
                         } else {
                             $hash = 'directory';
                         }
                         $stat[13] = $stat["hash"] = $hash;
                         $stat = json_encode($stat);
                     }
                     print json_encode(SystemTextEncoding::toUTF8($path)) . ':' . $stat . ($index < count($files) - 1 ? "," : "");
                 }
                 print '}';
             }
             break;
             break;
     }
 }
コード例 #3
0
ファイル: class.FileHasher.php プロジェクト: biggtfish/cms
 public function switchActions($actionName, $httpVars, $fileVars)
 {
     //$urlBase = $this->accessDriver
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     $streamData = $repository->streamData;
     $this->streamData = $streamData;
     $destStreamURL = $streamData["protocol"] . "://" . $repository->getId();
     switch ($actionName) {
         case "filehasher_signature":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             if (!file_exists($destStreamURL . $file)) {
                 break;
             }
             $cacheItem = AJXP_Cache::getItem("signatures", $destStreamURL . $file, array($this, "generateSignature"));
             $data = $cacheItem->getData();
             header("Content-Type:application/octet-stream");
             header("Content-Length", strlen($data));
             echo $data;
             break;
         case "filehasher_delta":
         case "filehasher_patch":
             // HANDLE UPLOAD DATA
             $this->logDebug("Received signature file, should compute delta now");
             if (!isset($fileVars) && !is_array($fileVars["userfile_0"])) {
                 throw new Exception("These action should find uploaded data");
             }
             $uploadedData = tempnam(AJXP_Utils::getAjxpTmpDir(), $actionName . "-sig");
             move_uploaded_file($fileVars["userfile_0"]["tmp_name"], $uploadedData);
             $fileUrl = $destStreamURL . AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $file = call_user_func(array($this->streamData["classname"], "getRealFSReference"), $fileUrl, true);
             if ($actionName == "filehasher_delta") {
                 $signatureFile = $uploadedData;
                 $deltaFile = tempnam(AJXP_Utils::getAjxpTmpDir(), $actionName . "-delta");
                 $this->logDebug("Received signature file, should compute delta now");
                 rsync_generate_delta($signatureFile, $file, $deltaFile);
                 $this->logDebug("Computed delta file, size is " . filesize($deltaFile));
                 header("Content-Type:application/octet-stream");
                 header("Content-Length:" . filesize($deltaFile));
                 readfile($deltaFile);
                 unlink($signatureFile);
                 unlink($deltaFile);
             } else {
                 $patched = $file . ".rdiff_patched";
                 $deltaFile = $uploadedData;
                 rsync_patch_file($file, $deltaFile, $patched);
                 rename($patched, $file);
                 unlink($deltaFile);
                 header("Content-Type:text/plain");
                 echo md5_file($file);
             }
             break;
         case "stat_hash":
             $selection = new UserSelection();
             $selection->initFromArray($httpVars);
             clearstatcache();
             header("Content-type:application/json");
             if ($selection->isUnique()) {
                 $node = $selection->getUniqueNode($this->accessDriver);
                 $stat = @stat($node->getUrl());
                 if (!$stat) {
                     print '{}';
                 } else {
                     if ($node->isLeaf()) {
                         $hash = $this->getFileHash($selection->getUniqueNode($this->accessDriver));
                     } else {
                         $hash = 'directory';
                     }
                     $stat[13] = $stat["hash"] = $hash;
                     print json_encode($stat);
                 }
             } else {
                 $files = $selection->getFiles();
                 print '{';
                 foreach ($files as $index => $path) {
                     $node = new AJXP_Node($destStreamURL . $path);
                     $stat = @stat($destStreamURL . $path);
                     if (!$stat) {
                         $stat = '{}';
                     } else {
                         if (!is_dir($node->getUrl())) {
                             $hash = $this->getFileHash($node);
                         } else {
                             $hash = 'directory';
                         }
                         $stat[13] = $stat["hash"] = $hash;
                         $stat = json_encode($stat);
                     }
                     print json_encode($path) . ':' . $stat . ($index < count($files) - 1 ? "," : "");
                 }
                 print '}';
             }
             break;
             break;
     }
 }