diff --git a/docs/DEBUG_INVALID_JSON.md b/docs/DEBUG_INVALID_JSON.md index d526aa02..990bac4f 100755 --- a/docs/DEBUG_INVALID_JSON.md +++ b/docs/DEBUG_INVALID_JSON.md @@ -8,22 +8,27 @@ Check the the HTTP response of the failing backend call by following these steps ![F12DeveloperConsole][F12DeveloperConsole] - Copy the URL causing the error and enter it in the address bar of your browser directly and hit enter. The copied URLs could look something like this (notice the query strings at the end): + - `http://:20211/api/table_devices.json?nocache=1704141103121` - `http://:20211/php/server/devices.php?action=getDevicesTotals` - - `http://:20211/php/server/devices.php?action=getDevicesList&status=all` + - `http://:20211/php/server/devices.php?action=getDevicesList&status=all` - Post the error response in the existing issue thread on GitHub or create a new issue and include the redacted response of the failing query. For reference, the above queries should return results in the following format: -First URL: +## First URL: + +- Should yield a valid JSON file + +## Second URL: ![array][array] -Second URL: +## Third URL: ![json][json] -You can copy and paste any JSON result (result of the second query) into an online JSON checker, such as [this one](https://jsonchecker.com/) to check if it's valid. +You can copy and paste any JSON result (result of the First and Third query) into an online JSON checker, such as [this one](https://jsonchecker.com/) to check if it's valid. [F12DeveloperConsole]: ./img/DEBUG/Invalid_JSON_repsonse_debug.png "F12DeveloperConsole" diff --git a/docs/README.md b/docs/README.md index 8c1d5215..69359daf 100755 --- a/docs/README.md +++ b/docs/README.md @@ -18,6 +18,7 @@ There is also an in-app Help / FAQ section that should be answering frequently a - [Debugging tips](/docs/DEBUG_TIPS.md) - [Invalid JSON errors debug help](/docs/DEBUG_INVALID_JSON.md) +- [Troubleshooting Plugins](/docs/DEBUG_PLUGINS.md) #### 🔝 Popular/Suggested diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js index c9a6e490..9fff7263 100755 --- a/front/js/pialert_common.js +++ b/front/js/pialert_common.js @@ -516,17 +516,34 @@ function getNameByMacAddress(macAddress) { // ----------------------------------------------------------------------------- // A function used to make the IP address orderable function formatIPlong(ipAddress) { - const parts = ipAddress.split('.'); + if (ipAddress.includes(':')) { + // IPv6 address + const parts = ipAddress.split(':'); - console.log(ipAddress) + if (parts.length !== 8) { + throw new Error('Invalid IPv6 address format'); + } - if (parts.length !== 4) { - throw new Error('Invalid IP address format'); + return parts.reduce((acc, part, index) => { + const hexValue = parseInt(part, 16); + if (isNaN(hexValue) || hexValue < 0 || hexValue > 0xFFFF) { + throw new Error('Invalid IPv6 address format'); + } + return acc | (hexValue << (112 - index * 16)); + }, 0); + } else { + // IPv4 address + const parts = ipAddress.split('.'); + + if (parts.length !== 4) { + throw new Error('Invalid IPv4 address format'); + } + + return (parseInt(parts[0]) << 24) | + (parseInt(parts[1]) << 16) | + (parseInt(parts[2]) << 8) | + parseInt(parts[3]); } - return (parseInt(parts[0]) << 24) | - (parseInt(parts[1]) << 16) | - (parseInt(parts[2]) << 8) | - parseInt(parts[3]); } // -----------------------------------------------------------------------------