Skip to content

Commit

Permalink
Move of LOG folder from /app/front/log to app/log
Browse files Browse the repository at this point in the history
  • Loading branch information
jokob-sk committed Dec 8, 2024
1 parent cd9c4a2 commit a7e35c4
Show file tree
Hide file tree
Showing 24 changed files with 90 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/i-have-an-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ body:
***Generally speaking, all bug reports should have logs provided.***
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
Additionally, any additional info? Screenshots? References? Anything that will give us more context about the issue you are encountering!
You can use `tail -100 /app/front/log/app.log` in the container if you have trouble getting to the log files.
You can use `tail -100 /app/log/app.log` in the container if you have trouble getting to the log files.
validations:
required: false
- type: checkboxes
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ db/*
db/pialert.db
db/app.db
front/log/*
/log/*
front/api/*
/api/*
**/plugins/**/*.log
Expand Down
2 changes: 1 addition & 1 deletion back/cron_script.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
export INSTALL_DIR=/app

LOG_FILE="${INSTALL_DIR}/front/log/execution_queue.log"
LOG_FILE="${INSTALL_DIR}/log/execution_queue.log"

# Check if there are any entries with cron_restart_backend
if grep -q "cron_restart_backend" "$LOG_FILE"; then
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
# - ${APP_DATA_LOCATION}/netalertx_dev/db:/app/db
- ${APP_DATA_LOCATION}/netalertx/db:/app/db
# (optional) useful for debugging if you have issues setting up the container
# - ${LOGS_LOCATION}:/app/front/log
# - ${LOGS_LOCATION}:/app/log
# ---------------------------------------------------------------------------
# DELETE START anyone trying to use this file: comment out / delete BELOW lines, they are only for development purposes
- ${APP_DATA_LOCATION}/netalertx/dhcp_samples/dhcp1.leases:/mnt/dhcp1.leases
Expand Down
6 changes: 3 additions & 3 deletions dockerfiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ docker run -d --rm --network=host \
| :------------- | :------------- | :-------------|
|| `:/app/config` | Folder which will contain the `app.conf` & `devices.csv` ([read about devices.csv](https://github.com/jokob-sk/NetAlertX/blob/main/docs/DEVICES_BULK_EDITING.md)) files (see below for details). |
|| `:/app/db` | Folder which will contain the `app.db` file |
| | `:/app/front/log` | Logs folder useful for debugging if you have issues setting up the container |
| | `:/app/log` | Logs folder useful for debugging if you have issues setting up the container |
| | `:/etc/pihole/pihole-FTL.db` | PiHole's `pihole-FTL.db` database file. Required if you want to use PiHole DB mapping. |
| | `:/etc/pihole/dhcp.leases` | PiHole's `dhcp.leases` file. Required if you want to use PiHole `dhcp.leases` file. This has to be matched with a corresponding `DHCPLSS_paths_to_check` setting entry (the path in the container must contain `pihole`)|
| | `:/app/api` | A simple [API endpoint](https://github.com/jokob-sk/NetAlertX/blob/main/docs/API.md) containing static (but regularly updated) json and other files. |
Expand Down Expand Up @@ -129,7 +129,7 @@ services:
- local/path/config:/app/config
- local/path/db:/app/db
# (optional) useful for debugging if you have issues setting up the container
- local/path/logs:/app/front/log
- local/path/logs:/app/log
environment:
- TZ=Europe/Berlin
- PORT=20211
Expand Down Expand Up @@ -178,7 +178,7 @@ services:
- ${APP_DATA_LOCATION}/netalertx/config:/app/config
- ${APP_DATA_LOCATION}/netalertx/db/:/app/db/
# (optional) useful for debugging if you have issues setting up the container
- ${LOGS_LOCATION}:/app/front/log
- ${LOGS_LOCATION}:/app/log
environment:
- TZ=${TZ}
- PORT=${PORT}
Expand Down
8 changes: 4 additions & 4 deletions dockerfiles/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ fi

# Create an empty log files
# Create the execution_queue.log and app_front.log files if they don't exist
touch "${INSTALL_DIR}"/front/log/{app.log,execution_queue.log,app_front.log,app.php_errors.log,stderr.log,stdout.log,db_is_locked.log}
touch "${INSTALL_DIR}"/log/{app.log,execution_queue.log,app_front.log,app.php_errors.log,stderr.log,stdout.log,db_is_locked.log}
touch "${INSTALL_DIR}"/api/user_notifications.json

echo "[INSTALL] Fixing permissions after copied starter config & DB"
chown -R nginx:www-data "${INSTALL_DIR}"/{config,front/log,db,api}
chown -R nginx:www-data "${INSTALL_DIR}"/{config,log,db,api}
chown -R nginx:www-data "${INSTALL_DIR}"/api/user_notifications.json

chmod 750 "${INSTALL_DIR}"/{config,front/log,db}
find "${INSTALL_DIR}"/{config,front/log,db} -type f -exec chmod 640 {} \;
chmod 750 "${INSTALL_DIR}"/{config,log,db}
find "${INSTALL_DIR}"/{config,log,db} -type f -exec chmod 640 {} \;

# Check if buildtimestamp.txt doesn't exist
if [ ! -f "${INSTALL_DIR}/front/buildtimestamp.txt" ]; then
Expand Down
2 changes: 1 addition & 1 deletion docs/DEBUG_TIPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Sometimes specific log sections are needed to debug issues. The Devices and Curr

### Permissions

* If facing issues (AJAX errors, can't write to DB, empty screen, etc,) make sure permissions are set correctly, and check the logs under `/app/front/log`.
* If facing issues (AJAX errors, can't write to DB, empty screen, etc,) make sure permissions are set correctly, and check the logs under `/app/log`.
* To solve permission issues you can try setting the owner and group of the `app.db` by executing the following on the host system: `docker exec netalertx chown -R www-data:www-data /app/db/app.db`.
* If still facing issues, try to map the app.db file (⚠ not folder) to `:/app/db/app.db` (see [docker-compose Examples](https://github.com/jokob-sk/NetAlertX/blob/main/dockerfiles/README.md#-docker-composeyml-examples) for details)

Expand Down
4 changes: 2 additions & 2 deletions docs/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ services:
- local/path/config:/app/config # ⚠ This has changed (🔺required)
- local/path/db:/app/db # ⚠ This has changed (🔺required)
# (optional) useful for debugging if you have issues setting up the container
- local/path/logs:/app/front/log # ⚠ This has changed (🟡optional)
- local/path/logs:/app/log # ⚠ This has changed (🟡optional)
environment:
- TZ=Europe/Berlin
- PORT=20211
Expand Down Expand Up @@ -135,7 +135,7 @@ services:
- local/path/config/app.conf:/app/config/app.conf # ⚠ This has changed (🔺required)
- local/path/db/app.db:/app/db/app.db # ⚠ This has changed (🔺required)
# (optional) useful for debugging if you have issues setting up the container
- local/path/logs:/app/front/log # ⚠ This has changed (🟡optional)
- local/path/logs:/app/log # ⚠ This has changed (🟡optional)
environment:
- TZ=Europe/Berlin
- PORT=20211
Expand Down
4 changes: 2 additions & 2 deletions docs/REVERSE_DNS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ services:
volumes:
- /home/netalertx/config:/app/config
- /home/netalertx/db:/app/db
- /home/netalertx/log:/app/front/log
- /home/netalertx/log:/app/log
environment:
- TZ=Europe/Berlin
- PORT=20211
Expand All @@ -66,7 +66,7 @@ services:
volumes:
- ./config/app.conf:/app/config/app.conf
- ./db:/app/db
- ./log:/app/front/log
- ./log:/app/log
- ./config/resolv.conf:/etc/resolv.conf # Mapping the /resolv.conf file for better name resolution
environment:
- TZ=Europe/Berlin
Expand Down
4 changes: 2 additions & 2 deletions docs/SYNOLOGY_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ services:
- local/path/config:/app/config
- local/path/db:/app/db
# (optional) useful for debugging if you have issues setting up the container
- local/path/logs:/app/front/log
- local/path/logs:/app/log
environment:
- TZ=Europe/Berlin
- PORT=20211
Expand All @@ -60,7 +60,7 @@ services:
- /volume1/app_storage/netalertx/config:/app/config
- /volume1/app_storage/netalertx/db:/app/db
# (optional) useful for debugging if you have issues setting up the container
# - local/path/logs:/app/front/log <- commented out with # ⚠
# - local/path/logs:/app/log <- commented out with # ⚠
```

![Adjusting docker-compose](/docs/img/SYNOLOGY/08_Adjust_docker_compose_volumes.png)
Expand Down
2 changes: 1 addition & 1 deletion docs/WEB_UI_PORT_DEBUG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ In the container execute:

`cat /var/log/nginx/error.log`

`cat /app/front/log/app.php_errors.log`
`cat /app/log/app.php_errors.log`

## 8. Make sure permissions are correct

Expand Down
2 changes: 1 addition & 1 deletion front/devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ function handleLoadingDialog(needsReload = false)
// console.log('needsReload:');
// console.log(needsReload);

$.get('log/execution_queue.log?nocache=' + Date.now(), function(data) {
$.get('/php/server/query_logs.php?file=execution_queue.log&nocache=' + Date.now(), function(data) {

if(data.includes("update_api|devices"))
{
Expand Down
2 changes: 1 addition & 1 deletion front/js/db_methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function renderList(
// Check if database is locked
function checkDbLock() {
$.ajax({
url: "log/db_is_locked.log", // Replace with the actual path to your PHP file
url: "/php/server/query_logs.php?file=db_is_locked.log",
type: "GET",

success: function (response) {
Expand Down
2 changes: 1 addition & 1 deletion front/js/ui_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function updateModalState() {
setTimeout(function() {
// Fetch the content from the log file using an AJAX request
$.ajax({
url: '/log/execution_queue.log',
url: '/php/server/query_logs.php?file=execution_queue.log',
type: 'GET',
success: function(data) {
// Update the content of the HTML element (e.g., a div with id 'logContent')
Expand Down
6 changes: 3 additions & 3 deletions front/php/components/logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ function renderLogArea($params) {
$content = file_get_contents($filePath);
}

// Prepare the download button HTML if filePath starts with /app/front
// Prepare the download button HTML if filePath starts with /app
$downloadButtonHtml = '';
if (strpos($filePath, '/app/front') === 0) {
if (strpos($filePath, '/app') === 0) {
$downloadButtonHtml = '
<span class="span-padding">
<a href="' . htmlspecialchars(str_replace('/app/front', '', $filePath)) . '" target="_blank">
<a href="' . htmlspecialchars(str_replace('/app/log/', '/php/server/query_logs.php?file=', $filePath)) . '" target="_blank">
<i class="fa fa-download"></i>
</a>
</span>';
Expand Down
25 changes: 7 additions & 18 deletions front/php/components/logs_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"fileName": "app.log",
"filePath": "/app/front/log/app.log",
"filePath": "/app/log/app.log",
"textAreaCssClass": "logs"

},
Expand All @@ -23,7 +23,7 @@
}
],
"fileName": "app_front.log",
"filePath": "/app/front/log/app_front.log",
"filePath": "/app/log/app_front.log",
"textAreaCssClass": "logs logs-small"
},
{
Expand All @@ -34,7 +34,7 @@
}
],
"fileName": "app.php_errors.log",
"filePath": "/app/front/log/app.php_errors.log",
"filePath": "/app/log/app.php_errors.log",
"textAreaCssClass": "logs logs-small"
},
{
Expand All @@ -45,7 +45,7 @@
}
],
"fileName": "execution_queue.log",
"filePath": "/app/front/log/execution_queue.log",
"filePath": "/app/log/execution_queue.log",
"textAreaCssClass": "logs logs-small"
},
{
Expand All @@ -55,17 +55,6 @@
"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": [
{
Expand All @@ -74,7 +63,7 @@
}
],
"fileName": "db_is_locked.log",
"filePath": "/app/front/log/db_is_locked.log",
"filePath": "/app/log/db_is_locked.log",
"textAreaCssClass": "logs logs-small"
},
{
Expand All @@ -85,7 +74,7 @@
}
],
"fileName": "stdout.log",
"filePath": "/app/front/log/stdout.log",
"filePath": "/app/log/stdout.log",
"textAreaCssClass": "logs logs-small"
},
{
Expand All @@ -96,7 +85,7 @@
}
],
"fileName": "stderr.log",
"filePath": "/app/front/log/stderr.log",
"filePath": "/app/log/stderr.log",
"textAreaCssClass": "logs logs-small"
}
]
2 changes: 1 addition & 1 deletion front/php/server/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//------------------------------------------------------------------------------
// DB File Path
$DBFILE = dirname(__FILE__).'/../../../db/app.db';
$DBFILE_LOCKED_FILE = dirname(__FILE__).'/../../../front/log/db_is_locked.log';
$DBFILE_LOCKED_FILE = dirname(__FILE__).'/../../../log/db_is_locked.log';

//------------------------------------------------------------------------------
// check if authenticated
Expand Down
38 changes: 38 additions & 0 deletions front/php/server/query_logs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

// ---- IMPORTS ----
//------------------------------------------------------------------------------
// Check if authenticated
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/security.php';
// Get init.php
require dirname(__FILE__).'/../server/init.php';
// ---- IMPORTS ----

//------------------------------------------------------------------------------
// Handle incoming requests
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// Get query string parameter ?file=settings_table.json
$file = isset($_GET['file']) ? $_GET['file'] : null;

// Check if file parameter is provided
if ($file) {
// Define the folder where files are located
$filePath = "/app/log/" . basename($file);

// Check if the file exists
if (file_exists($filePath)) {
// Send the response back to the client
header('Content-Type: text/plain');
echo file_get_contents($filePath);
} else {
// File not found response
http_response_code(404);
echo json_encode(["error" => "File not found"]);
}
} else {
// Missing file parameter response
http_response_code(400);
echo json_encode(["error" => "Missing 'file' parameter"]);
}
}
?>
2 changes: 1 addition & 1 deletion front/php/templates/timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$configFolderPath = dirname(__FILE__)."/../../../config/";
$config_file = "app.conf";
$logFolderPath = dirname(__FILE__)."/../../log/";
$logFolderPath = "/app/log/";
$log_file = "app_front.log";


Expand Down
2 changes: 1 addition & 1 deletion install/crontab
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# Schedule cron jobs
* * * * * /app/back/cron_script.sh
#* * * * * echo "$(date +'%Y-%m-%d %H:%M:%S') - Cron job ran" >> /app/front/log/cron_timestamp.log
#* * * * * echo "$(date +'%Y-%m-%d %H:%M:%S') - Cron job ran" >> /app/log/cron_timestamp.log
4 changes: 2 additions & 2 deletions install/start.debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fi
# Create an empty log files

# Create the execution_queue.log file if it doesn't exist
touch "${INSTALL_DIR}"/front/log/{app.log,execution_queue.log,app_front.log,app.php_errors.log,stderr.log,stdout.log,db_is_locked.log}
touch "${INSTALL_DIR}"/log/{app.log,execution_queue.log,app_front.log,app.php_errors.log,stderr.log,stdout.log,db_is_locked.log}
touch "${INSTALL_DIR}"/api/{user_notifications.json}


Expand All @@ -112,7 +112,7 @@ chmod -R a+rwx $WEB_UI_DIR

echo "[INSTALL] Fixing INSTALL_DIR: ${INSTALL_DIR}"

chmod -R a+rw $INSTALL_PATH/front/log
chmod -R a+rw $INSTALL_PATH/log
chmod -R a+rwx $INSTALL_DIR

echo "[INSTALL] Copy starter $DB_FILE and $CONF_FILE if they don't exist"
Expand Down
File renamed without changes.
4 changes: 1 addition & 3 deletions server/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
dbFileName = 'app.db'
confFileName = 'app.conf'
confPath = "/config/" + confFileName

dbPath = '/db/' + dbFileName


pluginsPath = applicationPath + '/front/plugins'
logPath = applicationPath + '/front/log'
# apiPath = applicationPath + '/api/'
logPath = applicationPath + '/log'
apiPath = applicationPath + '/api/'
reportTemplatesPath = applicationPath + '/front/report_templates/'
fullConfFolder = applicationPath + '/config'
Expand Down
Loading

0 comments on commit a7e35c4

Please sign in to comment.