удаление раздела Nginx логи

This commit is contained in:
rsgrinko committed 2026-07-24 19:28:17 +03:00
1 parent dc29aade3a
commit 31e84f478d
3 files changed
-154

No files matched your search

-1
View File
@@ -256,7 +256,6 @@
<li><a href="/admin/cacheInfo.php"><i class="fa fa-home"></i> <span>Кэширование</span></a></li>
<li><a href="/admin/threads.php"><i class="fa fa-home"></i> <span>Диспетчер очереди</span></a></li>
<li><a href="/admin/phpcmd.php"><i class="fa fa-home"></i> <span>Командная PHP строка</span></a></li>
<li><a href="/admin/nginx.php"><i class="fa fa-home"></i> <span>Логи nginx</span></a></li>
<?php } ?>
<li><a href="#"><i class="fa fa-home"></i> <span>В никуда</span></a></li>
-96
View File
@@ -1,96 +0,0 @@
<?php
/**
* Copyright (c) 2022 Roman Grinko <rsgrinko@gmail.com>
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
use Core\Helpers\Pagination;
use Core\Helpers\SystemFunctions;
use Core\SystemConfig;
require_once __DIR__ . '/inc/header.php';
global $USER;
if ($USER->isAdmin() === false) {
header('Location: ./');
die();
}
?>
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-home"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
<li>Логи nginx</li>
</ul>
<h4>Логи nginx</h4>
</div>
</div><!-- media -->
</div><!-- pageheader -->
<div class="contentpanel">
<!-- table -->
<div class="row">
<div class="col-md-12r">
<div class="table-responsive">
<table class="table table-primary table-hover mb30">
<thead>
<tr>
<th>IP</th>
<th>Дата</th>
<th>Запрос</th>
<th>Код</th>
<th>Размер</th>
<th>URL</th>
<th>Браузер</th>
</tr>
</thead>
<tbody>
<?php
$nginxLogFile = $_SERVER['DOCUMENT_ROOT'].'/../../log/it-stories.ru_access';
//$nginxLogFile = $_SERVER['DOCUMENT_ROOT'].'/../../log/test.log';
Pagination::execute($_REQUEST['page'], SystemFunctions::getNginxLogData($nginxLogFile, true), SystemConfig::getValue('PAGINATION_LIMIT'));
$limit = Pagination::getLimit();
$arLogs = SystemFunctions::getNginxLogData($nginxLogFile, false, $limit, true);
foreach ($arLogs as $elLog) {
?>
<tr>
<td><?= $elLog['ip'] ?></td>
<td><?= date('Y.m.d H:i:s', strtotime($elLog['date'] . ' +3 hour')) ?></td>
<td><?= $elLog['request'] ?></td>
<td><?= $elLog['httpCode'] ?></td>
<td><?= $elLog['size'] ? SystemFunctions::convertBytes($elLog['size']) : '' ?></td>
<td><?= $elLog['url'] ?></td>
<td><?= $elLog['userAgent'] ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div><!-- table-responsive -->
<?php Pagination::show('page') ?>
</div>
</div>
<!-- end table -->
</div><!-- contentpanel -->
<?php require_once __DIR__ . '/inc/footer.php'; ?>
@@ -686,63 +686,6 @@
return $count;
}
/**
* Парсинг логов nginx
*
* @param string $logPath Путь до файла логов
* @param bool $isOnlyCount Только получение количества
* @param string|null $limit Ограничение выборки "0, 10"
* @param bool $isReverse Перевернуть выборку
*
* @return array|int
* @throws CoreException
*/
public static function getNginxLogData(string $logPath, bool $isOnlyCount = false, ?string $limit = null, bool $isReverse = false)
{
if (!file_exists($logPath)) {
throw new CoreException('Файл логов не найден', CoreException::ERROR_FILE_NOT_FOUND);
}
$arLogs = file($logPath);
$logCount = count($arLogs);
if ($isOnlyCount) {
return $logCount;
}
if ($isReverse) {
$arLogs = array_reverse($arLogs);
}
$arLimit = [0, $logCount];
if ($limit !== null) {
$arLimit['start'] = (int)explode(',', $limit)[0];
$arLimit['stop'] = $arLimit['start'] + (int)explode(',', $limit)[1];
}
$regExp = '/(?<ip>[0-9.]+)\s+\-\s+\-\s\[(?<date>[^\]]+)\]\s"(?<request>[^"]+)"\s(?<code>\d+)\s+(?<size>\d+)\s"(?<url>[^"]+)"\s"(?<useragent>[^"]+)"/m';
$arResult = [];
$result = null;
$counter = 0;
foreach ($arLogs as $logEvent) {
$counter++;
if ($limit !== null && ($counter - 1) < $arLimit['start']) {
continue;
}
preg_match_all($regExp, $logEvent, $result, PREG_SET_ORDER, 0);
$result = array_shift($result);
$arResult[] = [
'ip' => $result['ip'],
'date' => $result['date'],
'request' => $result['request'],
'httpCode' => $result['code'],
'size' => $result['size'],
'url' => $result['url'],
'userAgent' => $result['useragent'],
];
$result = null;
if ($limit !== null && ($counter + 1) > $arLimit['stop']) {
break;
}
}
return $arResult;
}
/**
* Возвращает подсвеченную PHP строку
*