work on #523 - ip v6 ordering support

This commit is contained in:
Jokob-sk
2024-01-03 07:31:32 +11:00
parent c8267f75fa
commit a3e21ac17d
3 changed files with 35 additions and 12 deletions

View File

@@ -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://<pialert URL>:20211/api/table_devices.json?nocache=1704141103121`
- `http://<pialert URL>:20211/php/server/devices.php?action=getDevicesTotals`
- `http://<pialert URL>:20211/php/server/devices.php?action=getDevicesList&status=all`
- `http://<pialert URL>: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"

View File

@@ -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

View File

@@ -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]);
}
// -----------------------------------------------------------------------------