Commit 0141ceaf authored by bgm's avatar bgm Committed by Aegir user

Add ca.bidon.reporterror to keep an eye on INFRA-254 (fix)

parent d1d161fd
Subproject commit 5bdc08138128984a99e588a735bf0bc350d78827
<?php
/*
+--------------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2012-2013 |
+--------------------------------------------------------------------------+
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/>. |
+--------------------------------------------------------------------------+
*/
class CRM_Admin_Form_Setting_ReportError extends CRM_Admin_Form_Setting {
protected $_values;
function preProcess() {
// Needs to be here as form is built before default values are set
$this->_values = CRM_Core_BAO_Setting::getItem(REPORTERROR_SETTINGS_GROUP);
}
function setDefaultValues() {
$defaults = $this->_values;
$defaults['show_full_backtrace'] = CRM_Utils_Array::value('show_full_backtrace', $defaults, FALSE);
$defaults['show_post_data'] = CRM_Utils_Array::value('show_post_data', $defaults, FALSE);
$defaults['bots_sendreport'] = CRM_Utils_Array::value('bots_sendreport', $defaults, FALSE);
$defaults['bots_404'] = CRM_Utils_Array::value('bots_404', $defaults, FALSE);
$defaults['bots_regexp'] = CRM_Utils_Array::value('bots_regexp', $defaults, '(Googlebot|bingbot)');
return $defaults;
}
/**
* Function to build the form
*
* @return None
* @access public
*/
public function buildQuickForm() {
$this->applyFilter('__ALL__', 'trim');
$this->add('text', 'mailto',
ts('Error Report Recipient', array('domain' => 'ca.bidon.reporterror')),
CRM_Utils_Array::value('mailto', $this->_values),
FALSE);
$this->addYesNo('show_full_backtrace', ts('Display a full backtrace in e-mails?', array('domain' => 'ca.bidon.reporterror')));
$this->addYesNo('show_post_data', ts('Display POST data in e-mails?', array('domain' => 'ca.bidon.reporterror')));
$this->addYesNo('show_session_data', ts('Display session data in e-mails?', array('domain' => 'ca.bidon.reporterror')));
// Special handling of Contribution page errors.
// Get a list of contribution pages
$results = civicrm_api3('ContributionPage', 'get', array('is_active' => 1));
$contribution_pages = array(
0 => ts('- Select -'),
);
if($results['is_error'] == 0) {
foreach ($results['values'] as $val) {
$contribution_pages[$val['id']] = $val['title'];
}
}
$radio_choices = array(
'0' => ts('Do nothing (show the CiviCRM error)', array('domain' => 'ca.bidon.reporterror')),
'1' => ts('Redirect to front page of CMS', array('domain' => 'ca.bidon.reporterror')),
'2' => ts('Redirect to a specific contribution page', array('domain' => 'ca.bidon.reporterror'))
);
$this->addRadio('noreferer_handle',
ts('Enable transparent redirection?', array('domain' => 'ca.bidon.reporterror')),
$radio_choices,
array('options_per_line' => 1),
'<br/>' /* one option per line */
);
$this->addYesNo('noreferer_sendreport', ts('Send error reports for this particular error?', array('domain' => 'ca.bidon.reporterror')));
$this->add('select', 'noreferer_pageid',
ts('Redirect to Contribution Page', array('domain' => 'ca.bidon.reporterror')),
$contribution_pages,
TRUE);
// Special handling of Event page errors.
$results = civicrm_api3('Event', 'get', array('is_active' => 1));
$event_pages = array(
0 => ts('- Select -'),
);
if($results['is_error'] == 0) {
foreach ($results['values'] as $val) {
$event_pages[$val['id']] = $val['title'];
}
}
$radio_choices = array(
'0' => ts('Do nothing (show the CiviCRM error)', array('domain' => 'ca.bidon.reporterror')),
'1' => ts('Redirect to front page of CMS', array('domain' => 'ca.bidon.reporterror')),
'2' => ts('Redirect to a specific event registration page', array('domain' => 'ca.bidon.reporterror'))
);
$this->addRadio('noreferer_handle_event',
ts('Enable transparent redirection?', array('domain' => 'ca.bidon.reporterror')),
$radio_choices,
array('options_per_line' => 1),
'<br/>' /* one option per line */
);
$this->addYesNo('noreferer_sendreport_event', ts('Send error reports for this particular error?', array('domain' => 'ca.bidon.reporterror')));
$this->add('select', 'noreferer_handle_eventid',
ts('Redirect to Event Page', array('domain' => 'ca.bidon.reporterror')),
$event_pages,
TRUE);
// Special handling of bots
$this->addYesNo('bots_sendreport', ts('Send error reports for errors caused by bots?', array('domain' => 'ca.bidon.reporterror')), FALSE, TRUE);
$this->addYesNo('bots_404', ts('Respond with a 404 page not found error?', array('domain' => 'ca.bidon.reporterror')), FALSE, TRUE);
$this->add('text', 'bots_regexp',
ts('Bots to ignore', array('domain' => 'ca.bidon.reporterror')),
TRUE);
$this->addButtons(array(
array(
'type' => 'submit',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
}
/**
* Function to process the form
*
* @access public
* @return None
*/
public function postProcess() {
// store the submitted values in an array
$values = $this->exportValues();
$fields = array(
'noreferer_handle',
'noreferer_pageid',
'noreferer_sendreport',
'noreferer_handle_event',
'noreferer_handle_eventid',
'noreferer_sendreport_event',
'mailto',
'show_full_backtrace',
'show_post_data',
'show_session_data',
'bots_sendreport',
'bots_404',
'bots_regexp',
);
foreach ($fields as $field) {
$value = $values[$field];
$result = CRM_Core_BAO_Setting::setItem($value, REPORTERROR_SETTINGS_GROUP, $field);
}
// we will return to this form by default
CRM_Core_Session::setStatus(ts('Settings saved.', array('domain' => 'ca.bidon.reporterror')), '', 'success');
}
}
Report Error CiviCRM Extension
==============================
Sometimes CiviCRM can be real tough to debug. Especially when you are getting
fatal errors, but only by some users, and you can't recreate the problems.
This utility will send you a detailed email when a CiviCRM fatal error occurs.
* when the error was encountered
* which CiviCRM page threw the error
* which logged-in user encountered the error
* full request parameters ("get")
* optionally the "post" data
The extension can also offer to try to resolve some common errors:
* For contribution pages where the session has expired or the contribution
page URL is truncated, you can choose to gracefully redirect CiviCRM
errors to the site CMS default page, a specific contribution page or not
at all. You also have the option of not getting emails on contribution
page redirects (since crawlers can make them rather frequent).
* Detect bots and optionally generate a 404 http response instead of 'OK'.
To get the latest version of this module:
https://github.com/mlutfy/ca.bidon.reporterror
Distributed under the terms of the GNU Affero General public license (AGPL).
See LICENSE.txt for details.
Installation
------------
* Enable this extension in CiviCRM (Administer > System Settings > Manage Extensions)
* A new menu item will be added in Administer > System Settings > Report Errors,
which you can use to access the extensions settings form.
Requirements
------------
- CiviCRM >= 4.2
- Tested with CiviCRM 4.4 to 4.6.
Contributors
------------
* CiviCRM extension/integration written & maintained by Mathieu Lutfy (Coop SymbioTIC),
co-authored by Lola S (Freeform), Nicolas Ganivet (CiviDesk) and Young-Jin Kim (Emphanos).
* Based on the civicrm_error Drupal module initially written by Dave Hansen-Lange (dalin):
https://drupal.org/project/civicrm_error
Support
-------
Please post bug reports in the issue tracker of this project on github:
https://github.com/mlutfy/ca.bidon.reporterror/issues
For general support questions, please use the CiviCRM Extensions forum:
http://forum.civicrm.org/index.php/board,57.0.html
This is a community contributed extension written thanks to the financial
support of organisations using it, as well as the very helpful and collaborative
CiviCRM community.
If you appreciate this module, please consider donating 10$ to the CiviCRM project:
http://civicrm.org/participate/support-civicrm
While I do my best to provide volunteer support for this extension, please
consider financially contributing to support and further develop this extension.
Commercial support is available through Coop SymbioTIC:
https://www.symbiotic.coop
Copyright
---------
License: AGPL 3
Copyright (C) 2012-2015 CiviCRM LLC (info@civicrm.org)
http://www.civicrm.org
Copyright (C) 2012-2015 Mathieu Lutfy (mathieu@symbiotic.coop)
https://www.symbiotic.coop
<?xml version="1.0"?>
<extension key="ca.bidon.reporterror" type="module">
<file>reporterror</file>
<name>CiviCRM Report Error</name>
<description>Advanced error handler for CiviCRM that sends an e-mail with detailed information when fatal errors are encountered.</description>
<license>AGPL 3</license>
<maintainer>
<author>Mathieu Lutfy</author>
<email>mathieu@bidon.ca</email>
</maintainer>
<urls>
<url desc="Main Extension Page">https://github.com/mlutfy/ca.bidon.reporterror</url>
<url desc="Documentation">https://github.com/mlutfy/ca.bidon.reporterror/blob/master/README.md</url>
<url desc="Support">http://forum.civicrm.org/index.php/board,57.0.html</url>
<url desc="Licensing">http://civicrm.org/licensing</url>
</urls>
<releaseDate>2015-05-22</releaseDate>
<version>2.9</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.2</ver>
<ver>4.3</ver>
<ver>4.4</ver>
<ver>4.5</ver>
<ver>4.6</ver>
<ver>4.7</ver>
</compatibility>
<comments></comments>
<civix>
<namespace>CRM/ReportError</namespace>
</civix>
</extension>
<?php
// AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
/**
* (Delegated) Implementation of hook_civicrm_config
*/
function _reporterror_civix_civicrm_config(&$config = NULL) {
static $configured = FALSE;
if ($configured) return;
$configured = TRUE;
$template =& CRM_Core_Smarty::singleton();
$extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
$extDir = $extRoot . 'templates';
if ( is_array( $template->template_dir ) ) {
array_unshift( $template->template_dir, $extDir );
} else {
$template->template_dir = array( $extDir, $template->template_dir );
}
$include_path = $extRoot . PATH_SEPARATOR . get_include_path( );
set_include_path( $include_path );
}
/**
* (Delegated) Implementation of hook_civicrm_xmlMenu
*
* @param $files array(string)
*/
function _reporterror_civix_civicrm_xmlMenu(&$files) {
foreach (_reporterror_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
$files[] = $file;
}
}
/**
* Implementation of hook_civicrm_install
*/
function _reporterror_civix_civicrm_install() {
_reporterror_civix_civicrm_config();
if ($upgrader = _reporterror_civix_upgrader()) {
return $upgrader->onInstall();
}
}
/**
* Implementation of hook_civicrm_uninstall
*/
function _reporterror_civix_civicrm_uninstall() {
_reporterror_civix_civicrm_config();
if ($upgrader = _reporterror_civix_upgrader()) {
return $upgrader->onUninstall();
}
}
/**
* (Delegated) Implementation of hook_civicrm_enable
*/
function _reporterror_civix_civicrm_enable() {
_reporterror_civix_civicrm_config();
if ($upgrader = _reporterror_civix_upgrader()) {
if (is_callable(array($upgrader, 'onEnable'))) {
return $upgrader->onEnable();
}
}
}
/**
* (Delegated) Implementation of hook_civicrm_disable
*/
function _reporterror_civix_civicrm_disable() {
_reporterror_civix_civicrm_config();
if ($upgrader = _reporterror_civix_upgrader()) {
if (is_callable(array($upgrader, 'onDisable'))) {
return $upgrader->onDisable();
}
}
}
/**
* (Delegated) Implementation of hook_civicrm_upgrade
*
* @param $op string, the type of operation being performed; 'check' or 'enqueue'
* @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
*
* @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
* for 'enqueue', returns void
*/
function _reporterror_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
if ($upgrader = _reporterror_civix_upgrader()) {
return $upgrader->onUpgrade($op, $queue);
}
}
function _reporterror_civix_upgrader() {
if (!file_exists(__DIR__.'/CRM/ReportError/Upgrader.php')) {
return NULL;
} else {
return CRM_ReportError_Upgrader_Base::instance();
}
}
/**
* Search directory tree for files which match a glob pattern
*
* @param $dir string, base dir
* @param $pattern string, glob pattern, eg "*.txt"
* @return array(string)
*/
function _reporterror_civix_find_files($dir, $pattern) {
$todos = array($dir);
$result = array();
while (!empty($todos)) {
$subdir = array_shift($todos);
foreach (_reporterror_civix_glob("$subdir/$pattern") as $match) {
if (!is_dir($match)) {
$result[] = $match;
}
}
if ($dh = opendir($subdir)) {
while (FALSE !== ($entry = readdir($dh))) {
$path = $subdir . DIRECTORY_SEPARATOR . $entry;
if ($entry == '.' || $entry == '..') {
} elseif (is_dir($path)) {
$todos[] = $path;
}
}
closedir($dh);
}
}
return $result;
}
/**
* (Delegated) Implementation of hook_civicrm_managed
*
* Find any *.mgd.php files, merge their content, and return.
*/
function _reporterror_civix_civicrm_managed(&$entities) {
$mgdFiles = _reporterror_civix_find_files(__DIR__, '*.mgd.php');
foreach ($mgdFiles as $file) {
$es = include $file;
foreach ($es as $e) {
if (empty($e['module'])) {
$e['module'] = 'ca.bidon.reporterror';
}
$entities[] = $e;
}
}
}
/**
* Glob wrapper which is guaranteed to return an array.
*
* The documentation for glob() says, "On some systems it is impossible to
* distinguish between empty match and an error." Anecdotally, the return
* result for an empty match is sometimes array() and sometimes FALSE.
* This wrapper provides consistency.
*
* @see http://php.net/glob
* @param string $pattern
* @return array, possibly empty
*/
function _reporterror_civix_glob($pattern) {
$result = glob($pattern);
return is_array($result) ? $result : array();
}
This diff is collapsed.
{* this template is used for setting-up the report Error extension *}
<div class="crm-block crm-form-block crm-reporterror-form-block">
<h3>{ts domain='ca.bidon.reporterror'}General Setup{/ts}</h3>
<table class="form-layout-compressed" style="width:100%;">
<tr class="crm-reporterror-form-block">
<td class="label">{$form.mailto.label}</td>
<td>{$form.mailto.html}
<div class="description">{ts domain="ca.bidon.reporterror"}This usually is your domain administrator's email. Separate multiple email addresses with a comma (','). If left empty, no e-mails will be sent.{/ts}</div></td>
</tr>
<tr class="crm-reporterror-form-block">
<td class="label">{$form.show_full_backtrace.label}</td>
<td>{$form.show_full_backtrace.html}
<div class="description">{ts domain='ca.bidon.reporterror'}The full backtrace can provide more information on the variables passed to each function, but could expose more sensitive information.{/ts}</div>
</td>
</tr>
<tr class="crm-reporterror-form-block">
<td class="label">{$form.show_post_data.label}</td>
<td>{$form.show_post_data.html}
<div class="description">{ts domain='ca.bidon.reporterror'}POST data is usually the data submitted in forms. This can include sensitive information.{/ts}</div>
</td>
</tr>
<tr class="crm-reporterror-form-block">
<td class="label">{$form.show_session_data.label}</td>
<td>{$form.show_session_data.html}
<div class="description">{ts domain='ca.bidon.reporterror'}Session data can provide clues, but should probably be disabled most of the time, as it can include sensitive information.{/ts}</div>
</td>
</tr>
</table>
<h3>{ts domain='ca.bidon.reporterror'}Contribution pages with no referrer{/ts}</h3>
<p>{ts domain='ca.bidon.reporterror'}Sometimes users might restore their browser session or share the link of the contribution 'thank you' page, which will result in a fatal error. You can use the options below to redirect visitors to a more relevant location.{/ts}</p>
<table class="form-layout-compressed" style="width:100%;">
<tr class="crm-reporterror-form-block">
<td class="label">{$form.noreferer_sendreport.label}</td>
<td>{$form.noreferer_sendreport.html}</td>
</tr>
<tr class="crm-reporterror-form-block">
<td class="label">{$form.noreferer_handle.label}</td>
<td>{$form.noreferer_handle.html}</td>
</tr>
<tr class="crm-reporterror-form-block">
<td class="label">{$form.noreferer_pageid.label}</td>
<td>{$form.noreferer_pageid.html}</td>
</tr>
</table>
<h3>{ts domain='ca.bidon.reporterror'}Event registration pages with no referrer{/ts}</h3>
<p>{ts domain='ca.bidon.reporterror'}Sometimes users might restore their browser session or share the link of the event confirmation page, which will result in a fatal error. You can use the options below to redirect visitors to a more relevant location.{/ts}</p>
<table class="form-layout-compressed" style="width:100%;">
<tr class="crm-reporterror-form-block">
<td class="label">{$form.noreferer_sendreport_event.label}</td>
<td>{$form.noreferer_sendreport_event.html}</td>
</tr>
<tr class="crm-reporterror-form-block">
<td class="label">{$form.noreferer_handle_event.label}</td>
<td>{$form.noreferer_handle_event.html}</td>
</tr>
<tr class="crm-reporterror-form-block">
<td class="label">{$form.noreferer_handle_eventid.label}</td>
<td>{$form.noreferer_handle_eventid.html}</td>
</tr>
</table>
<h3>Bots and crawlers</h3>
<p>{ts domain='ca.bidon.reporterror'}Web crawlers used by search engines can often generate a lot of errors. In some cases, this might be because you have invalid links, but in most cases, the bots are just being annoying and crawling where they shouldn't.{/ts}</p>
<table class="form-layout-compressed" style="width:100%;">
<tr class="crm-reporterror-form-block">
<td class="label">{$form.bots_sendreport.label}</td>
<td>
{$form.bots_sendreport.html}
</td>
</tr>
<tr class="crm-reporterror-form-block">
<td class="label">{$form.bots_404.label}</td>
<td>
{$form.bots_404.html}
<p class="description">By default, CiviCRM always responds '200 OK', even if there was a fatal error. By responding to the request with a '404 not found' code, the bot is less likely to try again.</p>
</td>
</tr>
<tr class="crm-reporterror-form-block">
<td class="label">{$form.bots_regexp.label}</td>
<td>
{$form.bots_regexp.html}
<p class="description">{ts domain='ca.bidon.reporterror' 1='(Googlebot|bingbot)'}If in doubt, leave this as is. The default is: !1{/ts}</p>
</td>
</tr>
</table>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
<?xml version="1.0"?>
<menu>
<item>
<path>civicrm/admin/setting/reporterror</path>
<title>Report Error Settings</title>
<page_callback>CRM_Admin_Form_Setting_ReportError</page_callback>
<adminGroup>System Settings</adminGroup>
<access_arguments>administer CiviCRM</access_arguments>
</item>
</menu>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment