Esempio n. 1
0
 public static function displayError($exception)
 {
     switch (get_class($exception)) {
         case 'PDOException':
             self::$header = 'Database error';
             break;
         case 'Exception':
         default:
             self::$header = 'Application error';
             break;
     }
     // end switch
     $output = '';
     // Display Exception trace
     $output .= self::getFormatedTrace($exception);
     // Header
     $output .= '<table>';
     $output .= "<tr> <th colspan='2'>" . self::$header . "</th> \n </tr> \n";
     // Exception details
     $output .= "<tr> <td width='200'><b>File</b> </td> <td>" . $exception->getFile() . "</td> \n</tr> \n";
     $output .= "<tr> <td><b>Line</b> </td> <td>" . $exception->getLine() . "</td> \n </tr> \n";
     $output .= "<tr> <td><b>Exception code</b> </td> <td>" . $exception->getCode() . "</td> \n </tr> \n";
     $output .= "<tr> <td><b>Exception message</b> </td> <td>" . $exception->getMessage() . "</td> \n </tr> \n";
     $output .= "<tfoot> \n <tr> \n";
     $output .= "<td colspan='2'> \n";
     $output .= "Have you tried to run the <a href='test.php'>test page</a> ?<br />";
     $output .= "Check the online documentation on <a href='http://www.bacula-web.org' target='_blank'>Bacula-Web project site</a> <br />";
     $output .= "Rebort a bug or suggest a new feature in the <a href='http://bugs.bacula-web.org' target='_blank'>Bacula-Web\\'s bugtracking tool</a> <br />";
     $output .= "</td> \n";
     $output .= " \n</tr> \n </tfoot>";
     $output .= "</table>";
     echo $output;
     //die();
 }
Esempio n. 2
0
 protected function renderError()
 {
     $error = $this->getError();
     if (!in_array($error['code'], $this->handledErrorCode)) {
         $this->errorAction = null;
     }
     parent::renderError();
 }
Esempio n. 3
0
 public static function connect($dsn, $user = null, $password = null, $options = array())
 {
     try {
         if (is_null(self::$connection)) {
             self::$connection = new PDO($dsn, $user, $password);
         }
     } catch (PDOException $e) {
         CErrorHandler::displayError($e);
     }
     return self::$connection;
 }
 protected function render($view, $data)
 {
     if (Yii::app()->areAllClassesImported()) {
         parent::render($view, $data);
     } else {
         $data['version'] = $this->getVersionInfo();
         $data['time'] = time();
         $data['admin'] = $this->adminInfo;
         include $this->getViewFile($view, $data['code']);
     }
 }
Esempio n. 5
0
 /**
  * First sends the error to Airbrake and then calls the parent method
  * @param CErrorEvent $event
  */
 protected function handleError(CErrorEvent $event)
 {
     $client = $this->startClient();
     $trace = debug_backtrace();
     // skip the first 3 stacks as they do not tell the error position
     if (count($trace) > 3) {
         $trace = array_slice($trace, 3);
     }
     Yii::log('sending error report to Airbrake');
     $client->notifyOnError($event->message, $trace);
     parent::handleError($event);
 }
Esempio n. 6
0
 /**
  *
  */
 public function init()
 {
     parent::init();
     $admin = false;
     if (!craft()->isConsole() && Craft::isInstalled()) {
         // Set whether the currently logged in user is an admin.
         if (isset(craft()->userSession)) {
             if (($currentUser = craft()->userSession->getUser()) !== null) {
                 $admin = $currentUser->admin == 1 ? true : false;
             }
         }
     }
     $this->_devMode = craft()->config->get('devMode') || $admin;
 }
 protected function handleException($exception)
 {
     /* @var $client \AppEnlight\Client */
     $appEnlight = Yii::app()->getComponent('appenlight');
     /* initialziation */
     $client = $appEnlight->getClient();
     $appRequest = Yii::app()->getRequest();
     $appController = Yii::app()->getController();
     $category = 'exception.' . get_class($exception);
     if ($exception instanceof CHttpException) {
         $category .= '.' . $exception->statusCode;
     }
     /* report to be sent */
     $report = new AppEnlight\Endpoint\Data\Report();
     $report->setUsername($appEnlight->getUsername());
     /* get view name from action */
     if (isset($appController)) {
         $viewName = $appController->getViewPath();
     } elseif (Yii::app() instanceof CConsoleApplication) {
         $viewName = Yii::app()->getCommandPath();
     } else {
         $viewName = 'application.console';
     }
     $report->setViewName($viewName);
     /* getUrl doesn't exists in ConsoleApplication and causes errors */
     if (Yii::app() instanceof CConsoleApplication) {
         $report->setUrl($appEnlight->getHostName());
     } else {
         $report->setUrl($appEnlight->getHostName() . $appRequest->getUrl());
     }
     $report->setUserAgent($appRequest->getUserAgent());
     $report->setMessage($exception->__toString());
     $report->setRequestId($client->getUUID());
     $report->setError($exception->getMessage());
     $report->setHttpStatus($exception instanceof CHttpException ? $exception->statusCode : 500);
     $this->_processTrace($exception, $report);
     /* request is filled automatically */
     $request = new AppEnlight\Endpoint\Data\Report\Request();
     $report->setRequest($request);
     $client->addReport($report);
     $client->sendReports();
     parent::handleException($exception);
 }
Esempio n. 8
0
 public function render($view, $data)
 {
     if (CONFIG == 'production') {
         try {
             if ($data['type'] == 'CHttpException' && $data['code'] == 404) {
                 Yii::app()->runController($this->error404);
                 return true;
             }
             if ($view == 'exception' || $view == 'error') {
                 Yii::app()->user->setFlash('error', $data['message']);
             }
             $this->tryRedirectOnPreviousUrl();
         } catch (Exception $e) {
             Yii::log($e->getTraceAsString(), CLogger::LEVEL_ERROR);
         }
         Yii::app()->user->setFlash('error', $data['message']);
         $this->redirect($this->maintanance);
     } else {
         parent::render($view, $data);
     }
 }
 /**
  * @param \ErrorException $exception
  */
 protected function handleFatalError($exception)
 {
     \Rollbar::report_php_error($exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine());
     parent::handleException($exception);
 }
Esempio n. 10
0
 /**
  * Renders the exception information. This method will display information from current {@link error} value.
  */
 protected function renderError()
 {
     // This could be an exception because handleException can call renderError.
     $exception = $this->getException();
     // If the exception exists, and it's an instance of HttpException or devMode isn't enabled
     // set the errorAction to our TemplatesController->renderError().
     if (!YII_DEBUG || $exception instanceof HttpException) {
         $this->errorAction = 'templates/renderError';
     }
     parent::renderError();
 }
Esempio n. 11
0
 /**
  * Handles a PHP error.
  *
  * @param \CErrorEvent $event the PHP error event
  *
  * @return null
  */
 protected function handleError($event)
 {
     $trace = debug_backtrace();
     // Was this triggered by a Twig template directly?
     if (isset($trace[3]['object']) && $trace[3]['object'] instanceof \Twig_Template) {
         $exception = new \Twig_Error_Runtime($event->message);
         $this->handleTwigError($exception);
     } else {
         // Check to see if this happened while running a task
         foreach ($trace as $step) {
             if (isset($step['class']) && $step['class'] == __NAMESPACE__ . '\\TasksService' && $step['function'] == 'runTask') {
                 $task = craft()->tasks->getRunningTask();
                 if ($task) {
                     craft()->tasks->fail($task, $event->message . ' on line ' . $event->line . ' of ' . $event->file);
                 }
                 break;
             }
         }
         parent::handleError($event);
     }
 }
 protected function handleError($event)
 {
     Rollbar::report_php_error($event->code, $event->message, $event->file, $event->line);
     parent::handleError($event);
 }
Esempio n. 13
0
 /**
  * Forwards an exception to Whoops.
  * @param Exception $exception
  */
 protected function handleException($exception)
 {
     if ($exception instanceof CHttpException && $this->errorAction !== null || !YII_DEBUG) {
         parent::handleException($exception);
         return;
     }
     $this->disableLogRoutes();
     $this->whoops->handleException($exception);
 }
Esempio n. 14
0
 /**
  * Handles the exception.
  * @param Exception $exception the exception captured.
  */
 protected function handleException($exception)
 {
     $this->getSentryClient()->captureException($exception);
     parent::handleException($exception);
 }
 protected function handleError($e)
 {
     Monolog\Registry::main()->addError(self::codeToString($e->code) . ': ' . $e->message, array('code' => $e->code, 'message' => $e->message, 'file' => $e->file, 'line' => $e->line, 'params' => $e->params, 'environment' => Yii::app()->getComponent($this->monologComponentName)->environment));
     parent::handleError($e);
 }
 /**
  * Forwards an exception to Whoops.
  * @param Exception $exception
  */
 protected function handleException($exception)
 {
     if ($this->beforeHandling($exception)) {
         if (!headers_sent()) {
             $code = $exception instanceof CHttpException ? $exception->statusCode : 500;
             $msg = $this->getHttpHeader($code, get_class($exception));
             header("{$_SERVER['SERVER_PROTOCOL']} {$code} {$msg}");
         }
         if ($exception instanceof CHttpException || !YII_DEBUG) {
             parent::render('error', $exception);
         } else {
             if ($this->isAjaxRequest()) {
                 Yii::app()->displayException($exception);
             } else {
                 if ($this->errorAction) {
                     Yii::app()->runController($this->errorAction);
                 }
                 if (!$this->handled) {
                     $this->whoops->handleException($exception);
                 }
             }
         }
     }
 }
Esempio n. 17
0
 public function __construct(&$view)
 {
     // Loading configuration file parameters
     try {
         if (!FileConfig::open(CONFIG_FILE)) {
             throw new Exception("The configuration file is missing");
         } else {
             $this->catalog_nb = FileConfig::count_Catalogs();
         }
     } catch (Exception $e) {
         CErrorHandler::displayError($e);
     }
     // Template engine initalization
     $this->view = $view;
     // Checking template cache permissions
     if (!is_writable(VIEW_CACHE_DIR)) {
         throw new Exception("The template cache folder <b>" . VIEW_CACHE_DIR . "</b> must be writable by Apache user");
     }
     // Initialize smarty gettext function
     $language = FileConfig::get_Value('language');
     if (!$language) {
         throw new Exception("Language translation problem");
     }
     $this->translate = new CTranslation($language);
     $this->translate->set_Language($this->view);
     // Get catalog_id from http $_GET request
     if (!is_null(CHttpRequest::get_Value('catalog_id'))) {
         if (FileConfig::catalogExist(CHttpRequest::get_Value('catalog_id'))) {
             $this->catalog_current_id = CHttpRequest::get_Value('catalog_id');
             $_SESSION['catalog_id'] = $this->catalog_current_id;
         } else {
             $_SESSION['catalog_id'] = 0;
             $this->catalog_current_id = 0;
             throw new Exception('The catalog_id value provided does not correspond to a valid catalog, please verify the config.php file');
         }
     } else {
         if (isset($_SESSION['catalog_id'])) {
             // Stick with previously selected catalog_id
             $this->catalog_current_id = $_SESSION['catalog_id'];
         }
     }
     // Define catalog id and catalog label
     $this->view->assign('catalog_current_id', $this->catalog_current_id);
     $this->view->assign('catalog_label', FileConfig::get_Value('label', $this->catalog_current_id));
     // Getting database connection paremeter from configuration file
     $dsn = FileConfig::get_DataSourceName($this->catalog_current_id);
     $driver = FileConfig::get_Value('db_type', $this->catalog_current_id);
     $user = '';
     $pwd = '';
     if ($driver != 'sqlite') {
         $user = FileConfig::get_Value('login', $this->catalog_current_id);
         $pwd = FileConfig::get_Value('password', $this->catalog_current_id);
     }
     switch ($driver) {
         case 'mysql':
         case 'pgsql':
             $this->db_link = CDB::connect($dsn, $user, $pwd);
             break;
         case 'sqlite':
             $this->db_link = CDB::connect($dsn);
             break;
     }
     // Getting driver name from PDO connection
     $this->db_driver = CDB::getDriverName();
     // Set PDO connection options
     $this->db_link->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
     $this->db_link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $this->db_link->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('CDBResult', array($this)));
     // MySQL connection specific parameter
     if ($driver == 'mysql') {
         $this->db_link->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
     }
     // Bacula catalog selection
     if ($this->catalog_nb > 1) {
         // Catalogs list
         $this->view->assign('catalogs', FileConfig::get_Catalogs());
         // Catalogs count
         $this->view->assign('catalog_nb', $this->catalog_nb);
     }
 }
Esempio n. 18
0
            $job['compression'] = 'N/A';
        }
        // Job speed
        $start = $job['starttime'];
        $end = $job['endtime'];
        $seconds = DateTimeUtil::get_ElaspedSeconds($end, $start);
        if ($seconds !== false && $seconds > 0) {
            $speed = $job['jobbytes'] / $seconds;
            $job['speed'] = CUtils::Get_Human_Size($speed, 2) . '/s';
        } else {
            $job['speed'] = 'N/A';
        }
        // Job bytes more easy to read
        $job['jobbytes'] = CUtils::Get_Human_Size($job['jobbytes']);
        $job['jobfiles'] = CUtils::format_Number($job['jobfiles']);
        $jobs[] = $job;
    }
    // end while
} catch (Exception $e) {
    CErrorHandler::displayError($e);
}
$view->assign('jobs', $jobs);
$view->assign('backupjob_name', $backupjob_name);
$view->assign('backupjob_period', $backupjob_period);
$view->assign('backupjob_bytes', $backupjob_bytes);
$view->assign('backupjob_files', $backupjob_files);
// Set page name
$current_page = 'Backup job report';
$view->assign('page_name', $current_page);
// Process and display the template
$view->display('backupjob-report.tpl');
Esempio n. 19
0
 /**
  * Override CErrorHandler handle event to process error stack
  *
  * @param mixed $event
  */
 public function handle($event)
 {
     if (YII_DEBUG == false && $event instanceof CExceptionEvent && $event->exception instanceof XException && $this->errorAction != '') {
         // If a XException is thrown it should be handled friendly as the way exception is handled in NON DEBUG mode
         // Therefore, we will cast the exception into CHttpException so that CErrorHandler will runs errorAction
         $exception = $event->exception;
         $event->exception = new CHttpException(500, $exception->getMessage());
     }
     if (YII_DEBUG) {
         // Yii tries to run the errorAction if it's set even in debug mode
         // while we do not like that. It helps only if the action can provide
         // more details than Yii default error/exception debug report.
         $this->errorAction = null;
     }
     parent::handle($event);
     if ($this->sendNotificationEmail && array_search($this->Error['code'], $this->excludedCodes) === false) {
         // Send email to admin if debug is turn off
         $this->notifyByMail($this->Error);
     }
 }
 /**
  * Grant public access to protected method for error view rendering.
  *
  * @param $args
  * @return string
  */
 public function getArgumentsToString($args)
 {
     return parent::argumentsToString($args);
 }
Esempio n. 21
0
 public function handle($event)
 {
     parent::handle($event);
 }