[TASK] Create .htaccess or web.config file upon installation
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / FolderStructure / DefaultFactory.php
1 <?php
2 namespace TYPO3\CMS\Install\FolderStructure;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Core\Environment;
18
19 /**
20 * Factory returns default folder structure object hierarchy
21 */
22 class DefaultFactory
23 {
24 /**
25 * Get default structure object hierarchy
26 *
27 * @return StructureFacadeInterface
28 */
29 public function getStructure()
30 {
31 $rootNode = new RootNode($this->getDefaultStructureDefinition(), null);
32 $structureFacade = new StructureFacade($rootNode);
33 return $structureFacade;
34 }
35
36 /**
37 * Default definition of folder and file structure with dynamic
38 * permission settings
39 *
40 * @return array
41 */
42 protected function getDefaultStructureDefinition(): array
43 {
44 $filePermission = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fileCreateMask'];
45 $directoryPermission = $GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'];
46
47 $structure = [
48 // Note that root node has no trailing slash like all others
49 'name' => Environment::getPublicPath(),
50 'targetPermission' => $directoryPermission,
51 'children' => [
52 [
53 'name' => 'typo3temp',
54 'type' => DirectoryNode::class,
55 'targetPermission' => $directoryPermission,
56 'children' => [
57 [
58 'name' => 'index.html',
59 'type' => FileNode::class,
60 'targetPermission' => $filePermission,
61 'targetContent' => '',
62 ],
63 [
64 'name' => 'assets',
65 'type' => DirectoryNode::class,
66 'targetPermission' => $directoryPermission,
67 'children' => [
68 [
69 'name' => 'compressed',
70 'type' => DirectoryNode::class,
71 'targetPermission' => $directoryPermission
72 ],
73 [
74 'name' => 'css',
75 'type' => DirectoryNode::class,
76 'targetPermission' => $directoryPermission
77 ],
78 [
79 'name' => 'js',
80 'type' => DirectoryNode::class,
81 'targetPermission' => $directoryPermission
82 ],
83 [
84 'name' => 'images',
85 'type' => DirectoryNode::class,
86 'targetPermission' => $directoryPermission
87 ],
88 [
89 'name' => '_processed_',
90 'type' => DirectoryNode::class,
91 'targetPermission' => $directoryPermission
92 ]
93 ]
94 ],
95 [
96 'name' => 'var',
97 'type' => DirectoryNode::class,
98 'targetPermission' => $directoryPermission,
99 'children' => [
100 [
101 'name' => '.htaccess',
102 'type' => FileNode::class,
103 'targetPermission' => $filePermission,
104 'targetContentFile' => Environment::getFrameworkBasePath() . '/install/Resources/Private/FolderStructureTemplateFiles/typo3temp-var-htaccess',
105 ],
106 [
107 'name' => 'charset',
108 'type' => DirectoryNode::class,
109 'targetPermission' => $directoryPermission,
110 ],
111 [
112 'name' => 'cache',
113 'type' => DirectoryNode::class,
114 'targetPermission' => $directoryPermission,
115 ],
116 [
117 'name' => 'lock',
118 'type' => DirectoryNode::class,
119 'targetPermission' => $directoryPermission,
120 ]
121 ]
122 ],
123 ],
124 ],
125 [
126 'name' => 'typo3conf',
127 'type' => DirectoryNode::class,
128 'targetPermission' => $directoryPermission,
129 'children' => [
130 [
131 'name' => 'ext',
132 'type' => DirectoryNode::class,
133 'targetPermission' => $directoryPermission,
134 ],
135 [
136 'name' => 'l10n',
137 'type' => DirectoryNode::class,
138 'targetPermission' => $directoryPermission,
139 ],
140 ],
141 ],
142 [
143 'name' => !empty($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) ? rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') : 'fileadmin',
144 'type' => DirectoryNode::class,
145 'targetPermission' => $directoryPermission,
146 'children' => [
147 [
148 'name' => '_temp_',
149 'type' => DirectoryNode::class,
150 'targetPermission' => $directoryPermission,
151 'children' => [
152 [
153 'name' => '.htaccess',
154 'type' => FileNode::class,
155 'targetPermission' => $filePermission,
156 'targetContentFile' => Environment::getFrameworkBasePath() . '/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-htaccess',
157 ],
158 [
159 'name' => 'index.html',
160 'type' => FileNode::class,
161 'targetPermission' => $filePermission,
162 'targetContentFile' => Environment::getFrameworkBasePath() . '/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html',
163 ],
164 ],
165 ],
166 [
167 'name' => 'user_upload',
168 'type' => DirectoryNode::class,
169 'targetPermission' => $directoryPermission,
170 'children' => [
171 [
172 'name' => '_temp_',
173 'type' => DirectoryNode::class,
174 'targetPermission' => $directoryPermission,
175 'children' => [
176 [
177 'name' => 'index.html',
178 'type' => FileNode::class,
179 'targetPermission' => $filePermission,
180 'targetContent' => '',
181 ],
182 [
183 'name' => 'importexport',
184 'type' => DirectoryNode::class,
185 'targetPermission' => $directoryPermission,
186 'children' => [
187 [
188 'name' => '.htaccess',
189 'type' => FileNode::class,
190 'targetPermission' => $filePermission,
191 'targetContentFile' => Environment::getFrameworkBasePath() . '/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-user_upload-temp-importexport-htaccess',
192 ],
193 [
194 'name' => 'index.html',
195 'type' => FileNode::class,
196 'targetPermission' => $filePermission,
197 'targetContentFile' => Environment::getFrameworkBasePath() . '/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html',
198 ],
199 ],
200 ],
201 ],
202 ],
203 [
204 'name' => 'index.html',
205 'type' => FileNode::class,
206 'targetPermission' => $filePermission,
207 'targetContent' => '',
208 ],
209 ],
210 ],
211 ],
212 ],
213 ],
214 ];
215
216 // Have a default .htaccess if running apache web server or a default web.config if running IIS
217 if (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === 0) {
218 $structure['children'][] = [
219 'name' => '.htaccess',
220 'type' => FileNode::class,
221 'targetPermission' => $filePermission,
222 'targetContentFile' => Environment::getPublicPath() . '/typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/root-htaccess',
223 ];
224 } elseif (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') === 0) {
225 $structure['children'][] = [
226 'name' => 'web.config',
227 'type' => FileNode::class,
228 'targetPermission' => $filePermission,
229 'targetContentFile' => Environment::getPublicPath() . '/typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/root-web-config',
230 ];
231 }
232
233 return $structure;
234 }
235 }