Убираем показ ошибок SQL и записываем их в файл , 2.1.х
В 2.1.х ошибки базы данных выводятся прямо на экран, что не есть хорошо по нескольким причинам.
Во первых, это выдает настоящий префикс таблиц.
А во вторых юзер пугается и уходит, не сообщая администратору, что есть нехорошо.
Сделаем логирование ошибок в недоступный извне файл и просмотр их из админцентра.
Прежде всего, это не работает на Windows хостинге (хотя переделать легко).
Еще это не работает, когда включен Safe Mode
0. Создать через FTP в папке cache папку sql_cache с правами 777
1. ./ips_kernel/class_db.php
найти
$the_error .= "\n\nSQL error: ".$this->_get_error_string()."\n"; $the_error .= "SQL error code: ".$this->error_no."\n"; $the_error .= "Date: ".date("j.n.Y, G:i"); $out = "<html><head><title>IPS Driver Error</title> <style>P,BODY{ font-family:arial,sans-serif; font-size:11px; }</style></head><body> <br><br><blockquote><b>Ошибка с базой данных.</b><br> Вы можете попробовать обновить эту страницу, нажав <a href=\"java script:window.location=window.location;\">сюда</a>. <br><br><b>Возвращаемая ошибка</b><br> <form name='mysql'><textarea rows=\"15\" cols=\"60\">".htmlspecialchars($the_error)."</textarea></form><br>Приносим свои извинения за предоставленные неудобства.</blockquote></body></html>"; print $out;
заменить на
$_error_string = "<?php\n\$error['".time()."']=\""; $_error_string .= "\n==================================================="; $_error_string .= "\n Date: ". date( 'r' ); $_error_string .= "\n Error Number: " . $this->_get_error_number(); $_error_string .= "\n Error: " . $this->_get_error_string(); $_error_string .= "\n IP Address: " . $_SERVER['REMOTE_ADDR']; $_error_string .= "\n ".$the_error; $_error_string .= "\";\n?>"; if ( $FH = @fopen( ROOT_PATH . 'cache/sql_cache/sql_error_log_'.date('m_d_y').'.php', 'a' ) ) { @fwrite( $FH, $_error_string ); @fclose( $FH ); } print "<html><head><title>IPS Driver Error</title> <style>P,BODY{ font-family:arial,sans-serif; font-size:11px; }</style></head><body> <blockquote><h1>IPS Driver Error</h1><b>There appears to be an error with the database.</b><br> You can try to refresh the page by clicking <a href=\"java script:window.location=window.location;\">here</a> </body></html>";
2. ./sources/acp_loaders/acp_pages_admin.php
найти
5 => array( 'Процессы' , 'section=admin&act=sql&code=processes' ),
добавить после
6 => array( 'Журнал ошибок SQL', 'section=admin&act=sql&code=error_log'),
3. ./sources/action_admin/sql_mysql.php
найти
case 'export_tbl': $this->do_safe_backup(trim(urldecode(stripslashes($_GET['tbl'])))); break;
добавить после
case 'error_log': $this->view_error_log(); break;
найти
} ?>
добавить перед
function view_error_log() { $this->ipsclass->admin->page_detail = "Журнал ошибок SQL"; $this->ipsclass->admin->page_title = "SQL ".$this->true_version; if (file_exists( ROOT_PATH . 'cache/sql_cache/' . $this->ipsclass->input['log_name'] . ".php")) { $this->ipsclass->adskin->td_header[] = array( "Время" , "30%" ); $this->ipsclass->adskin->td_header[] = array( "Текст ошибки" , "70%" ); $this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Лог ошибок" ); require_once( ROOT_PATH . 'cache/sql_cache/'. $this->ipsclass->input['log_name'] . ".php"); foreach($error as $t => $e) { $t = date('r',$t); $e = $this->ipsclass->my_nl2br($e); $this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( $t, $e ) ); } $this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic('<a href=\''.$this->ipsclass->base_url.'§ion=admin&act=sql&code=error_log\'>Назад</a>','center','tdrow3',2); $this->ipsclass->html .= $this->ipsclass->adskin->end_table(); } else { $this->ipsclass->adskin->td_header[] = array( "Файлы ошибок" , "100%" ); $this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Лог ошибок" ); $files = $this->log_dir( ROOT_PATH . 'cache/sql_cache'); foreach($files as $f) { $name = substr($f,strrpos($f,'/')+1,-4); $this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( '<a href=\''.$this->ipsclass->base_url.'§ion=admin&act=sql&code=error_log&log_name='.$name.'\'>'.$f.'</a>' ) ); } $this->ipsclass->html .= $this->ipsclass->adskin->end_table(); } $this->ipsclass->admin->output(); } function log_dir($dir) { $dh = opendir($dir); while (false !== ($file = readdir($dh))) { if ( preg_match( "#^[_\.]#", $file ) ) { continue; } if ( $file != '.' && $file != '..' ) { $newpath = $dir."/".$file; if ( strpos( $file, ".php" ) !== false) { $files[]=$newpath; } } } closedir($dh); return $files; }
0 комментариев
Рекомендуемые комментарии
Комментариев для отображения не найдено.