mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
/data and /tmp standarization
This commit is contained in:
@@ -2,30 +2,59 @@
|
||||
|
||||
require '../server/init.php';
|
||||
|
||||
$logBasePath = rtrim(getenv('NETALERTX_LOG') ?: '/tmp/log', '/');
|
||||
|
||||
function resolveLogPath($path)
|
||||
{
|
||||
global $logBasePath;
|
||||
|
||||
if ($path === null || $path === '') {
|
||||
return $path;
|
||||
}
|
||||
|
||||
$placeholder = '__NETALERTX_LOG__';
|
||||
if (strpos($path, $placeholder) === 0) {
|
||||
return $logBasePath . substr($path, strlen($placeholder));
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// check if authenticated
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/security.php';
|
||||
|
||||
// Function to render the log area component
|
||||
function renderLogArea($params) {
|
||||
global $logBasePath;
|
||||
|
||||
$fileName = isset($params['fileName']) ? $params['fileName'] : '';
|
||||
$filePath = isset($params['filePath']) ? $params['filePath'] : '';
|
||||
$textAreaCssClass = isset($params['textAreaCssClass']) ? $params['textAreaCssClass'] : '';
|
||||
$buttons = isset($params['buttons']) ? $params['buttons'] : [];
|
||||
$content = "";
|
||||
|
||||
if (filesize($filePath) > 2000000) {
|
||||
$filePath = resolveLogPath($filePath);
|
||||
|
||||
if (!is_file($filePath)) {
|
||||
$content = "";
|
||||
$fileSizeMb = 0.0;
|
||||
} elseif (filesize($filePath) > 2000000) {
|
||||
$content = file_get_contents($filePath, false, null, -2000000);
|
||||
$fileSizeMb = filesize($filePath) / 1000000;
|
||||
} else {
|
||||
$content = file_get_contents($filePath);
|
||||
$fileSizeMb = filesize($filePath) / 1000000;
|
||||
}
|
||||
|
||||
// Prepare the download button HTML if filePath starts with /app
|
||||
// Prepare the download button HTML if filePath resides under the active log base path
|
||||
$downloadButtonHtml = '';
|
||||
if (strpos($filePath, '/app') === 0) {
|
||||
$logPrefix = $logBasePath . '/';
|
||||
if ($logPrefix !== '/' && strpos($filePath, $logPrefix) === 0) {
|
||||
$downloadName = basename($filePath);
|
||||
$downloadButtonHtml = '
|
||||
<span class="span-padding">
|
||||
<a href="' . htmlspecialchars(str_replace('/app/log/', '/php/server/query_logs.php?file=', $filePath)) . '" target="_blank">
|
||||
<a href="' . htmlspecialchars('/php/server/query_logs.php?file=' . rawurlencode($downloadName)) . '" target="_blank">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</span>';
|
||||
@@ -63,7 +92,7 @@ function renderLogArea($params) {
|
||||
</div>
|
||||
<div class="row logs-row">
|
||||
<div class="log-file col-sm-6 col-xs-12">' . htmlspecialchars($filePath) . '
|
||||
<div class="logs-size">' . number_format((filesize($filePath) / 1000000), 2, ",", ".") . ' MB'
|
||||
<div class="logs-size">' . number_format($fileSizeMb, 2, ",", ".") . ' MB'
|
||||
. $downloadButtonHtml .
|
||||
'</div>
|
||||
</div>
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
"event": "askRestartBackend()"
|
||||
}
|
||||
],
|
||||
"fileName": "app.log",
|
||||
"filePath": "/app/log/app.log",
|
||||
"fileName": "app.log",
|
||||
"filePath": "__NETALERTX_LOG__/app.log",
|
||||
"textAreaCssClass": "logs"
|
||||
|
||||
},
|
||||
@@ -22,8 +22,8 @@
|
||||
"event": "logManage('app_front.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "app_front.log",
|
||||
"filePath": "/app/log/app_front.log",
|
||||
"fileName": "app_front.log",
|
||||
"filePath": "__NETALERTX_LOG__/app_front.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
@@ -33,8 +33,8 @@
|
||||
"event": "logManage('app.php_errors.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "app.php_errors.log",
|
||||
"filePath": "/app/log/app.php_errors.log",
|
||||
"fileName": "app.php_errors.log",
|
||||
"filePath": "__NETALERTX_LOG__/app.php_errors.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
@@ -44,15 +44,19 @@
|
||||
"event": "logManage('execution_queue.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "execution_queue.log",
|
||||
"filePath": "/app/log/execution_queue.log",
|
||||
"fileName": "execution_queue.log",
|
||||
"filePath": "__NETALERTX_LOG__/execution_queue.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"labelStringCode": "Maint_PurgeLog",
|
||||
"event": "logManage('nginx-error.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "nginx/error.log",
|
||||
"filePath": "/var/log/nginx/error.log",
|
||||
"fileName": "nginx-error.log",
|
||||
"filePath": "__NETALERTX_LOG__/nginx-error.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
@@ -62,8 +66,8 @@
|
||||
"event": "logManage('db_is_locked.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "db_is_locked.log",
|
||||
"filePath": "/app/log/db_is_locked.log",
|
||||
"fileName": "db_is_locked.log",
|
||||
"filePath": "__NETALERTX_LOG__/db_is_locked.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
@@ -73,8 +77,8 @@
|
||||
"event": "logManage('stdout.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "stdout.log",
|
||||
"filePath": "/app/log/stdout.log",
|
||||
"fileName": "stdout.log",
|
||||
"filePath": "__NETALERTX_LOG__/stdout.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
@@ -84,8 +88,30 @@
|
||||
"event": "logManage('stderr.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "stderr.log",
|
||||
"filePath": "/app/log/stderr.log",
|
||||
"fileName": "stderr.log",
|
||||
"filePath": "__NETALERTX_LOG__/stderr.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"labelStringCode": "Maint_PurgeLog",
|
||||
"event": "logManage('IP_changes.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "IP_changes.log",
|
||||
"filePath": "__NETALERTX_LOG__/IP_changes.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"labelStringCode": "Maint_PurgeLog",
|
||||
"event": "logManage('crond.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "crond.log",
|
||||
"filePath": "__NETALERTX_LOG__/crond.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user