/** * onUncaughtException event listener * * @param iMSCP_Exception_Event $event * @return void */ public function onUncaughtException(iMSCP_Exception_Event $event) { if (iMSCP_Registry::isRegistered('config')) { $debug = iMSCP_Registry::get('config')->DEBUG; } else { $debug = 1; } $mail = $this->prepareMail($event->getException()); if (!empty($mail)) { $footprintsCacheFile = CACHE_PATH . '/mail_body_footprints.php'; $footprints = array(); $now = time(); // Load footprints cache file if (is_readable($footprintsCacheFile)) { if (!$debug) { $footprints = (include $footprintsCacheFile); } else { iMSCP_Utility_OpcodeCache::clearAllActive($footprintsCacheFile); // Be sure to load newest version on next call @unlink($footprintsCacheFile); } if (!is_array($footprints)) { $footprints = array(); } } # Remove expired entries from the cache foreach ($footprints as $footprint => $expireTime) { if ($expireTime <= $now) { unset($footprints[$footprint]); } } // Do not send mail for identical exception in next 24 hours if (!array_key_exists($mail['footprint'], $footprints) || $footprints[$mail['footprint']] < $now) { if (@mail($mail['rcptTo'], $mail['subject'], $mail['body'], $mail['header'])) { # Add mail footprint into the cache $footprints[$mail['footprint']] = strtotime("+24 hours"); } } // Update footprints cache file if (!$debug) { $fileContent = "<?php\n"; $fileContent .= "// File automatically generated by i-MSCP. Do not edit it manually.\n"; $fileContent .= "return " . var_export($footprints, true) . ";\n"; @file_put_contents($footprintsCacheFile, $fileContent, LOCK_EX); iMSCP_Utility_OpcodeCache::clearAllActive($footprintsCacheFile); // Be sure to load newest version on next call } } }
/** * onUncaughtException event listener * * @param iMSCP_Exception_Event $event * @return void */ public function onUncaughtException(iMSCP_Exception_Event $event) { $exception = $event->getException(); if (iMSCP_Registry::isRegistered('config')) { $debug = iMSCP_Registry::get('config')->DEBUG; } else { $debug = 1; } if ($debug) { $exception = $event->getException(); $this->message .= sprintf("An exception has been thrown in file %s at line %s:\n\n", $exception->getFile(), $exception->getLine()); $this->message .= preg_replace('#([\\t\\n]+|<br \\/>)#', ' ', $exception->getMessage()); /** @var $exception iMSCP_Exception_Database */ if ($exception instanceof iMSCP_Exception_Database) { $query = $exception->getQuery(); if ($query !== '') { $this->message .= sprintf("<br><br><strong>Query was:</strong><br><br>%s", $exception->getQuery()); } } } else { $exception = new iMSCP_Exception_Production($exception->getMessage(), $exception->getCode(), $exception); $this->message = $exception->getMessage(); } try { if ($this->templateFile) { $this->render(); } } catch (Exception $event) { } # Fallback to inline template in case something goes wrong with template engine if (!($tpl = $this->templateEngine)) { echo <<<HTML <!DOCTYPE html> <html> \t<head> \t<title>i-MSCP - internet Multi Server Control Panel - Fatal Error</title> \t<meta charset="UTF-8"> \t<meta name="robots" content="nofollow, noindex"> \t<link rel="icon" href="/themes/default/assets/images/favicon.ico"> \t<link rel="stylesheet" href="/themes/default/assets/css/jquery-ui-black.css"> \t<link rel="stylesheet" href="/themes/default/assets/css/simple.css"> \t<!--[if (IE 7)|(IE 8)]> \t\t<link href="/themes/default/assets/css/ie78overrides.css?v=1425280612" rel="stylesheet"> \t<![endif]--> \t<script src="/themes/default/assets/js/jquery/jquery.js"></script> \t<script src="/themes/default/assets/js/jquery/jquery-ui.js"></script> \t<script src="/themes/default/assets/js/imscp.js"></script> \t<script> \t\t\$(function () { iMSCP.initApplication('simple'); }); \t</script> \t</head> \t<body class="black"> \t\t<div class="wrapper"> \t\t\t<div id="content"> \t\t\t\t<div id="message_container"> \t\t\t\t\t<h1>An unexpected error occurred</h1> \t\t\t\t\t<pre>{$this->message}</pre> \t\t\t\t\t<div class="buttons"> \t\t\t\t\t\t<a class="link_as_button" href="javascript:history.go(-1)" target="_self">Back</a> \t\t\t\t\t</div> \t\t\t\t</div> \t\t\t</div> \t\t</div> \t</body> </html> HTML; } else { $event->setParam('templateEngine', $tpl); layout_init($event); $tpl->parse('LAYOUT', 'layout'); $tpl->prnt(); } }