Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative Download Name #131

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Classes/Aspects/PublicUrlAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
***************************************************************/

use TYPO3\CMS\Core\Resource;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -90,17 +90,17 @@ public function generatePublicUrl(
$queryParameterArray['p'] = $resourceObject->getUid();
$queryParameterArray['t'] = 'p';
}
$queryParameterArray['token'] = GeneralUtility::hmac(
$queryParameterArray['fal_token'] = GeneralUtility::hmac(
implode('|', $queryParameterArray),
'BeResourceStorageDumpFile'
);

// $urlData['publicUrl'] is passed by reference, so we can change that here and the value will be taken into account
$urlData['publicUrl'] = BackendUtility::getAjaxUrl(
'FalSecuredownload::publicUrl',
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$urlData['publicUrl'] = (string) $uriBuilder->buildUriFromRoute(
'ajax_dump_file',
$queryParameterArray,
false,
true
UriBuilder::ABSOLUTE_URL
);
}
}
Expand Down
13 changes: 10 additions & 3 deletions Classes/Configuration/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

namespace BeechIt\FalSecuredownload\Configuration;

use TYPO3\CMS\Core\Configuration\ExtensionConfiguration as ExtensionConfigurationCore;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Wrapper for the extension configuration
*/
Expand All @@ -42,14 +45,18 @@ private static function init()
{
if (!self::$isInitialized) {
self::$isInitialized = true;

$extensionConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fal_securedownload']);
if (class_exists(ExtensionConfigurationCore::class)) {
$extensionConfig = GeneralUtility::makeInstance(ExtensionConfigurationCore::class)->get('fal_securedownload');
} else {
// Fallback for 8LTS
$extensionConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fal_securedownload']);
}
self::$loginRedirectUrl = $extensionConfig['login_redirect_url'];
self::$noAccessRedirectUrl = $extensionConfig['no_access_redirect_url'];
self::$forceDownload = (bool)$extensionConfig['force_download'];
self::$forceDownloadForExt = $extensionConfig['force_download_for_ext'];
self::$trackDownloads = (bool)$extensionConfig['track_downloads'];
self::$resumableDownload = (bool)(isset($extensionConfig['resumable_download']) ? $extensionConfig['resumable_download'] : false);
self::$resumableDownload = (isset($extensionConfig['resumable_download']) ? (bool)$extensionConfig['resumable_download'] : false);
}
}

Expand Down
106 changes: 106 additions & 0 deletions Classes/ContextMenu/ItemProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace BeechIt\FalSecuredownload\ContextMenu;

/*
* This source file is proprietary property of Beech Applications B.V.
* Date: 11-1-19
* All code (c) Beech Applications B.V. all rights reserved
*/

use BeechIt\FalSecuredownload\Service\Utility;
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ItemProvider extends AbstractProvider
{

/**
* @var Folder
*/
protected $folder;

/**
* @return int
*/
public function getPriority(): int
{
return 90;
}

/**
* @return bool
*/
public function canHandle(): bool
{
return $this->table === 'sys_file' || $this->table === 'sys_file_storage';
}

/**
* Initialize file object
*/
protected function initialize()
{
parent::initialize();
$resource = ResourceFactory::getInstance()
->retrieveFileOrFolderObject($this->identifier);

if ($resource instanceof Folder
&& !$resource->getStorage()->isPublic()
&& in_array(
$resource->getRole(),
[Folder::ROLE_DEFAULT, Folder::ROLE_USERUPLOAD],
true
)
) {
$this->folder = $resource;
}
}

/**
* Adds the folder permission menu item for folder of a non-public storage
*
* @param array $items
* @return array
*/
public function addItems(array $items): array
{
$this->initialize();
if ($this->folder instanceof Folder) {

$items += $this->prepareItems([
'permissions_divider' => [
'type' => 'divider',
],
'permissions' => [
'label' => 'LLL:EXT:fal_securedownload/Resources/Private/Language/locallang_be.xlf:clickmenu.folderpermissions',
'iconIdentifier' => 'action-folder',
'callbackAction' => 'folderPermissions'
]
]);
}

return $items;
}

/**
* @param string $itemName
* @return array
*/
protected function getAdditionalAttributes(string $itemName): array
{
/** @var Utility $utility */
$utility = GeneralUtility::makeInstance(Utility::class);
$folderRecord = $utility->getFolderRecord($this->folder);

return [
'data-callback-module' => 'TYPO3/CMS/FalSecuredownload/ContextMenuActions',
'data-folder-record-uid' => $folderRecord['uid'] ?? 0,
'data-storage' => $this->folder->getStorage()->getUid(),
'data-folder' => $this->folder->getIdentifier(),
'data-folder-hash' => $this->folder->getHashedIdentifier(),
];
}
}
17 changes: 9 additions & 8 deletions Classes/Controller/BePublicUrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* All code (c) Beech Applications B.V. all rights reserved
*/

use TYPO3\CMS\Core\Http\AjaxRequestHandler;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Resource\ProcessedFileRepository;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -18,15 +19,14 @@
*/
class BePublicUrlController
{

/**
* Dump file content
* Copy from /sysext/core/Resources/PHP/FileDumpEID.php
*
* @param array $params
* @param AjaxRequestHandler $ajaxObj
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function dumpFile($params = [], AjaxRequestHandler $ajaxObj = null)
public function dumpFile(ServerRequestInterface $request, ResponseInterface $response)
{
$parameters = ['eID' => 'dumpFile'];
if (GeneralUtility::_GP('t')) {
Expand All @@ -40,7 +40,7 @@ public function dumpFile($params = [], AjaxRequestHandler $ajaxObj = null)
}

if (GeneralUtility::hmac(implode('|', $parameters),
'BeResourceStorageDumpFile') === GeneralUtility::_GP('token')
'BeResourceStorageDumpFile') === GeneralUtility::_GP('fal_token')
) {
if (isset($parameters['f'])) {
$file = ResourceFactory::getInstance()->getFileObject($parameters['f']);
Expand All @@ -52,7 +52,7 @@ public function dumpFile($params = [], AjaxRequestHandler $ajaxObj = null)
/** @var \TYPO3\CMS\Core\Resource\ProcessedFile $file */
$file = GeneralUtility::makeInstance(ProcessedFileRepository::class)->findByUid($parameters['p']);
if ($file->isDeleted()) {
$file = null;
HttpUtility::setResponseCodeAndExit(HttpUtility::HTTP_STATUS_404);
}
$orgFile = $file->getOriginalFile();
}
Expand All @@ -68,6 +68,7 @@ public function dumpFile($params = [], AjaxRequestHandler $ajaxObj = null)

ob_start();
$file->getStorage()->dumpFileContents($file);

exit;
} else {
HttpUtility::setResponseCodeAndExit(HttpUtility::HTTP_STATUS_403);
Expand Down
18 changes: 7 additions & 11 deletions Classes/Domain/Repository/ProcessedFileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ public function findByUid($uid)
throw new \InvalidArgumentException('uid has to be integer.', 1316779798);
}

if (version_compare(TYPO3_branch, '8.7', '>=')) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$row = $queryBuilder
->select('*')
->from($this->table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter((int)$uid, \PDO::PARAM_INT)))
->execute()
->fetch();
} else {
$row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $this->table, 'uid=' . (int)$uid);
}
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$row = $queryBuilder
->select('*')
->from($this->table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter((int)$uid, \PDO::PARAM_INT)))
->execute()
->fetch();

if (empty($row) || !is_array($row)) {
throw new \RuntimeException(
Expand Down
52 changes: 16 additions & 36 deletions Classes/FormEngine/DownloadStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Lang\LanguageService;
Expand All @@ -51,33 +50,22 @@ public function render()
return $this->resultArray;
}

if (version_compare(TYPO3_branch, '8.7', '>=')) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file');
$statistics = $queryBuilder
->selectLiteral(
$queryBuilder->getConnection()->getDatabasePlatform()->getCountExpression(
$queryBuilder->quoteIdentifier('tx_falsecuredownload_download.file')
) . ' AS ' . $queryBuilder->quoteIdentifier('cnt'))
->addSelect('sys_file.name')
->from('sys_file')
->join('sys_file', 'tx_falsecuredownload_download', 'tx_falsecuredownload_download',
$queryBuilder->expr()->eq('tx_falsecuredownload_download.file', $queryBuilder->quoteIdentifier('sys_file.uid'))
)
->where($queryBuilder->expr()->eq('tx_falsecuredownload_download.feuser', $queryBuilder->createNamedParameter((int)$row['uid'], \PDO::PARAM_INT)))
->groupBy('sys_file.name')
->orderBy('sys_file.name')
->execute()
->fetchAll();
} else {
$db = $this->getDatabase();
$statistics = $db->exec_SELECTgetRows(
'sys_file.name, count(tx_falsecuredownload_download.file) as cnt',
'sys_file JOIN tx_falsecuredownload_download ON tx_falsecuredownload_download.file = sys_file.uid
AND tx_falsecuredownload_download.feuser = ' . (int)$row['uid'],
'',
'sys_file.name'
);
}
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file');
$statistics = $queryBuilder
->selectLiteral(
$queryBuilder->getConnection()->getDatabasePlatform()->getCountExpression(
$queryBuilder->quoteIdentifier('tx_falsecuredownload_download.file')
) . ' AS ' . $queryBuilder->quoteIdentifier('cnt'))
->addSelect('sys_file.name')
->from('sys_file')
->join('sys_file', 'tx_falsecuredownload_download', 'tx_falsecuredownload_download',
$queryBuilder->expr()->eq('tx_falsecuredownload_download.file', $queryBuilder->quoteIdentifier('sys_file.uid'))
)
->where($queryBuilder->expr()->eq('tx_falsecuredownload_download.feuser', $queryBuilder->createNamedParameter((int)$row['uid'], \PDO::PARAM_INT)))
->groupBy('sys_file.name')
->orderBy('sys_file.name')
->execute()
->fetchAll();

$lang = $this->getLanguageService();
$markup = [];
Expand Down Expand Up @@ -110,12 +98,4 @@ protected function getLanguageService()
{
return $GLOBALS['LANG'];
}

/**
* @return DatabaseConnection
*/
protected function getDatabase()
{
return $GLOBALS['TYPO3_DB'];
}
}
10 changes: 6 additions & 4 deletions Classes/Hooks/AbstractBeButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
***************************************************************/

use BeechIt\FalSecuredownload\Service\Utility;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Abstract utility class for classes that want to add album add/edit buttons
* somewhere like a ClickMenuOptions class.
* Abstract utility class for classes that want to add BE buttons
* to edit folder permissions
*/
abstract class AbstractBeButtons
{
Expand Down Expand Up @@ -153,7 +153,9 @@ protected function buildAddUrl(Folder $folder)
protected function buildUrl(array $parameters)
{
$parameters['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
return BackendUtility::getModuleUrl('record_edit', $parameters);
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);

return $uriBuilder->buildUriFromRoute('record_edit', $parameters);
}

/**
Expand Down
Loading