mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
This commit is contained in:
76
front/php/components/logs.php
Executable file
76
front/php/components/logs.php
Executable file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
require '../server/init.php';
|
||||
|
||||
// Function to render the log area component
|
||||
function renderLogArea($params) {
|
||||
$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) {
|
||||
$content = file_get_contents($filePath, false, null, -2000000);
|
||||
} else {
|
||||
$content = file_get_contents($filePath);
|
||||
}
|
||||
|
||||
// Render the log area HTML
|
||||
$html = '
|
||||
<div class="log-area box box-solid box-primary">
|
||||
<div class="row logs-row col-sm-12 col-xs-12">
|
||||
<textarea id="app_log" class="' . $textAreaCssClass . '" cols="70" rows="10" wrap="off" readonly>'
|
||||
.$content.
|
||||
'</textarea>
|
||||
</div>
|
||||
<div class="row logs-row">
|
||||
<div class="log-file col-sm-8 col-xs-12">' . $fileName . '
|
||||
<div class="logs-size">' . number_format((filesize($filePath) / 1000000), 2, ",", ".") . ' MB
|
||||
<span class="span-padding"><a href="' . $filePath . '" target="_blank"><i class="fa fa-download"></i></a></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-4 col-xs-12">
|
||||
';
|
||||
|
||||
// Render each button
|
||||
foreach ($buttons as $button) {
|
||||
$labelStringCode = isset($button['labelStringCode']) ? $button['labelStringCode'] : '';
|
||||
$event = isset($button['event']) ? $button['event'] : '';
|
||||
|
||||
$html .= '
|
||||
<div class="col-sm-6 col-xs-6">
|
||||
<button class="btn btn-primary" onclick="' . $event . '">' . lang($labelStringCode) . '</button>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
$html .= '
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
// Load default data from JSON file
|
||||
$defaultDataFile = 'logs_defaults.json';
|
||||
$defaultData = file_exists($defaultDataFile) ? json_decode(file_get_contents($defaultDataFile), true) : [];
|
||||
|
||||
// Check if JSON data is submitted via POST
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['items'])) {
|
||||
$items = json_decode($_POST['items'], true);
|
||||
} else {
|
||||
$items = $defaultData;
|
||||
}
|
||||
|
||||
// Render the log areas with the retrieved or default data
|
||||
$html = '';
|
||||
foreach ($items as $item) {
|
||||
$html .= renderLogArea($item);
|
||||
}
|
||||
|
||||
echo $html;
|
||||
exit();
|
||||
?>
|
||||
80
front/php/components/logs_defaults.json
Executable file
80
front/php/components/logs_defaults.json
Executable file
@@ -0,0 +1,80 @@
|
||||
[
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"labelStringCode": "Maint_PurgeLog",
|
||||
"event": "logManage('app.log', 'cleanLog')"
|
||||
},
|
||||
{
|
||||
"labelStringCode": "Maint_RestartServer",
|
||||
"event": "askRestartBackend()"
|
||||
}
|
||||
],
|
||||
"fileName": "app.log",
|
||||
"filePath": "/app/front/log/app.log",
|
||||
"textAreaCssClass": "logs"
|
||||
|
||||
},
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"labelStringCode": "Maint_PurgeLog",
|
||||
"event": "logManage('app_front.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "app_front.log",
|
||||
"filePath": "/app/front/log/app_front.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"labelStringCode": "Maint_PurgeLog",
|
||||
"event": "logManage('app.php_errors.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "app.php_errors.log",
|
||||
"filePath": "/app/front/log/app.php_errors.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
"buttons": [
|
||||
],
|
||||
"fileName": "nginx/error.log",
|
||||
"filePath": "/var/log/nginx/error.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"labelStringCode": "Maint_PurgeLog",
|
||||
"event": "logManage('app_front.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "app_front.log",
|
||||
"filePath": "/app/front/log/app_front.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"labelStringCode": "Maint_PurgeLog",
|
||||
"event": "logManage('stdout.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "stdout.log",
|
||||
"filePath": "/app/front/log/stdout.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
},
|
||||
{
|
||||
"buttons": [
|
||||
{
|
||||
"labelStringCode": "Maint_PurgeLog",
|
||||
"event": "logManage('stderr.log', 'cleanLog')"
|
||||
}
|
||||
],
|
||||
"fileName": "stderr.log",
|
||||
"filePath": "/app/front/log/stderr.log",
|
||||
"textAreaCssClass": "logs logs-small"
|
||||
}
|
||||
]
|
||||
@@ -28,10 +28,7 @@ if(array_key_exists('settings', $_REQUEST) != FALSE)
|
||||
|
||||
// call functions based on requested params
|
||||
switch ($FUNCTION) {
|
||||
case 'restartBackend':
|
||||
|
||||
restartBackend();
|
||||
break;
|
||||
|
||||
case 'savesettings':
|
||||
|
||||
saveSettings();
|
||||
@@ -228,6 +225,7 @@ function displayMessage($message, $logAlert = FALSE, $logConsole = TRUE, $logFil
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// Adds an action to perform into the execution_queue.log file
|
||||
function addToExecutionQueue($action)
|
||||
{
|
||||
@@ -247,27 +245,6 @@ function addToExecutionQueue($action)
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
function restartBackend()
|
||||
{
|
||||
$command = 'pkill -f "python /app/server" && (python /app/server > /dev/null 2>&1 &) && echo "done" 2>&1';
|
||||
|
||||
// Execute the command
|
||||
$output = [];
|
||||
$output_str = "";
|
||||
$return_var = 0;
|
||||
exec($command, $output, $return_var);
|
||||
|
||||
// Format the output
|
||||
foreach ($output as $line) {
|
||||
$output_str .= $line . "\n";
|
||||
}
|
||||
|
||||
|
||||
echo "Command result: $return_var, $output_str";
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
function cleanLog($logFile)
|
||||
|
||||
@@ -384,6 +384,9 @@
|
||||
"MQTT_USER_name": "MQTT user",
|
||||
"MQTT_display_name": "MQTT",
|
||||
"MQTT_icon": "<i class=\"fa fa-square-rss\"></i>",
|
||||
"Maint_PurgeLog": "",
|
||||
"Maint_RestartServer": "",
|
||||
"Maint_Restart_Server_noti_text": "",
|
||||
"Maintenance_Running_Version": "Installierte Version",
|
||||
"Maintenance_Status": "Status",
|
||||
"Maintenance_Title": "Wartungswerkzeuge",
|
||||
|
||||
@@ -358,6 +358,9 @@
|
||||
"Login_Toggle_Alert_headline": "Password Alert!",
|
||||
"Login_Toggle_Info": "Password Information",
|
||||
"Login_Toggle_Info_headline": "Password Information",
|
||||
"Maint_PurgeLog": "Purge log",
|
||||
"Maint_RestartServer": "Restart server",
|
||||
"Maint_Restart_Server_noti_text": "Are you sure you want to restart the backend server? This may casue app inconsistency. Backup your setup first. <br/> <br/> Note: This may take a few minutes.",
|
||||
"Maintenance_Running_Version": "Installed version",
|
||||
"Maintenance_Status": "Status",
|
||||
"Maintenance_Title": "Maintenance tools",
|
||||
|
||||
@@ -382,6 +382,9 @@
|
||||
"MQTT_USER_name": "Usuario de MQTT",
|
||||
"MQTT_display_name": "MQTT",
|
||||
"MQTT_icon": "<i class=\"fa fa-square-rss\"></i>",
|
||||
"Maint_PurgeLog": "",
|
||||
"Maint_RestartServer": "",
|
||||
"Maint_Restart_Server_noti_text": "",
|
||||
"Maintenance_Running_Version": "Versión instalada",
|
||||
"Maintenance_Status": "Situación",
|
||||
"Maintenance_Title": "Herramientas de mantenimiento",
|
||||
|
||||
@@ -358,6 +358,9 @@
|
||||
"Login_Toggle_Alert_headline": "",
|
||||
"Login_Toggle_Info": "",
|
||||
"Login_Toggle_Info_headline": "",
|
||||
"Maint_PurgeLog": "",
|
||||
"Maint_RestartServer": "",
|
||||
"Maint_Restart_Server_noti_text": "",
|
||||
"Maintenance_Running_Version": "Version installée",
|
||||
"Maintenance_Status": "État",
|
||||
"Maintenance_Title": "Outils d'entretien",
|
||||
@@ -684,4 +687,4 @@
|
||||
"settings_update_item_warning": "",
|
||||
"test_event_icon": "",
|
||||
"test_event_tooltip": ""
|
||||
}
|
||||
}
|
||||
@@ -358,6 +358,9 @@
|
||||
"Login_Toggle_Alert_headline": "Avviso password!",
|
||||
"Login_Toggle_Info": "Informazioni password",
|
||||
"Login_Toggle_Info_headline": "Informazioni password",
|
||||
"Maint_PurgeLog": "",
|
||||
"Maint_RestartServer": "",
|
||||
"Maint_Restart_Server_noti_text": "",
|
||||
"Maintenance_Running_Version": "Versione installata",
|
||||
"Maintenance_Status": "Stato",
|
||||
"Maintenance_Title": "Strumenti di manutenzione",
|
||||
@@ -684,4 +687,4 @@
|
||||
"settings_update_item_warning": "Aggiorna il valore qui sotto. Fai attenzione a seguire il formato precedente. <b>La convalida non viene eseguita.</b>",
|
||||
"test_event_icon": "fa-vial-circle-check",
|
||||
"test_event_tooltip": "Salva le modifiche prima di provare le nuove impostazioni."
|
||||
}
|
||||
}
|
||||
@@ -358,6 +358,9 @@
|
||||
"Login_Toggle_Alert_headline": "Passord Varsling!",
|
||||
"Login_Toggle_Info": "Passordinformasjon",
|
||||
"Login_Toggle_Info_headline": "Passordinformasjon",
|
||||
"Maint_PurgeLog": "",
|
||||
"Maint_RestartServer": "",
|
||||
"Maint_Restart_Server_noti_text": "",
|
||||
"Maintenance_Running_Version": "Installert versjon",
|
||||
"Maintenance_Status": "Status",
|
||||
"Maintenance_Title": "Vedlikeholdsverktøy",
|
||||
|
||||
@@ -358,6 +358,9 @@
|
||||
"Login_Toggle_Alert_headline": "Alert Hasła!",
|
||||
"Login_Toggle_Info": "Informacje o haśle",
|
||||
"Login_Toggle_Info_headline": "Informacje o haśle",
|
||||
"Maint_PurgeLog": "",
|
||||
"Maint_RestartServer": "",
|
||||
"Maint_Restart_Server_noti_text": "",
|
||||
"Maintenance_Running_Version": "Zainstalowana wersja",
|
||||
"Maintenance_Status": "Status",
|
||||
"Maintenance_Title": "Narzędzia konserwacyjne",
|
||||
|
||||
@@ -358,6 +358,9 @@
|
||||
"Login_Toggle_Alert_headline": "",
|
||||
"Login_Toggle_Info": "",
|
||||
"Login_Toggle_Info_headline": "",
|
||||
"Maint_PurgeLog": "",
|
||||
"Maint_RestartServer": "",
|
||||
"Maint_Restart_Server_noti_text": "",
|
||||
"Maintenance_Running_Version": "",
|
||||
"Maintenance_Status": "",
|
||||
"Maintenance_Title": "",
|
||||
|
||||
5
front/php/templates/language/ru_ru.json
Normal file → Executable file
5
front/php/templates/language/ru_ru.json
Normal file → Executable file
@@ -358,6 +358,9 @@
|
||||
"Login_Toggle_Alert_headline": "Предупреждение о пароле!",
|
||||
"Login_Toggle_Info": "Информация о пароле",
|
||||
"Login_Toggle_Info_headline": "Информация о пароле",
|
||||
"Maint_PurgeLog": "",
|
||||
"Maint_RestartServer": "",
|
||||
"Maint_Restart_Server_noti_text": "",
|
||||
"Maintenance_Running_Version": "Установленная версия",
|
||||
"Maintenance_Status": "Статус",
|
||||
"Maintenance_Title": "Инструменты обслуживания",
|
||||
@@ -684,4 +687,4 @@
|
||||
"settings_update_item_warning": "Обновить значение ниже. Будьте осторожны, следуя предыдущему формату. <b>Проверка не выполняется.</b>",
|
||||
"test_event_icon": "fa-vial-circle-check",
|
||||
"test_event_tooltip": "Сначала сохраните изменения, прежде чем проверять настройки."
|
||||
}
|
||||
}
|
||||
@@ -358,6 +358,9 @@
|
||||
"Login_Toggle_Alert_headline": "",
|
||||
"Login_Toggle_Info": "",
|
||||
"Login_Toggle_Info_headline": "",
|
||||
"Maint_PurgeLog": "",
|
||||
"Maint_RestartServer": "",
|
||||
"Maint_Restart_Server_noti_text": "",
|
||||
"Maintenance_Running_Version": "",
|
||||
"Maintenance_Status": "",
|
||||
"Maintenance_Title": "",
|
||||
|
||||
@@ -358,6 +358,9 @@
|
||||
"Login_Toggle_Alert_headline": "",
|
||||
"Login_Toggle_Info": "",
|
||||
"Login_Toggle_Info_headline": "",
|
||||
"Maint_PurgeLog": "",
|
||||
"Maint_RestartServer": "",
|
||||
"Maint_Restart_Server_noti_text": "",
|
||||
"Maintenance_Running_Version": "",
|
||||
"Maintenance_Status": "",
|
||||
"Maintenance_Title": "",
|
||||
|
||||
Reference in New Issue
Block a user