diff --git a/.gitignore b/.gitignore index b2804d3f..b2cdee76 100755 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ db/pialert.db db/app.db front/log/* front/api/* +/api/* **/plugins/**/*.log **/%40eaDir/ **/@eaDir/ diff --git a/Dockerfile b/Dockerfile index fed5d18e..2f372649 100755 --- a/Dockerfile +++ b/Dockerfile @@ -72,6 +72,6 @@ COPY install/crontab /etc/crontabs/root RUN ${INSTALL_DIR}/dockerfiles/pre-setup.sh HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=2 \ - CMD curl -sf -o /dev/null ${LISTEN_ADDR}:${PORT}/api/app_state.json + CMD curl -sf -o /dev/null ${LISTEN_ADDR}:${PORT}/php/server/query_json.php?file=app_state.json ENTRYPOINT ["/init"] diff --git a/front/api/.gitignore b/api/.gitignore similarity index 100% rename from front/api/.gitignore rename to api/.gitignore diff --git a/docker-compose.yml b/docker-compose.yml index 4fbb5941..9c5a033a 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,7 +39,7 @@ services: - ${DEV_LOCATION}/install/user-mapping.debian.sh:/app/install/user-mapping.debian.sh - ${DEV_LOCATION}/install/install.debian.sh:/app/install/install.debian.sh - ${DEV_LOCATION}/install/install_dependencies.debian.sh:/app/install/install_dependencies.debian.sh - - ${DEV_LOCATION}/front/api:/app/front/api + - ${DEV_LOCATION}/api:/app/api - ${DEV_LOCATION}/front/php:/app/front/php - ${DEV_LOCATION}/front/deviceDetails.php:/app/front/deviceDetails.php - ${DEV_LOCATION}/front/deviceDetailsEdit.php:/app/front/deviceDetailsEdit.php diff --git a/dockerfiles/README.md b/dockerfiles/README.md index 4e7ac884..36ec6b68 100755 --- a/dockerfiles/README.md +++ b/dockerfiles/README.md @@ -58,7 +58,7 @@ docker run -d --rm --network=host \ | | `:/app/front/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/front/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. | +| | `:/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. | | | `:/app/front/plugins//ignore_plugin` | Map a file `ignore_plugin` to ignore a plugin. Plugins can be soft-disabled via settings. More in the [Plugin docs](https://github.com/jokob-sk/NetAlertX/blob/main/front/plugins/README.md). | | | `:/etc/resolv.conf` | Use a custom `resolv.conf` file for [better name resolution](https://github.com/jokob-sk/NetAlertX/blob/main/docs/REVERSE_DNS.md). | diff --git a/dockerfiles/setup.sh b/dockerfiles/setup.sh index 97023e84..ccecf4d2 100755 --- a/dockerfiles/setup.sh +++ b/dockerfiles/setup.sh @@ -107,11 +107,11 @@ 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}"/front/api/user_notifications.json +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,front/api} -chown -R nginx:www-data "${INSTALL_DIR}"/front/api/user_notifications.json +chown -R nginx:www-data "${INSTALL_DIR}"/{config,front/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 {} \; diff --git a/docs/API.md b/docs/API.md index 83a85ac1..49aa3462 100755 --- a/docs/API.md +++ b/docs/API.md @@ -9,7 +9,7 @@ The endpoints are updated when objects in the API endpoints are changed. ### Location of the endpoints -In the container, these files are located under the `/app/front/api/` folder and thus on the `/api/` url. +In the container, these files are located under the `/app/api/` folder. You can acces sthem via the `/php/server/query_json.php?file=user_notifications.json` endpoint. ### Available endpoints diff --git a/docs/DEBUG_PLUGINS.md b/docs/DEBUG_PLUGINS.md index c59d2571..edd317d3 100755 --- a/docs/DEBUG_PLUGINS.md +++ b/docs/DEBUG_PLUGINS.md @@ -55,7 +55,7 @@ Input data from the plugin might cause mapping issues in specific edge cases. Lo 17:31:05 [Plugins] SQL sqlParams for mapping: [('01:01:01:01:01:01', '172.30.0.1', 0, 'aaaa', 'vvvvvvvvv', 'PIHOLE'), ('02:42:ac:1e:00:02', '172.30.0.2', 0, 'dddd', 'vvvvv2222', 'PIHOLE')] 🔺 17:31:05 [API] Update API starting -17:31:06 [API] Updating table_plugins_history.json file in /front/api +17:31:06 [API] Updating table_plugins_history.json file in /api ``` > The debug output between the 🔻red arrows🔺 is important for debugging (arrows added only to highlight the section on this page, they are not available in the actual debug log) diff --git a/front/deviceDetailsEdit.php b/front/deviceDetailsEdit.php index ed72943c..da91b809 100755 --- a/front/deviceDetailsEdit.php +++ b/front/deviceDetailsEdit.php @@ -68,7 +68,7 @@ // some race condition, need to implement delay setTimeout(() => { - $.get('api/table_settings.json?nocache=' + Date.now(), function(res) { + $.get('/php/server/query_json.php', { file: 'table_settings.json', nocache: Date.now() }, function(res) { settingsData = res["data"]; diff --git a/front/devices.php b/front/devices.php index 9c3d4690..1c07dea1 100755 --- a/front/devices.php +++ b/front/devices.php @@ -199,26 +199,31 @@ function getDevicesTotals() { // Fetch data via AJAX $.ajax({ - url: '/api/table_devices_tiles.json?nocache=' + Date.now(), - type: "GET", - dataType: "json", - success: function(response) { - if (response && response.data) { - resultJSON = response.data[0]; // Assuming the structure {"data": [ ... ]} - - // Save the result to cache - setCache("getDevicesTotals", JSON.stringify(resultJSON)); + url: '/php/server/query_json.php', + type: "GET", + dataType: "json", + data: { + file: 'table_devices_tiles.json', // Pass the file parameter + nocache: Date.now() // Prevent caching with a timestamp + }, + success: function(response) { + if (response && response.data) { + resultJSON = response.data[0]; // Assuming the structure {"data": [ ... ]} + + // Save the result to cache + setCache("getDevicesTotals", JSON.stringify(resultJSON)); - // Process the fetched data - processDeviceTotals(resultJSON); - } else { - console.error("Invalid response format from API"); + // Process the fetched data + processDeviceTotals(resultJSON); + } else { + console.error("Invalid response format from API"); + } + }, + error: function(xhr, status, error) { + console.error("Failed to fetch devices data:", error); } - }, - error: function(xhr, status, error) { - console.error("Failed to fetch devices data:", error); - } }); + } diff --git a/front/js/common.js b/front/js/common.js index a2731c03..68c03628 100755 --- a/front/js/common.js +++ b/front/js/common.js @@ -115,10 +115,10 @@ function cacheSettings() return new Promise((resolve, reject) => { if(!getCache('completedCalls').includes('cacheSettings')) { - $.get('api/table_settings.json?nocache=' + Date.now(), function(resSet) { - - $.get('api/plugins.json?nocache=' + Date.now(), function(resPlug) { + $.get('/php/server/query_json.php', { file: 'table_settings.json', nocache: Date.now() }, function(resSet) { + $.get('/php/server/query_json.php', { file: 'plugins.json', nocache: Date.now() }, function(resPlug) { + pluginsData = resPlug["data"]; settingsData = resSet["data"]; @@ -225,7 +225,7 @@ function cacheStrings() { }); // Fetch strings and translations from plugins - $.get(`api/table_plugins_language_strings.json?nocache=${Date.now()}`) + $.get('/php/server/query_json.php', { file: 'table_plugins_language_strings.json', nocache: Date.now() }) .done((pluginRes) => { const data = pluginRes["data"]; @@ -702,7 +702,7 @@ function forceLoadUrl(relativeUrl) { // ----------------------------------------------------------------------------- function navigateToDeviceWithIp (ip) { - $.get('api/table_devices.json?nocache=' + Date.now(), function(res) { + $.get('/php/server/query_json.php', { file: 'table_devices.json', nocache: Date.now() }, function(res) { devices = res["data"]; @@ -924,7 +924,7 @@ function cacheDevices() // if(!getCache('completedCalls').includes('cacheDevices')) // { - $.get('api/table_devices.json?nocache=' + Date.now(), function(data) { + $.get('/php/server/query_json.php', { file: 'table_devices.json', nocache: Date.now() }, function(data) { // console.log(data) @@ -1290,7 +1290,7 @@ function clearCache() { // ----------------------------------------------------------------------------- // Function to check if cache needs to be refreshed because of setting changes function checkSettingChanges() { - $.get('api/app_state.json?nocache=' + Date.now(), function(appState) { + $.get('/php/server/query_json.php', { file: 'app_state.json', nocache: Date.now() }, function(appState) { const importedMilliseconds = parseInt(appState["settingsImported"] * 1000); const lastReloaded = parseInt(sessionStorage.getItem(sessionStorageKey + '_time')); @@ -1345,7 +1345,7 @@ async function waitForGraphQLServer() { // Returns 1 if running, 0 otherwise async function isGraphQLServerRunning() { try { - const response = await $.get('api/app_state.json?nocache=' + Date.now()); + const response = await $.get('/php/server/query_json.php', { file: 'app_state.json', nocache: Date.now()}); console.log("graphQLServerStarted: " + response["graphQLServerStarted"]); setCache("graphQLServerStarted", response["graphQLServerStarted"]); return response["graphQLServerStarted"]; diff --git a/front/js/handle_version.js b/front/js/handle_version.js index fc4166cf..07e1f7f2 100755 --- a/front/js/handle_version.js +++ b/front/js/handle_version.js @@ -33,7 +33,7 @@ function versionUpdateUI(){ // Checks if a new version is available via the global app_state.json function checkIfNewVersionAvailable() { - $.get('api/app_state.json?nocache=' + Date.now(), function(appState) { + $.get('/php/server/query_json.php', { file: 'app_state.json', nocache: Date.now() }, function(appState) { // console.log(appState["isNewVersionChecked"]) // console.log(appState["isNewVersion"]) diff --git a/front/multiEditCore.php b/front/multiEditCore.php index f50b0aad..632b47ae 100755 --- a/front/multiEditCore.php +++ b/front/multiEditCore.php @@ -77,7 +77,7 @@ // some race condition, need to implement delay setTimeout(() => { - $.get('api/table_settings.json?nocache=' + Date.now(), function(res) { + $.get('/php/server/query_json.php', { file: 'table_settings.json', nocache: Date.now() }, function(res) { settingsData = res["data"]; diff --git a/front/php/components/graph_online_history.php b/front/php/components/graph_online_history.php index f238c6b9..2010c3d8 100755 --- a/front/php/components/graph_online_history.php +++ b/front/php/components/graph_online_history.php @@ -8,7 +8,7 @@