TYPO3 API  SVNRelease
class.tx_em_reports_extensionstatus.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010 Steffen Kamper <steffen@typo3.org>
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 
00028 class tx_em_reports_ExtensionStatus  implements tx_reports_StatusProvider {
00029 
00030     /**
00031      * @var string
00032      */
00033     protected $ok = '';
00034 
00035     /**
00036      * @var string
00037      */
00038     protected $upToDate = '';
00039 
00040     /**
00041      * @var string
00042      */
00043     protected $error = '';
00044 
00045     /**
00046      * Determines the status of extension manager
00047      *
00048      * @return  array   List of statuses
00049      * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
00050      */
00051     public function getStatus() {
00052         $this->ok = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_ok');
00053         $this->upToDate = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_uptodate');
00054         $this->error = t3lib_div::strtoupper($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_error'));
00055         $status = $this->getInsecuredExtensionsInSystem();
00056 
00057         $statuses = array(
00058             'mainRepositoryCheck' => $this->checkMainRepositoryCheck(),
00059             'extensionsSecurityStatusNotInstalled' => $status[0],
00060             'extensionsSecurityStatusInstalled' => $status[1],
00061         );
00062 
00063         return $statuses;
00064     }
00065 
00066     /**
00067      * Checks main repository in sys_ter (existance, has extensions / update older tha 7 days
00068      *
00069      * @return  tx_reports_reports_status_Status    An tx_reports_reports_status_Status object representing whether
00070      */
00071     protected function checkMainRepositoryCheck() {
00072         $value = $this->ok;
00073         $severity = tx_reports_reports_status_Status::OK;
00074         $message = '';
00075 
00076         $tables = array_keys($GLOBALS{'TYPO3_DB'}->admin_get_tables());
00077         if (!in_array('sys_ter', $tables)) {
00078             $value = $this->error;
00079             $severity = tx_reports_reports_status_Status::ERROR;
00080             $message = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_sysTerNotFound');
00081         } else {
00082             $row = $GLOBALS{'TYPO3_DB'}->exec_SELECTgetSingleRow(
00083                 '*', 'sys_ter', 'uid=1'
00084             );
00085             if (!is_array($row) || $row['title'] !== 'TYPO3.org Main Repository') {
00086                 $value = $this->error;
00087                 $severity = tx_reports_reports_status_Status::ERROR;
00088                 $message = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_MainRepositoryNotFound');
00089             } else {
00090                 if ($row['extCount'] == 0) {
00091                     $value = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_NoExtensionsFound');
00092                     $severity = tx_reports_reports_status_Status::WARNING;
00093                     $message = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_MainRepositoryNoExtensions');
00094                 } else {
00095                     if ($row['lastUpdated'] < $GLOBALS['EXEC_TIME'] - (3600*24*7)) {
00096                         $value = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_ExtensionsNotUpToDate');
00097                         $severity = tx_reports_reports_status_Status::NOTICE;
00098                         $message = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_MainRepositoryOldList');
00099                     } else {
00100                         $value = $this->upToDate;
00101                     }
00102                 }
00103             }
00104         }
00105 
00106         return t3lib_div::makeInstance('tx_reports_reports_status_Status',
00107             $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_StatusMainRepository'),
00108             $value,
00109             $message,
00110             $severity
00111         );
00112     }
00113 
00114 
00115     /**
00116      * Checks if there are insecure extensions in system
00117      *
00118      * @return  tx_reports_reports_status_Status    An tx_reports_reports_status_Status object representing whether
00119      */
00120     protected function getInsecuredExtensionsInSystem() {
00121         $value    = array(
00122             $this->ok,
00123             $this->ok
00124         );
00125         $message  = array('', '');
00126         $severity = array(tx_reports_reports_status_Status::OK, tx_reports_reports_status_Status::OK);
00127        $initialMessage = array(
00128            $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_insecureInstalledExtensions') . '<br><br>',
00129            $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_insecureExistingExtensions') . '<br><br>',
00130        );
00131         $extensionList = array();
00132         $installedExtensionList = array();
00133         $extensionCompareList = array();
00134         $unsecureList = array();
00135 
00136         /** @var $list tx_em_Extensions_List */
00137         $list = t3lib_div::makeInstance('tx_em_Extensions_List');
00138         $extList = $list->getInstalledExtensions(TRUE);
00139 
00140         foreach ($extList as $extension) {
00141             $extensionList[] = '"' . $extension['extkey'] . '"';
00142             $extensionCompareList[] = $extension['extkey'] . '|' . $extension['version'];
00143             if ($extension['installed']) {
00144                 $installedExtensionList[] = $extension['extkey'];
00145             }
00146         }
00147 
00148             // prepare flat list of extensions for sql
00149         $flatList = implode(',', $extensionList);
00150             // get insecure extensions from database
00151         $insecureListRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00152             'extkey, version',
00153             'cache_extensions',
00154             'reviewstate=-1 and extkey IN(' . $flatList . ')'
00155         );
00156         foreach ($insecureListRows as $row) {
00157             $unsecureList[] = $row['extkey'] . '|' . $row['version'];
00158         }
00159 
00160         $resultArray = array_intersect($extensionCompareList, $unsecureList);
00161 
00162         if (count($resultArray) > 0) {
00163             $count = array(0, 0);
00164             foreach ($resultArray as $result) {
00165                 $temp = explode('|', $result);
00166                 $index = in_array($temp[0], $installedExtensionList) ? 0 : 1;
00167                 $severity[$index] = $index === 0 ? tx_reports_reports_status_Status::ERROR : tx_reports_reports_status_Status::WARNING;
00168                 $count[$index]++;
00169                 if ($message[$index] === '') {
00170                     $message[$index] = $initialMessage[$index];
00171                 }
00172                 $message[$index] .= '<strong>' . $temp[0] . '</strong> (version ' . $temp[1] . ')<br>';
00173             }
00174             if ($count[0]) {
00175                 $value[0] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_insecureExtensionsFound'), $count[0]);
00176             }
00177             if ($count[1]) {
00178                 $value[1] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_insecureExtensionsFound'), $count[1]);
00179             }
00180         }
00181 
00182         $status[0] = t3lib_div::makeInstance('tx_reports_reports_status_Status',
00183             $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_StatusInstalledExtensions'),
00184             $value[0],
00185             $message[0],
00186             $severity[0]
00187         );
00188 
00189         $status[1] = t3lib_div::makeInstance('tx_reports_reports_status_Status',
00190             $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:reports_StatusExistingExtensions'),
00191             $value[1],
00192             $message[1],
00193             $severity[1]
00194         );
00195 
00196         return $status;
00197     }
00198 
00199 }
00200 
00201 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/em/classes/reports/class.tx_em_reports_extensionstatus.php'])) {
00202     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/em/classes/reports/class.tx_em_reports_extensionstatus.php']);
00203 }
00204 
00205 ?>