diff --git a/class/class.logs.php b/class/class.logs.php index 68bdab0..bb0cdf9 100644 --- a/class/class.logs.php +++ b/class/class.logs.php @@ -9,7 +9,7 @@ * @package AVE.cms * @version 4.x * @filesource - * @copyright © 2007-2014 AVE.cms, http://www.ave-cms.ru + * @copyright © 2007-2026 AVE.cms, https://ave4cms.ru * */ @@ -160,7 +160,6 @@ ]; } - // Передаем данные в шаблон для вывода и отображаем страницу $AVE_Template->assign('logs', $_lines); $AVE_Template->assign('content', $AVE_Template->fetch('logs/404.tpl')); } @@ -201,150 +200,130 @@ $AVE_Template->assign('content', $AVE_Template->fetch('logs/sql.tpl')); } - /** - * Метод, предназначенный для удаление записей Журнала событий - * - */ function logDelete() { global $AVE_Template; - $logfile = BASE_DIR . $this->_logdir; - - if(file_exists($logfile)) - unlink($logfile); - - // Сохраняем системное сообщение в журнал + if(file_exists($logfile)) unlink($logfile); reportLog($AVE_Template->get_config_vars('LOGS_CLEAN')); - header('Location:index.php?do=logs&cp=' . SESSION); exit; } - /** - * Метод, предназначенный для удаление записей Журнала событий 404 - * - */ function DeleteSql() { global $AVE_Template; - $logfile = BASE_DIR . $this->_sqldir; - - if(file_exists($logfile)) - unlink($logfile); - - // Сохраняем системное сообщение в журнал + if(file_exists($logfile)) unlink($logfile); reportLog($AVE_Template->get_config_vars('LOGS_SQL_CLEAN')); - header('Location:index.php?do=logs&action=logsql&cp=' . SESSION); exit; } - /** - * Метод, предназначенный для удаление записей Журнала событий 404 - * - */ function Delete404() { global $AVE_Template; - $logfile = BASE_DIR . $this->_404dir; - - if(file_exists($logfile)) - unlink($logfile); - - // Сохраняем системное сообщение в журнал + if(file_exists($logfile)) unlink($logfile); reportLog($AVE_Template->get_config_vars('LOGS_404_CLEAN')); - header('Location:index.php?do=logs&action=log404&cp=' . SESSION); exit; } /** - * Метод, предназначенный для экспорта системных сообщений - * + * Экспорт системных сообщений */ function logExport() { global $AVE_Template; - $file_name = BASE_DIR . $this->_logdir; + if (!file_exists($file_name)) exit; + $dateName = 'system_log_' . date('dmyhis', time()) . '.csv'; - // Определяем заголовки документа - header('Content-Encoding: windows-1251'); - header('Content-type: text/csv; charset=windows-1251'); - header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + header('Content-type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $dateName . '"'); - header('Content-Length: ' . filesize($file_name)); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); - // Выводим данные - readfile($file_name); + echo "\xEF\xBB\xBF"; - // Сохраняем системное сообщение в журнал + $fp = fopen($file_name, 'rb'); + $out = fopen('php://output', 'w'); + + while (($data = fgetcsv($fp, 0, ',', '"', '\\')) !== FALSE) { + if (isset($data[2])) $data[2] = urldecode($data[2]); + fputcsv($out, $data, ',', '"', '\\'); + } + + fclose($fp); + fclose($out); reportLog($AVE_Template->get_config_vars('LOGS_EXPORT')); - exit; } /** - * Метод, предназначенный для экспорта сообщений 404 - * + * Экспорт сообщений 404 */ function Export404() { global $AVE_Template; - $file_name = BASE_DIR . $this->_404dir; - $dateName = 'system_log_' . date('dmyhis', time()) . '.csv'; + if (!file_exists($file_name)) exit; - // Определяем заголовки документа - header('Content-Encoding: windows-1251'); - header('Content-type: text/csv; charset=windows-1251'); - header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + $dateName = 'system_404_' . date('dmyhis', time()) . '.csv'; + + header('Content-type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $dateName . '"'); - header('Content-Length: ' . filesize($file_name)); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); - // Выводим данные - readfile($file_name); + echo "\xEF\xBB\xBF"; - // Сохраняем системное сообщение в журнал + $fp = fopen($file_name, 'rb'); + $out = fopen('php://output', 'w'); + + while (($data = fgetcsv($fp, 0, ',', '"', '\\')) !== FALSE) { + if (isset($data[2])) $data[2] = urldecode($data[2]); + if (isset($data[4])) $data[4] = urldecode($data[4]); + if (isset($data[5])) $data[5] = urldecode($data[5]); + fputcsv($out, $data, ',', '"', '\\'); + } + + fclose($fp); + fclose($out); reportLog($AVE_Template->get_config_vars('LOGS_EXPORT')); - exit; } /** - * Метод, предназначенный для экспорта сообщений MySql - * + * Экспорт сообщений MySql */ function ExportSql() { global $AVE_Template; - $file_name = BASE_DIR . $this->_sqldir; - $dateName = 'system_log_' . date('dmyhis', time()) . '.csv'; + if (!file_exists($file_name)) exit; - // Определяем заголовки документа - header('Content-Encoding: windows-1251'); - header('Content-type: text/csv; charset=windows-1251'); - header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + $dateName = 'system_sql_' . date('dmyhis', time()) . '.csv'; + + header('Content-type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $dateName . '"'); - header('Content-Length: ' . filesize($file_name)); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); - // Выводим данные - readfile($file_name); + echo "\xEF\xBB\xBF"; - // Сохраняем системное сообщение в журнал + $fp = fopen($file_name, 'rb'); + $out = fopen('php://output', 'w'); + + while (($data = fgetcsv($fp, 0, ',', '"', '\\')) !== FALSE) { + fputcsv($out, $data, ',', '"', '\\'); + } + + fclose($fp); + fclose($out); reportLog($AVE_Template->get_config_vars('LOGS_EXPORT')); - exit; } }