/** * Parse * * @param DOMNode $contribNode */ protected function parseSpecificContributions(&$contribNode) { parent::parseSpecificContributions($contribNode); if ($contribNode->nodeName != "actions") { return; } // Cannot use zip features on FTP ! // Remove "compress" action $actionXpath = new DOMXPath($contribNode->ownerDocument); $compressNodeList = $actionXpath->query('action[@name="compress"]', $contribNode); if (!$compressNodeList->length) { return; } unset($this->actions["compress"]); $compressNode = $compressNodeList->item(0); $contribNode->removeChild($compressNode); // Disable "download" if selection is multiple $nodeList = $actionXpath->query('action[@name="download"]/gui/selectionContext', $contribNode); $selectionNode = $nodeList->item(0); $values = array("dir" => "false", "unique" => "true"); foreach ($selectionNode->attributes as $attribute) { if (isset($values[$attribute->name])) { $attribute->value = $values[$attribute->name]; } } $nodeList = $actionXpath->query('action[@name="download"]/processing/clientListener[@name="selectionChange"]', $contribNode); $listener = $nodeList->item(0); $listener->parentNode->removeChild($listener); }
public function switchAction($action, $httpVars, $fileVars) { $errorMessage = "This is a demo, all 'write' actions are disabled!"; switch ($action) { //------------------------------------ // WRITE ACTIONS //------------------------------------ case "put_content": case "copy": case "move": case "rename": case "delete": case "mkdir": case "mkfile": case "chmod": case "compress": return AJXP_XMLWriter::sendMessage(null, $errorMessage, false); break; //------------------------------------ // UPLOAD //------------------------------------ //------------------------------------ // UPLOAD //------------------------------------ case "upload": return array("ERROR" => array("CODE" => "", "MESSAGE" => $errorMessage)); break; default: break; } return parent::switchAction($action, $httpVars, $fileVars); }
public function loadNodeInfo(AJXP_Node &$node, $parentNode = false, $details = false) { parent::loadNodeInfo($node, $parentNode, $details); if (!$node->isLeaf()) { $node->setLabel(rtrim($node->getLabel(), "/")); } }
/** * Parse * @param DOMNode $contribNode */ protected function parseSpecificContributions(&$contribNode) { parent::parseSpecificContributions($contribNode); if ($contribNode->nodeName != "actions") { return; } $this->disableArchiveBrowsingContributions($contribNode); }
/** * Parse * @param DOMNode $contribNode */ protected function parseSpecificContributions(&$contribNode) { parent::parseSpecificContributions($contribNode); if ($contribNode->nodeName != "actions" || isset($this->pluginConf["SMB_ENABLE_ZIP"]) && $this->pluginConf["SMB_ENABLE_ZIP"] == true) { return; } $this->disableArchiveBrowsingContributions($contribNode); }
public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false) { parent::loadNodeInfo($ajxpNode, $parentNode, $details); if (!$ajxpNode->isRoot()) { // Retrieving stored details $originalNode = self::$output[$ajxpNode->getLabel()]; if (isset($originalNode["meta"])) { $meta = $originalNode["meta"]; } else { $meta = array(); } $label = $originalNode["label"]; if (!$ajxpNode->isLeaf()) { $meta["icon"] = "mime_empty.png"; } // Overriding display name with repository name $ajxpNode->setLabel($label); $ajxpNode->mergeMetadata($meta); } }
public function init($repository, $options = array()) { parent::init($repository, $options); AJXP_MetaStreamWrapper::appendMetaWrapper("auth.dav", "Pydio\\Access\\Core\\Stream\\AuthWrapper", "pydio.dav"); AJXP_MetaStreamWrapper::appendMetaWrapper("path.dav", "Pydio\\Access\\Core\\Stream\\PathWrapper", "pydio.dav"); }
public function switchAction($action, $httpVars, $filesVars) { if (!isset($this->actions[$action])) { return false; } $repository = ConfService::getRepository(); if (!$repository->detectStreamWrapper(true)) { return false; } $streamData = $repository->streamData; $destStreamURL = $streamData["protocol"] . "://" . $repository->getId(); $wrapperClassName = $streamData["classname"]; if (empty($httpVars["file"])) { return; } $file = $destStreamURL . AJXP_Utils::decodeSecureMagic($httpVars["file"]); $mess = ConfService::getMessages(); $node = new AJXP_Node($file); AJXP_Controller::applyHook("node.read", array($node)); 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) { 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); $destRepoAccess = $destRepoObject->getAccessType(); $plugin = AJXP_PluginsService::findPlugin("access", $destRepoAccess); $destWrapperData = $plugin->detectStreamWrapper(true); $destStreamURL = $destWrapperData["protocol"] . "://{$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 uploadActions($action, $httpVars, $filesVars) { switch ($action) { case "trigger_remote_copy": if (!$this->hasFilesToCopy()) { break; } $toCopy = $this->getFileNameToCopy(); AJXP_XMLWriter::header(); AJXP_XMLWriter::triggerBgAction("next_to_remote", array(), "Copying file " . $toCopy . " to ftp server"); AJXP_XMLWriter::close(); exit(1); break; case "next_to_remote": if (!$this->hasFilesToCopy()) { break; } $fData = $this->getNextFileToCopy(); $nextFile = ''; if ($this->hasFilesToCopy()) { $nextFile = $this->getFileNameToCopy(); } $this->logDebug("Base64 : ", array("from" => $fData["destination"], "to" => base64_decode($fData['destination']))); $destPath = $this->urlBase . base64_decode($fData['destination']) . "/" . $fData['name']; //$destPath = AJXP_Utils::decodeSecureMagic($destPath); // DO NOT "SANITIZE", THE URL IS ALREADY IN THE FORM ajxp.ftp://repoId/filename $destPath = SystemTextEncoding::fromPostedFileName($destPath); $node = new AJXP_Node($destPath); $this->logDebug("Copying file to server", array("from" => $fData["tmp_name"], "to" => $destPath, "name" => $fData["name"])); try { AJXP_Controller::applyHook("node.before_create", array(&$node)); $fp = fopen($destPath, "w"); $fSource = fopen($fData["tmp_name"], "r"); while (!feof($fSource)) { fwrite($fp, fread($fSource, 4096)); } fclose($fSource); $this->logDebug("Closing target : begin ftp copy"); // Make sur the script does not time out! @set_time_limit(240); fclose($fp); $this->logDebug("FTP Upload : end of ftp copy"); @unlink($fData["tmp_name"]); AJXP_Controller::applyHook("node.change", array(null, &$node)); } catch (Exception $e) { $this->logDebug("Error during ftp copy", array($e->getMessage(), $e->getTrace())); } $this->logDebug("FTP Upload : shoud trigger next or reload nextFile={$nextFile}"); AJXP_XMLWriter::header(); if ($nextFile != '') { AJXP_XMLWriter::triggerBgAction("next_to_remote", array(), "Copying file " . SystemTextEncoding::toUTF8($nextFile) . " to remote server"); } else { AJXP_XMLWriter::triggerBgAction("reload_node", array(), "Upload done, reloading client."); } AJXP_XMLWriter::close(); exit(1); break; case "upload": $rep_source = AJXP_Utils::securePath("/" . $httpVars['dir']); $this->logDebug("Upload : rep_source ", array($rep_source)); $logMessage = ""; foreach ($filesVars as $boxName => $boxData) { if (substr($boxName, 0, 9) != "userfile_") { continue; } $this->logDebug("Upload : rep_source ", array($rep_source)); $err = AJXP_Utils::parseFileDataErrors($boxData); if ($err != null) { $errorCode = $err[0]; $errorMessage = $err[1]; break; } if (isset($httpVars["auto_rename"])) { $destination = $this->urlBase . $rep_source; $boxData["name"] = fsAccessDriver::autoRenameForDest($destination, $boxData["name"]); } $boxData["destination"] = base64_encode($rep_source); $destCopy = AJXP_XMLWriter::replaceAjxpXmlKeywords($this->repository->getOption("TMP_UPLOAD")); $this->logDebug("Upload : tmp upload folder", array($destCopy)); if (!is_dir($destCopy)) { if (!@mkdir($destCopy)) { $this->logDebug("Upload error : cannot create temporary folder", array($destCopy)); $errorCode = 413; $errorMessage = "Warning, cannot create folder for temporary copy."; break; } } if (!$this->isWriteable($destCopy)) { $this->logDebug("Upload error: cannot write into temporary folder"); $errorCode = 414; $errorMessage = "Warning, cannot write into temporary folder."; break; } $this->logDebug("Upload : tmp upload folder", array($destCopy)); if (isset($boxData["input_upload"])) { try { $destName = tempnam($destCopy, ""); $this->logDebug("Begining reading INPUT stream"); $input = fopen("php://input", "r"); $output = fopen($destName, "w"); $sizeRead = 0; while ($sizeRead < intval($boxData["size"])) { $chunk = fread($input, 4096); $sizeRead += strlen($chunk); fwrite($output, $chunk, strlen($chunk)); } fclose($input); fclose($output); $boxData["tmp_name"] = $destName; $this->storeFileToCopy($boxData); $this->logDebug("End reading INPUT stream"); } catch (Exception $e) { $errorCode = 411; $errorMessage = $e->getMessage(); break; } } else { $destName = $destCopy . "/" . basename($boxData["tmp_name"]); if ($destName == $boxData["tmp_name"]) { $destName .= "1"; } if (move_uploaded_file($boxData["tmp_name"], $destName)) { $boxData["tmp_name"] = $destName; $this->storeFileToCopy($boxData); } else { $mess = ConfService::getMessages(); $errorCode = 411; $errorMessage = "{$mess['33']} " . $boxData["name"]; break; } } } if (isset($errorMessage)) { $this->logDebug("Return error {$errorCode} {$errorMessage}"); return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage)); } else { $this->logDebug("Return success"); return array("SUCCESS" => true, "PREVENT_NOTIF" => true); } break; default: break; } session_write_close(); exit; }
/** * @param $src * @param $dest * @param $basedir * @throws Exception * @return zipfile */ public function makeZip($src, $dest, $basedir) { $zipEncoding = ConfService::getCoreConf("ZIP_ENCODING"); @set_time_limit(0); require_once AJXP_BIN_FOLDER . "/pclzip.lib.php"; $filePaths = array(); foreach ($src as $item) { $realFile = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $this->urlBase . "/" . $item); $realFile = AJXP_Utils::securePath($realFile); if (basename($item) == "") { $filePaths[] = array(PCLZIP_ATT_FILE_NAME => $realFile); } else { $shortName = basename($item); if (!empty($zipEncoding)) { $test = iconv(SystemTextEncoding::getEncoding(), $zipEncoding, $shortName); if ($test !== false) { $shortName = $test; } } $filePaths[] = array(PCLZIP_ATT_FILE_NAME => $realFile, PCLZIP_ATT_FILE_NEW_SHORT_NAME => $shortName); } } $this->logDebug("Pathes", $filePaths); self::$filteringDriverInstance = $this; $archive = new PclZip($dest); if ($basedir == "__AJXP_ZIP_FLAT__/") { $vList = $archive->create($filePaths, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_ADD_TEMP_FILE_ON, PCLZIP_CB_PRE_ADD, 'zipPreAddCallback'); } else { $basedir = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $this->urlBase) . trim($basedir); $this->logDebug("Basedir", array($basedir)); $vList = $archive->create($filePaths, PCLZIP_OPT_REMOVE_PATH, $basedir, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_ADD_TEMP_FILE_ON, PCLZIP_CB_PRE_ADD, 'zipPreAddCallback'); } if (!$vList) { throw new Exception("Zip creation error : ({$dest}) " . $archive->errorInfo(true)); } self::$filteringDriverInstance = null; return $vList; }
function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } $errorMessage = "This is a demo, all 'write' actions are disabled!"; switch ($action) { //------------------------------------ // ONLINE EDIT //------------------------------------ case "public_url": if ($httpVars["sub_action"] == "delegate_repo") { return AJXP_XMLWriter::sendMessage(null, $errorMessage, false); } else { print $errorMessage; } exit(0); break; //------------------------------------ // WRITE ACTIONS //------------------------------------ //------------------------------------ // WRITE ACTIONS //------------------------------------ case "put_content": case "copy": case "move": case "rename": case "delete": case "mkdir": case "mkfile": case "chmod": case "compress": return AJXP_XMLWriter::sendMessage(null, $errorMessage, false); break; //------------------------------------ // UPLOAD //------------------------------------ //------------------------------------ // UPLOAD //------------------------------------ case "upload": return array("ERROR" => array("CODE" => "", "MESSAGE" => $errorMessage)); break; default: break; } return parent::switchAction($action, $httpVars, $fileVars); }
public function makeSharedRepositoryOptions($httpVars, $repository) { $newOptions = parent::makeSharedRepositoryOptions($httpVars, $repository); $newOptions["DROPBOX_OAUTH_TOKENS"] = $this->getTokens(); return $newOptions; }
function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } $errorMessage = "This is a demo, all 'write' actions are disabled!"; switch ($action) { //------------------------------------ // ONLINE EDIT //------------------------------------ case "edit": if (isset($save) && $save == 1) { $xmlBuffer .= AJXP_XMLWriter::sendMessage(null, $errorMessage, false); } else { $this->readFile($this->getPath() . "/" . SystemTextEncoding::fromUTF8(Utils::securePath($_GET["file"])), "plain"); } exit(0); break; case "public_url": print $errorMessage; exit(0); break; //------------------------------------ // COPY / MOVE //------------------------------------ //------------------------------------ // COPY / MOVE //------------------------------------ case "copy": case "move": case "rename": case "delete": case "mkdir": case "mkfile": case "chmod": return AJXP_XMLWriter::sendMessage(null, $errorMessage, false); break; //------------------------------------ // UPLOAD //------------------------------------ //------------------------------------ // UPLOAD //------------------------------------ case "upload": $fancyLoader = false; foreach ($fileVars as $boxName => $boxData) { if ($boxName == "Filedata") { $fancyLoader = true; } } if ($fancyLoader) { header('HTTP/1.0 ' . $errorMessage); die('Error ' . $errorMessage); } else { print "<html><script language=\"javascript\">\n"; print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext('" . str_replace("'", "\\'", $errorMessage) . "');"; print "</script></html>"; } exit; break; default: break; } return parent::switchAction($action, $httpVars, $fileVars); }
protected function filecopy($srcFile, $destFile) { if (AJXP_MetaStreamWrapper::nodesUseSameWrappers($srcFile, $destFile)) { $srcFilePath = str_replace($this->urlBase, "", $srcFile); $destFilePath = str_replace($this->urlBase, "", $destFile); $destDirPath = dirname($destFilePath); list($connection, $remote_base_path) = sftpAccessWrapper::getSshConnection($srcFile); $remoteSrc = $remote_base_path . $srcFilePath; $remoteDest = $remote_base_path . $destDirPath; $this->logDebug("SSH2 CP", array("cmd" => 'cp ' . $remoteSrc . ' ' . $remoteDest)); ssh2_exec($connection, 'cp ' . $remoteSrc . ' ' . $remoteDest); AJXP_Controller::applyHook("node.change", array(new AJXP_Node($srcFile), new AJXP_Node($destFile), true)); } else { parent::filecopy($srcFile, $destFile); } }
public function makeSharedRepositoryOptions($httpVars, $repository) { $newOptions = parent::makeSharedRepositoryOptions($httpVars, $repository); $newOptions["CONTAINER"] = $this->repository->getOption("CONTAINER"); return $newOptions; }
/** * @return zipfile */ function makeZip($src, $dest, $basedir) { @set_time_limit(0); require_once AJXP_BIN_FOLDER . "/pclzip.lib.php"; $filePaths = array(); foreach ($src as $item) { $realFile = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $this->urlBase . "/" . $item); $realFile = AJXP_Utils::securePath($realFile); $basedir = trim(dirname($realFile)); $filePaths[] = array(PCLZIP_ATT_FILE_NAME => $realFile, PCLZIP_ATT_FILE_NEW_SHORT_NAME => basename($item)); } AJXP_Logger::debug("Pathes", $filePaths); AJXP_Logger::debug("Basedir", array($basedir)); self::$filteringDriverInstance = $this; $archive = new PclZip($dest); $vList = $archive->create($filePaths, PCLZIP_OPT_REMOVE_PATH, $basedir, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_ADD_TEMP_FILE_ON, PCLZIP_CB_PRE_ADD, 'zipPreAddCallback'); if (!$vList) { throw new Exception("Zip creation error : ({$dest}) " . $archive->errorInfo(true)); } self::$filteringDriverInstance = null; return $vList; }