public static function error_handling_live($err_no, $err_str, $err_file, $err_line, $err_context) { $exception = new ErrorException($err_str, 0, $err_no, $err_file, $err_line); $ErrorHandler = new ErrorHandler($exception); $ErrorHandler->ProcessError(); return; }
/** Registers this with an ErrorHandler. Will register as a late-binding handler, so other error handlers take precedence. */ static function registerWith(ErrorHandler $eh, $includeWarnings = self::NoWarnings) { self::$fullMap = self::$fullMap ?: self::$errorMap + self::$warningMap; $errors = self::getBits(self::$errorMap); if ($includeWarnings) { $errors |= self::getBits(self::$warningMap); } $eh->addErrorHandler($errors, "/^(.*)\$/", [__CLASS__, 'handleError'], ErrorHandler::Late); }
/** * register handler * $errorLevel determines level at which an Exception is thrown (NULL forces error_reporting() return value, 0 to disable error reporting) * * @param integer $errorLevel * @param boolean $displayErrors * * @throws \RuntimeException * @return \vxPHP\Debug\ErrorHandler */ public static function register($errorLevel = NULL, $displayErrors = TRUE) { if (self::$handler) { throw new \RuntimeException('Error handler already registered.'); } self::$handler = new static(); self::$handler->setLevel($errorLevel)->setDisplayErrors($displayErrors); // disable "native" error display mechanism ini_set('display_errors', 0); // set handler set_error_handler(array(self::$handler, 'handle')); return self::$handler; }
/** * Tests */ public function testShouldDisplay404Error() { $request = new NeechyRequest(); $page = Page::find_by_title('NeechyPage'); try { throw new NeechyWebServiceError('Testing 404 Error', 404); } catch (NeechyError $e) { $handler = new ErrorHandler($request); $response = $handler->handle_error($e); } $this->assertEquals(404, $response->status); $this->assertContains($e->getMessage(), $response->body); $this->assertContains('Testing 404 Error', $response->body); }
public static function shutdownCheck() { //error_log("shutdown check"); if ($error = error_get_last()) { if ($error['type'] == E_COMPILE_ERROR) { $exception = new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']); if (strpos($exception->getMessage(), "Cannot redeclare class") !== false) { //send email alerts for duplicate class declarations.. error already logged by php $ErrorHandler = new ErrorHandler($exception); $ErrorHandler->email_alert(); } } } return; }
/** * Enables the debug tools. * * This method registers an error handler and an exception handler. * * If the Symfony ClassLoader component is available, a special * class loader is also registered. * * @param int $errorReportingLevel The level of error reporting you want * @param bool $displayErrors Whether to display errors (for development) or just log them (for production) */ public static function enable($errorReportingLevel = E_ALL, $displayErrors = true) { if (static::$enabled) { return; } static::$enabled = true; if (null !== $errorReportingLevel) { error_reporting($errorReportingLevel); } else { error_reporting(E_ALL); } if ('cli' !== PHP_SAPI) { ini_set('display_errors', 0); ExceptionHandler::register(); } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) { // CLI - display errors only if they're not already logged to STDERR ini_set('display_errors', 1); } if ($displayErrors) { ErrorHandler::register(new ErrorHandler(new BufferingLogger())); } else { ErrorHandler::register()->throwAt(0, true); } DebugClassLoader::enable(); }
/** * return array of domain ids which can administer given user * * * Possible options: * - none * * @param string $uid * @param array $opt associative array of options * @return array array of domain ids or FALSE on error */ function get_domains_of_admin($uid, $opt) { global $config; $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return false; } /* table's name */ $t_name =& $config->data_sql->domain_attrs->table_name; /* col names */ $c =& $config->data_sql->domain_attrs->cols; /* flags */ $f =& $config->data_sql->domain_attrs->flag_values; $an =& $config->attr_names; $q = "select " . $c->did . " \n\t\t from " . $t_name . "\n\t\t\twhere " . $c->name . " = '" . $an['admin'] . "' and \n\t\t\t " . $c->value . " = " . $this->sql_format($uid, "s") . " and \n\t\t\t (" . $c->flags . " & " . $f['DB_DELETED'] . ") = 0 and\n\t\t\t\t (" . $c->flags . " & " . $f['DB_FOR_SERWEB'] . ") = " . $f['DB_FOR_SERWEB']; $res = $this->db->query($q); if (DB::isError($res)) { ErrorHandler::log_errors($res); return false; } $out = array(); for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) { $out[$i] = $row[$c->did]; } $res->free(); return $out; }
public static function displayMessages() { foreach (self::$messages as $message) { echo "<li>{$message}</li>"; } self::$messages = array(); }
public function dispatch() { $helper = HelperFactory::getHelper("Http"); $conf = $helper->parseGet($_GET); try { $staticRoute = $this->getCotrollerByAlias(ucfirst($conf["controller"])); if ($staticRoute !== false) { $conf["controller"] = $staticRoute['controller']; if ($staticRoute['action'] != '') { $conf["action"] = $staticRoute['action']; } } $controller = ControllerFactory::getController(ucfirst($conf["controller"])); $controller->applyFilters($conf); $action = $conf["action"] . "Action"; $controller->startUp($conf); call_user_func_array(array($controller, $action), $conf["param"]); $controller->render($conf["action"]); } catch (Doctrine_Connection_Exception $e) { exit($e->getMessage()); ErrorHandler::displayError("Found a Doctrine connection error.<br>\n\t\t\t\t\t\t\t\t\t \tMake suere that you have started the Doctrine\n\t\t\t\t\t\t\t\t\t \tsubsystem.<br>"); } catch (MissingControllerException $e) { exit("<h1>ERROR</h1><br><h2>Missing Controller</h2>"); } catch (MissingClassException $e) { exit("<h1>ERROR</h1><br><h2>Missing class</h2>"); } catch (Exception $e) { exit($e->getMessage()); $controller = ControllerFactory::getController("_404"); $controller->startUp(); $controller->render("index"); } }
private static function CheckErrors() { if (!ErrorHandler::IsEmpty()) { ErrorHandler::Show(); die; } }
/** * Verifies a recaptcha * * @param $priv_key private recaptcha key * @return true on success */ public function verify() { $error = ErrorHandler::getInstance(); $conf = RecaptchaConfig::getInstance(); if (empty($_POST['recaptcha_challenge_field']) || empty($_POST['recaptcha_response_field'])) { $error->add('No captcha answer given.'); return false; } if (!$conf->getPublicKey() || !$conf->getPrivateKey()) { die('ERROR - Get Recaptcha API key at http://recaptcha.net/api/getkey'); } $params = array('privatekey' => $conf->getPrivateKey(), 'remoteip' => client_ip(), 'challenge' => $_POST['recaptcha_challenge_field'], 'response' => $_POST['recaptcha_response_field']); $http = new HttpClient($this->api_url_verify); $res = $http->post($params); $answers = explode("\n", $res); if (trim($answers[0]) == 'true') { return true; } switch ($answers[1]) { case 'incorrect-captcha-sol': $e = 'Incorrect captcha solution'; break; default: $e = 'untranslated error: ' . $answers[1]; } $error->add($e); return false; }
public static function install() { if (isset(self::$prev)) { throw new Exception('ErrorHandler: Alread Installed'); } self::$prev = set_error_handler(array(__CLASS__, 'handler')); }
/** * delete all user's records from user_attrs */ function delete_user_attrs($uid) { global $config; $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return false; } /* table's name */ $t_name =& $config->data_sql->user_attrs->table_name; /* col names */ $c =& $config->data_sql->user_attrs->cols; /* flags */ $f =& $config->data_sql->user_attrs->flag_values; $q = "delete from " . $t_name . " \n\t\t where " . $c->uid . " = '" . $uid . "'"; $res = $this->db->query($q); if (DB::isError($res)) { if ($res->getCode() == DB_ERROR_NOSUCHTABLE) { return true; } else { ErrorHandler::log_errors($res); return false; } } return true; }
/** * Purge old acc records * * Possible options parameters: * none * * @param array $opt associative array of options * @return bool TRUE on success, FALSE on failure */ function delete_acc($opt) { global $config; if (!$config->keep_acc_interval) { return true; } $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return 0; } /* table's name */ $t_name =& $config->data_sql->acc->table_name; /* col names */ $c =& $config->data_sql->acc->cols; /* flags */ $f =& $config->data_sql->acc->flag_values; if ($this->db_host['parsed']['phptype'] == 'mysql') { $q = "delete from " . $t_name . " \n\t\t\t\twhere DATE_ADD(" . $c->request_timestamp . ", INTERVAL " . $config->keep_acc_interval . " DAY) < now()"; } else { $q = "delete from " . $t_name . " \n\t\t\t\twhere (" . $c->request_timestamp . " + INTERVAL '" . $config->keep_acc_interval . " DAY') < now()"; } $res = $this->db->query($q); if (DB::isError($res)) { //expect that table mayn't exist in installed version if ($res->getCode() != DB_ERROR_NOSUCHTABLE) { ErrorHandler::log_errors($res); return false; } } return true; }
public static function debug($message) { if (!DEBUG) { return; } ErrorHandler::error(500, "Debug", "<pre>" . $message . "</pre>", 3); }
/** * return array of credentials of user * * Possible options: * - none * * @param string $uid uid of user * @param array $opt array of options * @return array array of credentials */ function get_credentials($uid, $opt) { global $config; $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return false; } /* table's name */ $t_name =& $config->data_sql->credentials->table_name; /* col names */ $c =& $config->data_sql->credentials->cols; /* flags */ $f =& $config->data_sql->credentials->flag_values; $q = "select " . $c->did . ", \n\t\t " . $c->uname . ",\n\t\t " . $c->realm . ",\n\t\t " . $c->password . ",\n\t\t " . $c->ha1 . ",\n\t\t " . $c->ha1b . ",\n\t\t " . $c->flags . "\n\t\t from " . $t_name . " \n\t\t\twhere " . $c->uid . " = " . $this->sql_format($uid, "s") . " and\n\t\t\t " . $c->flags . " & " . $f['DB_DELETED'] . " = 0\n\t\t\torder by " . $c->realm . ", " . $c->uname; $res = $this->db->query($q); if (DB::isError($res)) { ErrorHandler::log_errors($res); return false; } $out = array(); for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) { $out[$i] = new Credential($uid, $row[$c->did], $row[$c->uname], $row[$c->realm], $row[$c->password], $row[$c->ha1], $row[$c->ha1b], $row[$c->flags]); } $res->free(); return $out; }
/** * Show Permission denied page */ public function actionPermissionDenied() { // TODO: logout user, redirect to admin login form and the error should be dislayed in the form ErrorHandler::logError('Permission denied!<br />- You do not have enough privilege to access the page you requested or<br />- The requested page is accessible but a service on that page cannot be performed on your behalf.'); Yii::app()->layout = 'permission'; $this->render('PermissionDenied'); }
/** * @return string */ private function ShowExistingErrorMessagesIfExceptionExists() { if ($this->m_exception != null) { return "<div class='well'>\n <h3>Error Message ({$this->m_exception->getCode()})</h3>\n <h6 class ='h6'>\n {$this->m_errorHandler->GetErrorMessageByCode($this->m_exception->getCode())}\n </h6>\n </div>"; } return ""; }
/** * Create the single instance of class * * @param none * @return Object self::$singleInstance Instance */ public static function getInstance() { if (!self::$singleInstance instanceof self) { self::$singleInstance = new self(); } return self::$singleInstance; }
public function getDecodeJson($key, $default = null) { ErrorHandler::start(); $params = json_decode($this->getParam($key), $default); ErrorHandler::stop(); return (array) $params; }
/** * Delete credentials from DB * * On error this method returning FALSE. * * Possible options: * - none * * * @return bool */ function del_credentials($uid, $did, $uname, $realm, $opt) { global $config; $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return false; } /* table name */ $t_name =& $config->data_sql->credentials->table_name; /* col names */ $c =& $config->data_sql->credentials->cols; /* flags */ $f =& $config->data_sql->credentials->flag_values; $q = "delete from " . $t_name . "\n\t\t where " . $c->uid . " = " . $this->sql_format($uid, "s") . " and\n\t\t " . $c->uname . " = " . $this->sql_format($uname, "s") . " and\n\t\t " . $c->realm . " = " . $this->sql_format($realm, "s"); if ($config->auth['use_did']) { $q .= " and " . $c->did . " = " . $this->sql_format($did, "s"); } $res = $this->db->query($q); if (DB::isError($res)) { ErrorHandler::log_errors($res); return false; } return true; }
public static function stop() { self::$Enabled = false; error_reporting(E_ALL); restore_error_handler(); register_shutdown_function("exit"); }
public function serve() { try { NeechySecurity::start_session(); NeechySecurity::prevent_csrf(); $this->request = NeechyRequest::load(); $this->validate_environment(); $handler = $this->load_handler(); $response = $handler->handle(); } catch (NeechyError $e) { $handler = new ErrorHandler($this->request); $response = $handler->handle_error($e); } $response->send_headers(); $response->render(); }
public static function Handler($errNo, $errStr, $errFile, $errLine) { $backtrace = ErrorHandler::GetBacktrace(2); //Creating error message. $error_message = "\nErrNo: {$errNo}\n TEXT: {$errStr}\n LOCATION: {$errFile}\n LINE: {$errLine} at" . date('F j, Y, g:i:a') . " Showing Backtrace: {$backtrace}" . "\n"; if (LOG_ERRORS) { error_log($error_message, 3, LOG_ERROR_FILE); } if (SEND_ERROR_MAIL == true) { error_log($error_message, 1, ADMIN_ERROR_MAIL, "From: " . SENDMAIL_FROM . "\r\nTo: " . ADMIN_ERROR_MAIL); } if ($errNo == E_WARNING && IS_WARNING_FATAL == false || ($errNo == E_NOTICE || $errNo == E_USER_NOTICE)) { if (DEBUGGING) { echo '<div class="error_box"> <b> <pre>' . $error_message . '</pre> </b> </div>'; } } else { if (DEBUGGING) { echo '<div class="error_box"> <b> <pre>' . $error_message . '</pre> </b> </div>'; } else { echo SITE_GENERIC_FORM_MESSAGE; ob_clean(); include '500.php'; flush(); ob_flush(); ob_end_clean(); exit; } exit; } }
/** * Enable or disable domain * * Possible options: * * did (int) default: null * id of domain which will be en/disabled * this option is REQUIRED * * disable (bool) default: false * if true domain will be disabled, otherwise wil be enabled * * @param array $opt associative array of options * @return bool TRUE on success, FALSE on failure */ function enable_domain($opt) { global $config; $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return false; } /* table's name */ $td_name =& $config->data_sql->domain->table_name; /* col names */ $cd =& $config->data_sql->domain->cols; /* flags */ $fd =& $config->data_sql->domain->flag_values; $o_did = isset($opt['did']) ? $opt['did'] : null; $o_disable = isset($opt['disable']) ? $opt['disable'] : false; if (is_null($o_did)) { ErrorHandler::log_errors(PEAR::raiseError('domain for en/disable is not specified')); return false; } $q = "update " . $td_name . " set "; if ($o_disable) { $q .= $cd->flags . " = " . $cd->flags . " | " . $fd['DB_DISABLED']; } else { $q .= $cd->flags . " = " . $cd->flags . " & ~" . $fd['DB_DISABLED']; } $q .= " where " . $cd->did . " = " . $this->sql_format($o_did, "s"); $res = $this->db->query($q); if (DB::isError($res)) { ErrorHandler::log_errors($res); return false; } return true; }
public static function Handler($errNo, $errStr, $errFile, $errLine) { $backtrace = ErrorHandler::GetBacktrace(2); //Error message to be displayed, logged, or mailed $error_message = "\nERRNO: {$errNo}\nTEXT: {$errStr}" . "\nLOCATION: {$errFile}, line " . "{$errLine}, at " . date('F j, Y, g:i a') . "\nShowing backtrace:\n{$backtrace}\n\n"; if (SEND_ERROR_MAIL == true) { error_log($error_message, 1, ADMIN_ERROR_MAIL, "From: " . SENDMAIL_FROM . "\r\nTo: " . ADMIN_ERROR_MAIL); } //Log the error, in case LOG_ERRORS is true if (LOG_ERRORS == true) { error_log($error_message, 3, LOG_ERRORS_FILE); } /* Warnings don't abort execution if IS_WARNING_FATAL is false E_NOTICE and E_USER_NOTICE errors don't abort execution */ if ($errNo == E_WARNING && IS_WARNING_FATAL == false || ($errNo == E_NOTICE || $errNo == E_USER_NOTICE)) { // Show message only if DEBUGGING is true if (DEBUGGING == true) { echo '<div class="error_box"><pre>' . $error_message . '</pre></div>'; } } else { // Show error message if (DEBUGGING == true) { echo '<div class="error_box"><pre>' . $error_message . '</pre></div>'; } else { echo SITE_GENERIC_ERROR_MESSAGE; } // Stop processing the request exit; } }
function shutdownHandler() { if (is_null($e = error_get_last()) === false) { $error = new myError($e); ErrorHandler::handler($error); } }
/** * delete alias of user * * @param string $uid owner of the contact * @param string $username username part from URI * @param string $did domain part from URI * @param string $flags flags of the URI * @param array $opt various options * @return bool TRUE on success, FALSE on failure */ function delete_uri($uid, $scheme, $username, $did, $flags, $opt) { global $config; $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return false; } /* table name */ $t_name =& $config->data_sql->uri->table_name; /* col names */ $c =& $config->data_sql->uri->cols; /* flags */ $f =& $config->data_sql->uri->flag_values; $q = "delete from " . $t_name . "\n\t\t where " . $c->uid . " = " . $this->sql_format($uid, "s") . " and \n\t\t " . $c->scheme . " = " . $this->sql_format($scheme, "s") . " and \n\t\t " . $c->username . " = " . $this->sql_format($username, "s") . " and \n\t\t " . $c->did . " = " . $this->sql_format($did, "s") . " and \n\t\t " . $c->flags . " = " . $this->sql_format($flags, "n"); $res = $this->db->query($q); if (DB::isError($res)) { ErrorHandler::log_errors($res); return false; } if (isModuleLoaded('xxl')) { // get domain: $alias_d = domainname of $did $alias_uri = "sip:" . $username . "@" . $alias_d; if (false === $this->clear_proxy_xxl($alias_uri, null, $errors)) { ErrorHandler::add_error($errors); return false; } } return true; }
/** * get all versions of file specific for domain * * Possible options parameters: * none * * @param string $did domain id * @param string $file filename (with path) * @param array $opt associative array of options * @return array array of versions of file or FALSE on failure */ function get_file_versions($did, $file, $opt) { global $config; $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return false; } /* table's name */ $td_name =& $config->data_sql->domain_settings->table_name; /* col names */ $cd =& $config->data_sql->domain_settings->cols; /* flags */ $fd =& $config->data_sql->domain_settings->flag_values; $q = "select " . $cd->version . ", " . $cd->timestamp . ", " . $cd->flags . " \n\t\t from " . $td_name . " \n\t\t\t where " . $cd->did . " = " . $this->sql_format($did, "s") . " and\n\t\t\t " . $cd->filename . " = " . $this->sql_format($file, "s"); $res = $this->db->query($q); if (DB::isError($res)) { ErrorHandler::log_errors($res); return false; } $out = array(); while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) { $out[$row[$cd->version]]['timestamp'] = $row[$cd->timestamp]; $out[$row[$cd->version]]['deleted'] = (bool) ($row[$cd->flags] & $fd["DB_DELETED"]); $out[$row[$cd->version]]['dir'] = (bool) ($row[$cd->flags] & $fd["DB_DIR"]); } $res->free(); return $out; }
function get_missed_calls_of_yesterday($uid, $opt) { global $config; $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return false; } if ($this->db_host['parsed']['phptype'] == 'mysql') { $q_date = " date_format(request_timestamp, '%Y-%m-%d')=date_format(DATE_SUB(CURDATE(), INTERVAL 1 DAY), '%Y-%m-%d') "; } else { $q_date = " date_trunc('day', request_timestamp)=date_trunc('day', (CURRENT_DATE - INTERVAL '1 DAY')) "; } $q = "SELECT from_uri, sip_from, request_timestamp, sip_status " . "FROM " . $config->data_sql->table_missed_calls . " " . "WHERE to_uid='" . $uid . "' and " . $q_date . "ORDER BY request_timestamp DESC "; $res = $this->db->query($q); if (DB::isError($res)) { ErrorHandler::log_errors($res); return false; } $out = array(); while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { $out[] = $row; } $res->free(); return $out; }