[TASK] Decouple security report from install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Report / InstallStatusReport.php
1 <?php
2 namespace TYPO3\CMS\Install\Report;
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\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Reports\Status;
20 use TYPO3\CMS\Install\Service\Exception;
21
22 /**
23 * Provides an installation status report
24 *
25 * @author Ingo Renner <ingo@typo3.org>
26 */
27 class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface {
28
29 protected $reportList = 'FileSystem,RemainingUpdates,NewVersion';
30
31 /**
32 * Compiles a collection of system status checks as a status report.
33 *
34 * @return Status[]
35 */
36 public function getStatus() {
37 $reports = array();
38 $reportMethods = explode(',', $this->reportList);
39 foreach ($reportMethods as $reportMethod) {
40 $reports[$reportMethod] = $this->{'get' . $reportMethod . 'Status'}();
41 }
42 return $reports;
43 }
44
45 /**
46 * Checks for several directories being writable.
47 *
48 * @return \TYPO3\CMS\Reports\Status Indicates status of the file system
49 */
50 protected function getFileSystemStatus() {
51 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_writable');
52 $message = '';
53 $severity = Status::OK;
54 // Requirement level
55 // -1 = not required, but if it exists may be writable or not
56 // 0 = not required, if it exists the dir should be writable
57 // 1 = required, don't has to be writable
58 // 2 = required, has to be writable
59 $checkWritable = array(
60 'typo3temp/' => 2,
61 'typo3temp/pics/' => 2,
62 'typo3temp/temp/' => 2,
63 'typo3temp/llxml/' => 2,
64 'typo3temp/cs/' => 2,
65 'typo3temp/GB/' => 2,
66 'typo3temp/locks/' => 2,
67 'typo3conf/' => 2,
68 'typo3conf/ext/' => 0,
69 'typo3conf/l10n/' => 0,
70 TYPO3_mainDir . 'ext/' => -1,
71 'uploads/' => 2,
72 'uploads/pics/' => 0,
73 'uploads/media/' => 0,
74 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] => -1,
75 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0
76 );
77 foreach ($checkWritable as $relPath => $requirementLevel) {
78 if (!@is_dir((PATH_site . $relPath))) {
79 // If the directory is missing, try to create it
80 GeneralUtility::mkdir(PATH_site . $relPath);
81 }
82 if (!@is_dir((PATH_site . $relPath))) {
83 if ($requirementLevel > 0) {
84 // directory is required
85 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_missingDirectory');
86 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />';
87 $severity = Status::ERROR;
88 } else {
89 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExist'), $relPath);
90 if ($requirementLevel == 0) {
91 $message .= ' ' . $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldAlsoBeWritable');
92 }
93 $message .= '<br />';
94 if ($severity < Status::WARNING) {
95 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_nonExistingDirectory');
96 $severity = Status::WARNING;
97 }
98 }
99 } else {
100 if (!is_writable((PATH_site . $relPath))) {
101 switch ($requirementLevel) {
102 case 0:
103 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldBeWritable'), (PATH_site . $relPath)) . '<br />';
104 if ($severity < Status::WARNING) {
105 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_recommendedWritableDirectory');
106 $severity = Status::WARNING;
107 }
108 break;
109 case 2:
110 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_requiredWritableDirectory');
111 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryMustBeWritable'), (PATH_site . $relPath)) . '<br />';
112 $severity = Status::ERROR;
113 break;
114 }
115 }
116 }
117 }
118 return GeneralUtility::makeInstance(Status::class, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_fileSystem'), $value, $message, $severity);
119 }
120
121 /**
122 * Checks if there are still updates to perform
123 *
124 * @return \TYPO3\CMS\Reports\Status Represents whether the installation is completely updated yet
125 */
126 protected function getRemainingUpdatesStatus() {
127 $value = $GLOBALS['LANG']->getLL('status_updateComplete');
128 $message = '';
129 $severity = Status::OK;
130 if (!GeneralUtility::compat_version(TYPO3_branch)) {
131 $value = $GLOBALS['LANG']->getLL('status_updateIncomplete');
132 $severity = Status::WARNING;
133 $url = BackendUtility::getModuleUrl('system_InstallInstall');
134 $message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.install_update'), '<a href="' . htmlspecialchars($url) . '">', '</a>');
135 }
136 return GeneralUtility::makeInstance(Status::class, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remainingUpdates'), $value, $message, $severity);
137 }
138
139
140 /**
141 * Checks if there is a new minor TYPO3 version to update to
142 *
143 * @return \TYPO3\CMS\Reports\Status Represents whether there is a new version available online
144 */
145 protected function getNewVersionStatus() {
146 $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
147 /** @var \TYPO3\CMS\Install\Service\CoreVersionService $coreVersionService */
148 $coreVersionService = $objectManager->get(\TYPO3\CMS\Install\Service\CoreVersionService::class);
149
150 // No updates for development versions
151 if (!$coreVersionService->isInstalledVersionAReleasedVersion()) {
152 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_isDevelopmentVersion'), Status::NOTICE);
153 }
154
155 // If fetching version matrix fails we can not do anything except print out the current version
156 try {
157 $coreVersionService->updateVersionMatrix();
158 } catch (Exception\RemoteFetchException $remoteFetchException) {
159 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remoteFetchException'), Status::NOTICE);
160 }
161
162 try {
163 $isUpdateAvailable = $coreVersionService->isYoungerPatchReleaseAvailable();
164 } catch (Exception\CoreVersionServiceException $coreVersionServiceException) {
165 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_patchLevelNotFoundInReleaseMatrix'), Status::WARNING);
166 }
167
168 if (!$isUpdateAvailable) {
169 // Everything is fine, working with the latest version
170 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, '', Status::OK);
171 }
172
173 // There is an update available
174 $newVersion = $coreVersionService->getYoungestPatchRelease();
175 if ($coreVersionService->isUpdateSecurityRelevant()) {
176 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersionSecurityRelevant'), $newVersion), Status::ERROR);
177 } else {
178 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersion'), $newVersion), Status::WARNING);
179 }
180 }
181
182 }