Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / classes / reports / class.tx_em_reports_extensionstatus.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 class tx_em_reports_ExtensionStatus implements tx_reports_StatusProvider {
29
30 /**
31 * @var string
32 */
33 protected $ok = '';
34
35 /**
36 * @var string
37 */
38 protected $error = '';
39
40 /**
41 * Determines the status of extension manager
42 *
43 * @return array List of statuses
44 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
45 */
46 public function getStatus() {
47 $this->ok = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_ok');
48 $this->error = t3lib_div::strtoupper($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_error'));
49 $status = $this->getInsecuredExtensionsInSystem();
50
51 $statuses = array(
52 'mainRepositoryCheck' => $this->checkMainRepositoryCheck(),
53 'extensionsSecurityStatusNotInstalled' => $status[0],
54 'extensionsSecurityStatusInstalled' => $status[1],
55 );
56
57 return $statuses;
58 }
59
60 /**
61 * Checks main repository in sys_ter (existance, has extensions / update older tha 7 days
62 *
63 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether
64 */
65 protected function checkMainRepositoryCheck() {
66 $value = $this->ok;
67 $severity = tx_reports_reports_status_Status::OK;
68 $message = '';
69
70 $tables = array_keys($GLOBALS{'TYPO3_DB'}->admin_get_tables());
71 if (!in_array('sys_ter', $tables)) {
72 $value = $this->error;
73 $severity = tx_reports_reports_status_Status::ERROR;
74 $message = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_sysTerNotFound');
75 } else {
76 $row = $GLOBALS{'TYPO3_DB'}->exec_SELECTgetSingleRow(
77 '*', 'sys_ter', 'uid=1'
78 );
79 if (!is_array($row) || $row['title'] !== 'TYPO3.org Main Repository') {
80 $value = $this->error;
81 $severity = tx_reports_reports_status_Status::ERROR;
82 $message = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_MainRepositoryNotFound');
83 } else {
84 if ($row['extCount'] == 0) {
85 $value = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_NoExtensionsFound');
86 $severity = tx_reports_reports_status_Status::WARNING;
87 $message = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_MainRepositoryNoExtensions');
88 } else {
89 if ($row['lastUpdated'] < $GLOBALS['EXEC_TIME'] - (3600*24*7)) {
90 $value = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_ExtensionsNotUpToDate');
91 $severity = tx_reports_reports_status_Status::NOTICE;
92 $message = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_MainRepositoryOldList');
93 }
94 }
95 }
96 }
97
98 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
99 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_StatusMainRepository'),
100 $value,
101 $message,
102 $severity
103 );
104 }
105
106
107 /**
108 * Checks if there are insecure extensions in system
109 *
110 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether
111 */
112 protected function getInsecuredExtensionsInSystem() {
113 $value = array(
114 $this->ok,
115 $this->ok
116 );
117 $message = array('', '');
118 $severity = array(tx_reports_reports_status_Status::OK, tx_reports_reports_status_Status::OK);
119 $initialMessage = array(
120 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_insecureInstalledExtensions') . '<br><br>',
121 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_insecureExistingExtensions') . '<br><br>',
122 );
123 $extensionList = array();
124 $installedExtensionList = array();
125 $extensionCompareList = array();
126 $unsecureList = array();
127
128 /** @var $list tx_em_Extensions_List */
129 $list = t3lib_div::makeInstance('tx_em_Extensions_List');
130 $extList = $list->getInstalledExtensions(TRUE);
131
132 foreach ($extList as $extension) {
133 $extensionList[] = '"' . $extension['extkey'] . '"';
134 $extensionCompareList[] = $extension['extkey'] . '|' . $extension['version'];
135 if ($extension['installed']) {
136 $installedExtensionList[] = $extension['extkey'];
137 }
138 }
139
140 // prepare flat list of extensions for sql
141 $flatList = implode(',', $extensionList);
142 // get insecure extensions from database
143 $insecureListRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
144 'extkey, version',
145 'cache_extensions',
146 'reviewstate=-1 and extkey IN(' . $flatList . ')'
147 );
148 foreach ($insecureListRows as $row) {
149 $unsecureList[] = $row['extkey'] . '|' . $row['version'];
150 }
151
152 $resultArray = array_intersect($extensionCompareList, $unsecureList);
153
154 if (count($resultArray) > 0) {
155 $count = array(0, 0);
156 foreach ($resultArray as $result) {
157 $temp = explode('|', $result);
158 $index = in_array($temp[0], $installedExtensionList) ? 0 : 1;
159 $severity[$index] = $index === 0 ? tx_reports_reports_status_Status::ERROR : tx_reports_reports_status_Status::WARNING;
160 $count[$index]++;
161 if ($message[$index] === '') {
162 $message[$index] = $initialMessage[$index];
163 }
164 $message[$index] .= '<strong>' . $temp[0] . '</strong> (version ' . $temp[1] . ')<br>';
165 }
166 if ($count[0]) {
167 $value[0] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_insecureExtensionsFound'), $count[0]);
168 }
169 if ($count[1]) {
170 $value[1] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_insecureExtensionsFound'), $count[1]);
171 }
172 }
173
174 $status[0] = t3lib_div::makeInstance('tx_reports_reports_status_Status',
175 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_StatusInstalledExtensions'),
176 $value[0],
177 $message[0],
178 $severity[0]
179 );
180
181 $status[1] = t3lib_div::makeInstance('tx_reports_reports_status_Status',
182 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_StatusExistingExtensions'),
183 $value[1],
184 $message[1],
185 $severity[1]
186 );
187
188 return $status;
189 }
190
191 }
192
193 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/em/classes/reports/class.tx_em_reports_extensionstatus.php'])) {
194 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/em/classes/reports/class.tx_em_reports_extensionstatus.php']);
195 }
196
197 ?>