|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the TYPO3 CMS project. |
|
7
|
|
|
* |
|
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
10
|
|
|
* of the License, or any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please read the |
|
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
14
|
|
|
* |
|
15
|
|
|
* The TYPO3 project - inspiring people to share! |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Form\Domain\Configuration; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; |
|
21
|
|
|
use TYPO3\CMS\Core\Crypto\Random; |
|
22
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
|
23
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
24
|
|
|
use TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessing; |
|
25
|
|
|
use TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor; |
|
26
|
|
|
use TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\AddHmacDataConverter; |
|
27
|
|
|
use TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\ConverterDto; |
|
28
|
|
|
use TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\FinisherTranslationLanguageConverter; |
|
29
|
|
|
use TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\RemoveHmacDataConverter; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @internal |
|
33
|
|
|
*/ |
|
34
|
|
|
class FormDefinitionConversionService implements SingletonInterface |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Add a new value "_orig_<propertyName>" for each scalar property value |
|
39
|
|
|
* within the form definition as a sibling of the property key. |
|
40
|
|
|
* "_orig_<propertyName>" is an array which contains the property value |
|
41
|
|
|
* and a hmac hash for the property value. |
|
42
|
|
|
* "_orig_<propertyName>" will be used to validate the form definition on saving. |
|
43
|
|
|
* @see \TYPO3\CMS\Form\Domain\Configuration\FormDefinitionValidationService::validateFormDefinitionProperties() |
|
44
|
|
|
* |
|
45
|
|
|
* @param array $formDefinition |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
public function addHmacData(array $formDefinition): array |
|
49
|
|
|
{ |
|
50
|
|
|
// Extend the hmac hashing key with a "per form editor session" unique key. |
|
51
|
|
|
$sessionToken = $this->generateSessionToken(); |
|
52
|
|
|
$this->persistSessionToken($sessionToken); |
|
53
|
|
|
|
|
54
|
|
|
$converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition); |
|
55
|
|
|
|
|
56
|
|
|
GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach( |
|
57
|
|
|
GeneralUtility::makeInstance( |
|
58
|
|
|
ArrayProcessing::class, |
|
59
|
|
|
'addHmacData', |
|
60
|
|
|
'(^identifier$|renderables\.([\d]+)\.identifier$)', |
|
61
|
|
|
GeneralUtility::makeInstance( |
|
62
|
|
|
AddHmacDataConverter::class, |
|
63
|
|
|
$converterDto, |
|
64
|
|
|
$sessionToken |
|
65
|
|
|
) |
|
66
|
|
|
) |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
return $converterDto->getFormDefinition(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Remove the "_orig_<propertyName>" values from the form definition. |
|
74
|
|
|
* |
|
75
|
|
|
* @param array $formDefinition |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
public function removeHmacData(array $formDefinition): array |
|
79
|
|
|
{ |
|
80
|
|
|
$converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition); |
|
81
|
|
|
|
|
82
|
|
|
GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach( |
|
83
|
|
|
GeneralUtility::makeInstance( |
|
84
|
|
|
ArrayProcessing::class, |
|
85
|
|
|
'removeHmacData', |
|
86
|
|
|
'(_orig_.*|.*\._orig_.*)\.hmac', |
|
87
|
|
|
GeneralUtility::makeInstance( |
|
88
|
|
|
RemoveHmacDataConverter::class, |
|
89
|
|
|
$converterDto |
|
90
|
|
|
) |
|
91
|
|
|
) |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
return $converterDto->getFormDefinition(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Migrate various finisher options |
|
99
|
|
|
* |
|
100
|
|
|
* @param array $formDefinition |
|
101
|
|
|
* @return array |
|
102
|
|
|
*/ |
|
103
|
|
|
public function migrateFinisherConfiguration(array $formDefinition): array |
|
104
|
|
|
{ |
|
105
|
|
|
$converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition); |
|
106
|
|
|
|
|
107
|
|
|
GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach( |
|
108
|
|
|
GeneralUtility::makeInstance( |
|
109
|
|
|
ArrayProcessing::class, |
|
110
|
|
|
'migrateFinisherLanguageSettings', |
|
111
|
|
|
'^finishers\.([\d]+)\.options.translation.language$', |
|
112
|
|
|
GeneralUtility::makeInstance( |
|
113
|
|
|
FinisherTranslationLanguageConverter::class, |
|
114
|
|
|
$converterDto |
|
115
|
|
|
) |
|
116
|
|
|
) |
|
117
|
|
|
); |
|
118
|
|
|
|
|
119
|
|
|
return $converterDto->getFormDefinition(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param string $sessionToken |
|
124
|
|
|
*/ |
|
125
|
|
|
protected function persistSessionToken(string $sessionToken) |
|
126
|
|
|
{ |
|
127
|
|
|
$this->getBackendUser()->setAndSaveSessionData('extFormProtectionSessionToken', $sessionToken); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Generates the random token which is used in the hash for the form tokens. |
|
132
|
|
|
* |
|
133
|
|
|
* @return string |
|
134
|
|
|
*/ |
|
135
|
|
|
protected function generateSessionToken() |
|
136
|
|
|
{ |
|
137
|
|
|
return GeneralUtility::makeInstance(Random::class)->generateRandomHexString(64); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return BackendUserAuthentication |
|
142
|
|
|
*/ |
|
143
|
|
|
protected function getBackendUser(): BackendUserAuthentication |
|
144
|
|
|
{ |
|
145
|
|
|
return $GLOBALS['BE_USER']; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|