Compare commits

...

2 commits

Author SHA1 Message Date
0e3dc04af8
fix: Formatting IPv6 display #84
Wraps IPv6 host in square brackets, returns as-is for domain names
or IPv4 addresses.
2024-09-09 19:50:30 +07:00
61cc98e378
feat!: Added IPv6 only information to the table
The IP address information of the remote node is replaced with
information on whether the remote node only supports IPv6 or not.
2024-09-09 19:17:39 +07:00
4 changed files with 42 additions and 17 deletions

View file

@ -1,19 +1,21 @@
<script> <script>
import { getModalStore } from '@skeletonlabs/skeleton'; import { getModalStore } from '@skeletonlabs/skeleton';
import { formatHostname } from '$lib/utils/strings';
const modalStore = getModalStore(); const modalStore = getModalStore();
/** @type {string} */
export let ip;
/** @type {boolean} */
export let is_tor;
/** @type {string} */
export let hostname;
/** @type {number} */
export let port;
// if (is_tor) { /**
// hostname = hostname.substring(0, 8) + '[...].onion'; * @type {{
// } * is_tor: boolean,
* hostname: string,
* port: number,
* ipv6_only: boolean
* }}
*/
export let is_tor;
export let hostname;
export let port;
export let ipv6_only;
/** /**
* @param {string} onionAddr * @param {string} onionAddr
@ -40,8 +42,8 @@
</button><br />.onion:<span class="text-indigo-800 dark:text-indigo-400">{port}</span> </button><br />.onion:<span class="text-indigo-800 dark:text-indigo-400">{port}</span>
<span class="text-gray-700 dark:text-gray-400">(TOR)</span> <span class="text-gray-700 dark:text-gray-400">(TOR)</span>
{:else} {:else}
{hostname}:<span class="text-indigo-800 dark:text-indigo-400">{port}</span> {formatHostname(hostname)}:<span class="text-indigo-800 dark:text-indigo-400">{port}</span><br />
{#if ip !== ''} {#if ipv6_only}
<br /><span class="text-gray-700 dark:text-gray-400">{ip}</span> <span class="text-rose-800 dark:text-rose-400">(IPv6 only)</span>
{/if} {/if}
{/if} {/if}

View file

@ -1,3 +1,26 @@
/**
* Modifies the input string based on whether it is an IPv6 address.
* If the input is an IPv6 address, it wraps it in square brackets `[ ]`.
* Otherwise, it returns the input string as-is (for domain names or
* IPv4 addresses). AND I'M SORRY USING REGEX FOR THIS!
*
* @param {string} hostname
* @returns {string} - The modified string, IPv6 addresses wrapped in `[ ]`.
*/
export const formatHostname = (hostname) => {
// const ipv6Pattern = /^(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/; // full
// pattern for both full and compressed IPv6 addresses.
// source: https://regex101.com/library/cP9mH9?filterFlavors=dotnet&filterFlavors=javascript&orderBy=RELEVANCE&search=ip
// This may be incorrect, but let's assume it's correct. xD
const ipv6Pattern =
/^(([0-9A-Fa-f]{1,4}:){7})([0-9A-Fa-f]{1,4})$|(([0-9A-Fa-f]{1,4}:){1,6}:)(([0-9A-Fa-f]{1,4}:){0,4})([0-9A-Fa-f]{1,4})$/;
if (ipv6Pattern.test(hostname)) {
return `[${hostname}]`;
}
return hostname;
};
/** /**
* @param {number} bytes * @param {number} bytes
* @param {number} decimals * @param {number} decimals

View file

@ -211,10 +211,10 @@
<tr> <tr>
<td <td
><HostPortCell ><HostPortCell
ip={row.ip}
is_tor={row.is_tor} is_tor={row.is_tor}
hostname={row.hostname} hostname={row.hostname}
port={row.port} port={row.port}
ipv6_only={row.ipv6_only}
/> />
<a class="anchor" href="/remote-nodes/logs/?node_id={row.id}">[Logs]</a> <a class="anchor" href="/remote-nodes/logs/?node_id={row.id}">[Logs]</a>
</td> </td>

View file

@ -3,7 +3,7 @@
import { format, formatDistance } from 'date-fns'; import { format, formatDistance } from 'date-fns';
import { loadData, loadNodeInfo } from './api-handler'; import { loadData, loadNodeInfo } from './api-handler';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { formatHashes, formatBytes } from '$lib/utils/strings'; import { formatHostname, formatHashes, formatBytes } from '$lib/utils/strings';
import { import {
DtSrRowsPerPage, DtSrRowsPerPage,
DtSrThSort, DtSrThSort,
@ -71,7 +71,7 @@
<tbody> <tbody>
<tr> <tr>
<td class="font-bold">Hostname:Port</td> <td class="font-bold">Hostname:Port</td>
<td>{nodeInfo?.hostname}:{nodeInfo?.port}</td> <td>{formatHostname(nodeInfo?.hostname)}:{nodeInfo?.port}</td>
</tr> </tr>
<tr> <tr>
<td class="font-bold">Public IP</td> <td class="font-bold">Public IP</td>