Commit e9e4b6ed3cb763f66eea016e88cbcd97478d6b9c
1 parent
18eca58f
Exists in
master
Adicionado modulo Error (para exibir detalhes de erros ocorridos), adicionado tr…
…y a /module/index.php para pegar erros e redirecionar para /modules/Error
Showing
5 changed files
with
353 additions
and
20 deletions
Show diff stats
ieducar/module/index.php
| ... | ... | @@ -39,29 +39,50 @@ require_once 'CoreExt/Controller/Request.php'; |
| 39 | 39 | require_once 'CoreExt/Controller/Front.php'; |
| 40 | 40 | require_once 'CoreExt/DataMapper.php'; |
| 41 | 41 | |
| 42 | -// Objeto de requisição | |
| 43 | -$request = new CoreExt_Controller_Request(); | |
| 42 | +require_once 'modules/Error/Mailers/NotificationMailer.php'; | |
| 44 | 43 | |
| 45 | -// Helper de URL. Auxilia para criar uma URL no formato http://www.example.org/module | |
| 46 | -$url = CoreExt_View_Helper_UrlHelper::getInstance(); | |
| 47 | -$url = $url->url($request->get('REQUEST_URI'), array('components' => CoreExt_View_Helper_UrlHelper::URL_HOST)); | |
| 44 | +try | |
| 45 | +{ | |
| 46 | + // Objeto de requisição | |
| 47 | + $request = new CoreExt_Controller_Request(); | |
| 48 | 48 | |
| 49 | -// Configura o baseurl da request | |
| 50 | -$request->setBaseurl(sprintf('%s/module', $url)); | |
| 49 | + // Helper de URL. Auxilia para criar uma URL no formato http://www.example.org/module | |
| 50 | + $url = CoreExt_View_Helper_UrlHelper::getInstance(); | |
| 51 | + $url = $url->url($request->get('REQUEST_URI'), array('components' => CoreExt_View_Helper_UrlHelper::URL_HOST)); | |
| 51 | 52 | |
| 52 | -// Configura o DataMapper para usar uma instância de clsBanco com fetch de resultados | |
| 53 | -// usando o tipo FETCH_ASSOC | |
| 54 | -CoreExt_DataMapper::setDefaultDbAdapter(new clsBanco(array('fetchMode' => clsBanco::FETCH_ASSOC))); | |
| 53 | + // Configura o baseurl da request | |
| 54 | + $request->setBaseurl(sprintf('%s/module', $url)); | |
| 55 | 55 | |
| 56 | -// Inicia o Front Controller | |
| 57 | -$frontController = CoreExt_Controller_Front::getInstance(); | |
| 58 | -$frontController->setRequest($request); | |
| 56 | + // Configura o DataMapper para usar uma instância de clsBanco com fetch de resultados | |
| 57 | + // usando o tipo FETCH_ASSOC | |
| 58 | + CoreExt_DataMapper::setDefaultDbAdapter(new clsBanco(array('fetchMode' => clsBanco::FETCH_ASSOC))); | |
| 59 | 59 | |
| 60 | -// Configura o caminho aonde os módulos estão instalados | |
| 61 | -$frontController->setOptions( | |
| 62 | - array('basepath' => PROJECT_ROOT . DS . 'modules') | |
| 63 | -); | |
| 64 | -$frontController->dispatch(); | |
| 60 | + // Inicia o Front Controller | |
| 61 | + $frontController = CoreExt_Controller_Front::getInstance(); | |
| 62 | + $frontController->setRequest($request); | |
| 65 | 63 | |
| 66 | -// Resultado | |
| 67 | -print $frontController->getViewContents(); | |
| 68 | 64 | \ No newline at end of file |
| 65 | + // Configura o caminho aonde os módulos estão instalados | |
| 66 | + $frontController->setOptions( | |
| 67 | + array('basepath' => PROJECT_ROOT . DS . 'modules') | |
| 68 | + ); | |
| 69 | + | |
| 70 | + $frontController->dispatch(); | |
| 71 | + | |
| 72 | + // Resultado | |
| 73 | + print $frontController->getViewContents(); | |
| 74 | +} | |
| 75 | +catch (Exception $e) { | |
| 76 | + $lastError = error_get_last(); | |
| 77 | + | |
| 78 | + @session_start(); | |
| 79 | + $_SESSION['last_error_message'] = $e->getMessage(); | |
| 80 | + $_SESSION['last_php_error_message'] = $lastError['message']; | |
| 81 | + $_SESSION['last_php_error_line'] = $lastError['line']; | |
| 82 | + $_SESSION['last_php_error_file'] = $lastError['file']; | |
| 83 | + @session_write_close(); | |
| 84 | + | |
| 85 | + error_log("Erro inesperado (pego em /module/index.php): " . $e->getMessage()); | |
| 86 | + NotificationMailer::unexpectedError($e->getMessage()); | |
| 87 | + | |
| 88 | + die("<script>document.location.href = '/module/Error/unexpected';</script>"); | |
| 89 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +* { | |
| 2 | + margin: 0; | |
| 3 | + padding: 0; | |
| 4 | +} | |
| 5 | + | |
| 6 | +body { | |
| 7 | + align: center; | |
| 8 | + font-size: 85%; | |
| 9 | + font-family: verdana, arial, sans-serif; | |
| 10 | + line-height: 160% | |
| 11 | +} | |
| 12 | + | |
| 13 | +div#error { | |
| 14 | + position: absolute; | |
| 15 | + left: 250px; | |
| 16 | + top: 35px; | |
| 17 | + border: 1px solid #666; | |
| 18 | + width: 800px; | |
| 19 | +} | |
| 20 | + | |
| 21 | +div.content { | |
| 22 | + padding: 25px; | |
| 23 | +} | |
| 24 | + | |
| 25 | +div.detail { | |
| 26 | + margin-top: 25px; | |
| 27 | +} | |
| 28 | + | |
| 29 | +h1 { | |
| 30 | + padding-bottom: 15px; | |
| 31 | + font-size: 300%; | |
| 32 | +} | |
| 33 | + | |
| 34 | +ol { | |
| 35 | + list-style-position: inside; | |
| 36 | + margin-top: 20px; | |
| 37 | +} | |
| 0 | 38 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,117 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * i-Educar - Sistema de gestão escolar | |
| 5 | + * | |
| 6 | + * Copyright (C) 2006 Prefeitura Municipal de ItajaÃÂ | |
| 7 | + * <ctima@itajai.sc.gov.br> | |
| 8 | + * | |
| 9 | + * Este programa é software livre; você pode redistribuÃ-lo e/ou modificá-lo | |
| 10 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
| 11 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
| 12 | + * qualquer versão posterior. | |
| 13 | + * | |
| 14 | + * Este programa é distribuÃÂdo na expectativa de que seja útil, porém, SEM | |
| 15 | + * NENHUMA GARANTIA; nem mesmo a garantia implÃÂcita de COMERCIABILIDADE OU | |
| 16 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÃFICA. Consulte a Licença Pública Geral | |
| 17 | + * do GNU para mais detalhes. | |
| 18 | + * | |
| 19 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
| 20 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
| 21 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
| 22 | + * | |
| 23 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
| 24 | + * @category i-Educar | |
| 25 | + * @license @@license@@ | |
| 26 | + * @package Mailer | |
| 27 | + * @subpackage Modules | |
| 28 | + * @since Arquivo disponÃÂvel desde a versão ? | |
| 29 | + * @version $Id$ | |
| 30 | + */ | |
| 31 | + | |
| 32 | +require_once 'Portabilis/Mailer.php'; | |
| 33 | +require_once 'Portabilis/String/Utils.php'; | |
| 34 | +require_once 'Portabilis/Utils/User.php'; | |
| 35 | +require_once 'Portabilis/Utils/Database.php'; | |
| 36 | + | |
| 37 | +class NotificationMailer extends Portabilis_Mailer | |
| 38 | +{ | |
| 39 | + static function unexpectedDataBaseError($appError, $pgError, $sql) { | |
| 40 | + if (self::canSendEmail()) { | |
| 41 | + $lastError = error_get_last(); | |
| 42 | + $userId = Portabilis_Utils_User::currentUserId(); | |
| 43 | + | |
| 44 | + $to = self::notificationEmail(); | |
| 45 | + $subject = "[Erro inesperado bd] i-Educar - " . self::host(); | |
| 46 | + $message = "Olá!\n\n" . | |
| 47 | + "Ocorreu um erro inesperado no banco de dados, detalhes abaixo:\n\n" . | |
| 48 | + " ERRO APP: ' . $appError\n" . | |
| 49 | + " ERRO PHP: ' . {$lastError['message']}\n" . | |
| 50 | + " ERRO POSTGRES: $pgError\n" . | |
| 51 | + " LINHA {$lastError['line']} em {$lastError['file']}\n" . | |
| 52 | + " SQL: {$sql}\n" . | |
| 53 | + " ID USUÁRIO {$userId}\n" . | |
| 54 | + "\n\n-\n\n" . | |
| 55 | + "Você recebeu este email pois seu email foi configurado para receber " . | |
| 56 | + "notificações de erros."; | |
| 57 | + | |
| 58 | + // only send email, if a notification email was set. | |
| 59 | + return ($to ? self::mail($to, $subject, $message) : false); | |
| 60 | + } | |
| 61 | + } | |
| 62 | + | |
| 63 | + static function unexpectedError($appError) { | |
| 64 | + if (self::canSendEmail()) { | |
| 65 | + $lastError = error_get_last(); | |
| 66 | + $user = self::tryLoadUser(); | |
| 67 | + | |
| 68 | + $to = self::notificationEmail(); | |
| 69 | + $subject = "[Erro inesperado] i-Educar - " . self::host(); | |
| 70 | + $message = "Olá!\n\n" . | |
| 71 | + "Ocorreu um erro inesperado, detalhes abaixo:\n\n" . | |
| 72 | + " ERRO APP: ' . $appError\n" . | |
| 73 | + " ERRO PHP: ' . {$lastError['message']}\n" . | |
| 74 | + " LINHA {$lastError['line']} em {$lastError['file']}\n" . | |
| 75 | + " USUÁRIO {$user['matricula']} email {$user['email']}\n" . | |
| 76 | + "\n\n-\n\n" . | |
| 77 | + "Você recebeu este email pois seu email foi configurado para receber " . | |
| 78 | + "notificações de erros."; | |
| 79 | + | |
| 80 | + // only send email, if a notification email was set. | |
| 81 | + return ($to ? self::mail($to, $subject, $message) : false); | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + // common error mailer methods | |
| 86 | + | |
| 87 | + protected static function canSendEmail() { | |
| 88 | + return $GLOBALS['coreExt']['Config']->modules->error->send_notification_email == true; | |
| 89 | + } | |
| 90 | + | |
| 91 | + protected static function notificationEmail() { | |
| 92 | + $email = $GLOBALS['coreExt']['Config']->modules->error->notification_email; | |
| 93 | + | |
| 94 | + if (! is_string($email)) { | |
| 95 | + error_log("Não foi definido um email para receber detalhes dos erros, por favor adicione a opção " . | |
| 96 | + "'modules.error_notification.email = email@dominio.com' ao arquivo ini de configuração."); | |
| 97 | + | |
| 98 | + return false; | |
| 99 | + } | |
| 100 | + | |
| 101 | + return $email; | |
| 102 | + } | |
| 103 | + | |
| 104 | + protected static function tryLoadUser() { | |
| 105 | + try { | |
| 106 | + | |
| 107 | + $sql = 'select matricula, email from portal.funcionario WHERE ref_cod_pessoa_fj = $1 '; | |
| 108 | + $options = array('params' => Portabilis_Utils_User::currentUserId(), 'return_only' => 'first-row'); | |
| 109 | + $user = Portabilis_Utils_Database::fetchPreparedQuery($sql, $options); | |
| 110 | + | |
| 111 | + } catch (Exception $e) { | |
| 112 | + $user = array('matricula' => 'Erro ao obter', 'email' => 'Erro ao obter'); | |
| 113 | + } | |
| 114 | + | |
| 115 | + return $user; | |
| 116 | + } | |
| 117 | +} | |
| 0 | 118 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,67 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +error_reporting(E_ALL); | |
| 4 | +ini_set("display_errors", 1); | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * i-Educar - Sistema de gestão escolar | |
| 8 | + * | |
| 9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
| 10 | + * <ctima@itajai.sc.gov.br> | |
| 11 | + * | |
| 12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
| 13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
| 14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
| 15 | + * qualquer versão posterior. | |
| 16 | + * | |
| 17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
| 18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
| 19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
| 20 | + * do GNU para mais detalhes. | |
| 21 | + * | |
| 22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
| 23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
| 24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
| 25 | + * | |
| 26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
| 27 | + * @category i-Educar | |
| 28 | + * @license @@license@@ | |
| 29 | + * @package Portabilis | |
| 30 | + * @subpackage lib | |
| 31 | + * @since Arquivo disponível desde a versão ? | |
| 32 | + * @version $Id$ | |
| 33 | + */ | |
| 34 | + | |
| 35 | +require_once 'lib/Portabilis/Controller/ErrorCoreController.php'; | |
| 36 | + | |
| 37 | +class UnauthorizedController extends Portabilis_Controller_ErrorCoreController | |
| 38 | +{ | |
| 39 | + protected $_titulo = 'Acesso não autorizado'; | |
| 40 | + | |
| 41 | + protected function setHeader() { | |
| 42 | + header("HTTP/1.1 403 Forbidden"); | |
| 43 | + } | |
| 44 | + | |
| 45 | + public function Gerar() { | |
| 46 | + $linkToSupport = $GLOBALS['coreExt']['Config']->modules->error->link_to_support; | |
| 47 | + | |
| 48 | + echo " | |
| 49 | + <div id='error' class='small'> | |
| 50 | + <div class='content'> | |
| 51 | + <h1>Acesso não autorizado</h1> | |
| 52 | + | |
| 53 | + <p class='explanation'> | |
| 54 | + Seu usuário não possui autorização para realizar esta ação, | |
| 55 | + <strong> tente seguir as etapas abaixo:</strong> | |
| 56 | + | |
| 57 | + <ol> | |
| 58 | + <li><a href='/intranet/index.php'>Volte para o sistema</a></li> | |
| 59 | + <li>Solicite ao responsável pelo sistema, para adicionar ao seu usuário a permissão necessária e tente novamente</li> | |
| 60 | + <li>Caso o erro persista, por favor, <a target='_blank' href='$linkToSupport'>solicite suporte</a>.</li> | |
| 61 | + </ol> | |
| 62 | + </p> | |
| 63 | + | |
| 64 | + </div> | |
| 65 | + </div>"; | |
| 66 | + } | |
| 67 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,91 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +error_reporting(E_ALL); | |
| 4 | +ini_set("display_errors", 1); | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * i-Educar - Sistema de gestão escolar | |
| 8 | + * | |
| 9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
| 10 | + * <ctima@itajai.sc.gov.br> | |
| 11 | + * | |
| 12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
| 13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
| 14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
| 15 | + * qualquer versão posterior. | |
| 16 | + * | |
| 17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
| 18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
| 19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
| 20 | + * do GNU para mais detalhes. | |
| 21 | + * | |
| 22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
| 23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
| 24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
| 25 | + * | |
| 26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
| 27 | + * @category i-Educar | |
| 28 | + * @license @@license@@ | |
| 29 | + * @package Portabilis | |
| 30 | + * @subpackage lib | |
| 31 | + * @since Arquivo disponível desde a versão ? | |
| 32 | + * @version $Id$ | |
| 33 | + */ | |
| 34 | + | |
| 35 | +require_once 'lib/Portabilis/Controller/ErrorCoreController.php'; | |
| 36 | + | |
| 37 | +class UnexpectedController extends Portabilis_Controller_ErrorCoreController | |
| 38 | +{ | |
| 39 | + protected $_titulo = 'Erro inesperado'; | |
| 40 | + | |
| 41 | + protected function setHeader() { | |
| 42 | + header("HTTP/1.1 500 Internal Server Error"); | |
| 43 | + } | |
| 44 | + | |
| 45 | + public function Gerar() { | |
| 46 | + $linkToSupport = $GLOBALS['coreExt']['Config']->modules->error->link_to_support; | |
| 47 | + | |
| 48 | + if ($GLOBALS['coreExt']['Config']->modules->error->show_details) { | |
| 49 | + $detail = "<br /><h3>Erro app</h3>{$this->getSession()->last_error_message}"; | |
| 50 | + $detail .= "<br /><h3>Erro php</h3>{$this->getSession()->last_php_error_message}"; | |
| 51 | + $detail .= "<br /><h3>Arquivo</h3>(linha: {$this->getSession()->last_php_error_line}) "; | |
| 52 | + $detail .= "{$this->getSession()->last_php_error_file}"; | |
| 53 | + | |
| 54 | + unset($this->getSession()->last_error_message); | |
| 55 | + unset($this->getSession()->last_php_error_message); | |
| 56 | + unset($this->getSession()->last_php_error_line); | |
| 57 | + unset($this->getSession()->last_php_error_file); | |
| 58 | + | |
| 59 | + if (! $detail) | |
| 60 | + $detail = 'Sem detalhes do erro.'; | |
| 61 | + | |
| 62 | + $detail = "<h2>Detalhes:</h2> | |
| 63 | + <p>$detail</p>"; | |
| 64 | + } | |
| 65 | + else | |
| 66 | + $detail = '<p>Visualização de detalhes do erro desativada.</p>'; | |
| 67 | + | |
| 68 | + echo " | |
| 69 | + <div id='error' class='small'> | |
| 70 | + <div class='content'> | |
| 71 | + <h1>Erro inesperado</h1> | |
| 72 | + | |
| 73 | + <p class='explanation'> | |
| 74 | + Desculpe-nos, algum erro inesperado ocorreu, | |
| 75 | + <strong> tente seguir as etapas abaixo:</strong> | |
| 76 | + | |
| 77 | + <ol> | |
| 78 | + <li><a href='/intranet/index.php'>Tente novamente</a></li> | |
| 79 | + <li><a href='/intranet/logof.php'>Faça logoff do sistema</a> e tente novamente</li> | |
| 80 | + <li>Caso o erro persista, por favor, <a target='_blank' href='$linkToSupport'>solicite suporte</a>.</li> | |
| 81 | + </ol> | |
| 82 | + </p> | |
| 83 | + | |
| 84 | + <div class='detail'> | |
| 85 | + $detail | |
| 86 | + </div> | |
| 87 | + | |
| 88 | + </div> | |
| 89 | + </div>"; | |
| 90 | + } | |
| 91 | +} | ... | ... |