public function applyAction($actionName, $httpVars, $fileVars) { $messages = ConfService::getMessages(); if ($actionName == "index") { $repository = ConfService::getRepository(); $repositoryId = $repository->getId(); $userSelection = new UserSelection($repository, $httpVars); if ($userSelection->isEmpty()) { $userSelection->addFile("/"); } $nodes = $userSelection->buildNodes($repository->driverInstance); if (isset($httpVars["verbose"]) && $httpVars["verbose"] == "true") { $this->verboseIndexation = true; } if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) { AJXP_Controller::applyActionInBackground($repositoryId, "index", $httpVars); AJXP_XMLWriter::header(); AJXP_XMLWriter::triggerBgAction("check_index_status", array("repository_id" => $repositoryId), sprintf($messages["core.index.8"], $nodes[0]->getPath()), true, 2); if (!isset($httpVars["inner_apply"])) { AJXP_XMLWriter::close(); } return null; } // GIVE BACK THE HAND TO USER session_write_close(); foreach ($nodes as $node) { $dir = $node->getPath() == "/" || is_dir($node->getUrl()); // SIMPLE FILE if (!$dir) { try { $this->logDebug("Indexing - node.index " . $node->getUrl()); AJXP_Controller::applyHook("node.index", array($node)); } catch (Exception $e) { $this->logDebug("Error Indexing Node " . $node->getUrl() . " (" . $e->getMessage() . ")"); } } else { try { $this->recursiveIndexation($node); } catch (Exception $e) { $this->logDebug("Indexation of " . $node->getUrl() . " interrupted by error: (" . $e->getMessage() . ")"); } } } } else { if ($actionName == "check_index_status") { $repoId = $httpVars["repository_id"]; list($status, $message) = $this->getIndexStatus(ConfService::getRepositoryById($repoId), AuthService::getLoggedUser()); if (!empty($status)) { AJXP_XMLWriter::header(); AJXP_XMLWriter::triggerBgAction("check_index_status", array("repository_id" => $repoId), $message, true, 3); AJXP_XMLWriter::close(); } else { AJXP_XMLWriter::header(); AJXP_XMLWriter::triggerBgAction("info_message", array(), $messages["core.index.5"], true, 5); AJXP_XMLWriter::close(); } } } return null; }
/** * @param UserSelection $userSelection */ function filterUserSelection(&$userSelection) { if ($userSelection->isEmpty()) { foreach ($this->filters as $path => $virtual) { $userSelection->addFile($path); } } else { $newFiles = array(); foreach ($userSelection->getFiles() as $f) { if (isset($this->virtualPaths[$f])) { $newFiles[] = $this->virtualPaths[$f]; } else { $testB = base64_decode($f); if (isset($this->virtualPaths[$testB])) { $newFiles[] = $this->virtualPaths[$testB]; } } } $userSelection->setFiles($newFiles); } }
public function preProcessMove($actionName, &$httpVars, &$fileVars) { $destO = AJXP_Utils::decodeSecureMagic($httpVars["dest"]); $dest = substr($destO, 1, strpos(ltrim($destO, "/"), "/")); if (empty($dest)) { $dest = ltrim($destO, "/"); } $userSelection = new UserSelection(); $userSelection->initFromHttpVars($httpVars); if (!$userSelection->isEmpty()) { $testFileO = $userSelection->getUniqueFile(); $testFile = substr($testFileO, 1, strpos(ltrim($testFileO, "/"), "/")); if (empty($testFile)) { $testFile = ltrim($testFileO, "/"); } if ($actionName == "move") { if (strstr($dest, "ENCFS_CLEAR_") != false && strstr($testFile, "ENCFS_CLEAR_") === false || strstr($dest, "ENCFS_CLEAR_") === false && strstr($testFile, "ENCFS_CLEAR_") !== false || strstr($dest, "ENCFS_CLEAR_") != false && strstr($testFile, "ENCFS_CLEAR_") !== false && $testFile != $dest) { $httpVars["force_copy_delete"] = "true"; $this->logDebug("One mount to another, copy/delete instead of move ({$dest}, {$testFile})"); } } else { if ($actionName == "delete" && RecycleBinManager::recycleEnabled()) { if (strstr($testFile, "ENCFS_CLEAR_") !== false) { $httpVars["force_copy_delete"] = "true"; $this->logDebug("One mount to another, copy/delete instead of move"); } } else { if ($actionName == "restore") { if (strstr(RecycleBinManager::getFileOrigin($testFile), "ENCFS_CLEAR_")) { $httpVars["force_copy_delete"] = "true"; $this->logDebug("One mount to another, copy/delete instead of move"); } } } } } }
public function switchAction($actionName, $httpVars, $fileVars) { $this->baseURL = rtrim($this->getFilteredOption("ETHERPAD_SERVER"), "/"); $this->apiKey = $this->getFilteredOption("ETHERPAD_APIKEY"); $userSelection = new UserSelection(ConfService::getRepository(), $httpVars); if ($userSelection->isEmpty()) { throw new Exception("Empty selection"); } $repository = ConfService::getRepository(); if (!$repository->detectStreamWrapper(false)) { return false; } $selectedNode = $userSelection->getUniqueNode(); $selectedNode->loadNodeInfo(); if (!$selectedNode->isLeaf()) { throw new Exception("Cannot handle folders, please select a file!"); } $nodeExtension = strtolower(pathinfo($selectedNode->getPath(), PATHINFO_EXTENSION)); // Determine pad ID if ($nodeExtension == "pad") { $padID = file_get_contents($selectedNode->getUrl()); } else { // TRY TO LOAD PAD ID FROM NODE SHARED METADATA $metadata = $selectedNode->retrieveMetadata("etherpad", AJXP_METADATA_ALLUSERS, AJXP_METADATA_SCOPE_GLOBAL, false); if (isset($metadata["pad_id"])) { $padID = $metadata["pad_id"]; } else { $padID = AJXP_Utils::generateRandomString(); $selectedNode->setMetadata("etherpad", array("pad_id" => $padID), AJXP_METADATA_ALLUSERS, AJXP_METADATA_SCOPE_GLOBAL, false); } } require_once "etherpad-client/etherpad-lite-client.php"; $client = new EtherpadLiteClient($this->apiKey, $this->baseURL . "/api"); $loggedUser = AuthService::getLoggedUser(); $userName = $loggedUser->getId(); $userLabel = $loggedUser->mergedRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, $userName); $res = $client->createAuthorIfNotExistsFor($userName, $userLabel); $authorID = $res->authorID; $res2 = $client->createGroupIfNotExistsFor($loggedUser->getGroupPath()); $groupID = $res2->groupID; $fullId = $groupID . "\$" . $padID; if ($actionName == "etherpad_create") { $resP = $client->listPads($groupID); $currentContent = file_get_contents($selectedNode->getUrl()); if ($nodeExtension == "html" && strpos($currentContent, "<html>") === false) { $currentContent = "<html><head></head><body>{$currentContent}</body></html>"; } if (!in_array($fullId, $resP->padIDs)) { $client->createGroupPad($groupID, $padID, null); if ($nodeExtension == "html" && !empty($currentContent)) { $client->setHTML($fullId, $currentContent); } else { if ($nodeExtension != "pad") { $client->setText($fullId, $currentContent); } } } else { if ($nodeExtension != "pad") { // If someone is already connected, do not override. $existingAuthors = $client->listAuthorsOfPad($fullId); if (!count($existingAuthors->authorIDs)) { if ($nodeExtension == "html" && !empty($currentContent)) { $client->setHTML($fullId, $currentContent); } else { $client->setText($fullId, $currentContent); } } } } $res4 = $client->createSession($groupID, $authorID, time() + 14400); $sessionID = $res4->sessionID; setcookie('sessionID', $sessionID, null, "/"); $padID = $groupID . '$' . $padID; $data = array("url" => $this->baseURL . "/p/" . $padID, "padID" => $padID, "sessionID" => $sessionID); HTMLWriter::charsetHeader('application/json'); echo json_encode($data); } else { if ($actionName == "etherpad_save") { $padID = $httpVars["pad_id"]; if ($nodeExtension == "html" || $nodeExtension == "pad") { $res = $client->getHTML($padID); $content = $res->html; } else { $res = $client->getText($padID); $content = $res->text; } if ($nodeExtension == "pad") { // Create a new file and save the content in it. $origUrl = $selectedNode->getUrl(); $mess = ConfService::getMessages(); $dateStamp = date(" Y-m-d H:i", time()); $startUrl = preg_replace('"\\.pad$"', $dateStamp . '.html', $origUrl); $newNode = new AJXP_Node($startUrl); AJXP_Controller::applyHook("node.before_create", array($newNode, strlen($content))); file_put_contents($newNode->getUrl(), $content); AJXP_Controller::applyHook("node.change", array(null, $newNode)); } else { AJXP_Controller::applyHook("node.before_change", array($selectedNode, strlen($content))); file_put_contents($selectedNode->getUrl(), $content); clearstatcache(true, $selectedNode->getUrl()); $selectedNode->loadNodeInfo(true); AJXP_Controller::applyHook("node.change", array($selectedNode, $selectedNode)); } } else { if ($actionName == "etherpad_close") { // WE SHOULD DETECT IF THERE IS NOBODY CONNECTED ANYMORE, AND DELETE THE PAD. // BUT SEEMS LIKE THERE'S NO WAY TO PROPERLY REMOVE AN AUTHOR VIA API $sessionID = $httpVars["session_id"]; $client->deleteSession($sessionID); } else { if ($actionName == "etherpad_proxy_api") { if ($httpVars["api_action"] == "list_pads") { $res = $client->listPads($groupID); } else { if ($httpVars["api_action"] == "list_authors_for_pad") { $res = $client->listAuthorsOfPad($httpVars["pad_id"]); } } HTMLWriter::charsetHeader("application/json"); echo json_encode($res); } else { if ($actionName == "etherpad_get_content") { HTMLWriter::charsetHeader("text/plain"); echo $client->getText($httpVars["pad_id"])->text; } } } } } return null; }
public function switchAction($action, $httpVars, $filesVars) { if (!isset($this->actions[$action])) { return false; } $repository = ConfService::getRepository(); if (!$repository->detectStreamWrapper(true)) { return false; } $convert = $this->getFilteredOption("IMAGE_MAGICK_CONVERT"); if (empty($convert)) { return false; } $streamData = $repository->streamData; $destStreamURL = $streamData["protocol"] . "://" . $repository->getId(); $flyThreshold = 1024 * 1024 * intval($this->getFilteredOption("ONTHEFLY_THRESHOLD", $repository->getId())); $selection = new UserSelection($repository); $selection->initFromHttpVars($httpVars); if ($action == "imagick_data_proxy") { $this->extractAll = false; if (isset($httpVars["all"])) { $this->extractAll = true; } $file = $selection->getUniqueFile(); if (($size = filesize($destStreamURL . $file)) === false) { return false; } else { if ($size > $flyThreshold) { $this->useOnTheFly = true; } else { $this->useOnTheFly = false; } } if ($this->extractAll) { $node = new AJXP_Node($destStreamURL . $file); AJXP_Controller::applyHook("node.read", array($node)); } $cache = AJXP_Cache::getItem("imagick_" . ($this->extractAll ? "full" : "thumb"), $destStreamURL . $file, array($this, "generateJpegsCallback")); $cacheData = $cache->getData(); if (!$this->useOnTheFly && $this->extractAll) { // extract all on first view $ext = pathinfo($file, PATHINFO_EXTENSION); $prefix = str_replace(".{$ext}", "", $cache->getId()); $files = $this->listExtractedJpg($destStreamURL . $file, $prefix); header("Content-Type: application/json"); print json_encode($files); return false; } else { if ($this->extractAll) { // on the fly extract mode $ext = pathinfo($file, PATHINFO_EXTENSION); $prefix = str_replace(".{$ext}", "", $cache->getId()); $files = $this->listPreviewFiles($destStreamURL . $file, $prefix); header("Content-Type: application/json"); print json_encode($files); return false; } else { header("Content-Type: image/jpeg; name=\"" . basename($file) . "\""); header("Content-Length: " . strlen($cacheData)); header('Cache-Control: public'); header("Pragma:"); header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 10000) . " GMT"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5 * 24 * 3600) . " GMT"); print $cacheData; return false; } } } else { if ($action == "get_extracted_page" && isset($httpVars["file"])) { $file = (defined('AJXP_SHARED_CACHE_DIR') ? AJXP_SHARED_CACHE_DIR : AJXP_CACHE_DIR) . "/imagick_full/" . AJXP_Utils::decodeSecureMagic($httpVars["file"]); if (!is_file($file)) { $srcfile = AJXP_Utils::decodeSecureMagic($httpVars["src_file"]); if ($repository->hasContentFilter()) { $contentFilter = $repository->getContentFilter(); $srcfile = $contentFilter->filterExternalPath($srcfile); } $size = filesize($destStreamURL . "/" . $srcfile); if ($size > $flyThreshold) { $this->useOnTheFly = true; } else { $this->useOnTheFly = false; } if ($this->useOnTheFly) { $this->onTheFly = true; } $this->generateJpegsCallback($destStreamURL . $srcfile, $file); } if (!is_file($file)) { return false; } header("Content-Type: image/jpeg; name=\"" . basename($file) . "\""); header("Content-Length: " . filesize($file)); header('Cache-Control: public'); readfile($file); exit(1); } else { if ($action == "delete_imagick_data" && !$selection->isEmpty()) { /* $files = $this->listExtractedJpg(AJXP_CACHE_DIR."/".$httpVars["file"]); foreach ($files as $file) { if(is_file(AJXP_CACHE_DIR."/".$file["file"])) unlink(AJXP_CACHE_DIR."/".$file["file"]); } */ } } } }
public function switchAction($action, $httpVars, $fileVars) { $selection = new UserSelection(); $dir = $httpVars["dir"] or ""; $dir = AJXP_Utils::decodeSecureMagic($dir); if ($dir == "/") { $dir = ""; } $selection->initFromHttpVars($httpVars); if (!$selection->isEmpty()) { //$this->filterUserSelectionToHidden($selection->getFiles()); } $urlBase = "pydio://" . ConfService::getRepository()->getId(); $mess = ConfService::getMessages(); switch ($action) { case "monitor_compression": $percentFile = fsAccessWrapper::getRealFSReference($urlBase . $dir . "/.zip_operation_" . $httpVars["ope_id"]); $percent = 0; if (is_file($percentFile)) { $percent = intval(file_get_contents($percentFile)); } if ($percent < 100) { AJXP_XMLWriter::header(); AJXP_XMLWriter::triggerBgAction("monitor_compression", $httpVars, $mess["powerfs.1"] . " ({$percent}%)", true, 1); AJXP_XMLWriter::close(); } else { @unlink($percentFile); AJXP_XMLWriter::header(); if ($httpVars["on_end"] == "reload") { AJXP_XMLWriter::triggerBgAction("reload_node", array(), "powerfs.2", true, 2); } else { $archiveName = AJXP_Utils::sanitize($httpVars["archive_name"], AJXP_SANITIZE_FILENAME); $archiveName = str_replace("'", "\\'", $archiveName); $jsCode = "\n PydioApi.getClient().downloadSelection(null, \$('download_form'), 'postcompress_download', {ope_id:'" . $httpVars["ope_id"] . "',archive_name:'" . $archiveName . "'});\n "; AJXP_XMLWriter::triggerBgJsAction($jsCode, $mess["powerfs.3"], true); AJXP_XMLWriter::triggerBgAction("reload_node", array(), "powerfs.2", true, 2); } AJXP_XMLWriter::close(); } break; case "postcompress_download": $archive = AJXP_Utils::getAjxpTmpDir() . DIRECTORY_SEPARATOR . $httpVars["ope_id"] . "_" . AJXP_Utils::sanitize(AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]), AJXP_SANITIZE_FILENAME); $fsDriver = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("access"); if (is_file($archive)) { if (!$fsDriver->getFilteredOption("USE_XSENDFILE", ConfService::getRepository()) && !$fsDriver->getFilteredOption("USE_XACCELREDIRECT", ConfService::getRepository())) { register_shutdown_function("unlink", $archive); } $fsDriver->readFile($archive, "force-download", $httpVars["archive_name"], false, null, true); } else { echo "<script>alert('Cannot find archive! Is ZIP correctly installed?');</script>"; } break; case "compress": case "precompress": $archiveName = AJXP_Utils::sanitize(AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]), AJXP_SANITIZE_FILENAME); if (!ConfService::currentContextIsCommandLine() && ConfService::backgroundActionsSupported()) { $opeId = substr(md5(time()), 0, 10); $httpVars["ope_id"] = $opeId; AJXP_Controller::applyActionInBackground(ConfService::getRepository()->getId(), $action, $httpVars); AJXP_XMLWriter::header(); $bgParameters = array("dir" => SystemTextEncoding::toUTF8($dir), "archive_name" => SystemTextEncoding::toUTF8($archiveName), "on_end" => isset($httpVars["on_end"]) ? $httpVars["on_end"] : "reload", "ope_id" => $opeId); AJXP_XMLWriter::triggerBgAction("monitor_compression", $bgParameters, $mess["powerfs.1"] . " (0%)", true); AJXP_XMLWriter::close(); session_write_close(); exit; } $rootDir = fsAccessWrapper::getRealFSReference($urlBase) . $dir; $percentFile = $rootDir . "/.zip_operation_" . $httpVars["ope_id"]; $compressLocally = $action == "compress" ? true : false; // List all files $todo = array(); $args = array(); $replaceSearch = array($rootDir, "\\"); $replaceReplace = array("", "/"); foreach ($selection->getFiles() as $selectionFile) { $baseFile = $selectionFile; $args[] = escapeshellarg(substr($selectionFile, strlen($dir) + ($dir == "/" ? 0 : 1))); $selectionFile = fsAccessWrapper::getRealFSReference($urlBase . $selectionFile); $todo[] = ltrim(str_replace($replaceSearch, $replaceReplace, $selectionFile), "/"); if (is_dir($selectionFile)) { $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($selectionFile), RecursiveIteratorIterator::SELF_FIRST); foreach ($objects as $name => $object) { $todo[] = str_replace($replaceSearch, $replaceReplace, $name); } } if (trim($baseFile, "/") == "") { // ROOT IS SELECTED, FIX IT $args = array(escapeshellarg(basename($rootDir))); $rootDir = dirname($rootDir); break; } } $cmdSeparator = PHP_OS == "WIN32" || PHP_OS == "WINNT" || PHP_OS == "Windows" ? "&" : ";"; if (!$compressLocally) { $archiveName = AJXP_Utils::getAjxpTmpDir() . DIRECTORY_SEPARATOR . $httpVars["ope_id"] . "_" . $archiveName; } chdir($rootDir); $cmd = $this->getFilteredOption("ZIP_PATH") . " -r " . escapeshellarg($archiveName) . " " . implode(" ", $args); $fsDriver = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("access"); $c = $fsDriver->getConfigs(); if ((!isset($c["SHOW_HIDDEN_FILES"]) || $c["SHOW_HIDDEN_FILES"] == false) && stripos(PHP_OS, "win") === false) { $cmd .= " -x .\\*"; } $cmd .= " " . $cmdSeparator . " echo ZIP_FINISHED"; $proc = popen($cmd, "r"); $toks = array(); $handled = array(); $finishedEchoed = false; while (!feof($proc)) { set_time_limit(20); $results = fgets($proc, 256); if (strlen($results) == 0) { } else { $tok = strtok($results, "\n"); while ($tok !== false) { $toks[] = $tok; if ($tok == "ZIP_FINISHED") { $finishedEchoed = true; } else { $test = preg_match('/(\\w+): (.*) \\(([^\\(]+)\\) \\(([^\\(]+)\\)/', $tok, $matches); if ($test !== false) { $handled[] = $matches[2]; } } $tok = strtok("\n"); } if ($finishedEchoed) { $percent = 100; } else { $percent = min(round(count($handled) / count($todo) * 100), 100); } file_put_contents($percentFile, $percent); } // avoid a busy wait if ($percent < 100) { usleep(1); } } pclose($proc); file_put_contents($percentFile, 100); break; default: break; } }
function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } $selection = new UserSelection(); $dir = $httpVars["dir"] or ""; $dir = AJXP_Utils::securePath($dir); if ($dir == "/") { $dir = ""; } $selection->initFromHttpVars($httpVars); if (!$selection->isEmpty()) { //$this->filterUserSelectionToHidden($selection->getFiles()); } $urlBase = "ajxp.fs://" . ConfService::getRepository()->getId(); $mess = ConfService::getMessages(); switch ($action) { case "monitor_compression": $percentFile = fsAccessWrapper::getRealFSReference($urlBase . $dir . "/.zip_operation_" . $httpVars["ope_id"]); $percent = 0; if (is_file($percentFile)) { $percent = intval(file_get_contents($percentFile)); } if ($percent < 100) { AJXP_XMLWriter::header(); AJXP_XMLWriter::triggerBgAction("monitor_compression", $httpVars, $mess["powerfs.1"] . " ({$percent}%)", true, 1); AJXP_XMLWriter::close(); } else { @unlink($percentFile); AJXP_XMLWriter::header(); if ($httpVars["on_end"] == "reload") { AJXP_XMLWriter::triggerBgAction("reload_node", array(), "powerfs.2", true, 2); } else { $archiveName = $httpVars["archive_name"]; $jsCode = "\n \$('download_form').action = window.ajxpServerAccessPath;\n \$('download_form').secure_token.value = window.Connexion.SECURE_TOKEN;\n \$('download_form').select('input').each(function(input){\n if(input.name!='get_action' && input.name!='secure_token') input.remove();\n });\n \$('download_form').insert(new Element('input', {type:'hidden', name:'ope_id', value:'" . $httpVars["ope_id"] . "'}));\n \$('download_form').insert(new Element('input', {type:'hidden', name:'archive_name', value:'" . $archiveName . "'}));\n \$('download_form').insert(new Element('input', {type:'hidden', name:'get_action', value:'postcompress_download'}));\n \$('download_form').submit();\n "; AJXP_XMLWriter::triggerBgJsAction($jsCode, "powerfs.3", true); AJXP_XMLWriter::triggerBgAction("reload_node", array(), "powerfs.2", true, 2); } AJXP_XMLWriter::close(); } break; case "postcompress_download": $archive = AJXP_Utils::getAjxpTmpDir() . "/" . $httpVars["ope_id"] . "_" . $httpVars["archive_name"]; //$fsDriver = new fsAccessDriver("fake", ""); $fsDriver = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("access"); $fsDriver->readFile($archive, "force-download", $httpVars["archive_name"], false, null, true); break; case "compress": case "precompress": if (!ConfService::currentContextIsCommandLine() && ConfService::backgroundActionsSupported()) { $opeId = substr(md5(time()), 0, 10); $httpVars["ope_id"] = $opeId; AJXP_Controller::applyActionInBackground(ConfService::getRepository()->getId(), $action, $httpVars); AJXP_XMLWriter::header(); $bgParameters = array("dir" => $dir, "archive_name" => $httpVars["archive_name"], "on_end" => isset($httpVars["on_end"]) ? $httpVars["on_end"] : "reload", "ope_id" => $opeId); AJXP_XMLWriter::triggerBgAction("monitor_compression", $bgParameters, $mess["powerfs.1"] . " (0%)", true); AJXP_XMLWriter::close(); session_write_close(); exit; } $rootDir = fsAccessWrapper::getRealFSReference($urlBase) . $dir; $percentFile = $rootDir . "/.zip_operation_" . $httpVars["ope_id"]; $compressLocally = $action == "compress" ? true : false; // List all files $todo = array(); $args = array(); $replaceSearch = array($rootDir, "\\"); $replaceReplace = array("", "/"); foreach ($selection->getFiles() as $selectionFile) { $args[] = '"' . substr($selectionFile, strlen($dir) + ($dir == "/" ? 0 : 1)) . '"'; $selectionFile = fsAccessWrapper::getRealFSReference($urlBase . $selectionFile); $todo[] = ltrim(str_replace($replaceSearch, $replaceReplace, $selectionFile), "/"); if (is_dir($selectionFile)) { $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($selectionFile), RecursiveIteratorIterator::SELF_FIRST); foreach ($objects as $name => $object) { $todo[] = str_replace($replaceSearch, $replaceReplace, $name); } } } $cmdSeparator = PHP_OS == "WIN32" || PHP_OS == "WINNT" || PHP_OS == "Windows" ? "&" : ";"; $archiveName = $httpVars["archive_name"]; if (!$compressLocally) { $archiveName = AJXP_Utils::getAjxpTmpDir() . "/" . $httpVars["ope_id"] . "_" . $archiveName; } chdir($rootDir); $cmd = "zip -r \"" . $archiveName . "\" " . implode(" ", $args); $fsDriver = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("access"); $c = $fsDriver->getConfigs(); if (!isset($c["SHOW_HIDDEN_FILES"]) || $c["SHOW_HIDDEN_FILES"] == false) { $cmd .= " -x .\\*"; } $cmd .= " " . $cmdSeparator . " echo ZIP_FINISHED"; $proc = popen($cmd, "r"); $toks = array(); $handled = array(); $finishedEchoed = false; while (!feof($proc)) { set_time_limit(20); $results = fgets($proc, 256); if (strlen($results) == 0) { } else { $tok = strtok($results, "\n"); while ($tok !== false) { $toks[] = $tok; if ($tok == "ZIP_FINISHED") { $finishedEchoed = true; } else { $test = preg_match('/(\\w+): (.*) \\(([^\\(]+)\\) \\(([^\\(]+)\\)/', $tok, $matches); if ($test !== false) { $handled[] = $matches[2]; } } $tok = strtok("\n"); } if ($finishedEchoed) { $percent = 100; } else { $percent = min(round(count($handled) / count($todo) * 100), 100); } file_put_contents($percentFile, $percent); } // avoid a busy wait if ($percent < 100) { usleep(1); } } pclose($proc); file_put_contents($percentFile, 100); break; default: break; } }
/** * Main callback for all share- actions. * @param string $action * @param array $httpVars * @param array $fileVars * @return null * @throws Exception */ public function switchAction($action, $httpVars, $fileVars) { if (strpos($action, "sharelist") === false && !isset($this->accessDriver)) { throw new Exception("Cannot find access driver!"); } if (strpos($action, "sharelist") === false && $this->accessDriver->getId() == "access.demo") { $errorMessage = "This is a demo, all 'write' actions are disabled!"; if ($httpVars["sub_action"] == "delegate_repo") { return AJXP_XMLWriter::sendMessage(null, $errorMessage, false); } else { print $errorMessage; } return null; } switch ($action) { //------------------------------------ // SHARING FILE OR FOLDER //------------------------------------ case "share": $subAction = isset($httpVars["sub_action"]) ? $httpVars["sub_action"] : ""; // REST API COMPATIBILITY if (empty($subAction) && isset($httpVars["simple_share_type"])) { $subAction = "create_minisite"; if (!isset($httpVars["simple_right_read"]) && !isset($httpVars["simple_right_download"])) { $httpVars["simple_right_read"] = $httpVars["simple_right_download"] = "true"; } $httpVars["create_guest_user"] = "******"; if ($httpVars["simple_share_type"] == "private" && !isset($httpVars["guest_user_pass"])) { throw new Exception("Please provide a guest_user_pass for private link"); } } $userSelection = new UserSelection(ConfService::getRepository(), $httpVars); $ajxpNode = $userSelection->getUniqueNode(); if (!file_exists($ajxpNode->getUrl())) { throw new Exception("Cannot share a non-existing file: " . $ajxpNode->getUrl()); } $this->updateToMaxAllowedValue($httpVars, "downloadlimit", "FILE_MAX_DOWNLOAD"); $this->updateToMaxAllowedValue($httpVars, "expiration", "FILE_MAX_EXPIRATION"); $httpHash = null; $originalHash = null; if (!isset($httpVars["share_scope"]) || !in_array($httpVars["share_scope"], array("public", "private"))) { $httpVars["share_scope"] = "private"; } $shareScope = $httpVars["share_scope"]; $plainResult = 'unknown sub_action'; if ($subAction == "delegate_repo") { $auth = $this->getAuthorization("folder", "workspace"); if (!$auth) { $mess = ConfService::getMessages(); throw new Exception($mess["351"]); } $users = array(); $groups = array(); $this->getRightsManager()->createUsersFromParameters($httpVars, $users, $groups); $result = $this->createSharedRepository($httpVars, $isUpdate, $users, $groups); if (is_a($result, "Repository")) { if (!$isUpdate) { $this->getShareStore()->storeShare($this->repository->getId(), array("REPOSITORY" => $result->getUniqueId(), "OWNER_ID" => AuthService::getLoggedUser()->getId()), "repository"); } AJXP_Controller::applyHook($isUpdate ? "node.share.update" : "node.share.create", array('type' => 'repository', 'repository' => &$this->repository, 'accessDriver' => &$this->accessDriver, 'new_repository' => &$result)); if ($ajxpNode->hasMetaStore() && !$ajxpNode->isRoot()) { $this->getShareStore()->getMetaManager()->addShareInMeta($ajxpNode, "repository", $result->getUniqueId(), $shareScope == "public", $originalHash); } $plainResult = 200; } else { $plainResult = $result; } } else { if ($subAction == "create_minisite") { if (isset($httpVars["hash"]) && !empty($httpVars["hash"])) { $httpHash = $httpVars["hash"]; } $result = $this->createSharedMinisite($httpVars, $isUpdate); if (!is_array($result)) { $url = $result; } else { list($hash, $url) = $result; if ($ajxpNode->hasMetaStore() && !$ajxpNode->isRoot()) { $this->getShareStore()->getMetaManager()->addShareInMeta($ajxpNode, "minisite", $hash, $shareScope == "public", $httpHash != null && $hash != $httpHash ? $httpHash : null); } } $plainResult = $url; } else { if ($subAction == "share_node") { $httpVars["return_json"] = true; if (isset($httpVars["hash"]) && !empty($httpVars["hash"])) { $httpHash = $httpVars["hash"]; } $ajxpNode->loadNodeInfo(); $results = $this->shareNode($ajxpNode, $httpVars, $isUpdate); if (is_array($results) && $ajxpNode->hasMetaStore() && !$ajxpNode->isRoot()) { foreach ($results as $shareObject) { if ($shareObject instanceof \Pydio\OCS\Model\TargettedLink) { $hash = $shareObject->getHash(); $this->getShareStore()->getMetaManager()->addShareInMeta($ajxpNode, "ocs_remote", $hash, $shareScope == "public", $hash); } else { if (is_a($shareObject, "ShareLink")) { $hash = $shareObject->getHash(); $this->getShareStore()->getMetaManager()->addShareInMeta($ajxpNode, "minisite", $hash, $shareScope == "public", $httpHash != null && $hash != $httpHash ? $httpHash : null); } else { if (is_a($shareObject, "Repository")) { $this->getShareStore()->getMetaManager()->addShareInMeta($ajxpNode, "repository", $shareObject->getUniqueId(), $shareScope == "public", null); } } } } } } } } AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId())); /* * Send IM to inform that node has been shared or unshared. * Should be done only if share scope is public. */ if ($shareScope == "public") { $ajxpNode->loadNodeInfo(); $content = AJXP_XMLWriter::writeNodesDiff(["UPDATE" => array($ajxpNode->getPath() => $ajxpNode)]); AJXP_Controller::applyHook("msg.instant", array($content, $ajxpNode->getRepositoryId(), null, null, [$ajxpNode->getPath()])); } if (!isset($httpVars["return_json"])) { header("Content-Type: text/plain"); print $plainResult; } else { $compositeShare = $this->getShareStore()->getMetaManager()->getCompositeShareForNode($ajxpNode); header("Content-type:application/json"); if (!empty($compositeShare)) { echo json_encode($this->compositeShareToJson($compositeShare)); } else { echo json_encode(array()); } } // as the result can be quite small (e.g error code), make sure it's output in case of OB active. flush(); break; case "toggle_link_watch": $userSelection = new UserSelection($this->repository, $httpVars); $shareNode = $selectedNode = $userSelection->getUniqueNode(); $watchValue = $httpVars["set_watch"] == "true" ? true : false; $folder = false; if (isset($httpVars["element_type"]) && $httpVars["element_type"] == "folder") { $folder = true; $selectedNode = new AJXP_Node("pydio://" . AJXP_Utils::sanitize($httpVars["repository_id"], AJXP_SANITIZE_ALPHANUM) . "/"); } $shares = array(); $this->getShareStore()->getMetaManager()->getSharesFromMeta($shareNode, $shares, false); if (!count($shares)) { break; } if (isset($httpVars["element_id"]) && isset($shares[$httpVars["element_id"]])) { $elementId = $httpVars["element_id"]; } else { $sKeys = array_keys($shares); $elementId = $sKeys[0]; } if ($this->watcher !== false) { if (!$folder) { if ($watchValue) { $this->watcher->setWatchOnFolder($selectedNode, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_USERS_READ, array($elementId)); } else { $this->watcher->removeWatchFromFolder($selectedNode, AuthService::getLoggedUser()->getId(), true, $elementId); } } else { if ($watchValue) { $this->watcher->setWatchOnFolder($selectedNode, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_BOTH); } else { $this->watcher->removeWatchFromFolder($selectedNode, AuthService::getLoggedUser()->getId()); } } } $mess = ConfService::getMessages(); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["share_center.47"], null); AJXP_XMLWriter::close(); break; case "load_shared_element_data": $node = null; if (isset($httpVars["hash"]) && $httpVars["element_type"] == "file") { // LEGACY LINKS $parsedMeta = array($httpVars["hash"] => array("type" => "file")); $jsonData = array(); foreach ($parsedMeta as $shareId => $shareMeta) { $jsonData[] = $this->shareToJson($shareId, $shareMeta, $node); } header("Content-type:application/json"); echo json_encode($jsonData); } else { $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]); $node = new AJXP_Node($this->urlBase . $file); $loggedUser = AuthService::getLoggedUser(); if (isset($httpVars["owner"]) && $loggedUser->isAdmin() && $loggedUser->getGroupPath() == "/" && $loggedUser->getId() != AJXP_Utils::sanitize($httpVars["owner"], AJXP_SANITIZE_EMAILCHARS)) { // Impersonate the current user $node->setUser(AJXP_Utils::sanitize($httpVars["owner"], AJXP_SANITIZE_EMAILCHARS)); } if (!file_exists($node->getUrl())) { $mess = ConfService::getMessages(); throw new Exception(str_replace('%s', "Cannot find file " . $file, $mess["share_center.219"])); } if (isset($httpVars["tmp_repository_id"]) && AuthService::getLoggedUser()->isAdmin()) { $compositeShare = $this->getShareStore()->getMetaManager()->getCompositeShareForNode($node, true); } else { $compositeShare = $this->getShareStore()->getMetaManager()->getCompositeShareForNode($node); } if (empty($compositeShare)) { $mess = ConfService::getMessages(); throw new Exception(str_replace('%s', "Cannot find share for node " . $file, $mess["share_center.219"])); } header("Content-type:application/json"); $json = $this->compositeShareToJson($compositeShare); echo json_encode($json); } break; case "unshare": $mess = ConfService::getMessages(); $userSelection = new UserSelection($this->repository, $httpVars); if (isset($httpVars["hash"])) { $sanitizedHash = AJXP_Utils::sanitize($httpVars["hash"], AJXP_SANITIZE_ALPHANUM); $ajxpNode = $userSelection->isEmpty() ? null : $userSelection->getUniqueNode(); $result = $this->getShareStore()->deleteShare($httpVars["element_type"], $sanitizedHash, false, false, $ajxpNode); if ($result !== false) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["share_center.216"], null); AJXP_XMLWriter::close(); } } else { $userSelection = new UserSelection($this->repository, $httpVars); $ajxpNode = $userSelection->getUniqueNode(); $shares = array(); $this->getShareStore()->getMetaManager()->getSharesFromMeta($ajxpNode, $shares, false); if (isset($httpVars["element_id"]) && isset($shares[$httpVars["element_id"]])) { $elementId = $httpVars["element_id"]; if (isset($shares[$elementId])) { $shares = array($elementId => $shares[$elementId]); } } if (count($shares)) { $res = true; foreach ($shares as $shareId => $share) { $t = isset($share["type"]) ? $share["type"] : "file"; try { $result = $this->getShareStore()->deleteShare($t, $shareId, false, true); } catch (Exception $e) { if ($e->getMessage() == "repo-not-found") { $result = true; } else { throw $e; } } $this->getShareStore()->getMetaManager()->removeShareFromMeta($ajxpNode, $shareId); $res = $result && $res; } if ($res !== false) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["share_center.216"], null); AJXP_XMLWriter::close(); AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId())); if (isset($httpVars["share_scope"]) && $httpVars["share_scope"] == "public") { $ajxpNode->loadNodeInfo(); $content = AJXP_XMLWriter::writeNodesDiff(["UPDATE" => [$ajxpNode->getPath() => $ajxpNode]]); AJXP_Controller::applyHook("msg.instant", array($content, $ajxpNode->getRepositoryId(), null, null, [$ajxpNode->getPath()])); } } } } break; case "reset_counter": if (isset($httpVars["hash"])) { $userId = AuthService::getLoggedUser()->getId(); if (isset($httpVars["owner_id"]) && $httpVars["owner_id"] != $userId) { if (!AuthService::getLoggedUser()->isAdmin()) { throw new Exception("You are not allowed to access this resource"); } $userId = $httpVars["owner_id"]; } $this->getShareStore()->resetDownloadCounter($httpVars["hash"], $userId); } else { $userSelection = new UserSelection($this->repository, $httpVars); $ajxpNode = $userSelection->getUniqueNode(); $metadata = $this->getShareStore()->getMetaManager()->getNodeMeta($ajxpNode); if (!isset($metadata["shares"]) || !is_array($metadata["shares"])) { return null; } if (isset($httpVars["element_id"]) && isset($metadata["shares"][$httpVars["element_id"]])) { $this->getShareStore()->resetDownloadCounter($httpVars["element_id"], $httpVars["owner_id"]); } else { $keys = array_keys($metadata["shares"]); foreach ($keys as $key) { $this->getShareStore()->resetDownloadCounter($key, null); } } } break; case "update_shared_element_data": if (!in_array($httpVars["p_name"], array("counter", "tags"))) { return null; } $hash = AJXP_Utils::decodeSecureMagic($httpVars["element_id"]); $userSelection = new UserSelection($this->repository, $httpVars); $ajxpNode = $userSelection->getUniqueNode(); if ($this->getShareStore()->shareIsLegacy($hash)) { // Store in metadata $metadata = $this->getShareStore()->getMetaManager()->getNodeMeta($ajxpNode); if (isset($metadata["shares"][$httpVars["element_id"]])) { if (!is_array($metadata["shares"][$httpVars["element_id"]])) { $metadata["shares"][$httpVars["element_id"]] = array(); } $metadata["shares"][$httpVars["element_id"]][$httpVars["p_name"]] = $httpVars["p_value"]; // Set Private=true by default. $this->getShareStore()->getMetaManager()->setNodeMeta($ajxpNode, $metadata, true); } } else { // TODO: testUserCanEditShare ? $this->getShareStore()->updateShareProperty($hash, $httpVars["p_name"], $httpVars["p_value"]); } break; case "sharelist-load": $parentRepoId = isset($httpVars["parent_repository_id"]) ? $httpVars["parent_repository_id"] : ""; $userContext = $httpVars["user_context"]; $currentUser = true; if ($userContext == "global" && AuthService::getLoggedUser()->isAdmin()) { $currentUser = false; } else { if ($userContext == "user" && AuthService::getLoggedUser()->isAdmin() && !empty($httpVars["user_id"])) { $currentUser = AJXP_Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS); } } $nodes = $this->listSharesAsNodes("/data/repositories/{$parentRepoId}/shares", $currentUser, $parentRepoId); AJXP_XMLWriter::header(); if ($userContext == "current") { AJXP_XMLWriter::sendFilesListComponentConfig('<columns template_name="ajxp_user.shares"> <column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/> <column messageId="share_center.132" attributeName="shared_element_parent_repository_label" sortType="String"/> <column messageId="3" attributeName="share_type_readable" sortType="String"/> </columns>'); } else { AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchDisplayMode="list" switchGridMode="filelist" template_name="ajxp_conf.repositories"> <column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/> <column messageId="share_center.159" attributeName="owner" sortType="String"/> <column messageId="3" attributeName="share_type_readable" sortType="String"/> <column messageId="share_center.52" attributeName="share_data" sortType="String"/> </columns>'); } foreach ($nodes as $node) { AJXP_XMLWriter::renderAjxpNode($node); } AJXP_XMLWriter::close(); break; case "sharelist-clearExpired": $accessType = ConfService::getRepository()->getAccessType(); $currentUser = $accessType != "ajxp_conf" && $accessType != "ajxp_admin"; $count = $this->getShareStore()->clearExpiredFiles($currentUser); AJXP_XMLWriter::header(); if ($count) { AJXP_XMLWriter::sendMessage("Removed " . count($count) . " expired links", null); } else { AJXP_XMLWriter::sendMessage("Nothing to do", null); } AJXP_XMLWriter::close(); break; default: break; } return null; }
function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } $xmlBuffer = ""; foreach ($httpVars as $getName => $getValue) { ${$getName} = Utils::securePath(SystemTextEncoding::magicDequote($getValue)); } $selection = new UserSelection(); $selection->initFromHttpVars($httpVars); if (isset($dir) && $action != "upload") { $safeDir = $dir; $dir = SystemTextEncoding::fromUTF8($dir); } if (isset($dest)) { $dest = SystemTextEncoding::fromUTF8($dest); } $mess = ConfService::getMessages(); $recycleBinOption = $this->repository->getOption("RECYCLE_BIN"); // FILTER ACTION FOR DELETE if ($recycleBinOption != "" && $action == "delete" && $dir != "/" . $recycleBinOption) { $action = "move"; $dest = "/" . $recycleBinOption; $dest_node = "AJAXPLORER_RECYCLE_NODE"; } // FILTER ACTION FOR RESTORE if ($recycleBinOption != "" && $action == "restore" && $dir == "/" . $recycleBinOption) { $originalRep = RecycleBinManager::getFileOrigin($selection->getUniqueFile()); if ($originalRep != "") { $action = "move"; $dest = $originalRep; } } switch ($action) { //------------------------------------ // DOWNLOAD, IMAGE & MP3 PROXYS //------------------------------------ case "download": AJXP_Logger::logAction("Download", array("files" => $selection)); $zip = false; if ($selection->isUnique()) { if (is_dir($this->getPath() . "/" . $selection->getUniqueFile())) { $zip = true; $dir .= "/" . basename($selection->getUniqueFile()); } } else { $zip = true; } if ($zip) { // Make a temp zip and send it as download $this->downFile($this->makeName($selection->getFiles()), "force-download", "archive.zip"); } else { $this->downFile($this->makeName($selection->getUniqueFile()), "force-download", $selection->getUniqueFile()); } exit(0); break; case "image_proxy": $this->downFile($this->makeName($file), "image", $file); exit(0); break; case "mp3_proxy": $this->downFile($this->makeName($file), "mp3", $file); exit(0); break; //------------------------------------ // ONLINE EDIT //------------------------------------ //------------------------------------ // ONLINE EDIT //------------------------------------ case "edit": if (isset($save) && $save == 1) { AJXP_Logger::logAction("Online Edition", array("file" => SystemTextEncoding::fromUTF8($file))); $code = stripslashes($code); $code = str_replace("<", "<", $code); $this->SSHOperation->setRemoteContent($this->makeName($file), $code); echo $mess[115]; } else { $this->sendFile($this->SSHOperation->getRemoteContent($this->makeName($file)), "plain", $file); } exit(0); break; //------------------------------------ // COPY / MOVE //------------------------------------ //------------------------------------ // COPY / MOVE //------------------------------------ case "copy": case "move": if ($selection->isEmpty()) { $errorMessage = $mess[113]; break; } $result = ""; if ($action == "move") { $result = $this->SSHOperation->moveFile($this->makeName($selection->getFiles()), $this->makeName($dest)); } else { $result = $this->SSHOperation->copyFile($this->makeName($selection->getFiles()), $this->makeName($dest)); } $mess = ConfService::getMessages(); if (strlen($result)) { $errorMessage = $mess[114]; } else { foreach ($selection->getFiles() as $files) { $logMessage .= $mess[34] . " " . SystemTextEncoding::toUTF8(basename($file)) . " " . $mess[$action == "move" ? 74 : 73] . " " . SystemTextEncoding::toUTF8($dest) . "\n"; } AJXP_Logger::logAction($action == "move" ? "Move" : "Copy", array("files" => $selection, "destination" => $dest)); } $reload_current_node = true; if (isset($dest_node)) { $reload_dest_node = $dest_node; } $reload_file_list = true; break; //------------------------------------ // CHANGE FILE PERMISSION //------------------------------------ //------------------------------------ // CHANGE FILE PERMISSION //------------------------------------ case "chmod": $messtmp = ""; $changedFiles = array(); $value = "0" . decoct(octdec(ltrim($chmod_value, "0"))); // On error, the command will fail $result = $this->SSHOperation->chmodFile($this->makeName($selection->getFiles()), $chmod_value); $mess = ConfService::getMessages(); if (strlen($result)) { $errorMessage = $mess[114]; } else { $logMessage = "Successfully changed permission to " . $chmod_value . " for " . count($selection->getFiles()) . " files or folders"; AJXP_Logger::logAction("Chmod", array("dir" => $dir, "filesCount" => count($selection->getFiles()))); $reload_file_list = $dir; } break; //------------------------------------ // SUPPRIMER / DELETE //------------------------------------ //------------------------------------ // SUPPRIMER / DELETE //------------------------------------ case "delete": if ($selection->isEmpty()) { $errorMessage = $mess[113]; break; } $logMessages = array(); $result = $this->SSHOperation->deleteFile($this->makeName($selection->getFiles())); if (strlen($result)) { $mess = ConfService::getMessages(); $errorMessage = $mess[120]; } else { $mess = ConfService::getMessages(); foreach ($selection->getFiles() as $file) { $logMessages[] = "{$mess['34']} " . SystemTextEncoding::toUTF8($file) . " {$mess['44']}."; } $logMessage = join("\n", $logMessages); } AJXP_Logger::logAction("Delete", array("files" => $selection)); $reload_current_node = true; $reload_file_list = true; break; //------------------------------------ // RENOMMER / RENAME //------------------------------------ //------------------------------------ // RENOMMER / RENAME //------------------------------------ case "rename": $filename_new = $dir . "/" . $filename_new; $error = $this->SSHOperation->moveFile($this->makeName($file), $this->makeName($filename_new)); if ($error != null) { $errorMessage = $error; break; } $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new); $reload_current_node = true; $reload_file_list = basename($filename_new); AJXP_Logger::logAction("Rename", array("original" => $file, "new" => $filename_new)); break; //------------------------------------ // CREER UN REPERTOIRE / CREATE DIR //------------------------------------ //------------------------------------ // CREER UN REPERTOIRE / CREATE DIR //------------------------------------ case "mkdir": $messtmp = ""; $dirname = Utils::processFileName($dirname); $error = $this->SSHOperation->createRemoteDirectory($this->makeName($dir . "/" . $dirname)); if (isset($error)) { $errorMessage = $error; break; } $reload_file_list = $dirname; $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} "; if ($dir == "") { $messtmp .= "/"; } else { $messtmp .= SystemTextEncoding::toUTF8($dir); } $logMessage = $messtmp; $reload_current_node = true; AJXP_Logger::logAction("Create Dir", array("dir" => $dir . "/" . $dirname)); break; //------------------------------------ // CREER UN FICHIER / CREATE FILE //------------------------------------ //------------------------------------ // CREER UN FICHIER / CREATE FILE //------------------------------------ case "mkfile": $messtmp = ""; $filename = Utils::processFileName($filename); $error = $this->SSHOperation->setRemoteContent($this->makeName($dir . "/" . $filename), ""); if (isset($error)) { $errorMessage = $error; break; } $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} "; if ($dir == "") { $messtmp .= "/"; } else { $messtmp .= SystemTextEncoding::toUTF8($dir); } $logMessage = $messtmp; $reload_file_list = $filename; AJXP_Logger::logAction("Create File", array("file" => $dir . "/" . $filename)); break; //------------------------------------ // UPLOAD //------------------------------------ //------------------------------------ // UPLOAD //------------------------------------ case "upload": $fancyLoader = false; if (isset($fileVars["Filedata"])) { $fancyLoader = true; if ($dir != "") { $dir = "/" . base64_decode($dir); } } if ($dir != "") { $rep_source = "/{$dir}"; } else { $rep_source = ""; } $destination = $rep_source; $logMessage = ""; //$fancyLoader = false; foreach ($fileVars as $boxName => $boxData) { if ($boxName != "Filedata" && substr($boxName, 0, 9) != "userfile_") { continue; } if ($boxName == "Filedata") { $fancyLoader = true; } $err = Utils::parseFileDataErrors($boxData, $fancyLoader); if ($err != null) { $errorMessage = $err; break; } $userfile_name = $boxData["name"]; $userfile_name = Utils::processFileName($userfile_name); if (!$this->SSHOperation->uploadFile($boxData["tmp_name"], $this->makeName($destination . "/" . $userfile_name))) { $errorMessage = ($fancyLoader ? "411 " : "") . "{$mess['33']} " . $userfile_name; break; } $logMessage .= "{$mess['34']} " . SystemTextEncoding::toUTF8($userfile_name) . " {$mess['35']} {$dir}"; AJXP_Logger::logAction("Upload File", array("file" => $dir . "/" . $userfile_name)); } if ($fancyLoader) { if (isset($errorMessage)) { header('HTTP/1.0 ' . $errorMessage); die('Error ' . $errorMessage); } else { header('HTTP/1.0 200 OK'); die("200 OK"); } } else { print "<html><script language=\"javascript\">\n"; if (isset($errorMessage)) { print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext('" . str_replace("'", "\\'", $errorMessage) . "');"; } else { print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext();"; } print "</script></html>"; } exit; break; //------------------------------------ // Public URL //------------------------------------ //------------------------------------ // Public URL //------------------------------------ case "public_url": $file = SystemTextEncoding::fromUTF8($file); $url = $this->makePubliclet($file, $password, $expiration); header("Content-type:text/plain"); echo $url; exit(1); break; //------------------------------------ // XML LISTING //------------------------------------ //------------------------------------ // XML LISTING //------------------------------------ case "ls": if (!isset($dir) || $dir == "/") { $dir = ""; } $searchMode = $fileListMode = $completeMode = false; if (isset($mode)) { if ($mode == "search") { $searchMode = true; } else { if ($mode == "file_list") { $fileListMode = true; } else { if ($mode == "complete") { $completeMode = true; } } } } $nom_rep = $dir; AJXP_Exception::errorToXml($nom_rep); $result = $this->SSHOperation->listFilesIn($nom_rep); AJXP_XMLWriter::header(); foreach ($result as $file) { $attributes = ""; $fileName = SystemTextEncoding::toUTF8($file["name"]); $icon = Utils::mimetype($fileName, "image", $file["isDir"] == 1); if ($searchMode) { if ($file["isDir"] == 0) { $attributes = "is_file=\"true\" icon=\"" . SystemTextEncoding::toUTF8($icon) . "\""; } } else { if ($fileListMode) { $atts = array(); $atts[] = "is_file=\"" . (1 - $file["isDir"]) . "\""; $atts[] = "is_image=\"" . Utils::is_image($fileName) . "\""; $atts[] = "mimestring=\"" . Utils::mimetype($fileName, "type", $file["isDir"] == 1) . "\""; $atts[] = "ajxp_modiftime=\"" . $this->dateModif($file["time"]) . "\""; $atts[] = "filesize=\"" . Utils::roundSize($file["size"]) . "\""; $atts[] = "bytesize=\"" . $file["size"] . "\""; $atts[] = "filename=\"" . str_replace("&", "&", $dir . "/" . $fileName) . "\""; $atts[] = "icon=\"" . ($file["isDir"] == 1 ? "folder.png" : SystemTextEncoding::toUTF8($icon)) . "\""; $attributes = join(" ", $atts); } else { if ($file["isDir"] == 1) { $link = SERVER_ACCESS . "?dir=" . $dir . "/" . $fileName; $link = urlencode($link); $folderBaseName = str_replace("&", "&", $fileName); $folderFullName = "{$dir}/" . $folderBaseName; $parentFolderName = $dir; if (!$completeMode) { $icon = CLIENT_RESOURCES_FOLDER . "/images/foldericon.png"; $openicon = CLIENT_RESOURCES_FOLDER . "/images/openfoldericon.png"; if (preg_match("/\\.zip\$/", $file["name"])) { $icon = $openicon = CLIENT_RESOURCES_FOLDER . "/images/crystal/actions/16/accessories-archiver.png"; } $attributes = "icon=\"{$icon}\" openicon=\"{$openicon}\" filename=\"" . $folderFullName . "\" src=\"{$link}\""; } } } } if (strlen($attributes) > 0) { print "<tree text=\"" . str_replace("&", "&", SystemTextEncoding::toUTF8($this->SSHOperation->unescapeFileName($file["name"]))) . "\" {$attributes}>"; print "</tree>"; } } AJXP_XMLWriter::close(); exit(1); break; } if (isset($logMessage) || isset($errorMessage)) { $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false); } if (isset($requireAuth)) { $xmlBuffer .= AJXP_XMLWriter::requireAuth(false); } if (isset($reload_current_node) && $reload_current_node == "true") { $xmlBuffer .= AJXP_XMLWriter::reloadCurrentNode(false); } if (isset($reload_dest_node) && $reload_dest_node != "") { $xmlBuffer .= AJXP_XMLWriter::reloadNode($reload_dest_node, false); } if (isset($reload_file_list)) { $xmlBuffer .= AJXP_XMLWriter::reloadFileList($reload_file_list, false); } return $xmlBuffer; }
public function switchAction($action, $httpVars, $filesVars) { $repository = ConfService::getRepository(); if (!$repository->detectStreamWrapper(true)) { return false; } $selection = new UserSelection($repository, $httpVars); if ($selection->isEmpty()) { return; } $node = $selection->getUniqueNode(); $file = $node->getUrl(); AJXP_Controller::applyHook("node.read", array($node)); $wrapperClassName = AJXP_MetaStreamWrapper::actualRepositoryWrapperClass($repository->getId()); $mess = ConfService::getMessages(); switch ($action) { case "eml_get_xml_structure": $params = array('include_bodies' => false, 'decode_bodies' => false, 'decode_headers' => 'UTF-8'); $decoder = $this->getStructureDecoder($file, $wrapperClassName == "imapAccessWrapper"); $xml = $decoder->getXML($decoder->decode($params)); if (function_exists("imap_mime_header_decode")) { $doc = new DOMDocument(); $doc->loadXML($xml); $xPath = new DOMXPath($doc); $headers = $xPath->query("//headername"); $changes = false; foreach ($headers as $headerNode) { if ($headerNode->firstChild->nodeValue == "Subject") { $headerValueNode = $headerNode->nextSibling->nextSibling; $value = $headerValueNode->nodeValue; $elements = imap_mime_header_decode($value); $decoded = ""; foreach ($elements as $element) { $decoded .= $element->text; $charset = $element->charset; } if ($decoded != $value) { $value = SystemTextEncoding::changeCharset($charset, "UTF-8", $decoded); $node = $doc->createElement("headervalue", $value); $res = $headerNode->parentNode->replaceChild($node, $headerValueNode); $changes = true; } } } if ($changes) { $xml = $doc->saveXML(); } } print $xml; break; case "eml_get_bodies": require_once "Mail/mimeDecode.php"; $params = array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => false); if ($wrapperClassName == "imapAccessWrapper") { $cache = AJXP_Cache::getItem("eml_remote", $file, null, array("EmlParser", "computeCacheId")); $content = $cache->getData(); } else { $content = file_get_contents($file); } $decoder = new Mail_mimeDecode($content); $structure = $decoder->decode($params); $html = $this->_findPartByCType($structure, "text", "html"); $text = $this->_findPartByCType($structure, "text", "plain"); if ($html != false && isset($html->ctype_parameters) && isset($html->ctype_parameters["charset"])) { $charset = $html->ctype_parameters["charset"]; } if (isset($charset)) { header('Content-Type: text/xml; charset=' . $charset); header('Cache-Control: no-cache'); print '<?xml version="1.0" encoding="' . $charset . '"?>'; print '<email_body>'; } else { AJXP_XMLWriter::header("email_body"); } if ($html !== false) { print '<mimepart type="html"><![CDATA['; $text = $html->body; print $text; print "]]></mimepart>"; } if ($text !== false) { print '<mimepart type="plain"><![CDATA['; print $text->body; print "]]></mimepart>"; } AJXP_XMLWriter::close("email_body"); break; case "eml_dl_attachment": $attachId = $httpVars["attachment_id"]; if (!isset($attachId)) { break; } require_once "Mail/mimeDecode.php"; $params = array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => false); if ($wrapperClassName == "imapAccessWrapper") { $cache = AJXP_Cache::getItem("eml_remote", $file, null, array("EmlParser", "computeCacheId")); $content = $cache->getData(); } else { $content = file_get_contents($file); } $decoder = new Mail_mimeDecode($content); $structure = $decoder->decode($params); $part = $this->_findAttachmentById($structure, $attachId); if ($part !== false) { $fake = new fsAccessDriver("fake", ""); $fake->readFile($part->body, "file", $part->d_parameters['filename'], true); exit; } else { //var_dump($structure); } break; case "eml_cp_attachment": $attachId = $httpVars["attachment_id"]; $destRep = AJXP_Utils::decodeSecureMagic($httpVars["destination"]); if (!isset($attachId)) { AJXP_XMLWriter::sendMessage(null, "Wrong Parameters"); break; } require_once "Mail/mimeDecode.php"; $params = array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => false); if ($wrapperClassName == "imapAccessWrapper") { $cache = AJXP_Cache::getItem("eml_remote", $file, null, array("EmlParser", "computeCacheId")); $content = $cache->getData(); } else { $content = file_get_contents($file); } $decoder = new Mail_mimeDecode($content); $structure = $decoder->decode($params); $part = $this->_findAttachmentById($structure, $attachId); AJXP_XMLWriter::header(); if ($part !== false) { $destStreamURL = $selection->currentBaseUrl(); if (isset($httpVars["dest_repository_id"])) { $destRepoId = $httpVars["dest_repository_id"]; if (AuthService::usersEnabled()) { $loggedUser = AuthService::getLoggedUser(); if (!$loggedUser->canWrite($destRepoId)) { throw new Exception($mess[364]); } } $destRepoObject = ConfService::getRepositoryById($destRepoId); $destRepoObject->detectStreamWrapper(true); $destStreamURL = "pydio://{$destRepoId}"; } $destFile = $destStreamURL . $destRep . "/" . $part->d_parameters['filename']; $fp = fopen($destFile, "w"); if ($fp !== false) { fwrite($fp, $part->body, strlen($part->body)); fclose($fp); AJXP_XMLWriter::sendMessage(sprintf($mess["editor.eml.7"], $part->d_parameters["filename"], $destRep), NULL); } else { AJXP_XMLWriter::sendMessage(null, $mess["editor.eml.8"]); } } else { AJXP_XMLWriter::sendMessage(null, $mess["editor.eml.9"]); } AJXP_XMLWriter::close(); break; default: break; } }
public function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } parent::accessPreprocess($action, $httpVars, $fileVars); $selection = new UserSelection(); $dir = $httpVars["dir"] or ""; if ($this->wrapperClassName == "fsAccessWrapper") { $dir = fsAccessWrapper::patchPathForBaseDir($dir); } $dir = AJXP_Utils::securePath($dir); if ($action != "upload") { $dir = AJXP_Utils::decodeSecureMagic($dir); } $selection->initFromHttpVars($httpVars); if (!$selection->isEmpty()) { $this->filterUserSelectionToHidden($selection->getFiles()); } $mess = ConfService::getMessages(); $newArgs = RecycleBinManager::filterActions($action, $selection, $dir, $httpVars); if (isset($newArgs["action"])) { $action = $newArgs["action"]; } if (isset($newArgs["dest"])) { $httpVars["dest"] = SystemTextEncoding::toUTF8($newArgs["dest"]); } //Re-encode! // FILTER DIR PAGINATION ANCHOR $page = null; if (isset($dir) && strstr($dir, "%23") !== false) { $parts = explode("%23", $dir); $dir = $parts[0]; $page = $parts[1]; } $pendingSelection = ""; $logMessage = null; $reloadContextNode = false; switch ($action) { //------------------------------------ // DOWNLOAD //------------------------------------ case "download": $this->logInfo("Download", array("files" => $this->addSlugToPath($selection))); @set_error_handler(array("HTMLWriter", "javascriptErrorHandler"), E_ALL & ~E_NOTICE); @register_shutdown_function("restore_error_handler"); $zip = false; if ($selection->isUnique()) { if (is_dir($this->urlBase . $selection->getUniqueFile())) { $zip = true; $base = basename($selection->getUniqueFile()); $uniqDir = dirname($selection->getUniqueFile()); if (!empty($uniqDir) && $uniqDir != "/") { $dir = dirname($selection->getUniqueFile()); } } else { if (!file_exists($this->urlBase . $selection->getUniqueFile())) { throw new Exception("Cannot find file!"); } } $node = $selection->getUniqueNode($this); } else { $zip = true; } if ($zip) { // Make a temp zip and send it as download $loggedUser = AuthService::getLoggedUser(); $file = AJXP_Utils::getAjxpTmpDir() . "/" . ($loggedUser ? $loggedUser->getId() : "shared") . "_" . time() . "tmpDownload.zip"; $zipFile = $this->makeZip($selection->getFiles(), $file, empty($dir) ? "/" : $dir); if (!$zipFile) { throw new AJXP_Exception("Error while compressing"); } if (!$this->getFilteredOption("USE_XSENDFILE", $this->repository->getId()) && !$this->getFilteredOption("USE_XACCELREDIRECT", $this->repository->getId())) { register_shutdown_function("unlink", $file); } $localName = ($base == "" ? "Files" : $base) . ".zip"; if (isset($httpVars["archive_name"])) { $localName = AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]); } $this->readFile($file, "force-download", $localName, false, false, true); } else { $localName = ""; AJXP_Controller::applyHook("dl.localname", array($this->urlBase . $selection->getUniqueFile(), &$localName, $this->wrapperClassName)); $this->readFile($this->urlBase . $selection->getUniqueFile(), "force-download", $localName); } if (isset($node)) { AJXP_Controller::applyHook("node.read", array(&$node)); } break; case "prepare_chunk_dl": $chunkCount = intval($httpVars["chunk_count"]); $fileId = $this->urlBase . $selection->getUniqueFile(); $sessionKey = "chunk_file_" . md5($fileId . time()); $totalSize = $this->filesystemFileSize($fileId); $chunkSize = intval($totalSize / $chunkCount); $realFile = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $fileId, true); $chunkData = array("localname" => basename($fileId), "chunk_count" => $chunkCount, "chunk_size" => $chunkSize, "total_size" => $totalSize, "file_id" => $sessionKey); $_SESSION[$sessionKey] = array_merge($chunkData, array("file" => $realFile)); HTMLWriter::charsetHeader("application/json"); print json_encode($chunkData); $node = $selection->getUniqueNode($this); AJXP_Controller::applyHook("node.read", array(&$node)); break; case "download_chunk": $chunkIndex = intval($httpVars["chunk_index"]); $chunkKey = $httpVars["file_id"]; $sessData = $_SESSION[$chunkKey]; $realFile = $sessData["file"]; $chunkSize = $sessData["chunk_size"]; $offset = $chunkSize * $chunkIndex; if ($chunkIndex == $sessData["chunk_count"] - 1) { // Compute the last chunk real length $chunkSize = $sessData["total_size"] - $chunkSize * ($sessData["chunk_count"] - 1); if (call_user_func(array($this->wrapperClassName, "isRemote"))) { register_shutdown_function("unlink", $realFile); } } $this->readFile($realFile, "force-download", $sessData["localname"] . "." . sprintf("%03d", $chunkIndex + 1), false, false, true, $offset, $chunkSize); break; case "compress": // Make a temp zip and send it as download $loggedUser = AuthService::getLoggedUser(); if (isset($httpVars["archive_name"])) { $localName = AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]); $this->filterUserSelectionToHidden(array($localName)); } else { $localName = (basename($dir) == "" ? "Files" : basename($dir)) . ".zip"; } $file = AJXP_Utils::getAjxpTmpDir() . "/" . ($loggedUser ? $loggedUser->getId() : "shared") . "_" . time() . "tmpCompression.zip"; if (isset($httpVars["compress_flat"])) { $baseDir = "__AJXP_ZIP_FLAT__/"; } else { $baseDir = $dir; } $zipFile = $this->makeZip($selection->getFiles(), $file, $baseDir); if (!$zipFile) { throw new AJXP_Exception("Error while compressing file {$localName}"); } register_shutdown_function("unlink", $file); $tmpFNAME = $this->urlBase . $dir . "/" . str_replace(".zip", ".tmp", $localName); copy($file, $tmpFNAME); try { AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($tmpFNAME), filesize($tmpFNAME))); } catch (Exception $e) { @unlink($tmpFNAME); throw $e; } @rename($tmpFNAME, $this->urlBase . $dir . "/" . $localName); AJXP_Controller::applyHook("node.change", array(null, new AJXP_Node($this->urlBase . $dir . "/" . $localName), false)); //$reloadContextNode = true; //$pendingSelection = $localName; $newNode = new AJXP_Node($this->urlBase . $dir . "/" . $localName); if (!isset($nodesDiffs)) { $nodesDiffs = $this->getNodesDiffArray(); } $nodesDiffs["ADD"][] = $newNode; break; case "stat": clearstatcache(); header("Content-type:application/json"); if ($selection->isUnique()) { $stat = @stat($this->urlBase . $selection->getUniqueFile()); if (!$stat) { print '{}'; } else { print json_encode($stat); } } else { $files = $selection->getFiles(); print '{'; foreach ($files as $index => $path) { $stat = @stat($this->urlBase . $path); if (!$stat) { $stat = '{}'; } else { $stat = json_encode($stat); } print json_encode($path) . ':' . $stat . ($index < count($files) - 1 ? "," : ""); } print '}'; } break; //------------------------------------ // ONLINE EDIT //------------------------------------ //------------------------------------ // ONLINE EDIT //------------------------------------ case "get_content": $dlFile = $this->urlBase . $selection->getUniqueFile(); $this->logInfo("Get_content", array("files" => $this->addSlugToPath($selection))); if (AJXP_Utils::getStreamingMimeType(basename($dlFile)) !== false) { $this->readFile($this->urlBase . $selection->getUniqueFile(), "stream_content"); } else { $this->readFile($this->urlBase . $selection->getUniqueFile(), "plain"); } $node = $selection->getUniqueNode($this); AJXP_Controller::applyHook("node.read", array(&$node)); break; case "put_content": if (!isset($httpVars["content"])) { break; } // Load "code" variable directly from POST array, do not "securePath" or "sanitize"... $code = $httpVars["content"]; $file = $selection->getUniqueFile(); $this->logInfo("Online Edition", array("file" => $this->addSlugToPath($file))); if (isset($httpVars["encode"]) && $httpVars["encode"] == "base64") { $code = base64_decode($code); } else { $code = str_replace("<", "<", SystemTextEncoding::magicDequote($code)); } $fileName = $this->urlBase . $file; $currentNode = new AJXP_Node($fileName); try { AJXP_Controller::applyHook("node.before_change", array(&$currentNode, strlen($code))); } catch (Exception $e) { header("Content-Type:text/plain"); print $e->getMessage(); return; } if (!is_file($fileName) || !$this->isWriteable($fileName, "file")) { header("Content-Type:text/plain"); print !$this->isWriteable($fileName, "file") ? "1001" : "1002"; return; } $fp = fopen($fileName, "w"); fputs($fp, $code); fclose($fp); clearstatcache(true, $fileName); AJXP_Controller::applyHook("node.change", array($currentNode, $currentNode, false)); header("Content-Type:text/plain"); print $mess[115]; break; //------------------------------------ // COPY / MOVE //------------------------------------ //------------------------------------ // COPY / MOVE //------------------------------------ case "copy": case "move": //throw new AJXP_Exception("", 113); if ($selection->isEmpty()) { throw new AJXP_Exception("", 113); } $loggedUser = AuthService::getLoggedUser(); if ($loggedUser != null && !$loggedUser->canWrite(ConfService::getCurrentRepositoryId())) { throw new AJXP_Exception("You are not allowed to write", 207); } $success = $error = array(); $dest = AJXP_Utils::decodeSecureMagic($httpVars["dest"]); $this->filterUserSelectionToHidden(array($httpVars["dest"])); if ($selection->inZip()) { // Set action to copy anycase (cannot move from the zip). $action = "copy"; $this->extractArchive($dest, $selection, $error, $success); } else { $move = $action == "move" ? true : false; if ($move && isset($httpVars["force_copy_delete"])) { $move = false; } $this->copyOrMove($dest, $selection->getFiles(), $error, $success, $move); } if (count($error)) { throw new AJXP_Exception(SystemTextEncoding::toUTF8(join("\n", $error))); } else { if (isset($httpVars["force_copy_delete"])) { $errorMessage = $this->delete($selection->getFiles(), $logMessages); if ($errorMessage) { throw new AJXP_Exception(SystemTextEncoding::toUTF8($errorMessage)); } $this->logInfo("Copy/Delete", array("files" => $this->addSlugToPath($selection), "destination" => $this->addSlugToPath($dest))); } else { $this->logInfo($action == "move" ? "Move" : "Copy", array("files" => $this->addSlugToPath($selection), "destination" => $this->addSlugToPath($dest))); } $logMessage = join("\n", $success); } if (!isset($nodesDiffs)) { $nodesDiffs = $this->getNodesDiffArray(); } // Assume new nodes are correctly created $selectedItems = $selection->getFiles(); foreach ($selectedItems as $selectedPath) { $newPath = $this->urlBase . $dest . "/" . basename($selectedPath); $newNode = new AJXP_Node($newPath); $nodesDiffs["ADD"][] = $newNode; if ($action == "move") { $nodesDiffs["REMOVE"][] = $selectedPath; } } if (!(RecycleBinManager::getRelativeRecycle() == $dest && $this->getFilteredOption("HIDE_RECYCLE", $this->repository->getId()) == true)) { //$reloadDataNode = $dest; } break; //------------------------------------ // DELETE //------------------------------------ //------------------------------------ // DELETE //------------------------------------ case "delete": if ($selection->isEmpty()) { throw new AJXP_Exception("", 113); } $logMessages = array(); $errorMessage = $this->delete($selection->getFiles(), $logMessages); if (count($logMessages)) { $logMessage = join("\n", $logMessages); } if ($errorMessage) { throw new AJXP_Exception(SystemTextEncoding::toUTF8($errorMessage)); } $this->logInfo("Delete", array("files" => $this->addSlugToPath($selection))); if (!isset($nodesDiffs)) { $nodesDiffs = $this->getNodesDiffArray(); } $nodesDiffs["REMOVE"] = array_merge($nodesDiffs["REMOVE"], $selection->getFiles()); break; case "purge": $hardPurgeTime = intval($this->repository->getOption("PURGE_AFTER")) * 3600 * 24; $softPurgeTime = intval($this->repository->getOption("PURGE_AFTER_SOFT")) * 3600 * 24; $shareCenter = AJXP_PluginsService::findPluginById('action.share'); if (!($shareCenter && $shareCenter->isEnabled())) { //action.share is disabled, don't look at the softPurgeTime $softPurgeTime = 0; } if ($hardPurgeTime > 0 || $softPurgeTime > 0) { $this->recursivePurge($this->urlBase, $hardPurgeTime, $softPurgeTime); } break; //------------------------------------ // RENAME //------------------------------------ //------------------------------------ // RENAME //------------------------------------ case "rename": $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]); $filename_new = AJXP_Utils::decodeSecureMagic($httpVars["filename_new"]); $dest = null; if (isset($httpVars["dest"])) { $dest = AJXP_Utils::decodeSecureMagic($httpVars["dest"]); $filename_new = ""; } $this->filterUserSelectionToHidden(array($filename_new)); $this->rename($file, $filename_new, $dest); $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new); //$reloadContextNode = true; //$pendingSelection = $filename_new; if (!isset($nodesDiffs)) { $nodesDiffs = $this->getNodesDiffArray(); } if ($dest == null) { $dest = AJXP_Utils::safeDirname($file); } $nodesDiffs["UPDATE"][$file] = new AJXP_Node($this->urlBase . $dest . "/" . $filename_new); $this->logInfo("Rename", array("original" => $this->addSlugToPath($file), "new" => $filename_new)); break; //------------------------------------ // CREER UN REPERTOIRE / CREATE DIR //------------------------------------ //------------------------------------ // CREER UN REPERTOIRE / CREATE DIR //------------------------------------ case "mkdir": $messtmp = ""; if (!isset($httpVars["dirname"])) { $uniq = $selection->getUniqueFile(); $dir = AJXP_Utils::safeDirname($uniq); $dirname = AJXP_Utils::safeBasename($uniq); } else { $dirname = AJXP_Utils::decodeSecureMagic($httpVars["dirname"], AJXP_SANITIZE_FILENAME); } $dirname = substr($dirname, 0, ConfService::getCoreConf("NODENAME_MAX_LENGTH")); $this->filterUserSelectionToHidden(array($dirname)); AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($dir . "/" . $dirname), -2)); $error = $this->mkDir($dir, $dirname, isset($httpVars["ignore_exists"]) ? true : false); if (isset($error)) { throw new AJXP_Exception($error); } $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} "; if ($dir == "") { $messtmp .= "/"; } else { $messtmp .= SystemTextEncoding::toUTF8($dir); } $logMessage = $messtmp; //$pendingSelection = $dirname; //$reloadContextNode = true; $newNode = new AJXP_Node($this->urlBase . $dir . "/" . $dirname); if (!isset($nodesDiffs)) { $nodesDiffs = $this->getNodesDiffArray(); } array_push($nodesDiffs["ADD"], $newNode); $this->logInfo("Create Dir", array("dir" => $this->addSlugToPath($dir) . "/" . $dirname)); break; //------------------------------------ // CREER UN FICHIER / CREATE FILE //------------------------------------ //------------------------------------ // CREER UN FICHIER / CREATE FILE //------------------------------------ case "mkfile": $messtmp = ""; if (empty($httpVars["filename"]) && isset($httpVars["node"])) { $filename = AJXP_Utils::decodeSecureMagic($httpVars["node"], AJXP_SANITIZE_FILENAME); } else { $filename = AJXP_Utils::decodeSecureMagic($httpVars["filename"], AJXP_SANITIZE_FILENAME); } $filename = substr($filename, 0, ConfService::getCoreConf("NODENAME_MAX_LENGTH")); $this->filterUserSelectionToHidden(array($filename)); $content = ""; if (isset($httpVars["content"])) { $content = $httpVars["content"]; } $error = $this->createEmptyFile($dir, $filename, $content); if (isset($error)) { throw new AJXP_Exception($error); } $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} "; if ($dir == "") { $messtmp .= "/"; } else { $messtmp .= SystemTextEncoding::toUTF8($dir); } $logMessage = $messtmp; //$reloadContextNode = true; //$pendingSelection = $dir."/".$filename; $this->logInfo("Create File", array("file" => $this->addSlugToPath($dir) . "/" . $filename)); $newNode = new AJXP_Node($this->urlBase . $dir . "/" . $filename); if (!isset($nodesDiffs)) { $nodesDiffs = $this->getNodesDiffArray(); } array_push($nodesDiffs["ADD"], $newNode); break; //------------------------------------ // CHANGE FILE PERMISSION //------------------------------------ //------------------------------------ // CHANGE FILE PERMISSION //------------------------------------ case "chmod": $files = $selection->getFiles(); $changedFiles = array(); $chmod_value = $httpVars["chmod_value"]; $recursive = $httpVars["recursive"]; $recur_apply_to = $httpVars["recur_apply_to"]; foreach ($files as $fileName) { $this->chmod($fileName, $chmod_value, $recursive == "on", $recursive == "on" ? $recur_apply_to : "both", $changedFiles); } $logMessage = "Successfully changed permission to " . $chmod_value . " for " . count($changedFiles) . " files or folders"; $this->logInfo("Chmod", array("dir" => $this->addSlugToPath($dir), "filesCount" => count($changedFiles))); if (!isset($nodesDiffs)) { $nodesDiffs = $this->getNodesDiffArray(); } $nodesDiffs["UPDATE"] = array_merge($nodesDiffs["UPDATE"], $selection->buildNodes($this)); break; //------------------------------------ // UPLOAD //------------------------------------ //------------------------------------ // UPLOAD //------------------------------------ case "upload": $repoData = array('base_url' => $this->urlBase, 'wrapper_name' => $this->wrapperClassName, 'chmod' => $this->repository->getOption('CHMOD_VALUE'), 'recycle' => $this->repository->getOption('RECYCLE_BIN')); $this->logDebug("Upload Files Data", $fileVars); $destination = $this->urlBase . AJXP_Utils::decodeSecureMagic($dir); $this->logDebug("Upload inside", array("destination" => $this->addSlugToPath($destination))); if (!$this->isWriteable($destination)) { $errorCode = 412; $errorMessage = "{$mess['38']} " . SystemTextEncoding::toUTF8($dir) . " {$mess['99']}."; $this->logDebug("Upload error 412", array("destination" => $this->addSlugToPath($destination))); return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage)); } foreach ($fileVars as $boxName => $boxData) { if (substr($boxName, 0, 9) != "userfile_") { continue; } $err = AJXP_Utils::parseFileDataErrors($boxData); if ($err != null) { $errorCode = $err[0]; $errorMessage = $err[1]; break; } $userfile_name = $boxData["name"]; try { $this->filterUserSelectionToHidden(array($userfile_name)); } catch (Exception $e) { return array("ERROR" => array("CODE" => 411, "MESSAGE" => "Forbidden")); } $userfile_name = AJXP_Utils::sanitize(SystemTextEncoding::fromPostedFileName($userfile_name), AJXP_SANITIZE_FILENAME); if (isset($httpVars["urlencoded_filename"])) { $userfile_name = AJXP_Utils::sanitize(SystemTextEncoding::fromUTF8(urldecode($httpVars["urlencoded_filename"])), AJXP_SANITIZE_FILENAME); } $this->logDebug("User filename " . $userfile_name); $userfile_name = substr($userfile_name, 0, ConfService::getCoreConf("NODENAME_MAX_LENGTH")); if (isset($httpVars["auto_rename"])) { $userfile_name = self::autoRenameForDest($destination, $userfile_name); } $already_existed = false; try { if (file_exists($destination . "/" . $userfile_name)) { $already_existed = true; AJXP_Controller::applyHook("node.before_change", array(new AJXP_Node($destination . "/" . $userfile_name), $boxData["size"])); } else { AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($destination . "/" . $userfile_name), $boxData["size"])); } AJXP_Controller::applyHook("node.before_change", array(new AJXP_Node($destination))); } catch (Exception $e) { $errorCode = 507; $errorMessage = $e->getMessage(); break; } if (isset($boxData["input_upload"])) { try { $this->logDebug("Begining reading INPUT stream"); $input = fopen("php://input", "r"); $output = fopen("{$destination}/" . $userfile_name, "w"); $sizeRead = 0; while ($sizeRead < intval($boxData["size"])) { $chunk = fread($input, 4096); $sizeRead += strlen($chunk); fwrite($output, $chunk, strlen($chunk)); } fclose($input); fclose($output); $this->logDebug("End reading INPUT stream"); } catch (Exception $e) { $errorCode = 411; $errorMessage = $e->getMessage(); break; } } else { $result = @move_uploaded_file($boxData["tmp_name"], "{$destination}/" . $userfile_name); if (!$result) { $realPath = call_user_func(array($this->wrapperClassName, "getRealFSReference"), "{$destination}/" . $userfile_name); $result = move_uploaded_file($boxData["tmp_name"], $realPath); } if (!$result) { $errorCode = 411; $errorMessage = "{$mess['33']} " . $userfile_name; break; } } if (isset($httpVars["appendto_urlencoded_part"])) { $appendTo = AJXP_Utils::sanitize(SystemTextEncoding::fromUTF8(urldecode($httpVars["appendto_urlencoded_part"])), AJXP_SANITIZE_FILENAME); if (file_exists($destination . "/" . $appendTo)) { $this->logDebug("Should copy stream from {$userfile_name} to {$appendTo}"); $partO = fopen($destination . "/" . $userfile_name, "r"); $appendF = fopen($destination . "/" . $appendTo, "a+"); while (!feof($partO)) { $buf = fread($partO, 1024); fwrite($appendF, $buf, strlen($buf)); } fclose($partO); fclose($appendF); $this->logDebug("Done, closing streams!"); } @unlink($destination . "/" . $userfile_name); $userfile_name = $appendTo; } $this->changeMode($destination . "/" . $userfile_name, $repoData); $createdNode = new AJXP_Node($destination . "/" . $userfile_name); //AJXP_Controller::applyHook("node.change", array(null, $createdNode, false)); $logMessage .= "{$mess['34']} " . SystemTextEncoding::toUTF8($userfile_name) . " {$mess['35']} {$dir}"; $this->logInfo("Upload File", array("file" => $this->addSlugToPath(SystemTextEncoding::fromUTF8($dir)) . "/" . $userfile_name)); } if (isset($errorMessage)) { $this->logDebug("Return error {$errorCode} {$errorMessage}"); return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage)); } else { $this->logDebug("Return success"); if ($already_existed) { return array("SUCCESS" => true, "UPDATED_NODE" => $createdNode); } else { return array("SUCCESS" => true, "CREATED_NODE" => $createdNode); } } return; break; case "lsync": if (!ConfService::currentContextIsCommandLine()) { die("This command must be accessed via CLI only."); } $fromNode = null; $toNode = null; $copyOrMove = false; if (isset($httpVars["from"])) { $fromNode = new AJXP_Node($this->urlBase . AJXP_Utils::decodeSecureMagic($httpVars["from"])); } if (isset($httpVars["to"])) { $toNode = new AJXP_Node($this->urlBase . AJXP_Utils::decodeSecureMagic($httpVars["to"])); } if (isset($httpVars["copy"]) && $httpVars["copy"] == "true") { $copyOrMove = true; } AJXP_Controller::applyHook("node.change", array($fromNode, $toNode, $copyOrMove)); break; //------------------------------------ // XML LISTING //------------------------------------ //------------------------------------ // XML LISTING //------------------------------------ case "ls": if (!isset($dir) || $dir == "/") { $dir = ""; } $lsOptions = $this->parseLsOptions(isset($httpVars["options"]) ? $httpVars["options"] : "a"); $startTime = microtime(); if (isset($httpVars["file"])) { $uniqueFile = AJXP_Utils::decodeSecureMagic($httpVars["file"]); } $dir = AJXP_Utils::securePath($dir); $path = $this->urlBase . ($dir != "" ? ($dir[0] == "/" ? "" : "/") . $dir : ""); $nonPatchedPath = $path; if ($this->wrapperClassName == "fsAccessWrapper") { $nonPatchedPath = fsAccessWrapper::unPatchPathForBaseDir($path); } if ($this->getFilteredOption("REMOTE_SORTING")) { $orderDirection = isset($httpVars["order_direction"]) ? strtolower($httpVars["order_direction"]) : "asc"; $orderField = isset($httpVars["order_column"]) ? $httpVars["order_column"] : null; if ($orderField != null && !in_array($orderField, array("ajxp_label", "filesize", "ajxp_modiftime", "mimestring"))) { $orderField = "ajxp_label"; } } if (isset($httpVars["recursive"]) && $httpVars["recursive"] == "true") { $max_depth = isset($httpVars["max_depth"]) ? intval($httpVars["max_depth"]) : 0; $max_nodes = isset($httpVars["max_nodes"]) ? intval($httpVars["max_nodes"]) : 0; $crt_depth = isset($httpVars["crt_depth"]) ? intval($httpVars["crt_depth"]) + 1 : 1; $crt_nodes = isset($httpVars["crt_nodes"]) ? intval($httpVars["crt_nodes"]) : 0; } else { $threshold = $this->repository->getOption("PAGINATION_THRESHOLD"); if (!isset($threshold) || intval($threshold) == 0) { $threshold = 500; } $limitPerPage = $this->repository->getOption("PAGINATION_NUMBER"); if (!isset($limitPerPage) || intval($limitPerPage) == 0) { $limitPerPage = 200; } } $countFiles = $this->countFiles($path, !$lsOptions["f"]); if (isset($crt_nodes)) { $crt_nodes += $countFiles; } if (isset($threshold) && isset($limitPerPage) && $countFiles > $threshold) { if (isset($uniqueFile)) { $originalLimitPerPage = $limitPerPage; $offset = $limitPerPage = 0; } else { $offset = 0; $crtPage = 1; if (isset($page)) { $offset = (intval($page) - 1) * $limitPerPage; $crtPage = $page; } $totalPages = floor($countFiles / $limitPerPage) + 1; } } else { $offset = $limitPerPage = 0; } $metaData = array(); if (RecycleBinManager::recycleEnabled() && $dir == "") { $metaData["repo_has_recycle"] = "true"; } $parentAjxpNode = new AJXP_Node($nonPatchedPath, $metaData); $parentAjxpNode->loadNodeInfo(false, true, $lsOptions["l"] ? "all" : "minimal"); AJXP_Controller::applyHook("node.read", array(&$parentAjxpNode)); if (AJXP_XMLWriter::$headerSent == "tree") { AJXP_XMLWriter::renderAjxpNode($parentAjxpNode, false); } else { AJXP_XMLWriter::renderAjxpHeaderNode($parentAjxpNode); } if (isset($totalPages) && isset($crtPage)) { $remoteOptions = null; if ($this->getFilteredOption("REMOTE_SORTING")) { $remoteOptions = array("remote_order" => "true", "currentOrderCol" => isset($orderField) ? $orderField : "ajxp_label", "currentOrderDir" => isset($orderDirection) ? $orderDirection : "asc"); } AJXP_XMLWriter::renderPaginationData($countFiles, $crtPage, $totalPages, $this->countFiles($path, TRUE), $remoteOptions); if (!$lsOptions["f"]) { AJXP_XMLWriter::close(); exit(1); } } $cursor = 0; $handle = opendir($path); if (!$handle) { throw new AJXP_Exception("Cannot open dir " . $nonPatchedPath); } closedir($handle); $fullList = array("d" => array(), "z" => array(), "f" => array()); if (isset($orderField) && isset($orderDirection) && $orderField == "ajxp_label" && $orderDirection == "desc") { $nodes = scandir($path, 1); } else { $nodes = scandir($path); } if (!empty($this->driverConf["SCANDIR_RESULT_SORTFONC"])) { usort($nodes, $this->driverConf["SCANDIR_RESULT_SORTFONC"]); } if (isset($orderField) && isset($orderDirection) && $orderField != "ajxp_label") { $toSort = array(); foreach ($nodes as $node) { if ($orderField == "filesize") { $toSort[$node] = is_file($nonPatchedPath . "/" . $node) ? $this->filesystemFileSize($nonPatchedPath . "/" . $node) : 0; } else { if ($orderField == "ajxp_modiftime") { $toSort[$node] = filemtime($nonPatchedPath . "/" . $node); } else { if ($orderField == "mimestring") { $toSort[$node] = pathinfo($node, PATHINFO_EXTENSION); } } } } if ($orderDirection == "asc") { asort($toSort); } else { arsort($toSort); } $nodes = array_keys($toSort); } //while (strlen($nodeName = readdir($handle)) > 0) { foreach ($nodes as $nodeName) { if ($nodeName == "." || $nodeName == "..") { continue; } if (isset($uniqueFile) && $nodeName != $uniqueFile) { $cursor++; continue; } if ($offset > 0 && $cursor < $offset) { $cursor++; continue; } $isLeaf = ""; if (!$this->filterNodeName($path, $nodeName, $isLeaf, $lsOptions)) { continue; } if (RecycleBinManager::recycleEnabled() && $dir == "" && "/" . $nodeName == RecycleBinManager::getRecyclePath()) { continue; } if ($limitPerPage > 0 && $cursor - $offset >= $limitPerPage) { break; } $currentFile = $nonPatchedPath . "/" . $nodeName; $meta = array(); if ($isLeaf != "") { $meta = array("is_file" => $isLeaf ? "1" : "0"); } $node = new AJXP_Node($currentFile, $meta); $node->setLabel($nodeName); $node->loadNodeInfo(false, false, $lsOptions["l"] ? "all" : "minimal"); if (!empty($node->metaData["nodeName"]) && $node->metaData["nodeName"] != $nodeName) { $node->setUrl($nonPatchedPath . "/" . $node->metaData["nodeName"]); } if (!empty($node->metaData["hidden"]) && $node->metaData["hidden"] === true) { continue; } if (!empty($node->metaData["mimestring_id"]) && array_key_exists($node->metaData["mimestring_id"], $mess)) { $node->mergeMetadata(array("mimestring" => $mess[$node->metaData["mimestring_id"]])); } if (isset($originalLimitPerPage) && $cursor > $originalLimitPerPage) { $node->mergeMetadata(array("page_position" => floor($cursor / $originalLimitPerPage) + 1)); } $nodeType = "d"; if ($node->isLeaf()) { if (AJXP_Utils::isBrowsableArchive($nodeName)) { if ($lsOptions["f"] && $lsOptions["z"]) { $nodeType = "f"; } else { $nodeType = "z"; } } else { $nodeType = "f"; } } // There is a special sorting, cancel the reordering of files & folders. if (isset($orderField) && $orderField != "ajxp_label") { $nodeType = "f"; } $fullList[$nodeType][$nodeName] = $node; $cursor++; if (isset($uniqueFile) && $nodeName != $uniqueFile) { break; } } if (isset($httpVars["recursive"]) && $httpVars["recursive"] == "true") { $breakNow = false; if (isset($max_depth) && $max_depth > 0 && $crt_depth >= $max_depth) { $breakNow = true; } if (isset($max_nodes) && $max_nodes > 0 && $crt_nodes >= $max_nodes) { $breakNow = true; } foreach ($fullList["d"] as &$nodeDir) { if ($breakNow) { $nodeDir->mergeMetadata(array("ajxp_has_children" => $this->countFiles($nodeDir->getUrl(), false, true) ? "true" : "false")); AJXP_XMLWriter::renderAjxpNode($nodeDir, true); continue; } $this->switchAction("ls", array("dir" => SystemTextEncoding::toUTF8($nodeDir->getPath()), "options" => $httpVars["options"], "recursive" => "true", "max_depth" => $max_depth, "max_nodes" => $max_nodes, "crt_depth" => $crt_depth, "crt_nodes" => $crt_nodes), array()); } } else { array_map(array("AJXP_XMLWriter", "renderAjxpNode"), $fullList["d"]); } array_map(array("AJXP_XMLWriter", "renderAjxpNode"), $fullList["z"]); array_map(array("AJXP_XMLWriter", "renderAjxpNode"), $fullList["f"]); // ADD RECYCLE BIN TO THE LIST if ($dir == "" && !$uniqueFile && RecycleBinManager::recycleEnabled() && $this->getFilteredOption("HIDE_RECYCLE", $this->repository->getId()) !== true) { $recycleBinOption = RecycleBinManager::getRelativeRecycle(); if (file_exists($this->urlBase . $recycleBinOption)) { $recycleNode = new AJXP_Node($this->urlBase . $recycleBinOption); $recycleNode->loadNodeInfo(); AJXP_XMLWriter::renderAjxpNode($recycleNode); } } $this->logDebug("LS Time : " . intval((microtime() - $startTime) * 1000) . "ms"); AJXP_XMLWriter::close(); break; } $xmlBuffer = ""; if (isset($logMessage) || isset($errorMessage)) { $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false); } if ($reloadContextNode) { if (!isset($pendingSelection)) { $pendingSelection = ""; } $xmlBuffer .= AJXP_XMLWriter::reloadDataNode("", $pendingSelection, false); } if (isset($reloadDataNode)) { $xmlBuffer .= AJXP_XMLWriter::reloadDataNode($reloadDataNode, "", false); } if (isset($nodesDiffs)) { $xmlBuffer .= AJXP_XMLWriter::writeNodesDiff($nodesDiffs, false); } return $xmlBuffer; }
public function preProcess($action, $httpVars, $fileVars) { if (!is_array($this->pluginConf)) { throw new Exception("Cannot find configuration for plugin notify.phpmail-lite! Make sur that you have filled the options in the GUI, or that the .inc file was dropped inside the /conf/ folder!"); } if ($action == "upload" && !isset($httpVars["dir"])) { return; } require "lib/class.phpmailer-lite.php"; // Parse options if (is_string($this->pluginConf["FROM"])) { $this->pluginConf["FROM"] = $this->parseStringOption($this->pluginConf["FROM"]); } if (is_string($this->pluginConf["TO"]) && $this->pluginConf["TO"] != "") { $froms = explode(",", $this->pluginConf["TO"]); $this->pluginConf["TO"] = array_map(array($this, "parseStringOption"), $froms); } $recipients = $this->pluginConf["TO"]; if ($this->pluginConf["SHARE"]) { if (isset($httpVars["PLUGINS_DATA"])) { $pData = $httpVars["PLUGINS_DATA"]; } else { $repo = ConfService::getRepository(); $pData = $repo->getOption("PLUGINS_DATA"); } if ($pData != null && isset($pData["SHARE_NOTIFICATION_ACTIVE"]) && isset($pData["SHARE_NOTIFICATION_EMAIL"]) && $pData["SHARE_NOTIFICATION_ACTIVE"] == "on") { $emails = array_map(array($this, "parseStringOption"), explode(",", $pData["SHARE_NOTIFICATION_EMAIL"])); if (is_array($recipients)) { $recipients = array_merge($recipients, $emails); } else { $recipients = $emails; } } } if ($recipients == "" || !count($recipients)) { return; } // NOW IF THERE ARE RECIPIENTS FOR ANY REASON, GO $mail = new PHPMailerLite(true); $mail->Mailer = $this->pluginConf["MAILER"]; $mail->SetFrom($this->pluginConf["FROM"]["address"], $this->pluginConf["FROM"]["name"]); foreach ($recipients as $address) { $mail->AddAddress($address["address"], $address["name"]); } $mail->WordWrap = 50; // set word wrap to 50 characters $mail->IsHTML(true); // set email format to HTML $userSelection = new UserSelection(); $userSelection->initFromHttpVars($httpVars); if ($action == "upload" && !isset($httpVars["simple_uploader"]) && !isset($httpVars["xhr_uploader"])) { // FLEX UPLOADER, BASE64 DECODE! if (isset($fileVars["userfile_0"])) { $file = $fileVars["userfile_0"]["name"]; } else { if (isset($httpVars["Filename"])) { $file = $httpVars["Filename"]; } } $folder = base64_decode($httpVars["dir"]); } else { $folder = $httpVars["dir"]; $file = ""; if (!$userSelection->isEmpty()) { $file = implode(",", array_map("basename", $userSelection->getFiles())); if ($folder == null) { $folder = dirname($userSelection->getUniqueFile()); } } if ($action == "upload" && isset($fileVars["userfile_0"])) { $file = $fileVars["userfile_0"]["name"]; } } $subject = array("%user", "AJXP_USER", "AJXP_FILE", "AJXP_FOLDER", "AJXP_ACTION", "AJXP_REPOSITORY"); $replace = array(AuthService::getLoggedUser()->getId(), AuthService::getLoggedUser()->getId(), $file, $folder, $action, ConfService::getRepository()->getDisplay()); $body = str_replace($subject, $replace, $this->pluginConf["BODY"]); $mail->Subject = str_replace($subject, $replace, $this->pluginConf["SUBJECT"]); $mail->Body = nl2br($body); $mail->AltBody = strip_tags($mail->Body); if (!$mail->Send()) { $message = "Message could not be sent. <p>"; $message .= "Mailer Error: " . $mail->ErrorInfo; throw new Exception($message); } }
function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } parent::accessPreprocess($action, $httpVars, $fileVars); $selection = new UserSelection(); $dir = $httpVars["dir"] or ""; $dir = AJXP_Utils::securePath($dir); if ($action != "upload") { $dir = AJXP_Utils::decodeSecureMagic($dir); } $selection->initFromHttpVars($httpVars); if (!$selection->isEmpty()) { $this->filterUserSelectionToHidden($selection->getFiles()); } $mess = ConfService::getMessages(); $newArgs = RecycleBinManager::filterActions($action, $selection, $dir, $httpVars); if (isset($newArgs["action"])) { $action = $newArgs["action"]; } if (isset($newArgs["dest"])) { $httpVars["dest"] = SystemTextEncoding::toUTF8($newArgs["dest"]); } //Re-encode! // FILTER DIR PAGINATION ANCHOR $page = null; if (isset($dir) && strstr($dir, "%23") !== false) { $parts = explode("%23", $dir); $dir = $parts[0]; $page = $parts[1]; } $pendingSelection = ""; $logMessage = null; $reloadContextNode = false; switch ($action) { //------------------------------------ // DOWNLOAD //------------------------------------ case "download": AJXP_Logger::logAction("Download", array("files" => $selection)); @set_error_handler(array("HTMLWriter", "javascriptErrorHandler"), E_ALL & ~E_NOTICE); @register_shutdown_function("restore_error_handler"); $zip = false; if ($selection->isUnique()) { if (is_dir($this->urlBase . $selection->getUniqueFile())) { $zip = true; $base = basename($selection->getUniqueFile()); $dir .= "/" . dirname($selection->getUniqueFile()); } else { if (!file_exists($this->urlBase . $selection->getUniqueFile())) { throw new Exception("Cannot find file!"); } } } else { $zip = true; } if ($zip) { // Make a temp zip and send it as download $loggedUser = AuthService::getLoggedUser(); $file = USERS_DIR . "/" . ($loggedUser ? $loggedUser->getId() : "shared") . "/" . time() . "tmpDownload.zip"; $zipFile = $this->makeZip($selection->getFiles(), $file, $dir); if (!$zipFile) { throw new AJXP_Exception("Error while compressing"); } register_shutdown_function("unlink", $file); $localName = ($base == "" ? "Files" : $base) . ".zip"; $this->readFile($file, "force-download", $localName, false, false, true); } else { $this->readFile($this->urlBase . $selection->getUniqueFile(), "force-download"); } break; case "compress": // Make a temp zip and send it as download $loggedUser = AuthService::getLoggedUser(); if (isset($httpVars["archive_name"])) { $localName = AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]); $this->filterUserSelectionToHidden(array($localName)); } else { $localName = (basename($dir) == "" ? "Files" : basename($dir)) . ".zip"; } $file = USERS_DIR . "/" . ($loggedUser ? $loggedUser->getId() : "shared") . "/" . time() . "tmpCompression.zip"; $zipFile = $this->makeZip($selection->getFiles(), $file, $dir); if (!$zipFile) { throw new AJXP_Exception("Error while compressing file {$localName}"); } register_shutdown_function("unlink", $file); copy($file, $this->urlBase . $dir . "/" . str_replace(".zip", ".tmp", $localName)); @rename($this->urlBase . $dir . "/" . str_replace(".zip", ".tmp", $localName), $this->urlBase . $dir . "/" . $localName); $reloadContextNode = true; $pendingSelection = $localName; break; case "stat": clearstatcache(); $stat = @stat($this->urlBase . $selection->getUniqueFile()); header("Content-type:application/json"); if (!$stat) { print '{}'; } else { print json_encode($stat); } break; //------------------------------------ // ONLINE EDIT //------------------------------------ //------------------------------------ // ONLINE EDIT //------------------------------------ case "get_content": $this->readFile($this->urlBase . $selection->getUniqueFile(), "plain"); break; case "put_content": if (!isset($httpVars["content"])) { break; } // Load "code" variable directly from POST array, do not "securePath" or "sanitize"... $code = $httpVars["content"]; $file = $selection->getUniqueFile($httpVars["file"]); AJXP_Logger::logAction("Online Edition", array("file" => $file)); if (isset($httpVars["encode"]) && $httpVars["encode"] == "base64") { $code = base64_decode($code); } else { $code = SystemTextEncoding::magicDequote($code); $code = str_replace("<", "<", $code); } $fileName = $this->urlBase . $file; if (!is_file($fileName) || !$this->isWriteable($fileName, "file")) { header("Content-Type:text/plain"); print !$this->isWriteable($fileName, "file") ? "1001" : "1002"; return; } $fp = fopen($fileName, "w"); fputs($fp, $code); fclose($fp); header("Content-Type:text/plain"); print $mess[115]; break; //------------------------------------ // COPY / MOVE //------------------------------------ //------------------------------------ // COPY / MOVE //------------------------------------ case "copy": case "move": if ($selection->isEmpty()) { throw new AJXP_Exception("", 113); } $success = $error = array(); $dest = AJXP_Utils::decodeSecureMagic($httpVars["dest"]); $this->filterUserSelectionToHidden(array($httpVars["dest"])); if ($selection->inZip()) { // Set action to copy anycase (cannot move from the zip). $action = "copy"; $this->extractArchive($dest, $selection, $error, $success); } else { $this->copyOrMove($dest, $selection->getFiles(), $error, $success, $action == "move" ? true : false); } if (count($error)) { throw new AJXP_Exception(SystemTextEncoding::toUTF8(join("\n", $error))); } else { $logMessage = join("\n", $success); AJXP_Logger::logAction($action == "move" ? "Move" : "Copy", array("files" => $selection, "destination" => $dest)); } $reloadContextNode = true; $reloadDataNode = $dest; break; //------------------------------------ // SUPPRIMER / DELETE //------------------------------------ //------------------------------------ // SUPPRIMER / DELETE //------------------------------------ case "delete": if ($selection->isEmpty()) { throw new AJXP_Exception("", 113); } $logMessages = array(); $errorMessage = $this->delete($selection->getFiles(), $logMessages); if (count($logMessages)) { $logMessage = join("\n", $logMessages); } if ($errorMessage) { throw new AJXP_Exception(SystemTextEncoding::toUTF8($errorMessage)); } AJXP_Logger::logAction("Delete", array("files" => $selection)); $reloadContextNode = true; break; //------------------------------------ // RENOMMER / RENAME //------------------------------------ //------------------------------------ // RENOMMER / RENAME //------------------------------------ case "rename": $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]); $filename_new = AJXP_Utils::decodeSecureMagic($httpVars["filename_new"]); $this->filterUserSelectionToHidden(array($filename_new)); $this->rename($file, $filename_new); $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new); $reloadContextNode = true; $pendingSelection = $filename_new; AJXP_Logger::logAction("Rename", array("original" => $file, "new" => $filename_new)); break; //------------------------------------ // CREER UN REPERTOIRE / CREATE DIR //------------------------------------ //------------------------------------ // CREER UN REPERTOIRE / CREATE DIR //------------------------------------ case "mkdir": $messtmp = ""; $dirname = AJXP_Utils::decodeSecureMagic($httpVars["dirname"], AJXP_SANITIZE_HTML_STRICT); $dirname = substr($dirname, 0, ConfService::getConf("MAX_CHAR")); $this->filterUserSelectionToHidden(array($dirname)); $error = $this->mkDir($dir, $dirname); if (isset($error)) { throw new AJXP_Exception($error); } $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} "; if ($dir == "") { $messtmp .= "/"; } else { $messtmp .= SystemTextEncoding::toUTF8($dir); } $logMessage = $messtmp; $pendingSelection = $dirname; $reloadContextNode = true; AJXP_Logger::logAction("Create Dir", array("dir" => $dir . "/" . $dirname)); break; //------------------------------------ // CREER UN FICHIER / CREATE FILE //------------------------------------ //------------------------------------ // CREER UN FICHIER / CREATE FILE //------------------------------------ case "mkfile": $messtmp = ""; $filename = AJXP_Utils::decodeSecureMagic($httpVars["filename"], AJXP_SANITIZE_HTML_STRICT); $filename = substr($filename, 0, ConfService::getConf("MAX_CHAR")); $this->filterUserSelectionToHidden(array($filename)); $error = $this->createEmptyFile($dir, $filename); if (isset($error)) { throw new AJXP_Exception($error); } $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} "; if ($dir == "") { $messtmp .= "/"; } else { $messtmp .= SystemTextEncoding::toUTF8($dir); } $logMessage = $messtmp; $reloadContextNode = true; $pendingSelection = $dir . "/" . $filename; AJXP_Logger::logAction("Create File", array("file" => $dir . "/" . $filename)); break; //------------------------------------ // CHANGE FILE PERMISSION //------------------------------------ //------------------------------------ // CHANGE FILE PERMISSION //------------------------------------ case "chmod": $messtmp = ""; $files = $selection->getFiles(); $changedFiles = array(); $chmod_value = $httpVars["chmod_value"]; $recursive = $httpVars["recursive"]; $recur_apply_to = $httpVars["recur_apply_to"]; foreach ($files as $fileName) { $error = $this->chmod($fileName, $chmod_value, $recursive == "on", $recursive == "on" ? $recur_apply_to : "both", $changedFiles); } if (isset($error)) { throw new AJXP_Exception($error); } //$messtmp.="$mess[34] ".SystemTextEncoding::toUTF8($filename)." $mess[39] "; $logMessage = "Successfully changed permission to " . $chmod_value . " for " . count($changedFiles) . " files or folders"; $reloadContextNode = true; AJXP_Logger::logAction("Chmod", array("dir" => $dir, "filesCount" => count($changedFiles))); break; //------------------------------------ // UPLOAD //------------------------------------ //------------------------------------ // UPLOAD //------------------------------------ case "upload": AJXP_Logger::debug("Upload Files Data", $fileVars); $destination = $this->urlBase . AJXP_Utils::decodeSecureMagic($dir); AJXP_Logger::debug("Upload inside", array("destination" => $destination)); if (!$this->isWriteable($destination)) { $errorCode = 412; $errorMessage = "{$mess['38']} " . SystemTextEncoding::toUTF8($dir) . " {$mess['99']}."; AJXP_Logger::debug("Upload error 412", array("destination" => $destination)); return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage)); } foreach ($fileVars as $boxName => $boxData) { if (substr($boxName, 0, 9) != "userfile_") { continue; } $err = AJXP_Utils::parseFileDataErrors($boxData); if ($err != null) { $errorCode = $err[0]; $errorMessage = $err[1]; break; } $userfile_name = $boxData["name"]; try { $this->filterUserSelectionToHidden(array($userfile_name)); } catch (Exception $e) { return array("ERROR" => array("CODE" => 411, "MESSAGE" => "Forbidden")); } $userfile_name = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($userfile_name), AJXP_SANITIZE_HTML_STRICT); $userfile_name = substr($userfile_name, 0, ConfService::getConf("MAX_CHAR")); if (isset($httpVars["auto_rename"])) { $userfile_name = self::autoRenameForDest($destination, $userfile_name); } if (isset($boxData["input_upload"])) { try { AJXP_Logger::debug("Begining reading INPUT stream"); $input = fopen("php://input", "r"); $output = fopen("{$destination}/" . $userfile_name, "w"); $sizeRead = 0; while ($sizeRead < intval($boxData["size"])) { $chunk = fread($input, 4096); $sizeRead += strlen($chunk); fwrite($output, $chunk, strlen($chunk)); } fclose($input); fclose($output); AJXP_Logger::debug("End reading INPUT stream"); } catch (Exception $e) { $errorCode = 411; $errorMessage = $e->getMessage(); break; } } else { if (!move_uploaded_file($boxData["tmp_name"], "{$destination}/" . $userfile_name)) { $errorCode = 411; $errorMessage = "{$mess['33']} " . $userfile_name; break; } } $this->changeMode($destination . "/" . $userfile_name); $logMessage .= "{$mess['34']} " . SystemTextEncoding::toUTF8($userfile_name) . " {$mess['35']} {$dir}"; AJXP_Logger::logAction("Upload File", array("file" => SystemTextEncoding::fromUTF8($dir) . "/" . $userfile_name)); } if (isset($errorMessage)) { AJXP_Logger::debug("Return error {$errorCode} {$errorMessage}"); return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage)); } else { AJXP_Logger::debug("Return success"); return array("SUCCESS" => true); } return; break; //------------------------------------ // SHARING FILE OR FOLDER //------------------------------------ //------------------------------------ // SHARING FILE OR FOLDER //------------------------------------ case "public_url": $subAction = isset($httpVars["sub_action"]) ? $httpVars["sub_action"] : ""; if ($subAction == "delegate_repo") { header("Content-type:text/plain"); $result = $this->createSharedRepository($httpVars); print $result; } else { if ($subAction == "list_shared_users") { header("Content-type:text/html"); $loggedUser = AuthService::getLoggedUser(); $allUsers = AuthService::listUsers(); $crtValue = $httpVars["value"]; $users = ""; foreach ($allUsers as $userId => $userObject) { if ($crtValue != "" && (strstr($userId, $crtValue) === false || strstr($userId, $crtValue) != 0)) { continue; } if ($userObject->hasParent() && $userObject->getParent() == $loggedUser->getId()) { $users .= "<li>" . $userId . "</li>"; } } if (strlen($users)) { print "<ul>" . $users . "</ul>"; } } else { $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]); $url = $this->makePubliclet($file, $httpVars["password"], $httpVars["expiration"]); header("Content-type:text/plain"); echo $url; } } break; //------------------------------------ // XML LISTING //------------------------------------ //------------------------------------ // XML LISTING //------------------------------------ case "ls": if (!isset($dir) || $dir == "/") { $dir = ""; } $lsOptions = $this->parseLsOptions(isset($httpVars["options"]) ? $httpVars["options"] : "a"); $startTime = microtime(); $dir = AJXP_Utils::securePath(SystemTextEncoding::magicDequote($dir)); $path = $this->urlBase . ($dir != "" ? "/" . $dir : ""); $threshold = $this->repository->getOption("PAGINATION_THRESHOLD"); if (!isset($threshold) || intval($threshold) == 0) { $threshold = 500; } $limitPerPage = $this->repository->getOption("PAGINATION_NUMBER"); if (!isset($limitPerPage) || intval($limitPerPage) == 0) { $limitPerPage = 200; } $countFiles = $this->countFiles($path, !$lsOptions["f"]); if ($countFiles > $threshold) { $offset = 0; $crtPage = 1; if (isset($page)) { $offset = (intval($page) - 1) * $limitPerPage; $crtPage = $page; } $totalPages = floor($countFiles / $limitPerPage) + 1; } else { $offset = $limitPerPage = 0; } $metaData = array(); $crtLabel = AJXP_Utils::xmlEntities(basename($dir), true); if (RecycleBinManager::recycleEnabled()) { if (RecycleBinManager::currentLocationIsRecycle($dir)) { $metaData["ajxp_mime"] = "ajxp_recycle"; $crtLabel = AJXP_Utils::xmlEntities($mess[122]); } else { if ($dir == "") { $metaData["repo_has_recycle"] = "true"; } } } if (AJXP_Utils::isBrowsableArchive($dir)) { $metaData["ajxp_mime"] = "ajxp_browsable_archive"; } AJXP_XMLWriter::renderHeaderNode(AJXP_Utils::xmlEntities($dir, true), $crtLabel, false, $metaData); if (isset($totalPages) && isset($crtPage)) { AJXP_XMLWriter::renderPaginationData($countFiles, $crtPage, $totalPages); if (!$lsOptions["f"]) { AJXP_XMLWriter::close(); exit(1); } } $cursor = 0; $handle = opendir($path); if (!$handle) { throw new AJXP_Exception("Cannot open dir " . $path); } closedir($handle); $fullList = array("d" => array(), "z" => array(), "f" => array()); $nodes = scandir($path); //while(strlen($nodeName = readdir($handle)) > 0){ foreach ($nodes as $nodeName) { if ($nodeName == "." || $nodeName == "..") { continue; } $isLeaf = is_file($path . "/" . $nodeName) || AJXP_Utils::isBrowsableArchive($nodeName); if (!$this->filterNodeName($path, $nodeName, $isLeaf, $lsOptions)) { continue; } if (RecycleBinManager::recycleEnabled() && $dir == "" && "/" . $nodeName == RecycleBinManager::getRecyclePath()) { continue; } $nodeType = "d"; if ($isLeaf) { if (AJXP_Utils::isBrowsableArchive($nodeName)) { if ($lsOptions["f"] && $lsOptions["z"]) { // See archives as files $nodeType = "f"; } else { $nodeType = "z"; } } else { $nodeType = "f"; } } if ($offset > 0 && $cursor < $offset) { $cursor++; continue; } if ($limitPerPage > 0 && $cursor - $offset >= $limitPerPage) { break; } $metaData = array(); $currentFile = $path . "/" . $nodeName; $metaData["is_file"] = $isLeaf ? "1" : "0"; $metaData["filename"] = AJXP_Utils::xmlEntities(SystemTextEncoding::toUTF8($dir . "/" . $nodeName)); $metaData["icon"] = AJXP_Utils::mimetype($nodeName, "image", !$isLeaf); if ($metaData["icon"] == "folder.png") { $metaData["openicon"] = "folder_open.png"; } if (!is_file($currentFile) || AJXP_Utils::isBrowsableArchive($nodeName)) { $link = SystemTextEncoding::toUTF8(SERVER_ACCESS . "?get_action=ls&options=dz&dir=" . $dir . "/" . $nodeName); $link = urlencode($link); $metaData["src"] = $link; } if ($lsOptions["l"]) { $metaData["file_group"] = @filegroup($currentFile) || "unknown"; $metaData["file_owner"] = @fileowner($currentFile) || "unknown"; $fPerms = @fileperms($currentFile); if ($fPerms !== false) { $fPerms = substr(decoct($fPerms), $isLeaf ? 2 : 1); } else { $fPerms = '0000'; } $metaData["file_perms"] = $fPerms; $metaData["mimestring"] = AJXP_Utils::mimetype($currentFile, "type", !$isLeaf); $datemodif = $this->date_modif($currentFile); $metaData["ajxp_modiftime"] = $datemodif ? $datemodif : "0"; $metaData["bytesize"] = 0; if ($isLeaf) { $metaData["bytesize"] = filesize($currentFile); if ($metaData["bytesize"] < 0) { $metaData["bytesize"] = sprintf("%u", $metaData["bytesize"]); } } $metaData["filesize"] = AJXP_Utils::roundSize($metaData["bytesize"]); if (AJXP_Utils::isBrowsableArchive($nodeName)) { $metaData["ajxp_mime"] = "ajxp_browsable_archive"; } $realFile = null; // A reference to the real file. AJXP_Controller::applyHook("ls.metadata", array($currentFile, &$metaData, $this->wrapperClassName, &$realFile)); } $attributes = ""; foreach ($metaData as $key => $value) { $attributes .= "{$key}=\"{$value}\" "; } $renderNodeData = array(AJXP_Utils::xmlEntities($dir . "/" . $nodeName, true), AJXP_Utils::xmlEntities($nodeName, true), $isLeaf, $metaData); $fullList[$nodeType][$nodeName] = $renderNodeData; $cursor++; } /* closedir($handle); foreach ($fullList as $key => $list){ uksort($list, 'strnatcasecmp'); $fullList[$key] = $list; } */ $allNodes = array_merge($fullList["d"], $fullList["z"], $fullList["f"]); array_map(array("AJXP_XMLWriter", "renderNodeArray"), $fullList["d"]); array_map(array("AJXP_XMLWriter", "renderNodeArray"), $fullList["z"]); array_map(array("AJXP_XMLWriter", "renderNodeArray"), $fullList["f"]); // ADD RECYCLE BIN TO THE LIST if ($dir == "" && RecycleBinManager::recycleEnabled()) { $recycleBinOption = RecycleBinManager::getRelativeRecycle(); if (file_exists($this->urlBase . $recycleBinOption)) { $recycleIcon = $this->countFiles($this->urlBase . $recycleBinOption, false, true) > 0 ? "trashcan_full.png" : "trashcan.png"; $recycleMetaData = array("ajxp_modiftime" => $this->date_modif($this->urlBase . $recycleBinOption), "mimestring" => AJXP_Utils::xmlEntities($mess[122]), "icon" => "{$recycleIcon}", "filesize" => "-", "ajxp_mime" => "ajxp_recycle"); $nullFile = null; AJXP_Controller::applyHook("ls.metadata", array($this->urlBase . $recycleBinOption, &$recycleMetaData, $this->wrapperClassName, &$nullFile)); AJXP_XMLWriter::renderNode($recycleBinOption, AJXP_Utils::xmlEntities($mess[122]), false, $recycleMetaData); } } AJXP_Logger::debug("LS Time : " . intval((microtime() - $startTime) * 1000) . "ms"); AJXP_XMLWriter::close(); return; break; } $xmlBuffer = ""; if (isset($logMessage) || isset($errorMessage)) { $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false); } if ($reloadContextNode) { if (!isset($pendingSelection)) { $pendingSelection = ""; } $xmlBuffer .= AJXP_XMLWriter::reloadDataNode("", $pendingSelection, false); } if (isset($reloadDataNode)) { $xmlBuffer .= AJXP_XMLWriter::reloadDataNode($reloadDataNode, "", false); } return $xmlBuffer; }