From a7e35c46979d48f044f0f5e4877f10d6a50f2640 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sun, 8 Dec 2024 21:06:44 +1100 Subject: [PATCH] Move of LOG folder from /app/front/log to app/log --- .github/ISSUE_TEMPLATE/i-have-an-issue.yml | 2 +- .gitignore | 1 + back/cron_script.sh | 2 +- docker-compose.yml | 2 +- dockerfiles/README.md | 6 ++-- dockerfiles/setup.sh | 8 ++--- docs/DEBUG_TIPS.md | 2 +- docs/MIGRATION.md | 4 +-- docs/REVERSE_DNS.md | 4 +-- docs/SYNOLOGY_GUIDE.md | 4 +-- docs/WEB_UI_PORT_DEBUG.md | 2 +- front/devices.php | 2 +- front/js/db_methods.js | 2 +- front/js/ui_components.js | 2 +- front/php/components/logs.php | 6 ++-- front/php/components/logs_defaults.json | 25 ++++---------- front/php/server/db.php | 2 +- front/php/server/query_logs.php | 38 ++++++++++++++++++++++ front/php/templates/timezone.php | 2 +- install/crontab | 2 +- install/start.debian.sh | 4 +-- {front/log => log}/.gitignore | 0 server/const.py | 4 +-- server/graphql_server/graphql_schema.py | 24 ++++++++------ 24 files changed, 90 insertions(+), 60 deletions(-) create mode 100644 front/php/server/query_logs.php rename {front/log => log}/.gitignore (100%) diff --git a/.github/ISSUE_TEMPLATE/i-have-an-issue.yml b/.github/ISSUE_TEMPLATE/i-have-an-issue.yml index d7094f729..b32ecf89b 100755 --- a/.github/ISSUE_TEMPLATE/i-have-an-issue.yml +++ b/.github/ISSUE_TEMPLATE/i-have-an-issue.yml @@ -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 diff --git a/.gitignore b/.gitignore index b2cdee76a..6110d9a91 100755 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ db/* db/pialert.db db/app.db front/log/* +/log/* front/api/* /api/* **/plugins/**/*.log diff --git a/back/cron_script.sh b/back/cron_script.sh index a9c2e3d4f..f7a10d6dd 100755 --- a/back/cron_script.sh +++ b/back/cron_script.sh @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 9c5a033a5..7e2dcc896 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/dockerfiles/README.md b/dockerfiles/README.md index 36ec6b687..e9b878ff4 100755 --- a/dockerfiles/README.md +++ b/dockerfiles/README.md @@ -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. | @@ -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 @@ -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} diff --git a/dockerfiles/setup.sh b/dockerfiles/setup.sh index ccecf4d2a..b572379af 100755 --- a/dockerfiles/setup.sh +++ b/dockerfiles/setup.sh @@ -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 diff --git a/docs/DEBUG_TIPS.md b/docs/DEBUG_TIPS.md index 9e67ccf9b..7324767f6 100755 --- a/docs/DEBUG_TIPS.md +++ b/docs/DEBUG_TIPS.md @@ -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) diff --git a/docs/MIGRATION.md b/docs/MIGRATION.md index 580d39017..f9fa21705 100755 --- a/docs/MIGRATION.md +++ b/docs/MIGRATION.md @@ -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 @@ -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 diff --git a/docs/REVERSE_DNS.md b/docs/REVERSE_DNS.md index f14a8abc2..78b02f80b 100755 --- a/docs/REVERSE_DNS.md +++ b/docs/REVERSE_DNS.md @@ -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 @@ -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 diff --git a/docs/SYNOLOGY_GUIDE.md b/docs/SYNOLOGY_GUIDE.md index a06d94f9c..d53bffda7 100755 --- a/docs/SYNOLOGY_GUIDE.md +++ b/docs/SYNOLOGY_GUIDE.md @@ -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 @@ -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) diff --git a/docs/WEB_UI_PORT_DEBUG.md b/docs/WEB_UI_PORT_DEBUG.md index 9c419c718..0b95b9201 100755 --- a/docs/WEB_UI_PORT_DEBUG.md +++ b/docs/WEB_UI_PORT_DEBUG.md @@ -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 diff --git a/front/devices.php b/front/devices.php index 1c07dea18..b2f036a83 100755 --- a/front/devices.php +++ b/front/devices.php @@ -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")) { diff --git a/front/js/db_methods.js b/front/js/db_methods.js index c0373a990..e73c56abc 100755 --- a/front/js/db_methods.js +++ b/front/js/db_methods.js @@ -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) { diff --git a/front/js/ui_components.js b/front/js/ui_components.js index fa23d2872..0a95e02f2 100755 --- a/front/js/ui_components.js +++ b/front/js/ui_components.js @@ -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') diff --git a/front/php/components/logs.php b/front/php/components/logs.php index ce9c1d17d..aa8d5d525 100755 --- a/front/php/components/logs.php +++ b/front/php/components/logs.php @@ -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 = ' - + '; diff --git a/front/php/components/logs_defaults.json b/front/php/components/logs_defaults.json index 31ddf4d29..130d54829 100755 --- a/front/php/components/logs_defaults.json +++ b/front/php/components/logs_defaults.json @@ -11,7 +11,7 @@ } ], "fileName": "app.log", - "filePath": "/app/front/log/app.log", + "filePath": "/app/log/app.log", "textAreaCssClass": "logs" }, @@ -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" }, { @@ -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" }, { @@ -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" }, { @@ -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": [ { @@ -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" }, { @@ -85,7 +74,7 @@ } ], "fileName": "stdout.log", - "filePath": "/app/front/log/stdout.log", + "filePath": "/app/log/stdout.log", "textAreaCssClass": "logs logs-small" }, { @@ -96,7 +85,7 @@ } ], "fileName": "stderr.log", - "filePath": "/app/front/log/stderr.log", + "filePath": "/app/log/stderr.log", "textAreaCssClass": "logs logs-small" } ] \ No newline at end of file diff --git a/front/php/server/db.php b/front/php/server/db.php index 0654ccc83..56a9e15a5 100755 --- a/front/php/server/db.php +++ b/front/php/server/db.php @@ -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 diff --git a/front/php/server/query_logs.php b/front/php/server/query_logs.php new file mode 100644 index 000000000..825afcf92 --- /dev/null +++ b/front/php/server/query_logs.php @@ -0,0 +1,38 @@ + "File not found"]); + } + } else { + // Missing file parameter response + http_response_code(400); + echo json_encode(["error" => "Missing 'file' parameter"]); + } +} +?> diff --git a/front/php/templates/timezone.php b/front/php/templates/timezone.php index b1412bd13..923ee32c6 100755 --- a/front/php/templates/timezone.php +++ b/front/php/templates/timezone.php @@ -6,7 +6,7 @@ $configFolderPath = dirname(__FILE__)."/../../../config/"; $config_file = "app.conf"; -$logFolderPath = dirname(__FILE__)."/../../log/"; +$logFolderPath = "/app/log/"; $log_file = "app_front.log"; diff --git a/install/crontab b/install/crontab index dd9f29881..8aa95cad8 100755 --- a/install/crontab +++ b/install/crontab @@ -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 diff --git a/install/start.debian.sh b/install/start.debian.sh index d7545b98b..6ec02274d 100755 --- a/install/start.debian.sh +++ b/install/start.debian.sh @@ -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} @@ -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" diff --git a/front/log/.gitignore b/log/.gitignore similarity index 100% rename from front/log/.gitignore rename to log/.gitignore diff --git a/server/const.py b/server/const.py index 7174b7176..97ccc59a7 100755 --- a/server/const.py +++ b/server/const.py @@ -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' diff --git a/server/graphql_server/graphql_schema.py b/server/graphql_server/graphql_schema.py index 0816644d5..b45b18f4c 100755 --- a/server/graphql_server/graphql_schema.py +++ b/server/graphql_server/graphql_schema.py @@ -115,8 +115,7 @@ def resolve_devices(self, info, options=None): device["devParentChildrenCount"] = get_number_of_children(device["devMac"], devices_data) device["devIpLong"] = format_ip_long(device.get("devLastIP", "")) - total_count = len(devices_data) - + mylog('none', f'[graphql_schema] devices_data: {devices_data}') @@ -161,14 +160,7 @@ def resolve_devices(self, info, options=None): elif status == "offline": devices_data = [device for device in devices_data if device["devPresentLastScan"] == 0] - # sorting - if options.sort: - for sort_option in options.sort: - devices_data = sorted( - devices_data, - key=lambda x: mixed_type_sort_key(x.get(sort_option.field)), - reverse=(sort_option.order.lower() == "desc") - ) + # Filter data if a search term is provided if options.search: @@ -189,6 +181,18 @@ def resolve_devices(self, info, options=None): ) ] + # sorting + if options.sort: + for sort_option in options.sort: + devices_data = sorted( + devices_data, + key=lambda x: mixed_type_sort_key(x.get(sort_option.field)), + reverse=(sort_option.order.lower() == "desc") + ) + + # capture total count after all the filtering and searching + total_count = len(devices_data) + # Then apply pagination if options.page and options.limit: start = (options.page - 1) * options.limit