Skip to content

Commit 622b939

Browse files
authored
Show ipv6 with correct in-url syntax (pterodactyl#3776)
1 parent e8e2911 commit 622b939

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

resources/scripts/components/dashboard/ServerRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { faEthernet, faHdd, faMemory, faMicrochip, faServer } from '@fortawesome
44
import { Link } from 'react-router-dom';
55
import { Server } from '@/api/server/getServer';
66
import getServerResourceUsage, { ServerPowerState, ServerStats } from '@/api/server/getServerResourceUsage';
7-
import { bytesToHuman, megabytesToHuman } from '@/helpers';
7+
import { bytesToHuman, megabytesToHuman, formatIp } from '@/helpers';
88
import tw from 'twin.macro';
99
import GreyRowBox from '@/components/elements/GreyRowBox';
1010
import Spinner from '@/components/elements/Spinner';
@@ -97,7 +97,7 @@ export default ({ server, className }: { server: Server; className?: string }) =
9797
{
9898
server.allocations.filter(alloc => alloc.isDefault).map(allocation => (
9999
<React.Fragment key={allocation.ip + allocation.port.toString()}>
100-
{allocation.alias || allocation.ip}:{allocation.port}
100+
{allocation.alias || formatIp(allocation.ip)}:{allocation.port}
101101
</React.Fragment>
102102
))
103103
}

resources/scripts/components/dashboard/search/SearchModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Link } from 'react-router-dom';
1313
import styled from 'styled-components/macro';
1414
import tw from 'twin.macro';
1515
import Input from '@/components/elements/Input';
16-
16+
import { formatIp } from '@/helpers';
1717
type Props = RequiredModalProps;
1818

1919
interface Values {
@@ -109,7 +109,7 @@ export default ({ ...props }: Props) => {
109109
<p css={tw`mt-1 text-xs text-neutral-400`}>
110110
{
111111
server.allocations.filter(alloc => alloc.isDefault).map(allocation => (
112-
<span key={allocation.ip + allocation.port.toString()}>{allocation.alias || allocation.ip}:{allocation.port}</span>
112+
<span key={allocation.ip + allocation.port.toString()}>{allocation.alias || formatIp(allocation.ip)}:{allocation.port}</span>
113113
))
114114
}
115115
</p>

resources/scripts/components/server/ServerDetailsBlock.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
22
import tw, { TwStyle } from 'twin.macro';
33
import { faCircle, faEthernet, faHdd, faMemory, faMicrochip, faServer } from '@fortawesome/free-solid-svg-icons';
44
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5-
import { bytesToHuman, megabytesToHuman } from '@/helpers';
5+
import { bytesToHuman, megabytesToHuman, formatIp } from '@/helpers';
66
import TitledGreyBox from '@/components/elements/TitledGreyBox';
77
import { ServerContext } from '@/state/server';
88
import CopyOnClick from '@/components/elements/CopyOnClick';
@@ -72,7 +72,7 @@ const ServerDetailsBlock = () => {
7272
const isTransferring = ServerContext.useStoreState(state => state.server.data!.isTransferring);
7373
const limits = ServerContext.useStoreState(state => state.server.data!.limits);
7474
const primaryAllocation = ServerContext.useStoreState(state => state.server.data!.allocations.filter(alloc => alloc.isDefault).map(
75-
allocation => (allocation.alias || allocation.ip) + ':' + allocation.port,
75+
allocation => (allocation.alias || formatIp(allocation.ip)) + ':' + allocation.port,
7676
)).toString();
7777

7878
const diskLimit = limits.disk ? megabytesToHuman(limits.disk) : 'Unlimited';

resources/scripts/components/server/network/AllocationRow.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import CopyOnClick from '@/components/elements/CopyOnClick';
1818
import DeleteAllocationButton from '@/components/server/network/DeleteAllocationButton';
1919
import setPrimaryServerAllocation from '@/api/server/network/setPrimaryServerAllocation';
2020
import getServerAllocations from '@/api/swr/getServerAllocations';
21+
import { formatIp } from '@/helpers';
2122

2223
const Code = styled.code`${tw`font-mono py-1 px-2 bg-neutral-900 rounded text-sm inline-block`}`;
2324
const Label = styled.label`${tw`uppercase text-xs mt-1 text-neutral-400 block px-1 select-none transition-colors duration-150`}`;
@@ -66,7 +67,7 @@ const AllocationRow = ({ allocation }: Props) => {
6667
<div css={tw`mr-4 flex-1 md:w-40`}>
6768
{allocation.alias ?
6869
<CopyOnClick text={allocation.alias}><Code css={tw`w-40 truncate`}>{allocation.alias}</Code></CopyOnClick> :
69-
<CopyOnClick text={allocation.ip}><Code>{allocation.ip}</Code></CopyOnClick>}
70+
<CopyOnClick text={formatIp(allocation.ip)}><Code>{formatIp(allocation.ip)}</Code></CopyOnClick>}
7071
<Label>{allocation.alias ? 'Hostname' : 'IP Address'}</Label>
7172
</div>
7273
<div css={tw`w-16 md:w-24 overflow-hidden`}>

resources/scripts/components/server/settings/SettingsContainer.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { LinkButton } from '@/components/elements/Button';
1313
import ServerContentBlock from '@/components/elements/ServerContentBlock';
1414
import isEqual from 'react-fast-compare';
1515
import CopyOnClick from '@/components/elements/CopyOnClick';
16+
import { formatIp } from '@/helpers';
1617

1718
export default () => {
1819
const username = useStoreState(state => state.user.data!.username);
@@ -30,10 +31,10 @@ export default () => {
3031
<TitledGreyBox title={'SFTP Details'} css={tw`mb-6 md:mb-10`}>
3132
<div>
3233
<Label>Server Address</Label>
33-
<CopyOnClick text={`sftp://${sftp.ip}:${sftp.port}`}>
34+
<CopyOnClick text={`sftp://${formatIp(sftp.ip)}:${sftp.port}`}>
3435
<Input
3536
type={'text'}
36-
value={`sftp://${sftp.ip}:${sftp.port}`}
37+
value={`sftp://${formatIp(sftp.ip)}:${sftp.port}`}
3738
readOnly
3839
/>
3940
</CopyOnClick>
@@ -59,7 +60,7 @@ export default () => {
5960
<div css={tw`ml-4`}>
6061
<LinkButton
6162
isSecondary
62-
href={`sftp://${username}.${id}@${sftp.ip}:${sftp.port}`}
63+
href={`sftp://${username}.${id}@${formatIp(sftp.ip)}:${sftp.port}`}
6364
>
6465
Launch SFTP
6566
</LinkButton>

resources/scripts/helpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ export function encodePathSegments (path: string): string {
6363
export function hashToPath (hash: string): string {
6464
return hash.length > 0 ? decodeURIComponent(hash.substr(1)) : '/';
6565
}
66+
67+
export function formatIp (ip: string): string {
68+
return /([a-f0-9:]+:+)+[a-f0-9]+/.test(ip) ? `[${ip}]` : ip;
69+
}

0 commit comments

Comments
 (0)