17033.diff
| typo3/sysext/reports/reports/status/class.tx_reports_reports_status_status.php (working copy) | ||
|---|---|---|
| 99 | 99 |
public function getSeverity() {
|
| 100 | 100 |
return $this->severity; |
| 101 | 101 |
} |
| 102 | ||
| 103 |
/** |
|
| 104 |
* Creates a string representation of a status. |
|
| 105 |
* |
|
| 106 |
* @return string String representation of this status. |
|
| 107 |
*/ |
|
| 108 |
public function __toString() {
|
|
| 109 |
$severity = array( |
|
| 110 |
self::NOTICE => 'NOTE', |
|
| 111 |
self::INFO => 'INFO', |
|
| 112 |
self::OK => 'OK', |
|
| 113 |
self::WARNING => 'WARN', |
|
| 114 |
self::ERROR => 'ERR', |
|
| 115 |
); |
|
| 116 | ||
| 117 |
// max length 80 characters |
|
| 118 |
$stringRepresentation = |
|
| 119 |
str_pad('[' . $severity[$this->severity] . ']', 7) .
|
|
| 120 |
str_pad($this->title, 40) . ' - ' . |
|
| 121 |
substr($this->value, 0, 30); |
|
| 122 | ||
| 123 |
return $stringRepresentation; |
|
| 124 |
} |
|
| 102 | 125 |
} |
| 103 | 126 | |
| 104 | 127 | |
| typo3/sysext/reports/reports/locallang.xml (working copy) | ||
|---|---|---|
| 52 | 52 |
<label index="status_configuration_DeprecationLogSize">Your deprecation log file currently takes up %s.</label> |
| 53 | 53 |
<label index="status_updateTaskTitle">System Status Update</label> |
| 54 | 54 |
<label index="status_updateTaskDescription">Runs a system status check and sends notifications if problems have been found.</label> |
| 55 |
<label index="status_updateTaskField_notificationEmail">Notification Email Address</label> |
|
| 56 |
<label index="status_updateTaskField_notificationEmail_invlaid">Empty or invalid notification email address.</label> |
|
| 57 |
<label index="status_updateTask_email_subject">System Status Notification for site %s</label> |
|
| 58 |
<label index="status_updateTask_email_site">Site</label> |
|
| 59 |
<label index="status_updateTask_email_issues">Issues</label> |
|
| 55 | 60 |
</languageKey> |
| 56 | 61 |
</data> |
| 57 | 62 |
</T3locallang> |
| typo3/sysext/reports/ext_autoload.php (working copy) | ||
|---|---|---|
| 16 | 16 |
'tx_reports_reports_status_configurationstatus' => $extensionPath . 'reports/status/class.tx_reports_reports_status_configurationstatus.php', |
| 17 | 17 |
'tx_reports_reports_status_status' => $extensionPath . 'reports/status/class.tx_reports_reports_status_status.php', |
| 18 | 18 |
'tx_reports_tasks_systemstatusupdatetask' => $extensionPath . 'tasks/class.tx_reports_tasks_systemstatusupdatetask.php', |
| 19 |
'tx_reports_tasks_systemstatusupdatetasknotificationemailfield' => $extensionPath . 'tasks/class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php', |
|
| 19 | 20 |
); |
| 20 | 21 |
?> |
| typo3/sysext/reports/ext_localconf.php (working copy) | ||
|---|---|---|
| 6 | 6 |
} |
| 7 | 7 | |
| 8 | 8 |
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['tx_reports_tasks_SystemStatusUpdateTask'] = array( |
| 9 |
'extension' => $_EXTKEY, |
|
| 10 |
'title' => 'LLL:EXT:' . $_EXTKEY . '/reports/locallang.xml:status_updateTaskTitle', |
|
| 11 |
'description' => 'LLL:EXT:' . $_EXTKEY . '/reports/locallang.xml:status_updateTaskDescription' |
|
| 9 |
'extension' => $_EXTKEY, |
|
| 10 |
'title' => 'LLL:EXT:' . $_EXTKEY . '/reports/locallang.xml:status_updateTaskTitle', |
|
| 11 |
'description' => 'LLL:EXT:' . $_EXTKEY . '/reports/locallang.xml:status_updateTaskDescription', |
|
| 12 |
'additionalFields' => 'tx_reports_tasks_SystemStatusUpdateTaskNotificationEmailField' |
|
| 12 | 13 |
); |
| 13 | 14 | |
| 14 | 15 |
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages']['tx_reports_WarningMessagePostProcessor'] = 'EXT:reports/reports/status/class.tx_reports_reports_status_warningmessagepostprocessor.php:tx_reports_reports_status_WarningMessagePostProcessor'; |
| typo3/sysext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php (revision 0) | ||
|---|---|---|
| 1 |
<?php |
|
| 2 |
/*************************************************************** |
|
| 3 |
* Copyright notice |
|
| 4 |
* |
|
| 5 |
* (c) 2010 Ingo Renner <ingo@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 |
* |
|
| 17 |
* This script is distributed in the hope that it will be useful, |
|
| 18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 |
* GNU General Public License for more details. |
|
| 21 |
* |
|
| 22 |
* This copyright notice MUST APPEAR in all copies of the script! |
|
| 23 |
***************************************************************/ |
|
| 24 | ||
| 25 | ||
| 26 |
/** |
|
| 27 |
* Additional field to set the notification email address(es) for system health |
|
| 28 |
* issue notifications. |
|
| 29 |
* |
|
| 30 |
* @author Ingo Renner <ingo@typo3.org> |
|
| 31 |
* @package TYPO3 |
|
| 32 |
* @subpackage reports |
|
| 33 |
*/ |
|
| 34 |
class tx_reports_tasks_SystemStatusUpdateTaskNotificationEmailField implements tx_scheduler_AdditionalFieldProvider {
|
|
| 35 | ||
| 36 | ||
| 37 |
/** |
|
| 38 |
* Additional fields |
|
| 39 |
* |
|
| 40 |
* @var array |
|
| 41 |
*/ |
|
| 42 |
protected $fields = array('notificationEmail');
|
|
| 43 | ||
| 44 |
/** |
|
| 45 |
* Field prefix. |
|
| 46 |
* |
|
| 47 |
* @var string |
|
| 48 |
*/ |
|
| 49 |
protected $fieldPrefix = 'SystemStatusUpdate'; |
|
| 50 | ||
| 51 |
/** |
|
| 52 |
* Gets additional fields to render in the form to add/edit a task |
|
| 53 |
* |
|
| 54 |
* @param array $taskInfo Values of the fields from the add/edit task form |
|
| 55 |
* @param tx_scheduler_Task $task The task object being eddited. Null when adding a task! |
|
| 56 |
* @param tx_scheduler_Module $schedulerModule Reference to the scheduler backend module |
|
| 57 |
* @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
|
|
| 58 |
*/ |
|
| 59 |
public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $schedulerModule) {
|
|
| 60 |
$fields = array('notificationEmail');
|
|
| 61 | ||
| 62 |
if ($schedulerModule->CMD == 'edit') {
|
|
| 63 |
$taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail(); |
|
| 64 |
} |
|
| 65 | ||
| 66 |
$additionalFields = array(); |
|
| 67 |
foreach ($fields as $field) {
|
|
| 68 |
$fieldName = $this->getFullFieldName($field); |
|
| 69 |
$fieldId = 'task_' . $fieldName; |
|
| 70 |
$fieldHtml = '<input type="text" ' |
|
| 71 |
. 'name="tx_scheduler[' . $fieldName . ']" ' |
|
| 72 |
. 'id="' . $fieldId . '" ' |
|
| 73 |
. 'value="' . $taskInfo[$fieldName] . '" />'; |
|
| 74 | ||
| 75 |
$additionalFields[$fieldId] = array( |
|
| 76 |
'code' => $fieldHtml, |
|
| 77 |
'label' => 'LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_' . $field, |
|
| 78 |
'cshKey' => '', |
|
| 79 |
'cshLabel' => $fieldId |
|
| 80 |
); |
|
| 81 |
} |
|
| 82 | ||
| 83 |
return $additionalFields; |
|
| 84 |
} |
|
| 85 | ||
| 86 |
/** |
|
| 87 |
* Validates the additional fields' values |
|
| 88 |
* |
|
| 89 |
* @param array $submittedData An array containing the data submitted by the add/edit task form |
|
| 90 |
* @param tx_scheduler_Module $schedulerModule Reference to the scheduler backend module |
|
| 91 |
* @return boolean True if validation was ok (or selected class is not relevant), false otherwise |
|
| 92 |
*/ |
|
| 93 |
public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $schedulerModule) {
|
|
| 94 |
$validInput = TRUE; |
|
| 95 |
$submittedData[$this->fieldPrefix . 'NotificationEmail'] = trim($submittedData[$this->fieldPrefix . 'NotificationEmail']); |
|
| 96 | ||
| 97 |
if ( |
|
| 98 |
empty($submittedData[$this->fieldPrefix . 'NotificationEmail']) |
|
| 99 |
|| !filter_var($submittedData[$this->fieldPrefix . 'NotificationEmail'], FILTER_VALIDATE_EMAIL) |
|
| 100 |
) {
|
|
| 101 |
$schedulerModule->addMessage( |
|
| 102 |
$GLOBALS['LANG']->sL('LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_notificationEmail_invalid'),
|
|
| 103 |
t3lib_FlashMessage::ERROR |
|
| 104 |
); |
|
| 105 |
$validInput = FALSE; |
|
| 106 |
} |
|
| 107 | ||
| 108 |
return $validInput; |
|
| 109 |
} |
|
| 110 | ||
| 111 |
/** |
|
| 112 |
* Takes care of saving the additional fields' values in the task's object |
|
| 113 |
* |
|
| 114 |
* @param array $submittedData An array containing the data submitted by the add/edit task form |
|
| 115 |
* @param tx_scheduler_Task $task Reference to the scheduler backend module |
|
| 116 |
* @return void |
|
| 117 |
*/ |
|
| 118 |
public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) {
|
|
| 119 | ||
| 120 |
if (!($task instanceof tx_reports_tasks_SystemStatusUpdateTask)) {
|
|
| 121 |
throw new InvalidArgumentException( |
|
| 122 |
'Expected a task of type tx_reports_tasks_SystemStatusUpdateTask, but got ' . get_class($task), |
|
| 123 |
1295012802 |
|
| 124 |
); |
|
| 125 |
} |
|
| 126 | ||
| 127 |
$task->setNotificationEmail($submittedData[$this->fieldPrefix . 'NotificationEmail']); |
|
| 128 |
} |
|
| 129 | ||
| 130 |
/** |
|
| 131 |
* Constructs the full field name which can be used in HTML markup. |
|
| 132 |
* |
|
| 133 |
* @param string $fieldName A raw field name |
|
| 134 |
* @return string Field name ready to use in HTML markup |
|
| 135 |
*/ |
|
| 136 |
protected function getFullFieldName($fieldName) {
|
|
| 137 |
return $this->fieldPrefix . ucfirst($fieldName); |
|
| 138 |
} |
|
| 139 | ||
| 140 |
} |
|
| 141 | ||
| 142 | ||
| 143 |
if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php'])) {
|
|
| 144 |
include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php']); |
|
| 145 |
} |
|
| 146 | ||
| 147 |
?> |
|
| typo3/sysext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetask.php (working copy) | ||
|---|---|---|
| 33 | 33 |
class tx_reports_tasks_SystemStatusUpdateTask extends tx_scheduler_Task {
|
| 34 | 34 | |
| 35 | 35 |
/** |
| 36 |
* Email address to send email notification to in case we find problems with |
|
| 37 |
* the system. |
|
| 38 |
* |
|
| 39 |
* @var string |
|
| 40 |
*/ |
|
| 41 |
protected $notificationEmail = NULL; |
|
| 42 | ||
| 43 |
/** |
|
| 36 | 44 |
* Executes the System Status Update task, determing the highest severity of |
| 37 | 45 |
* status reports and saving that to the registry to be displayed at login |
| 38 | 46 |
* if necessary. |
| ... | ... | |
| 48 | 56 | |
| 49 | 57 |
$registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
|
| 50 | 58 | |
| 59 |
if ($highestSeverity > tx_reports_reports_status_Status::OK) {
|
|
| 60 |
$this->sendNotificationEmail($systemStatus); |
|
| 61 |
} |
|
| 62 | ||
| 51 | 63 |
return true; |
| 52 | 64 |
} |
| 65 | ||
| 66 |
/** |
|
| 67 |
* Gets the notification email address. |
|
| 68 |
* |
|
| 69 |
* @return string Notification email address. |
|
| 70 |
*/ |
|
| 71 |
public function getNotificationEmail() {
|
|
| 72 |
return $this->notificationEmail; |
|
| 73 |
} |
|
| 74 | ||
| 75 |
/** |
|
| 76 |
* Sets the notification email address. |
|
| 77 |
* |
|
| 78 |
* @param string $notificationEmail Notification email address. |
|
| 79 |
*/ |
|
| 80 |
public function setNotificationEmail($notificationEmail) {
|
|
| 81 |
$this->notificationEmail = $notificationEmail; |
|
| 82 |
} |
|
| 83 | ||
| 84 |
/** |
|
| 85 |
* Sends a notification email, reporting system issues. |
|
| 86 |
* |
|
| 87 |
* @param array $systemStatus Array of statuses |
|
| 88 |
*/ |
|
| 89 |
protected function sendNotificationEmail(array $systemStatus) {
|
|
| 90 |
$systemIssues = array(); |
|
| 91 | ||
| 92 |
foreach ($systemStatus as $statusProvider) {
|
|
| 93 |
foreach ($statusProvider as $status) {
|
|
| 94 |
if ($status->getSeverity() > tx_reports_reports_status_Status::OK) {
|
|
| 95 |
$systemIssues[] = (string) $status; |
|
| 96 |
} |
|
| 97 |
} |
|
| 98 |
} |
|
| 99 | ||
| 100 |
$fromEmail = $this->getFromAddress(); |
|
| 101 | ||
| 102 |
$subject = sprintf( |
|
| 103 |
$GLOBALS['LANG']->getLL('status_updateTask_email_subject'),
|
|
| 104 |
$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] |
|
| 105 |
); |
|
| 106 | ||
| 107 |
$message = sprintf( |
|
| 108 |
$GLOBALS['LANG']->getLL('status_problemNotification'),
|
|
| 109 |
'', |
|
| 110 |
'' |
|
| 111 |
); |
|
| 112 |
$message .= CRLF . CRLF; |
|
| 113 |
$message .= $GLOBALS['LANG']->getLL('status_updateTask_email_site')
|
|
| 114 |
. ': ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; |
|
| 115 |
$message .= CRLF . CRLF; |
|
| 116 |
$message .= $GLOBALS['LANG']->getLL('status_updateTask_email_issues')
|
|
| 117 |
. ': ' .CRLF; |
|
| 118 |
$message .= implode(CRLF, $systemIssues); |
|
| 119 |
$message .= CRLF . CRLF; |
|
| 120 | ||
| 121 |
$mail = t3lib_div::makeInstance('t3lib_mail_Message');
|
|
| 122 |
$mail->setFrom(array($fromEmail => 'TYPO3 CMS')); |
|
| 123 |
$mail->setTo($this->notificationEmail); |
|
| 124 |
$mail->setSubject($subject); |
|
| 125 |
$mail->setBody($message); |
|
| 126 | ||
| 127 |
$mail->send(); |
|
| 128 |
} |
|
| 129 | ||
| 130 |
/** |
|
| 131 |
* Tries to generate an email address to use for the From field. |
|
| 132 |
* |
|
| 133 |
* @return string email address |
|
| 134 |
*/ |
|
| 135 |
protected function getFromAddress() {
|
|
| 136 |
$user = 'no-reply'; |
|
| 137 |
$host = php_uname('n');
|
|
| 138 | ||
| 139 |
// just get us a domain record we can use |
|
| 140 |
$domainRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( |
|
| 141 |
'domainName', |
|
| 142 |
'sys_domain', |
|
| 143 |
'hidden = 0', |
|
| 144 |
'', |
|
| 145 |
'pid ASC, sorting ASC' |
|
| 146 |
); |
|
| 147 | ||
| 148 |
if (!empty($domainRecord['domainName'])) {
|
|
| 149 |
$tempUrl = $domainRecord['domainName']; |
|
| 150 | ||
| 151 |
if (!t3lib_div::isFirstPartOfStr($tempUrl, 'http')) {
|
|
| 152 |
// shouldn't be the case anyways, but you never know |
|
| 153 |
// ... there're crazy people out there |
|
| 154 |
$tempUrl = 'http://' .$tempUrl; |
|
| 155 |
} |
|
| 156 | ||
| 157 |
$host = parse_url($tempUrl, PHP_URL_HOST); |
|
| 158 |
} |
|
| 159 | ||
| 160 |
return $user . '@' . $host; |
|
| 161 |
} |
|
| 53 | 162 |
} |
| 54 | 163 | |
| 55 | 164 | |