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

Commit

Permalink
Split Utils into many smaller classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 24, 2016
1 parent b576e43 commit 15502ce
Show file tree
Hide file tree
Showing 148 changed files with 3,239 additions and 2,578 deletions.
6 changes: 3 additions & 3 deletions core/src/conf/bootstrap_context.php
Expand Up @@ -125,14 +125,14 @@ function pydioAutoloader($className)

include_once(AJXP_INSTALL_PATH . "/core/compat.php");

use Pydio\Core\Utils\Utils;
use Pydio\Core\Utils\ApplicationState;

Utils::safeIniSet("session.cookie_httponly", 1);
ApplicationState::safeIniSet("session.cookie_httponly", 1);

if (is_file(AJXP_CONF_PATH."/bootstrap_conf.php")) {
include(AJXP_CONF_PATH."/bootstrap_conf.php");
if (isSet($AJXP_INISET)) {
foreach($AJXP_INISET as $key => $value) Utils::safeIniSet($key, $value);
foreach($AJXP_INISET as $key => $value) ApplicationState::safeIniSet($key, $value);
}
if (defined('AJXP_LOCALE')) {
setlocale(LC_CTYPE, AJXP_LOCALE);
Expand Down
6 changes: 3 additions & 3 deletions core/src/core/doc/PREVIOUS_RELEASES
Expand Up @@ -2347,7 +2347,7 @@ Rework "regexp" in listUsersPaginated / getUsersCount in class.sqlAuthDriver.php
Use HTML base tag instead of the previous complicated "travel_path_to_root" mechanism...
New access point for managing users self-service operations (currently reset password)
Make custom sort function to make sure users are sorted (fix #279)
New variable AJXP_SANITIZE_FILENAME, to be less restrictive on the allowed characters than AJXP_SANITIZE_HTML_STRICT. Particularly, allow commas in filename.
New variable InputFilter::SANITIZE_FILENAME, to be less restrictive on the allowed characters than InputFilter::SANITIZE_HTML_STRICT. Particularly, allow commas in filename.
Login: trim username and password to avoid trailing and ending white space problems
Better API for get_my_feed. Ability to force recycle_bin creation in workspace share
Add node.share.create hooks
Expand Down Expand Up @@ -2564,7 +2564,7 @@ preg_replace(): The /e modifier is deprecated in PHP5.5
Fix #404
Fix #392, by adding PRE and POST callbacks to PclZip
skipSecureToken actions were not taken into accounts in external files.
Disable at last native autocompletion on share dialog, by removing name attribute. Styling of the Minisite, customize Logo Always sanitize user names as AJXP_SANITIZE_EMAILCHARS Users dashboard, revert styling of FetchedResultPane, was ugly. To be improved still.
Disable at last native autocompletion on share dialog, by removing name attribute. Styling of the Minisite, customize Logo Always sanitize user names as InputFilter::SANITIZE_EMAILCHARS Users dashboard, revert styling of FetchedResultPane, was ugly. To be improved still.
Detect if minisite logo is a binary or a real filepath
Fix log.sql for ipv6 logging
Add a paddingBottom when FilesList is in gridMode, to avoid hiding last line with scrollbar, fix #172
Expand Down Expand Up @@ -2861,7 +2861,7 @@ serialized data can contain null bytes, store them in blob (details)
New functions in to be implemented by conf plugins (save/load/clearTemporaryKey, pruneTemporaryKeys) (details)
Replace AJXP_REBASE if present in the html templates and passed in START_PARAMETERS (details)
FS: Pass __AJXP_ZIP_FLAT__ to makeZip function to force all files to be at level 0 Fix tabulator et splitter resizing issues Download Cart. (details)
New variable AJXP_SANITIZE_FILENAME, to be less restrictive on the allowed characters than AJXP_SANITIZE_HTML_STRICT. Particularly, allow commas in filename. (details)
New variable InputFilter::SANITIZE_FILENAME, to be less restrictive on the allowed characters than InputFilter::SANITIZE_HTML_STRICT. Particularly, allow commas in filename. (details)
New invisibleBar, and autoFoldOnEvent options on Splitter New tabsTips option on Tabulator Fix simpleTooltip positioning and style Rework layout here and there, implements the new behaviours, still to be tested and validated. (details)
Expand and fix widgets, add a mode for horizontal tabulator positioning. (details)

Expand Down
3 changes: 2 additions & 1 deletion core/src/core/src/lib/pclzip.lib.php
Expand Up @@ -26,6 +26,7 @@
// --------------------------------------------------------------------------------

// ----- Constants
use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\Utils;

if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
Expand Down Expand Up @@ -65,7 +66,7 @@
// define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
// define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
if (!defined('PCLZIP_TEMPORARY_DIR')) {
define( 'PCLZIP_TEMPORARY_DIR', Utils::getAjxpTmpDir().DIRECTORY_SEPARATOR );
define( 'PCLZIP_TEMPORARY_DIR', ApplicationState::getAjxpTmpDir() .DIRECTORY_SEPARATOR );
}

// ----- Optional threshold ratio for use of temporary files
Expand Down
1 change: 0 additions & 1 deletion core/src/core/src/pydio/Core/Controller/CliRunner.php
Expand Up @@ -24,7 +24,6 @@
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Utils\UnixProcess;
use Pydio\Log\Core\Logger;
use Pydio\Tasks\Task;
use Pydio\Tasks\TaskService;
Expand Down
Expand Up @@ -18,7 +18,7 @@
*
* The latest code can be found at <http://pyd.io/>.
*/
namespace Pydio\Core\Utils;
namespace Pydio\Core\Controller;

defined('AJXP_EXEC') or die( 'Access not allowed');
/**
Expand Down
37 changes: 19 additions & 18 deletions core/src/core/src/pydio/Core/Controller/XMLWriter.php
Expand Up @@ -24,8 +24,9 @@
use Pydio\Access\Core\IAjxpWrapperProvider;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\LocaleService;
use Pydio\Core\Utils\StatHelper;
use Pydio\Core\Utils\Utils;
use Pydio\Core\Utils\Vars\InputFilter;
use Pydio\Core\Utils\Vars\StatHelper;
use Pydio\Core\Utils\Vars\StringHelper;
use Pydio\Core\Services;
use Pydio\Core\Services\ConfService;

Expand Down Expand Up @@ -199,18 +200,18 @@ public static function renderNode($nodeName, $nodeLabel, $isLeaf, $metaData = ar
{
$string = "<tree";
$metaData["filename"] = $nodeName;
if(Utils::detectXSS($nodeName)) $metaData["filename"] = "/XSS Detected - Please contact your admin";
if(InputFilter::detectXSS($nodeName)) $metaData["filename"] = "/XSS Detected - Please contact your admin";
if (!isSet($metaData["text"])) {
if(Utils::detectXSS($nodeLabel)) $nodeLabel = "XSS Detected - Please contact your admin";
if(InputFilter::detectXSS($nodeLabel)) $nodeLabel = "XSS Detected - Please contact your admin";
$metaData["text"] = $nodeLabel;
}else{
if(Utils::detectXSS($metaData["text"])) $metaData["text"] = "XSS Detected - Please contact your admin";
if(InputFilter::detectXSS($metaData["text"])) $metaData["text"] = "XSS Detected - Please contact your admin";
}
$metaData["is_file"] = ($isLeaf?"true":"false");
$metaData["ajxp_im_time"] = time();
foreach ($metaData as $key => $value) {
if(Utils::detectXSS($value)) $value = "XSS Detected!";
$value = Utils::xmlEntities($value, true);
if(InputFilter::detectXSS($value)) $value = "XSS Detected!";
$value = StringHelper::xmlEntities($value, true);
$string .= " $key=\"$value\"";
}
if ($close) {
Expand Down Expand Up @@ -286,7 +287,7 @@ public static function replaceAjxpXmlKeywords($xml, $stripSpaces = false)
if (array_key_exists($messId, $confMessages)) {
$message = $confMessages[$messId];
}
$xml = str_replace("CONF_MESSAGE[$messId]", Utils::xmlEntities($message), $xml);
$xml = str_replace("CONF_MESSAGE[$messId]", StringHelper::xmlEntities($message), $xml);
}
}
if (preg_match_all("/MIXIN_MESSAGE(\[.*?\])/", $xml, $matches, PREG_SET_ORDER)) {
Expand All @@ -296,7 +297,7 @@ public static function replaceAjxpXmlKeywords($xml, $stripSpaces = false)
if (array_key_exists($messId, $confMessages)) {
$message = $confMessages[$messId];
}
$xml = str_replace("MIXIN_MESSAGE[$messId]", Utils::xmlEntities($message), $xml);
$xml = str_replace("MIXIN_MESSAGE[$messId]", StringHelper::xmlEntities($message), $xml);
}
}
if ($stripSpaces) {
Expand All @@ -318,8 +319,8 @@ public static function replaceAjxpXmlKeywords($xml, $stripSpaces = false)
*/
public static function reloadDataNode($nodePath="", $pendingSelection="", $print = true)
{
$nodePath = Utils::xmlEntities($nodePath, true);
$pendingSelection = Utils::xmlEntities($pendingSelection, true);
$nodePath = StringHelper::xmlEntities($nodePath, true);
$pendingSelection = StringHelper::xmlEntities($pendingSelection, true);
return XMLWriter::write("<reload_instruction object=\"data\" node=\"$nodePath\" file=\"$pendingSelection\"/>", $print);
}

Expand All @@ -341,7 +342,7 @@ public static function writeNodesDiff($diffNodes, $print = false)
if (isSet($diffNodes["REMOVE"]) && count($diffNodes["REMOVE"])) {
$buffer .= "<remove>";
foreach ($diffNodes["REMOVE"] as $nodePath) {
$nodePath = Utils::xmlEntities($nodePath, true);
$nodePath = StringHelper::xmlEntities($nodePath, true);
$buffer .= "<tree filename=\"$nodePath\" ajxp_im_time=\"".time()."\"/>";
}
$buffer .= "</remove>";
Expand Down Expand Up @@ -406,10 +407,10 @@ public static function requireAuth($print = true)
*/
public static function triggerBgAction($actionName, $parameters, $messageId, $print=true, $delay = 0)
{
$messageId = Utils::xmlEntities($messageId);
$messageId = StringHelper::xmlEntities($messageId);
$data = XMLWriter::write("<trigger_bg_action name=\"$actionName\" messageId=\"$messageId\" delay=\"$delay\">", $print);
foreach ($parameters as $paramName=>$paramValue) {
$paramValue = Utils::xmlEntities($paramValue);
$paramValue = StringHelper::xmlEntities($paramValue);
$data .= XMLWriter::write("<param name=\"$paramName\" value=\"$paramValue\"/>", $print);
}
$data .= XMLWriter::write("</trigger_bg_action>", $print);
Expand Down Expand Up @@ -469,7 +470,7 @@ public static function writeBookmarks($allBookmarks, $context, $print = true, $f
$buffer .= XMLWriter::renderNode($path, $title, false, array('icon' => "mime_empty.png"), true, false);
}
} else {
$buffer .= "<bookmark path=\"".Utils::xmlEntities($path, true)."\" title=\"".Utils::xmlEntities($title, true)."\"/>";
$buffer .= "<bookmark path=\"". StringHelper::xmlEntities($path, true) ."\" title=\"". StringHelper::xmlEntities($title, true) ."\"/>";
}
}
if($print) {
Expand Down Expand Up @@ -502,7 +503,7 @@ public static function sendFilesListComponentConfig($config)
public static function toXmlElement($tagName, $attributes, $xmlChildren = ""){
$buffer = "<$tagName ";
foreach ($attributes as $attName => $attValue){
$buffer.= "$attName=\"".Utils::xmlEntities($attValue)."\" ";
$buffer.= "$attName=\"". StringHelper::xmlEntities($attValue) ."\" ";
}
if(!strlen($xmlChildren)) {
$buffer .= "/>";
Expand All @@ -523,10 +524,10 @@ public static function sendMessage($logMessage, $errorMessage, $print = true)
{
if ($errorMessage == null) {
$messageType = "SUCCESS";
$message = Utils::xmlContentEntities($logMessage);
$message = StringHelper::xmlContentEntities($logMessage);
} else {
$messageType = "ERROR";
$message = Utils::xmlContentEntities($errorMessage);
$message = StringHelper::xmlContentEntities($errorMessage);
}
return XMLWriter::write("<message type=\"$messageType\">".$message."</message>", $print);
}
Expand Down
8 changes: 6 additions & 2 deletions core/src/core/src/pydio/Core/Http/Cli/AuthCliMiddleware.php
Expand Up @@ -34,14 +34,18 @@
use Pydio\Core\Services\RepositoryService;
use Pydio\Core\Services\RolesService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\TextEncoder;
use Pydio\Core\Utils\Utils;
use Pydio\Log\Core\Logger;
use Zend\Diactoros\Response;

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


/**
* Authenticatino middleware used in Command Line context
* @package Pydio\Core\Http\Cli
*/
class AuthCliMiddleware
{
/**
Expand Down Expand Up @@ -155,7 +159,7 @@ public static function handleRequest(ServerRequestInterface $requestInterface, R

$requestInterface = $requestInterface->withAttribute("action", $options["a"]);

if(UsersService::usersEnabled() && Utils::detectApplicationFirstRun()){
if(UsersService::usersEnabled() && ApplicationState::detectApplicationFirstRun()){
RolesService::bootSequence();
}

Expand Down
19 changes: 16 additions & 3 deletions core/src/core/src/pydio/Core/Http/Message/RegistryMessage.php
Expand Up @@ -23,11 +23,15 @@
use Pydio\Core\Controller\XMLWriter;
use Pydio\Core\Http\Response\JSONSerializableResponseChunk;
use Pydio\Core\Http\Response\XMLDocSerializableResponseChunk;
use Pydio\Core\Utils\Utils;
use Pydio\Core\Utils\ApplicationState;

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


/**
* Class RegistryMessage
* Send a piece or a full registry as XML or JSON
* @package Pydio\Core\Http\Message
*/
class RegistryMessage implements XMLDocSerializableResponseChunk, JSONSerializableResponseChunk
{
/**
Expand All @@ -50,6 +54,12 @@ class RegistryMessage implements XMLDocSerializableResponseChunk, JSONSerializab
*/
protected $renderedXML;

/**
* RegistryMessage constructor.
* @param $registry
* @param null $xPath
* @param null $xPathObject
*/
public function __construct($registry, $xPath = null, $xPathObject = null)
{
$this->registry = $registry;
Expand All @@ -58,6 +68,9 @@ public function __construct($registry, $xPath = null, $xPathObject = null)
}


/**
* @return string
*/
public function getCharset()
{
return "UTF-8";
Expand Down Expand Up @@ -85,7 +98,7 @@ public function toXML()

} else {

Utils::safeIniSet("zlib.output_compression", "4096");
ApplicationState::safeIniSet("zlib.output_compression", "4096");
$xml = XMLWriter::replaceAjxpXmlKeywords($this->registry->saveXML());

}
Expand Down
20 changes: 17 additions & 3 deletions core/src/core/src/pydio/Core/Http/Middleware/SapiMiddleware.php
Expand Up @@ -26,11 +26,15 @@

use Pydio\Core\Http\Response\SerializableResponseStream;
use Pydio\Core\Http\Server;
use Pydio\Core\Utils\Utils;
use Pydio\Core\Utils\Vars\InputFilter;

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


/**
* Class SapiMiddleware
* Main Middleware for Http requests
* @package Pydio\Core\Http\Middleware
*/
class SapiMiddleware implements ITopLevelMiddleware
{

Expand Down Expand Up @@ -68,6 +72,10 @@ public function handleRequest(ServerRequestInterface $request, ResponseInterface
$this->emitResponse($request, $response);
}

/**
* @param ServerRequestInterface $request
* @param ResponseInterface $responseInterface
*/
protected function parseRequestRouteAndParams(ServerRequestInterface &$request, ResponseInterface &$responseInterface){

$serverData = $request->getServerParams();
Expand All @@ -82,12 +90,18 @@ protected function parseRequestRouteAndParams(ServerRequestInterface &$request,
$action = (strpos($serverData["HTTP_ACCEPT"], "text/html") !== false ? "get_boot_gui" : "ping");
}
$request = $request
->withAttribute("action", Utils::sanitize($action, AJXP_SANITIZE_EMAILCHARS))
->withAttribute("action", InputFilter::sanitize($action, InputFilter::SANITIZE_EMAILCHARS))
->withAttribute("api", "session")
;

}

/**
* Output the response to the browser, if no headers were already sent.
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return void
*/
public function emitResponse(ServerRequestInterface $request, ResponseInterface $response){
if($response !== false && $response->getBody() && $response->getBody() instanceof SerializableResponseStream){
/**
Expand Down
Expand Up @@ -25,7 +25,7 @@
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Http\Server;
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Utils\Utils;
use Pydio\Core\Utils\Vars\StringHelper;

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

Expand Down Expand Up @@ -85,7 +85,7 @@ public static function generateSecureToken()
$_SESSION["SECURE_TOKENS"][] = $_SESSION["FORCE_SECURE_TOKEN"];
return $_SESSION["FORCE_SECURE_TOKEN"];
}
$newToken = Utils::generateRandomString(32);
$newToken = StringHelper::generateRandomString(32);
$_SESSION["SECURE_TOKENS"][] = $newToken;
return $newToken;
}
Expand Down
Expand Up @@ -33,7 +33,7 @@
use Pydio\Core\Services\RolesService;
use Pydio\Core\Services\SessionService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Utils\Utils;
use Pydio\Core\Utils\ApplicationState;
use Pydio\Log\Core\Logger;

defined('AJXP_EXEC') or die('Access not allowed');
Expand Down Expand Up @@ -98,7 +98,7 @@ public static function handleRequest(ServerRequestInterface &$requestInterface,
LocaleService::setLanguage($requestInterface->getCookieParams()["AJXP_lang"]);
}

if(UsersService::usersEnabled() && Utils::detectApplicationFirstRun()){
if(UsersService::usersEnabled() && ApplicationState::detectApplicationFirstRun()){
try{
RolesService::bootSequence();
}catch (PydioException $e){
Expand Down
Expand Up @@ -25,9 +25,9 @@
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\ApplicationState;
use Pydio\Core\Utils\Vars\StatHelper;
use Pydio\Core\Utils\TextEncoder;
use Pydio\Core\Utils\Utils;
use Pydio\Log\Core\Logger;
use Zend\Diactoros\ServerRequestFactory;

Expand Down Expand Up @@ -196,7 +196,7 @@ public function readFile($node = null, $filePath = null, $data = null, $headerTy
set_error_handler('Pydio\Access\Driver\StreamProvider\FS\download_exception_handler');
// required for IE, otherwise Content-disposition is ignored
if (ini_get('zlib.output_compression')) {
Utils::safeIniSet('zlib.output_compression', 'Off');
ApplicationState::safeIniSet('zlib.output_compression', 'Off');
}

$isFile = ($data !== null) && !$confGzip;
Expand Down

0 comments on commit 15502ce

Please sign in to comment.