error_status = filter_input(INPUT_POST, 'error_status', FILTER_VALIDATE_INT, ['min_range' => 0, 'max_range' => 2]); $this->posted_error_id = filter_input(INPUT_POST, 'error_id', FILTER_VALIDATE_INT); $this->delete_status = filter_input(INPUT_POST, 'delete_status', FILTER_VALIDATE_INT, ['min_range' => 0, 'max_range' => 2]); $this->rowstart = filter_input(INPUT_GET, 'rowstart', FILTER_VALIDATE_INT) ?: 0; $this->error_id = filter_input(INPUT_GET, 'error_id', FILTER_VALIDATE_INT); if (isnum($this->error_status) && $this->posted_error_id) { dbquery("UPDATE ".DB_ERRORS." SET error_status='".$this->error_status."' WHERE error_id='".$this->posted_error_id."'"); $source_redirection_path = preg_replace("~".fusion_get_settings("site_path")."~", "", FUSION_REQUEST, 1); redirect(fusion_get_settings("siteurl").$source_redirection_path); } if (isset($_POST['delete_entries']) && isnum($this->delete_status)) { dbquery("DELETE FROM ".DB_ERRORS." WHERE error_status='".$_POST['delete_status']."'"); $source_redirection_path = preg_replace("~".fusion_get_settings("site_path")."~", "", FUSION_REQUEST, 1); redirect(fusion_get_settings("siteurl").$source_redirection_path); } $result = dbquery("SELECT * FROM ".DB_ERRORS." ORDER BY error_timestamp DESC LIMIT :rowstart,20", [':rowstart' => $this->rowstart]); while ($data = dbarray($result)) { $this->errors[$data['error_id']] = $data; } $this->rows = $this->errors ? dbcount('(error_id)', DB_ERRORS) : 0; } public static function getInstance($key = 'default') { if (!isset(self::$instances[$key])) { self::$instances[$key] = new static(); self::$locale = fusion_get_locale('', [ LOCALE.LOCALESET.'admin/errors.php', LOCALE.LOCALESET.'errors.php' ] ); } return self::$instances[$key]; } /** * Custom error handler for PHP processor * * @param $error_level - Severity * @param $error_message - $e->message * @param $error_file - The file in question, run a debug_backtrace()[2] in the file * @param $error_line - The line in question, run a debug_backtrace()[2] in the file */ public function setError($error_level, $error_message, $error_file, $error_line) { $userdata = fusion_get_userdata(); $showLiveError = TRUE; // directly show error - push to another instance $db = DatabaseFactory::getConnection(); $result = $db->query( "SELECT error_id, error_status FROM ".DB_ERRORS." WHERE error_message = :message AND error_file = :file AND error_line = :line AND error_status != '1' AND error_page = :page ORDER BY error_timestamp DESC LIMIT 1", [ ':message' => $error_message, ':file' => $error_file, ':page' => FUSION_REQUEST, ':line' => $error_line, ]); if ($db->countRows($result) == 0) { $db->query("INSERT INTO ".DB_ERRORS." ( error_level, error_message, error_file, error_line, error_page, error_user_level, error_user_ip, error_user_ip_type, error_status, error_timestamp ) VALUES ( :level, :message, :file, :line, :page, '".$userdata['user_level']."', '".USER_IP."', '".USER_IP_TYPE."', '0', '".time()."' )", [ ':level' => $error_level, ':message' => $error_message, ':file' => $error_file, ':page' => FUSION_REQUEST, ':line' => $error_line, ]); $errorId = $db->getLastId(); } else { $data = $db->fetchAssoc($result); $errorId = $data['error_id']; if ($data['error_status'] == 2) { $showLiveError = FALSE; } } if ($showLiveError) { $this->new_errors[$errorId] = [ "error_id" => $errorId, "error_level" => $error_level, "error_file" => $error_file, "error_line" => $error_line, "error_page" => FUSION_REQUEST, "error_message" => $error_message, "error_timestamp" => time(), "error_status" => 0, ]; } } /** * Administration Console */ public function display_administration() { $aidlink = fusion_get_aidlink(); $locale = self::$locale; define("NO_DEBUGGER", TRUE); $_GET['rowstart'] = isset($_GET['rowstart']) && isnum($_GET['rowstart']) ? $_GET['rowstart'] : 0; $tab_title['title'][] = $locale['ERROR_460']; $tab_title['id'][] = 'errors-list'; $tab_title['icon'][] = 'fa fa-bug m-r-10'; if ($this->error_id) { $tab_title['title'][] = $locale['ERROR_461']; $tab_title['id'][] = 'error-file'; $tab_title['icon'][] = 'fa fa-medkit m-r-10'; $tab_title['title'][] = $locale['ERROR_465']; $tab_title['id'][] = 'src-file'; $tab_title['icon'][] = 'fa fa-stethoscope m-r-10'; } $tab_active = tab_active($tab_title, $this->error_id ? 1 : 0); BreadCrumbs::getInstance()->addBreadCrumb(['link' => ADMIN."errors.php".$aidlink, 'title' => $locale['ERROR_400']]); opentable($locale['ERROR_400']); echo opentab($tab_title, $tab_active, 'error_tab'); echo opentabbody($tab_title['title'][0], $tab_title['id'][0], $tab_active); echo "
".$this->getErrorLogs()."
"; echo closetabbody(); if ($this->error_id) { // dump 1 and 2 add_to_head(""); define('no_debugger', 1); $data = dbarray(dbquery("SELECT * FROM ".DB_ERRORS." WHERE error_id=:errorid LIMIT 1", [':errorid' => $this->error_id])); if (!$data) { redirect(FUSION_SELF.$aidlink); } $thisFileContent = is_file($data['error_file']) ? file($data['error_file']) : []; $line_start = max($data['error_line'] - 10, 1); $line_end = min($data['error_line'] + 10, count($thisFileContent)); $output = implode("", array_slice($thisFileContent, $line_start - 1, $line_end - $line_start + 1)); $pageFilePath = BASEDIR.$data['error_page']; $pageContent = is_file($pageFilePath) ? file_get_contents($pageFilePath) : ''; add_to_jquery("$('#error_status_sel').bind('change', function(e){this.form.submit();});"); echo opentabbody($tab_title['title'][1], $tab_title['id'][1], $tab_active); ?>

--
-- --
TRUE, 'options' => self::get_logTypes() ]); echo closeform(); ?>
()
$data['error_timestamp'], 'text' => $data['error_message'] ]) ?>
:
'); add_to_jquery('new ClipboardJS(".copy-error");'); // Use clean request for absolute escape from SEO converging form path $html = openform('error_logform', 'post', clean_request('', [], FALSE)); $html .= '
'; $html .= "
".$locale['ERROR_440']."
\n"; $html .= "
\n"; $html .= form_select('delete_status', '', '', ['allowclear' => TRUE, 'options' => self::get_logTypes(), 'inline' => TRUE]); $html .= form_button('delete_entries', $locale['ERROR_453'], $locale['ERROR_453'], ['class' => 'm-l-10 btn-primary btn-sm']); $html .= "
\n"; $html .= "
\n"; $html .= closeform(); if (!empty($this->errors) or !empty($this->new_errors)) { $html .= "
"; $html .= ""; $html .= ""; $html .= ""; $html .= "\n"; $html .= "\n"; if (!empty($this->errors)) { foreach ($this->errors as $i => $data) { $link_title = $this->getMaxFolders($data['error_file'], 1); $html .= ""; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; /* Toggle Info */ $html .= "\n"; $html .= ''; } } if (!empty($this->new_errors)) { foreach ($this->new_errors as $i => $data) { $link_title = $this->getMaxFolders($data['error_file'], 1); $html .= ""; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; /* Toggle Info */ $html .= "\n"; $html .= ''; } } $html .= "
".$locale['ERROR_410']."".$locale['ERROR_462']."".$locale['ERROR_414']."
"; $html .= "".$link_title."
\n"; $html .= "".$data['error_page']."
\n"; $html .= "".$locale['ERROR_415']." ".$data['error_line']."
\n"; $html .= "".timer($data['error_timestamp'])."\n"; $html .= "
".$this->getSources($data['error_id'])."\n"; $html .= "".$locale['ERROR_450']."\n"; $html .= "".$locale['ERROR_451']."\n"; $html .= "".$locale['ERROR_452']."\n"; $html .= "".$locale['delete']."\n"; $html .= "
\n"; $html .= "

".$locale['ERROR_454']." : ".$this->get_errorTypes($data['error_level'])."

"; $html .= "
\n"; $html .= strtr($data['error_message'], ['#' => '
#'])."
\n"; $html .= "
"; $html .= "".$link_title."
\n"; $html .= "".$data['error_page']." **
\n"; $html .= "".$locale['ERROR_415']." ".$data['error_line']."
\n"; $html .= "".timer($data['error_timestamp'])."\n"; $html .= "
".$this->getSources($data['error_id'])."\n"; $html .= "".$locale['ERROR_450']."\n"; $html .= "".$locale['ERROR_451']."\n"; $html .= "".$locale['ERROR_452']."\n"; $html .= "".$locale['delete']."\n"; $html .= "
\n"; $html .= "

".$locale['ERROR_454']." : ".$this->get_errorTypes($data['error_level'])."

"; $html .= "
\n"; $html .= strtr($data['error_message'], ['#' => '
#'])."
\n"; $html .= "
\n
"; if ($this->rows > 20) { $html .= "
\n"; $html .= makepagenav($this->rowstart, 20, $this->rows, 3, ADMIN."errors.php".$aidlink."&"); $html .= "
\n"; } } else { $html .= "
".$locale['ERROR_418']."
\n"; } $this->errorjs(); return $html; } private static function get_logTypes() { $locale = self::$locale; return [ '0' => $locale['ERROR_450'], '1' => $locale['ERROR_451'], '2' => $locale['ERROR_452'] ]; } private static function getMaxFolders($url, $level = 2) { $return = ""; $tmpUrlArr = explode("/", $url); if (count($tmpUrlArr) > $level) { $tmpUrlArr = array_reverse($tmpUrlArr); for ($i = 0; $i < $level; $i++) { $return = $tmpUrlArr[$i].($i > 0 ? "/".$return : ""); } } else { $return = implode("/", $tmpUrlArr); } return $return; } private function getSources($error_id) { $aidlink = fusion_get_aidlink(); $link = ADMIN."errors.php$aidlink&rowstart=".$this->rowstart."&error_id=".$error_id."#file"; $html = "
\n"; $html .= "\n"; $html .= "\n"; $html .= "
\n"; return $html; } private static function get_errorTypes($type) { $locale = self::$locale; $error_types = [ self::E_ERROR => ["E_ERROR", $locale['E_ERROR']], self::E_WARNING => ["E_WARNING", $locale['E_WARNING']], self::E_PARSE => ["E_PARSE", $locale['E_PARSE']], self::E_NOTICE => ["E_NOTICE", $locale['E_NOTICE']], self::E_CORE_ERROR => ["E_CORE_ERROR", $locale['E_CORE_ERROR']], self::E_CORE_WARNING => ["E_CORE_WARNING", $locale['E_CORE_WARNING']], self::E_COMPILE_ERROR => ["E_COMPILE_ERROR", $locale['E_COMPILE_ERROR']], self::E_COMPILE_WARNING => ["E_COMPILE_WARNING", $locale['E_COMPILE_WARNING']], self::E_USER_ERROR => ["E_USER_ERROR", $locale['E_USER_ERROR']], self::E_USER_WARNING => ["E_USER_WARNING", $locale['E_USER_WARNING']], self::E_USER_NOTICE => ["E_USER_NOTICE", $locale['E_USER_NOTICE']], self::E_ALL => ["E_ALL", $locale['E_ALL']], self::E_STRICT => ["E_STRICT", $locale['E_STRICT']] ]; if (isset($error_types[$type])) { return $error_types[$type][1]; } return FALSE; } private static function errorjs() { if (checkrights("ERRO") || !defined("iAUTH") || !isset($_GET['aid']) || $_GET['aid'] == iAUTH) { // Show the "Apply"-button only when javascript is disabled" add_to_jquery(" $('a#footer_debug').bind('click', function(e) { e.preventDefault(); }); $('.change_status').hide(); $('#top').click(function(){ jQuery('html, body').animate({scrollTop:0}, 'slow'); return false; }); $('.move_error_log').bind('click', function() { var form = $('#error_logform'); var data = { 'aidlink' : '".fusion_get_aidlink()."', 'error_id' : $(this).data('id'), 'error_type' : $(this).data('type') }; var sendData = form.serialize() + '&' + $.param(data); $.ajax({ url: '".FUSION_ROOT.ADMIN."includes/error_logs_updater.php', dataType: 'json', method : 'GET', type: 'json', data: sendData, success: function(e) { console.log(e); if (e.status == 'OK') { var target_group_add = $('tr#rmd-'+e.fusion_error_id+' > td > a.e_status_'+ e.to); var target_group_remove = $('tr#rmd-'+e.fusion_error_id+' > td > a.e_status_'+ e.from) target_group_add.addClass('active'); target_group_remove.removeClass('active'); } else if (e.status == 'RMD') { $('tr#rmd-'+e.fusion_error_id).remove(); $('tr#err_rmd-'+e.fusion_error_id).remove(); } }, error : function(e) { console.log('fail'); } }); }); "); } } private static function printCode($source_code, $starting_line, $error_line = "", array $error_message = []) { $locale = fusion_get_locale(); if (is_array($source_code)) { return FALSE; } $error_message = [ 'time' => !empty($error_message['time']) ? $error_message['time'] : time(), 'text' => !empty($error_message['text']) ? $error_message['text'] : $locale['na'],]; $source_code = explode("\n", str_replace(["\r\n", "\r"], "\n", $source_code)); $line_count = $starting_line; $formatted_code = ""; $error_message = "
Line ".$error_line." -- ".timer($error_message['time'])."
".$error_message['text']."
\n"; foreach ($source_code as $code_line) { $code_line = self::codeWrap($code_line, 145); $line_class = ($line_count == $error_line ? "err_tbl-error-line" : "err_tbl1"); $formatted_code .= "\n".$line_count."\n"; if (preg_match('#<\?(php)?[^[:graph:]]#', $code_line)) { $formatted_code .= "".str_replace([ '', '' ], '', highlight_string($code_line, TRUE))."\n\n"; } else { $formatted_code .= "".preg_replace('#(<\?php )+#', '', str_replace([ '', '' ], '', highlight_string('\n\n"; if ($line_count == $error_line) { $formatted_code .= "\n".$error_message."\n"; } } $line_count++; } return "".$formatted_code."
"; } private static function codeWrap($code, $maxLength = 150) { $lines = explode("\n", $code); $count = count($lines); for ($i = 0; $i < $count; ++$i) { preg_match('`^\s*`', $code, $matches); $lines[$i] = wordwrap($lines[$i], $maxLength, "\n$matches[0]\t", TRUE); } return implode("\n", $lines); } /** Use this function to show error logs */ public function showFooterErrors() { $locale = self::$locale; $aidlink = fusion_get_aidlink(); $html = ''; if (iADMIN && checkrights("ERRO") && (count($this->errors) || count($this->new_errors)) && !defined("NO_DEBUGGER")) { $html .= "
"; $html .= "\n"; $html .= str_replace(["[ERROR_LOG_URL]", "[/ERROR_LOG_URL]"], [ "", "" ], $locale['err_101']); $html .= "L: ".count($this->errors)."\n"; $html .= "N: ".count($this->new_errors)."\n"; $html .= "
\n"; $cHtml = openmodal('tbody', $locale['ERROR_464'], ['class' => 'modal-lg modal-center zindex-boost', 'button_id' => 'footer_debug']); $cHtml .= $this->getErrorLogs(); $cHtml .= closemodal(); add_to_footer($cHtml); } return $html; } }