Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix some extensions issues. Move methods from Utils and ConfService t…
Browse files Browse the repository at this point in the history
…o new StatHelper class. Utils should be broken down further.
  • Loading branch information
cdujeu committed Jun 20, 2016
1 parent b2bf0a8 commit dd19721
Show file tree
Hide file tree
Showing 27 changed files with 473 additions and 453 deletions.
33 changes: 21 additions & 12 deletions core/src/core/src/pydio/Core/Controller/XMLWriter.php
Expand Up @@ -22,19 +22,13 @@

use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\IAjxpWrapperProvider;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Model\RepositoryInterface;
use Pydio\Core\Model\UserInterface;
use Pydio\Core\Serializer\RepositoryXML;
use Pydio\Core\Services\LocaleService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Utils\StatHelper;
use Pydio\Core\Utils\Utils;
use Pydio\Core\Services;
use Pydio\Conf\Core\AbstractAjxpUser;
use Pydio\Core\Services\ConfService;
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Utils\TextEncoder;


defined('AJXP_EXEC') or die( 'Access not allowed');

Expand Down Expand Up @@ -88,6 +82,13 @@ public static function close($docNode="tree", $print = true)
}
}

/**
* Wrap xml inside a <tree>...</tree> document, including <?xml> declaration.
* @param $content
* @param string $docNode
* @param array $attributes
* @return string
*/
public static function wrapDocument($content, $docNode = "tree", $attributes = array()){

if(self::$headerSent !== false && self::$headerSent == $docNode) {
Expand Down Expand Up @@ -259,10 +260,10 @@ public static function replaceAjxpXmlKeywords($xml, $stripSpaces = false)
$xml = str_replace("AJXP_SERVER_ACCESS", AJXP_SERVER_ACCESS, $xml);
}
$xml = str_replace("AJXP_APPLICATION_TITLE", ConfService::getCoreConf("APPLICATION_TITLE"), $xml);
$xml = str_replace("AJXP_MIMES_EDITABLE", Utils::getAjxpMimes("editable"), $xml);
$xml = str_replace("AJXP_MIMES_IMAGE", Utils::getAjxpMimes("image"), $xml);
$xml = str_replace("AJXP_MIMES_AUDIO", Utils::getAjxpMimes("audio"), $xml);
$xml = str_replace("AJXP_MIMES_ZIP", Utils::getAjxpMimes("zip"), $xml);
$xml = str_replace("AJXP_MIMES_EDITABLE", StatHelper::getAjxpMimes("editable"), $xml);
$xml = str_replace("AJXP_MIMES_IMAGE", StatHelper::getAjxpMimes("image"), $xml);
$xml = str_replace("AJXP_MIMES_AUDIO", StatHelper::getAjxpMimes("audio"), $xml);
$xml = str_replace("AJXP_MIMES_ZIP", StatHelper::getAjxpMimes("zip"), $xml);
$authDriver = ConfService::getAuthDriverImpl();
if ($authDriver != NULL) {
$loginRedirect = $authDriver->getLoginRedirect();
Expand Down Expand Up @@ -415,6 +416,14 @@ public static function triggerBgAction($actionName, $parameters, $messageId, $pr
return $data;
}

/**
* Send directly JavaScript code to the client
* @param $jsCode
* @param $messageId
* @param bool $print
* @param int $delay
* @return string
*/
public static function triggerBgJSAction($jsCode, $messageId, $print=true, $delay = 0)
{
$data = XMLWriter::write("<trigger_bg_action name=\"javascript_instruction\" messageId=\"$messageId\" delay=\"$delay\">", $print);
Expand Down
Expand Up @@ -24,12 +24,17 @@
use Psr\Http\Message\ServerRequestInterface;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Http\Server;
use Pydio\Core\Services\ConfService;
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Utils\Utils;

defined('AJXP_EXEC') or die('Access not allowed');


/**
* Class SecureTokenMiddleware
* CSRF Prevention
* @package Pydio\Core\Http\Middleware
*/
class SecureTokenMiddleware
{

Expand All @@ -43,7 +48,15 @@ class SecureTokenMiddleware
*/
public static function handleRequest(\Psr\Http\Message\ServerRequestInterface $requestInterface, \Psr\Http\Message\ResponseInterface $responseInterface, callable $next = null){

$pluginsUnSecureActions = ConfService::getDeclaredUnsecureActions();
$pluginsUnSecureActions = PluginsService::searchManifestsWithCache("//action[@skipSecureToken]", function($nodes){
$res = array();
/** @var \DOMElement $node */
foreach ($nodes as $node) {
$res[] = $node->getAttribute("name");
}
return $res;
});

$pluginsUnSecureActions[] = "get_secure_token";
if (!in_array($requestInterface->getAttribute("action"), $pluginsUnSecureActions) && self::getSecureToken()) {
$params = $requestInterface->getParsedBody();
Expand Down
Expand Up @@ -25,6 +25,7 @@
use Pydio\Access\Driver\StreamProvider\FS\fsAccessWrapper;
use Pydio\Core\Controller\HTMLWriter;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Utils\StatHelper;
use Pydio\Core\Utils\TextEncoder;
use Pydio\Core\Utils\Utils;
use Pydio\Log\Core\AJXP_Logger;
Expand Down Expand Up @@ -191,7 +192,7 @@ public function readFile($node = null, $filePath = null, $data = null, $headerTy

} else if ($headerType == "image") {

header("Content-Type: ".Utils::getImageMimeType(basename($filePathOrData))."; name=\"".$localName."\"");
header("Content-Type: ". StatHelper::getImageMimeType(basename($filePathOrData)) ."; name=\"".$localName."\"");
header("Content-Length: ".$size);
header('Cache-Control: public');

Expand Down Expand Up @@ -219,7 +220,7 @@ public function readFile($node = null, $filePath = null, $data = null, $headerTy
$mimeType = trim($splitChar[0]);
$this->logDebug("Detected mime $mimeType for $realfile");
} else {
$mimeType = Utils::getStreamingMimeType(basename($filePathOrData));
$mimeType = StatHelper::getStreamingMimeType(basename($filePathOrData));
}
header('Content-type: '.$mimeType);
}
Expand Down
65 changes: 1 addition & 64 deletions core/src/core/src/pydio/Core/Services/ConfService.php
Expand Up @@ -21,17 +21,12 @@
namespace Pydio\Core\Services;


use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Access\Core\AJXP_MetaStreamWrapper;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Auth\Core\AbstractAuthDriver;
use Pydio\Cache\Core\AbstractCacheDriver;
use Pydio\Conf\Core\AbstractAjxpUser;
use Pydio\Conf\Core\AbstractConfDriver;

use Pydio\Core\Model\Context;

use Pydio\Core\Model\UserInterface;
use Pydio\Core\PluginFramework\CoreInstanceProvider;
use Pydio\Core\Utils\Utils;
use Pydio\Core\Utils\VarsFilter;
Expand Down Expand Up @@ -327,65 +322,7 @@ public static function zipCreationEnabled()
if(!self::zipEnabled()) return false;
return ConfService::getCoreConf("ZIP_CREATION");
}


/**
* MISC CONFS
*/
/**
* Get all registered extensions, from both the conf/extensions.conf.php and from the plugins
* @static
* @return
*/
public static function getRegisteredExtensions()
{
return self::getInstance()->getRegisteredExtensionsInst();
}
/**
* See static method
* @return
*/
public function getRegisteredExtensionsInst()
{
if (!isSet($this->configs["EXTENSIONS"])) {
$EXTENSIONS = array();
$RESERVED_EXTENSIONS = array();
include_once(AJXP_CONF_PATH."/extensions.conf.php");
$EXTENSIONS = array_merge($RESERVED_EXTENSIONS, $EXTENSIONS);
foreach ($EXTENSIONS as $key => $value) {
unset($EXTENSIONS[$key]);
$EXTENSIONS[$value[0]] = $value;
}
$nodes = PluginsService::getInstance(Context::emptyContext())->searchAllManifests("//extensions/extension", "nodes", true);
$res = array();
/** @var \DOMElement $node */
foreach ($nodes as $node) {
$res[$node->getAttribute("mime")] = array($node->getAttribute("mime"), $node->getAttribute("icon"), $node->getAttribute("messageId"));
}
if (count($res)) {
$EXTENSIONS = array_merge($EXTENSIONS, $res);
}
$this->configs["EXTENSIONS"] = $EXTENSIONS;
}
return $this->configs["EXTENSIONS"];
}
/**
* Get the actions that declare to skip the secure token in the plugins
* @static
* @return array
*/
public static function getDeclaredUnsecureActions()
{
return PluginsService::searchManifestsWithCache("//action[@skipSecureToken]", function($nodes){
$res = array();
/** @var \DOMElement $node */
foreach ($nodes as $node) {
$res[] = $node->getAttribute("name");
}
return $res;
});
}


/**
* Get a config by its name
* @static
Expand Down

0 comments on commit dd19721

Please sign in to comment.