Fix IP address sorting to use numeric comparison

This commit is contained in:
remotetohome 2026-02-05 01:27:45 -06:00
parent f2746a375e
commit 1ccdf70bdf
1 changed files with 11 additions and 2 deletions

View File

@ -33,6 +33,13 @@ Connected Peers
let currentSortDirection = null;
const originalRowOrders = new Map(); // Store original order per table
function ipToNumber(ip) {
// Extract IP from formats like "10.9.0.132/32" or "99.92.101.230:56078"
const match = ip.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/);
if (!match) return 0;
return (parseInt(match[1]) << 24) + (parseInt(match[2]) << 16) + (parseInt(match[3]) << 8) + parseInt(match[4]);
}
function getSortValue(cell, sortType) {
switch (sortType) {
case 'number':
@ -43,6 +50,8 @@ Connected Peers
return cell.getAttribute('data-value') === '1' ? 1 : 0;
case 'date':
return new Date(cell.getAttribute('data-value') || 0).getTime();
case 'ip':
return ipToNumber(cell.textContent || '');
case 'text':
default:
return (cell.textContent || '').toLowerCase().trim();
@ -164,8 +173,8 @@ Connected Peers
<th scope="col" data-sort-column="0" data-sort-type="number">#</th>
<th scope="col" data-sort-column="1" data-sort-type="text">Name</th>
<th scope="col" data-sort-column="2" data-sort-type="text">Email</th>
<th scope="col" data-sort-column="3" data-sort-type="text">Allocated IPs</th>
<th scope="col" data-sort-column="4" data-sort-type="text">Endpoint</th>
<th scope="col" data-sort-column="3" data-sort-type="ip">Allocated IPs</th>
<th scope="col" data-sort-column="4" data-sort-type="ip">Endpoint</th>
<th scope="col" data-sort-column="5" data-sort-type="text">Public Key</th>
<th scope="col" data-sort-column="6" data-sort-type="bytes">Received</th>
<th scope="col" data-sort-column="7" data-sort-type="bytes">Transmitted</th>