mirror of
https://github.com/skidoodle/hostinfo
synced 2026-04-28 01:27:36 +02:00
Refactor ServerInfo and add icon and tab fallbacks
This commit is contained in:
@@ -7,13 +7,6 @@ export default function Error({ error }: { error: string }) {
|
||||
<ExclamationTriangleIcon className="w-6 h-6 text-red-600 dark:text-red-400" />
|
||||
</div>
|
||||
<h3 className="text-sm font-bold text-gray-900 dark:text-white mb-1">Unable to Load</h3>
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400 mb-6 max-w-50 leading-relaxed">{error}</p>
|
||||
<button
|
||||
onClick={() => window.location.reload()}
|
||||
className="px-4 py-2 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700 text-xs font-medium text-gray-700 dark:text-gray-300 rounded-md transition-colors shadow-sm"
|
||||
>
|
||||
Try Again
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
+79
-64
@@ -4,13 +4,13 @@ import {
|
||||
MapPinIcon,
|
||||
GlobeAltIcon,
|
||||
BuildingOfficeIcon,
|
||||
CpuChipIcon,
|
||||
ClipboardDocumentIcon,
|
||||
CheckIcon,
|
||||
ArrowTopRightOnSquareIcon
|
||||
CpuChipIcon
|
||||
} from '@heroicons/react/24/outline';
|
||||
import type { HostInfo } from '@/utils/types';
|
||||
import { browser } from 'wxt/browser';
|
||||
import Error from './Error';
|
||||
|
||||
const CopyButton = ({ text }: { text: string }) => {
|
||||
const [copied, setCopied] = useState(false);
|
||||
@@ -26,7 +26,7 @@ const CopyButton = ({ text }: { text: string }) => {
|
||||
return (
|
||||
<button
|
||||
onClick={handleCopy}
|
||||
className="ml-2 p-1 rounded-md text-gray-400 hover:text-gray-600 hover:bg-gray-100 dark:hover:text-gray-200 dark:hover:bg-gray-800 transition-all"
|
||||
className="ml-2 p-1 rounded-md text-gray-400 hover:text-gray-600 hover:bg-gray-100 dark:hover:text-gray-200 dark:hover:bg-gray-800 transition-all opacity-0 group-hover:opacity-100 focus:opacity-100 cursor-pointer"
|
||||
title="Copy to clipboard"
|
||||
>
|
||||
{copied ? <CheckIcon className="w-3.5 h-3.5 text-green-500" /> : <ClipboardDocumentIcon className="w-3.5 h-3.5" />}
|
||||
@@ -39,19 +39,21 @@ const InfoRow = ({
|
||||
label,
|
||||
value,
|
||||
href,
|
||||
canCopy
|
||||
canCopy,
|
||||
iconColor = "text-gray-400 dark:text-gray-500"
|
||||
}: {
|
||||
icon: any,
|
||||
label: string,
|
||||
value: string | null,
|
||||
href?: string,
|
||||
canCopy?: boolean
|
||||
canCopy?: boolean,
|
||||
iconColor?: string
|
||||
}) => {
|
||||
if (!value) return null;
|
||||
|
||||
return (
|
||||
<div className="flex items-start py-2.5 border-b border-gray-100 dark:border-gray-800 last:border-0">
|
||||
<div className="mt-0.5 mr-3 text-gray-400 dark:text-gray-500">
|
||||
<div className="group flex items-start py-3 border-b border-gray-100 dark:border-gray-800 last:border-0">
|
||||
<div className={`mt-0.5 mr-3 ${iconColor}`}>
|
||||
<Icon className="w-4 h-4" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
@@ -62,13 +64,12 @@ const InfoRow = ({
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="text-sm text-gray-900 dark:text-gray-100 hover:text-blue-600 dark:hover:text-blue-400 truncate transition-colors flex items-center gap-1"
|
||||
className="text-sm font-medium text-gray-900 dark:text-gray-100 hover:text-blue-600 dark:hover:text-blue-400 truncate transition-colors flex items-center gap-1.5"
|
||||
>
|
||||
<span className="truncate">{value}</span>
|
||||
<ArrowTopRightOnSquareIcon className="w-3 h-3 opacity-50" />
|
||||
</a>
|
||||
) : (
|
||||
<span className="text-sm text-gray-900 dark:text-gray-100 truncate select-all">{value}</span>
|
||||
<span className="text-sm font-medium text-gray-900 dark:text-gray-100 truncate select-all">{value}</span>
|
||||
)}
|
||||
{canCopy && <CopyButton text={value} />}
|
||||
</div>
|
||||
@@ -80,14 +81,33 @@ const InfoRow = ({
|
||||
export default function ServerInfo({ data }: { data: HostInfo }) {
|
||||
const { network, location, domain, isBrowserResource } = data;
|
||||
|
||||
// URL generation for flags
|
||||
const getFlagUrl = (code?: string | null) => {
|
||||
if (!code) return '';
|
||||
try {
|
||||
const path = `/${code.toLowerCase()}.webp`;
|
||||
return browser.runtime.getURL(path as any);
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
// Header Component
|
||||
const Header = ({ title, subtitle, icon: Icon }: { title: string, subtitle?: string, icon?: any }) => (
|
||||
<div className="px-5 py-4 bg-gray-50 dark:bg-gray-900/50 border-b border-gray-200 dark:border-gray-800 flex items-center gap-3">
|
||||
{Icon && <Icon className="w-6 h-6 text-gray-500" />}
|
||||
<div>
|
||||
<h2 className="text-base font-semibold text-gray-900 dark:text-white leading-tight">{title}</h2>
|
||||
{subtitle && <p className="text-xs text-gray-500 dark:text-gray-400 mt-0.5">{subtitle}</p>}
|
||||
const Header = ({ title, flagCode }: { title: string, flagCode?: string | null }) => (
|
||||
<div className="px-5 py-4 bg-gray-50/50 dark:bg-gray-900/50 border-b border-gray-200 dark:border-gray-800 flex items-center justify-between">
|
||||
<div className="min-w-0 pr-3">
|
||||
<h1 className="text-base font-bold text-gray-900 dark:text-white truncate" title={title}>
|
||||
{title}
|
||||
</h1>
|
||||
</div>
|
||||
{flagCode && (
|
||||
<img
|
||||
src={getFlagUrl(flagCode)}
|
||||
alt={flagCode}
|
||||
className="w-8 h-auto rounded shadow-sm border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800"
|
||||
onError={(e) => (e.currentTarget.style.display = 'none')}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -97,46 +117,55 @@ export default function ServerInfo({ data }: { data: HostInfo }) {
|
||||
<div className="w-80 bg-white dark:bg-gray-950 font-sans">
|
||||
<Header
|
||||
title="System Resource"
|
||||
subtitle="Local browser page"
|
||||
icon={CpuChipIcon}
|
||||
flagCode="unknown"
|
||||
/>
|
||||
<div className="p-6 flex flex-col items-center justify-center text-center">
|
||||
<div className="w-12 h-12 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center mb-3">
|
||||
<CpuChipIcon className="w-6 h-6 text-gray-400" />
|
||||
</div>
|
||||
<p className="text-sm text-gray-500">No network information available for this page.</p>
|
||||
<div className="p-5">
|
||||
<InfoRow
|
||||
icon={CpuChipIcon}
|
||||
label="Type"
|
||||
value="Local Browser Page"
|
||||
iconColor="text-orange-500"
|
||||
/>
|
||||
<InfoRow
|
||||
icon={GlobeAltIcon}
|
||||
label="URL"
|
||||
value={data.url}
|
||||
iconColor="text-gray-400"
|
||||
/>
|
||||
</div>
|
||||
<div className="px-5 pb-5 text-xs text-gray-400 text-center">
|
||||
This page is generated locally by your browser.
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!network) return null;
|
||||
|
||||
const flagUrl = location?.countryCode
|
||||
? `/${location.countryCode.toLowerCase()}.webp`
|
||||
: '';
|
||||
// Fallback if network data is missing
|
||||
if (!network) {
|
||||
return <Error error="Host information unavailable." />;
|
||||
}
|
||||
|
||||
// Local Network View
|
||||
if (network.isLocal) {
|
||||
return (
|
||||
<div className="w-80 bg-white dark:bg-gray-950 font-sans">
|
||||
<Header
|
||||
title="Private Network"
|
||||
subtitle="Local or internal resource"
|
||||
icon={ServerIcon}
|
||||
title={domain}
|
||||
flagCode="unknown"
|
||||
/>
|
||||
<div className="p-5">
|
||||
<InfoRow
|
||||
icon={CpuChipIcon}
|
||||
label="Type"
|
||||
value="Local / Private Network"
|
||||
iconColor="text-orange-500"
|
||||
/>
|
||||
<InfoRow
|
||||
icon={ServerIcon}
|
||||
label="IP Address"
|
||||
value={network.ip}
|
||||
canCopy
|
||||
/>
|
||||
<InfoRow
|
||||
icon={GlobeAltIcon}
|
||||
label="Hostname"
|
||||
value={network.hostname || 'Localhost'}
|
||||
canCopy
|
||||
iconColor="text-blue-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -146,64 +175,50 @@ export default function ServerInfo({ data }: { data: HostInfo }) {
|
||||
// Public Internet View
|
||||
return (
|
||||
<div className="w-80 bg-white dark:bg-gray-950 font-sans text-gray-900 dark:text-gray-100">
|
||||
<div className="px-5 py-4 border-b border-gray-200 dark:border-gray-800 flex items-center justify-between bg-gray-50 dark:bg-gray-900/50">
|
||||
<div className="min-w-0 pr-2">
|
||||
<h1 className="text-base font-bold text-gray-900 dark:text-white truncate" title={domain}>
|
||||
{domain}
|
||||
</h1>
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400 mt-0.5 flex items-center gap-1">
|
||||
<span className="w-1.5 h-1.5 rounded-full bg-green-500"></span>
|
||||
Publicly Accessible
|
||||
</p>
|
||||
</div>
|
||||
{location?.countryCode && (
|
||||
<img
|
||||
src={flagUrl}
|
||||
alt={location.countryCode}
|
||||
className="w-8 h-auto rounded shadow-sm border border-gray-200 dark:border-gray-700"
|
||||
onError={(e) => (e.currentTarget.style.display = 'none')}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<Header
|
||||
title="Host Information"
|
||||
flagCode={location?.countryCode || 'unknown'}
|
||||
/>
|
||||
|
||||
<div className="p-5 space-y-1">
|
||||
<div className="p-5 space-y-0.5">
|
||||
<InfoRow
|
||||
icon={ServerIcon}
|
||||
label="IP Address"
|
||||
value={network.ip}
|
||||
href={`https://ip.albert.lol/${network.ip}`}
|
||||
canCopy
|
||||
iconColor="text-blue-500"
|
||||
/>
|
||||
|
||||
<InfoRow
|
||||
icon={GlobeAltIcon}
|
||||
label="Hostname"
|
||||
value={network.hostname}
|
||||
canCopy
|
||||
iconColor="text-indigo-500"
|
||||
/>
|
||||
|
||||
<InfoRow
|
||||
icon={MapPinIcon}
|
||||
label="Location"
|
||||
value={location?.countryName || 'Unknown'}
|
||||
value={location?.countryName || 'Unknown Location'}
|
||||
iconColor="text-emerald-500"
|
||||
/>
|
||||
|
||||
<InfoRow
|
||||
icon={BuildingOfficeIcon}
|
||||
label="Organization / ASN"
|
||||
value={network.org}
|
||||
href={network.asn ? `https://bgp.he.net/${network.asn}` : undefined}
|
||||
iconColor="text-violet-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="px-5 pb-5 pt-1">
|
||||
<div className="px-5 pb-5 pt-2">
|
||||
<a
|
||||
href={`https://platform.censys.io/search?q=${network.hostname || domain}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex items-center justify-center w-full py-2 px-4 bg-gray-900 dark:bg-gray-100 hover:bg-gray-800 dark:hover:bg-gray-200 text-white dark:text-gray-900 rounded-md transition-colors text-xs font-medium shadow-sm"
|
||||
className="flex items-center justify-center w-full py-2 px-4 bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-800 text-gray-700 dark:text-gray-300 rounded-md transition-all text-xs font-medium shadow-sm hover:shadow cursor-pointer"
|
||||
>
|
||||
<GlobeAltIcon className="w-3.5 h-3.5 mr-2" />
|
||||
<GlobeAltIcon className="w-3.5 h-3.5 mr-2 text-gray-400" />
|
||||
Analyze on Censys
|
||||
</a>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user