mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-22 05:51:46 +03:00
Refactors diagnostic pages to use composables and shared components
Extracts common state management patterns into reusable composables: - useDiagnosticState: Manages loading, results, and error states - useClipboard: Handles copy-to-clipboard functionality - useExamples: Manages example selection and state Creates shared UI components to reduce duplication: - ExamplesCard: Displays selectable examples with consistent styling - ErrorCard: Standardized error message display - ResultsCard: Consistent results presentation - ActionButton: Reusable action buttons with loading states Refactored 35+ diagnostic pages across DNS, HTTP, TLS, Email, and Network categories. This improves code maintainability, reduces duplication, and ensures consistent UX. Co-Authored-By: liss-bot <liss-bot@d0h.co>
This commit is contained in:
1 parent
0d98397000
commit
6b3e440df2
45 files changed
+1965
-2180
No files matched your search
@@ -0,0 +1,44 @@
|
||||
<script lang="ts">
|
||||
import Icon, { type IconName } from '$lib/components/global/Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
loading?: boolean;
|
||||
disabled?: boolean;
|
||||
icon?: IconName;
|
||||
loadingIcon?: IconName;
|
||||
loadingText?: string;
|
||||
children: any;
|
||||
onclick?: () => void;
|
||||
class?: string;
|
||||
}
|
||||
|
||||
let {
|
||||
loading = false,
|
||||
disabled = false,
|
||||
icon,
|
||||
loadingIcon = 'loader',
|
||||
loadingText,
|
||||
children,
|
||||
onclick,
|
||||
class: className = '',
|
||||
}: Props = $props();
|
||||
|
||||
const isDisabled = $derived(loading || disabled);
|
||||
</script>
|
||||
|
||||
<button class="lookup-btn {className}" {onclick} disabled={isDisabled}>
|
||||
{#if loading}
|
||||
<Icon name={loadingIcon} size="sm" animate="spin" />
|
||||
{loadingText || children}
|
||||
{:else}
|
||||
{#if icon}
|
||||
<Icon name={icon} size="sm" />
|
||||
{/if}
|
||||
{@render children()}
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<style>
|
||||
/* Styles are already in diagnostics-pages.scss */
|
||||
/* .lookup-btn is defined globally */
|
||||
</style>
|
||||
@@ -0,0 +1,29 @@
|
||||
<script lang="ts">
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
title?: string;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
let { title = 'Error', error }: Props = $props();
|
||||
</script>
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>{title}</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
/* Styles are already in diagnostics-pages.scss */
|
||||
/* .error-card, .error-content are defined globally */
|
||||
</style>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script lang="ts" generics="T extends Record<string, any>">
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
|
||||
interface Props {
|
||||
examples: T[];
|
||||
selectedIndex?: number | null;
|
||||
onSelect: (example: T, index: number) => void;
|
||||
title?: string;
|
||||
getLabel: (example: T) => string;
|
||||
getDescription: (example: T) => string;
|
||||
getTooltip?: (example: T) => string;
|
||||
}
|
||||
|
||||
let {
|
||||
examples,
|
||||
selectedIndex = null,
|
||||
onSelect,
|
||||
title = 'Quick Examples',
|
||||
getLabel,
|
||||
getDescription,
|
||||
getTooltip,
|
||||
}: Props = $props();
|
||||
</script>
|
||||
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>{title}</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedIndex === i}
|
||||
onclick={() => onSelect(example, i)}
|
||||
use:tooltip={getTooltip ? getTooltip(example) : getDescription(example)}
|
||||
>
|
||||
<h5>{getLabel(example)}</h5>
|
||||
<p>{getDescription(example)}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* Styles are already in diagnostics-pages.scss */
|
||||
/* This component uses existing shared styles */
|
||||
</style>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
onCopy?: () => void;
|
||||
copied?: boolean;
|
||||
copyText?: string;
|
||||
copiedText?: string;
|
||||
showCopyButton?: boolean;
|
||||
children: any;
|
||||
}
|
||||
|
||||
let {
|
||||
title,
|
||||
onCopy,
|
||||
copied = false,
|
||||
copyText = 'Copy Results',
|
||||
copiedText = 'Copied!',
|
||||
showCopyButton = true,
|
||||
children,
|
||||
}: Props = $props();
|
||||
</script>
|
||||
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>{title}</h3>
|
||||
{#if showCopyButton && onCopy}
|
||||
<button class="copy-btn" onclick={onCopy} disabled={copied}>
|
||||
<span class={copied ? 'text-green-500' : ''}>
|
||||
<Icon name={copied ? 'check' : 'copy'} size="xs" />
|
||||
</span>
|
||||
{copied ? copiedText : copyText}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="card-content">
|
||||
{@render children()}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* Styles are already in diagnostics-pages.scss */
|
||||
/* .results-card, .copy-btn are defined globally */
|
||||
</style>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script lang="ts">
|
||||
import Icon, { type IconName } from '$lib/components/global/Icon.svelte';
|
||||
|
||||
interface StatusItem {
|
||||
icon: IconName;
|
||||
value: string;
|
||||
label: string;
|
||||
status?: 'success' | 'warning' | 'error' | 'info';
|
||||
tooltip?: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
items: StatusItem[];
|
||||
}
|
||||
|
||||
let { items }: Props = $props();
|
||||
</script>
|
||||
|
||||
<div class="status-overview">
|
||||
{#each items as item (item.label)}
|
||||
<div class="status-item {item.status || ''}">
|
||||
<Icon name={item.icon} size="sm" />
|
||||
<div>
|
||||
<strong>{item.value}</strong>
|
||||
<div class="status-text">{item.label}</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* Styles are already in diagnostics-pages.scss */
|
||||
/* .status-overview, .status-item are defined globally */
|
||||
.status-text {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
margin-top: 2px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script lang="ts">
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
title?: string;
|
||||
warnings: string[];
|
||||
}
|
||||
|
||||
let { title = 'Warning', warnings }: Props = $props();
|
||||
</script>
|
||||
|
||||
{#if warnings.length > 0}
|
||||
<div class="card warning-card">
|
||||
<div class="card-content">
|
||||
<div class="warning-content">
|
||||
<Icon name="alert-triangle" size="sm" />
|
||||
<div class="warning-messages">
|
||||
{#if title}
|
||||
<strong>{title}</strong>
|
||||
{/if}
|
||||
{#each warnings as warning (warning)}
|
||||
<p>{warning}</p>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
/* Styles are already in diagnostics-pages.scss */
|
||||
/* .warning-card, .warning-content are defined globally */
|
||||
.warning-messages {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
</style>
|
||||
@@ -18,7 +18,7 @@
|
||||
xl: 'w-10 h-10',
|
||||
};
|
||||
|
||||
type IconName = keyof typeof iconMap;
|
||||
export type IconName = keyof typeof iconMap;
|
||||
|
||||
/**
|
||||
* Get SVG content for the given icon name
|
||||
|
||||
@@ -240,7 +240,7 @@
|
||||
<div class="card loading-card">
|
||||
<div class="card-content">
|
||||
<div class="loading">
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Calculating distances...
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -221,7 +221,7 @@
|
||||
<div class="card loading-card">
|
||||
<div class="card-content">
|
||||
<div class="loading">
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Calculating IPs...
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Central export file for all composables
|
||||
export { useClipboard } from './useClipboard.svelte.js';
|
||||
export { useDiagnosticState } from './useDiagnosticState.svelte.js';
|
||||
export { useExamples } from './useExamples.svelte.js';
|
||||
|
||||
// Re-export types
|
||||
export type { DiagnosticState } from './useDiagnosticState.svelte.js';
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Clipboard composable for copying text with auto-reset feedback
|
||||
* Replaces the repeated copiedState pattern across 81+ files
|
||||
*/
|
||||
|
||||
export function useClipboard(autoResetMs: number = 1500) {
|
||||
let copiedStates = $state<Record<string, boolean>>({});
|
||||
|
||||
/**
|
||||
* Copy text to clipboard with feedback
|
||||
* @param text - Text to copy
|
||||
* @param id - Unique identifier for this copy action (optional)
|
||||
*/
|
||||
async function copy(text: string, id: string = 'default') {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedStates[id] = true;
|
||||
setTimeout(() => {
|
||||
copiedStates[id] = false;
|
||||
}, autoResetMs);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Failed to copy to clipboard:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a specific copy action is in "copied" state
|
||||
*/
|
||||
function isCopied(id: string = 'default'): boolean {
|
||||
return copiedStates[id] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset a specific copy state
|
||||
*/
|
||||
function reset(id: string = 'default') {
|
||||
copiedStates[id] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all copy states
|
||||
*/
|
||||
function resetAll() {
|
||||
copiedStates = {};
|
||||
}
|
||||
|
||||
return {
|
||||
get copiedStates() {
|
||||
return copiedStates;
|
||||
},
|
||||
copy,
|
||||
isCopied,
|
||||
reset,
|
||||
resetAll,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Common state management for diagnostic/tool pages
|
||||
* Replaces the repeated state pattern across 80+ files
|
||||
*/
|
||||
|
||||
export interface DiagnosticState<T = any> {
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
results: T | null;
|
||||
}
|
||||
|
||||
export function useDiagnosticState<T = any>() {
|
||||
let loading = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
let results = $state<T | null>(null);
|
||||
|
||||
function setLoading(value: boolean) {
|
||||
loading = value;
|
||||
}
|
||||
|
||||
function setError(errorMessage: string | null) {
|
||||
error = errorMessage;
|
||||
loading = false;
|
||||
}
|
||||
|
||||
function setResults(data: T | null) {
|
||||
results = data;
|
||||
error = null;
|
||||
loading = false;
|
||||
}
|
||||
|
||||
function reset() {
|
||||
loading = false;
|
||||
error = null;
|
||||
results = null;
|
||||
}
|
||||
|
||||
function startOperation() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
}
|
||||
|
||||
return {
|
||||
get loading() {
|
||||
return loading;
|
||||
},
|
||||
get error() {
|
||||
return error;
|
||||
},
|
||||
get results() {
|
||||
return results;
|
||||
},
|
||||
setLoading,
|
||||
setError,
|
||||
setResults,
|
||||
reset,
|
||||
startOperation,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Example selection management for diagnostic/tool pages
|
||||
* Handles example loading and selection tracking
|
||||
*/
|
||||
|
||||
export function useExamples<T extends { [key: string]: any }>(examples: T[]) {
|
||||
let selectedIndex = $state<number | null>(null);
|
||||
|
||||
function select(index: number) {
|
||||
selectedIndex = index;
|
||||
}
|
||||
|
||||
function clear() {
|
||||
selectedIndex = null;
|
||||
}
|
||||
|
||||
function isSelected(index: number): boolean {
|
||||
return selectedIndex === index;
|
||||
}
|
||||
|
||||
function getSelected(): T | null {
|
||||
if (selectedIndex === null) return null;
|
||||
return examples[selectedIndex] ?? null;
|
||||
}
|
||||
|
||||
return {
|
||||
get selectedIndex() {
|
||||
return selectedIndex;
|
||||
},
|
||||
select,
|
||||
clear,
|
||||
isSelected,
|
||||
getSelected,
|
||||
};
|
||||
}
|
||||
@@ -247,7 +247,7 @@
|
||||
<div class="action-section">
|
||||
<button class="check-btn lookup-btn" onclick={checkCAA} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Checking CAA...
|
||||
{:else}
|
||||
<Icon name="shield-check" size="sm" />
|
||||
|
||||
@@ -186,7 +186,7 @@
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={checkDNSSEC} disabled={loading || !domain.trim()}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Checking DNSSEC...
|
||||
{:else}
|
||||
<Icon name="search" size="sm" />
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { validateDNSLookupInput, formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ActionButton from '$lib/components/common/ActionButton.svelte';
|
||||
import ResultsCard from '$lib/components/common/ResultsCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import WarningCard from '$lib/components/common/WarningCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let domainName = $state('example.com');
|
||||
@@ -9,11 +15,9 @@
|
||||
let resolver = $state('cloudflare');
|
||||
let customResolver = $state('');
|
||||
let useCustomResolver = $state(false);
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
// Reactive validation state
|
||||
const isInputValid = $derived(() => {
|
||||
@@ -41,23 +45,22 @@
|
||||
{ value: 'opendns', label: 'OpenDNS (208.67.222.222)' },
|
||||
];
|
||||
|
||||
const examples = [
|
||||
const examplesList = [
|
||||
{ domain: 'example.com', type: 'A', description: 'Basic A record lookup' },
|
||||
{ domain: 'google.com', type: 'MX', description: 'Mail server records' },
|
||||
{ domain: 'cloudflare.com', type: 'AAAA', description: 'IPv6 addresses' },
|
||||
{ domain: '_dmarc.github.com', type: 'TXT', description: 'DMARC policy record' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
async function performLookup() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
// Client-side validation
|
||||
const validation = validateDNSLookupInput(domainName, useCustomResolver, customResolver);
|
||||
if (!validation.isValid) {
|
||||
error = validation.error || 'Invalid input';
|
||||
loading = false;
|
||||
diagnosticState.setError(validation.error || 'Invalid input');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -84,13 +87,13 @@
|
||||
|
||||
// Handle 404 as "no records found" (warning, not error)
|
||||
if (response.status === 404 && responseData.noRecords) {
|
||||
results = {
|
||||
diagnosticState.setResults({
|
||||
noRecords: true,
|
||||
message: responseData.message,
|
||||
name: responseData.name,
|
||||
type: responseData.type,
|
||||
resolver: useCustomResolver && customResolver ? customResolver.trim() : resolver,
|
||||
};
|
||||
});
|
||||
return; // Don't throw error, just set results
|
||||
}
|
||||
|
||||
@@ -115,33 +118,25 @@
|
||||
throw new Error(`Lookup failed (${response.status})`);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
// Enhanced error handling using utility
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(formatDNSError(err));
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
domainName = example.domain;
|
||||
recordType = example.type;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
performLookup();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.Answer?.length) return;
|
||||
|
||||
const text = results.Answer.map((r: unknown) => (r as { data: string }).data).join('\n');
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
if (!diagnosticState.results?.Answer?.length) return;
|
||||
const text = diagnosticState.results.Answer.map((r: unknown) => (r as { data: string }).data).join('\n');
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -155,27 +150,14 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Quick Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Query ${example.type} records for ${example.domain}`}
|
||||
>
|
||||
<h5>{example.domain} ({example.type})</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
getLabel={(ex) => `${ex.domain} (${ex.type})`}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Query ${ex.type} records for ${ex.domain}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -193,7 +175,7 @@
|
||||
bind:value={domainName}
|
||||
placeholder="example.com"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (domainName) performLookup();
|
||||
}}
|
||||
/>
|
||||
@@ -208,7 +190,7 @@
|
||||
id="type"
|
||||
bind:value={recordType}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (domainName) performLookup();
|
||||
}}
|
||||
>
|
||||
@@ -225,7 +207,7 @@
|
||||
id="dns-resolver"
|
||||
bind:value={resolver}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (domainName) performLookup();
|
||||
}}
|
||||
>
|
||||
@@ -240,7 +222,7 @@
|
||||
bind:value={customResolver}
|
||||
placeholder="8.8.8.8 or custom IP"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (domainName) performLookup();
|
||||
}}
|
||||
/>
|
||||
@@ -250,7 +232,7 @@
|
||||
type="checkbox"
|
||||
bind:checked={useCustomResolver}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (domainName) performLookup();
|
||||
}}
|
||||
/>
|
||||
@@ -260,45 +242,32 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={performLookup} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
Performing Lookup...
|
||||
{:else}
|
||||
<Icon name="search" size="sm" />
|
||||
Lookup DNS Records
|
||||
{/if}
|
||||
</button>
|
||||
<ActionButton
|
||||
loading={diagnosticState.loading}
|
||||
disabled={!isInputValid}
|
||||
icon="search"
|
||||
loadingText="Performing Lookup..."
|
||||
onclick={performLookup}
|
||||
>
|
||||
Lookup DNS Records
|
||||
</ActionButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Warnings -->
|
||||
{#if results?.warnings?.length > 0}
|
||||
<div class="card warning-card warns">
|
||||
<div class="card-content">
|
||||
<div class="warning-content">
|
||||
<Icon name="alert-triangle" size="sm" />
|
||||
<div class="warning-messages">
|
||||
{#each results.warnings as warning, index (index)}
|
||||
<p>{warning}</p>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<WarningCard warnings={diagnosticState.results?.warnings || []} />
|
||||
|
||||
<!-- No Records Warning -->
|
||||
{#if results?.noRecords}
|
||||
{#if diagnosticState.results?.noRecords}
|
||||
<div class="card warning-card">
|
||||
<div class="card-content">
|
||||
<div class="warning-content">
|
||||
<Icon name="info" size="md" />
|
||||
<div>
|
||||
<strong>No Records Found</strong>
|
||||
<p>{results.message}</p>
|
||||
<p class="help-text">Using resolver: {results.resolver}</p>
|
||||
<p>{diagnosticState.results.message}</p>
|
||||
<p class="help-text">Using resolver: {diagnosticState.results.resolver}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -306,72 +275,41 @@
|
||||
{/if}
|
||||
|
||||
<!-- Results -->
|
||||
{#if results && !results.noRecords}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>DNS Records Found</h3>
|
||||
{#if results.Answer?.length > 0}
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<span class={copiedState ? 'text-green-500' : ''}
|
||||
><Icon name={copiedState ? 'check' : 'copy'} size="xs" /></span
|
||||
>
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="card-content">
|
||||
{#if results.Answer?.length > 0}
|
||||
<div class="records-list">
|
||||
{#each results.Answer as record, i (i)}
|
||||
<div class="record-item">
|
||||
<div class="record-data mono">{record.data}</div>
|
||||
{#if record.TTL}
|
||||
<div class="record-ttl" use:tooltip={'Time To Live - how long this record can be cached'}>
|
||||
TTL: {record.TTL}s
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="card warning-card no-records">
|
||||
<div class="warning-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<p>No records found for <code>{domainName}</code> ({recordType})</p>
|
||||
{#if diagnosticState.results && !diagnosticState.results.noRecords}
|
||||
<ResultsCard
|
||||
title="DNS Records Found"
|
||||
onCopy={copyResults}
|
||||
copied={clipboard.isCopied()}
|
||||
showCopyButton={diagnosticState.results.Answer?.length > 0}
|
||||
>
|
||||
{#if diagnosticState.results.Answer?.length > 0}
|
||||
<div class="records-list">
|
||||
{#each diagnosticState.results.Answer as record, i (i)}
|
||||
<div class="record-item">
|
||||
<div class="record-data mono">{record.data}</div>
|
||||
{#if record.TTL}
|
||||
<div class="record-ttl" use:tooltip={'Time To Live - how long this record can be cached'}>
|
||||
TTL: {record.TTL}s
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Lookup Failed</strong>
|
||||
<p>{error}</p>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="card warning-card no-records">
|
||||
<div class="warning-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<p>No records found for <code>{domainName}</code> ({recordType})</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</ResultsCard>
|
||||
{/if}
|
||||
|
||||
<ErrorCard title="Lookup Failed" error={diagnosticState.error} />
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.action-section {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: var(--spacing-xl);
|
||||
}
|
||||
|
||||
.warns {
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
// Styles now use diagnostics-pages.scss
|
||||
// Most styles moved to shared stylesheet for reusability
|
||||
</style>
|
||||
@@ -212,7 +212,7 @@
|
||||
<div class="action-section">
|
||||
<button class="check-btn lookup-btn" onclick={checkNSSOA} disabled={loading || !domain.trim()}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Checking NS/SOA...
|
||||
{:else}
|
||||
<Icon name="server" size="sm" />
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ActionButton from '$lib/components/common/ActionButton.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let domainName = $state('example.com');
|
||||
let recordType = $state('A');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let lastQuery = $state<{ domain: string; type: string } | null>(null);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const recordTypes = [
|
||||
{ value: 'A', label: 'A', description: 'IPv4 address records' },
|
||||
@@ -28,17 +30,17 @@
|
||||
opendns: { name: 'OpenDNS', ip: '208.67.222.222', location: 'Global' },
|
||||
};
|
||||
|
||||
const examples = [
|
||||
const examplesList = [
|
||||
{ domain: 'google.com', type: 'A', description: 'Check A record propagation' },
|
||||
{ domain: 'github.com', type: 'AAAA', description: 'IPv6 propagation check' },
|
||||
{ domain: 'gmail.com', type: 'MX', description: 'Mail server propagation' },
|
||||
{ domain: '_dmarc.google.com', type: 'TXT', description: 'DMARC policy propagation' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
async function checkPropagation() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
lastQuery = { domain: domainName.trim(), type: recordType };
|
||||
|
||||
try {
|
||||
@@ -57,25 +59,19 @@
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
results = data.results;
|
||||
diagnosticState.setResults(data.results);
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'Unknown error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
domainName = example.domain;
|
||||
recordType = example.type;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
checkPropagation();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getStatusColor(result: unknown): string {
|
||||
const res = result as { error?: string; result?: { Answer?: unknown[] } };
|
||||
if (res.error) return 'error';
|
||||
@@ -91,8 +87,8 @@
|
||||
}
|
||||
|
||||
function areResultsConsistent(): boolean {
|
||||
const resultsArray = results as unknown[];
|
||||
if (!results || resultsArray.length === 0) return false;
|
||||
const resultsArray = diagnosticState.results as unknown[];
|
||||
if (!diagnosticState.results || resultsArray.length === 0) return false;
|
||||
|
||||
type DnsResult = { error?: string; result?: { Answer?: Array<{ data: string }> } };
|
||||
const successfulResults = resultsArray.filter((r: unknown) => {
|
||||
@@ -109,7 +105,7 @@
|
||||
}
|
||||
|
||||
async function copyAllResults() {
|
||||
const resultsArray = results as unknown[];
|
||||
const resultsArray = diagnosticState.results as unknown[];
|
||||
if (!resultsArray?.length) return;
|
||||
|
||||
const query = lastQuery as { domain?: string; type?: string };
|
||||
@@ -139,9 +135,7 @@
|
||||
text += '\n';
|
||||
});
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -155,27 +149,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Propagation Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Check ${example.type} record propagation for ${example.domain}`}
|
||||
>
|
||||
<h5>{example.domain} ({example.type})</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Propagation Examples"
|
||||
getLabel={(ex) => `${ex.domain} (${ex.type})`}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Check ${ex.type} record propagation for ${ex.domain}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -193,7 +175,7 @@
|
||||
bind:value={domainName}
|
||||
placeholder="example.com"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (domainName) checkPropagation();
|
||||
}}
|
||||
/>
|
||||
@@ -207,7 +189,7 @@
|
||||
id="type"
|
||||
bind:value={recordType}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (domainName) checkPropagation();
|
||||
}}
|
||||
>
|
||||
@@ -220,21 +202,22 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="check-btn" onclick={checkPropagation} disabled={loading || !domainName.trim()}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
Checking Propagation...
|
||||
{:else}
|
||||
<Icon name="globe" size="sm" />
|
||||
Check DNS Propagation
|
||||
{/if}
|
||||
</button>
|
||||
<ActionButton
|
||||
loading={diagnosticState.loading}
|
||||
disabled={!domainName.trim()}
|
||||
icon="globe"
|
||||
loadingText="Checking Propagation..."
|
||||
onclick={checkPropagation}
|
||||
class="check-btn"
|
||||
>
|
||||
Check DNS Propagation
|
||||
</ActionButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<div>
|
||||
@@ -253,16 +236,16 @@
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<button class="copy-btn" onclick={copyAllResults} disabled={copiedState}>
|
||||
<div class={copiedState ? 'status-success' : ''}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
<button class="copy-btn" onclick={copyAllResults} disabled={clipboard.isCopied()}>
|
||||
<div class={clipboard.isCopied() ? 'status-success' : ''}>
|
||||
<Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" />
|
||||
</div>
|
||||
{copiedState ? 'Copied!' : 'Copy All Results'}
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy All Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="resolvers-grid">
|
||||
{#each results as result, resultIndex (resultIndex)}
|
||||
{#each diagnosticState.results as result, resultIndex (resultIndex)}
|
||||
{@const res = result as { resolver: string }}
|
||||
{@const info = resolverInfo[res.resolver as keyof typeof resolverInfo]}
|
||||
{@const status = getStatusColor(result)}
|
||||
@@ -321,19 +304,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Propagation Check Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Propagation Check Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -241,7 +241,7 @@
|
||||
disabled={loading || !ipAddress.trim() || !isValidIP(ipAddress.trim())}
|
||||
>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Performing Reverse Lookup...
|
||||
{:else}
|
||||
<Icon name="search" size="sm" />
|
||||
|
||||
@@ -179,7 +179,7 @@
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={analyzeSOA} disabled={loading || !domain.trim()}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Analyzing SOA Record...
|
||||
{:else}
|
||||
<Icon name="search" size="sm" />
|
||||
|
||||
@@ -215,7 +215,7 @@
|
||||
<div class="action-section">
|
||||
<button class="evaluate-btn lookup-btn" onclick={evaluateSPF} disabled={loading || !domain.trim()}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Evaluating SPF...
|
||||
{:else}
|
||||
<Icon name="shield-check" size="sm" />
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let domain = $state('gmail.com');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const examplesList = [
|
||||
{ domain: 'gmail.com', description: 'Google Gmail DMARC policy' },
|
||||
{ domain: 'outlook.com', description: 'Microsoft Outlook DMARC setup' },
|
||||
{ domain: 'github.com', description: 'GitHub enterprise DMARC' },
|
||||
@@ -19,10 +19,10 @@
|
||||
{ domain: 'salesforce.com', description: 'Salesforce DMARC configuration' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
async function checkDMARC() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/email', {
|
||||
@@ -38,24 +38,19 @@
|
||||
throw new Error(`DMARC check failed: ${response.status}`);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'Unknown error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
domain = example.domain;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
checkDMARC();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getPolicyColor(policy: string): string {
|
||||
switch (policy) {
|
||||
case 'reject':
|
||||
@@ -94,30 +89,30 @@
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results) return;
|
||||
if (!diagnosticState.results) return;
|
||||
|
||||
let text = `DMARC Check for ${domain}\n`;
|
||||
text += `Generated at: ${new Date().toISOString()}\n\n`;
|
||||
|
||||
if (results.record) {
|
||||
text += `DMARC Record:\n${results.record}\n\n`;
|
||||
if (diagnosticState.results.record) {
|
||||
text += `DMARC Record:\n${diagnosticState.results.record}\n\n`;
|
||||
}
|
||||
|
||||
if (results.deliverabilityHints) {
|
||||
if (diagnosticState.results.deliverabilityHints) {
|
||||
text += `Email Deliverability Impact:\n`;
|
||||
text += `${results.deliverabilityHints.policyImpact}\n\n`;
|
||||
text += `${diagnosticState.results.deliverabilityHints.policyImpact}\n\n`;
|
||||
|
||||
if (results.deliverabilityHints.recommendations.length > 0) {
|
||||
if (diagnosticState.results.deliverabilityHints.recommendations.length > 0) {
|
||||
text += `Recommendations:\n`;
|
||||
results.deliverabilityHints.recommendations.forEach((rec: string) => {
|
||||
diagnosticState.results.deliverabilityHints.recommendations.forEach((rec: string) => {
|
||||
text += ` • ${rec}\n`;
|
||||
});
|
||||
text += `\n`;
|
||||
}
|
||||
}
|
||||
|
||||
if (results.parsed) {
|
||||
const p = results.parsed;
|
||||
if (diagnosticState.results.parsed) {
|
||||
const p = diagnosticState.results.parsed;
|
||||
text += `Policy Configuration:\n`;
|
||||
text += ` Main Policy: ${p.policy}\n`;
|
||||
if (p.subdomainPolicy) text += ` Subdomain Policy: ${p.subdomainPolicy}\n`;
|
||||
@@ -128,9 +123,7 @@
|
||||
if (p.reporting.forensic) text += ` Forensic Reports: ${p.reporting.forensic}\n`;
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -144,27 +137,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>DMARC Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Check DMARC policy for ${example.domain}`}
|
||||
>
|
||||
<h5>{example.domain}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="DMARC Examples"
|
||||
getLabel={(ex) => ex.domain}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Check DMARC policy for ${ex.domain}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -173,7 +154,7 @@
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-group">
|
||||
<label for="domain" use:tooltip={'Enter the domain to check DMARC policy for'}>
|
||||
<label for="domain">
|
||||
Domain Name
|
||||
<input
|
||||
id="domain"
|
||||
@@ -181,7 +162,7 @@
|
||||
bind:value={domain}
|
||||
placeholder="example.com"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (domain) checkDMARC();
|
||||
}}
|
||||
/>
|
||||
@@ -189,8 +170,8 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="check-btn lookup-btn" onclick={checkDMARC} disabled={loading || !domain.trim()}>
|
||||
{#if loading}
|
||||
<button class="check-btn lookup-btn" onclick={checkDMARC} disabled={diagnosticState.loading || !domain.trim()}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Checking DMARC...
|
||||
{:else}
|
||||
@@ -203,33 +184,35 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results && results.hasRecord}
|
||||
{#if diagnosticState.results && diagnosticState.results.hasRecord}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>DMARC Policy Analysis</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
<button class="copy-btn" onclick={copyResults} disabled={clipboard.isCopied()}>
|
||||
<Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
{#if results.parsed && results.deliverabilityHints}
|
||||
{#if diagnosticState.results.parsed && diagnosticState.results.deliverabilityHints}
|
||||
<!-- Email Deliverability Impact -->
|
||||
<div class="deliverability-section">
|
||||
<div class="deliverability-overview {getPolicyColor(results.parsed.policy)}">
|
||||
<Icon name={getPolicyIcon(results.parsed.policy)} size="md" />
|
||||
<div class="deliverability-overview {getPolicyColor(diagnosticState.results.parsed.policy)}">
|
||||
<Icon name={getPolicyIcon(diagnosticState.results.parsed.policy)} size="md" />
|
||||
<div>
|
||||
<h4>Email Deliverability Impact</h4>
|
||||
<p class="policy-impact">{results.deliverabilityHints.policyImpact}</p>
|
||||
{#if results.deliverabilityHints.alignmentComplexity?.strict}
|
||||
<p class="alignment-warning">{results.deliverabilityHints.alignmentComplexity.strict}</p>
|
||||
<p class="policy-impact">{diagnosticState.results.deliverabilityHints.policyImpact}</p>
|
||||
{#if diagnosticState.results.deliverabilityHints.alignmentComplexity?.strict}
|
||||
<p class="alignment-warning">
|
||||
{diagnosticState.results.deliverabilityHints.alignmentComplexity.strict}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Recommendations -->
|
||||
{#if results.deliverabilityHints.recommendations.length > 0}
|
||||
{@const hintsData = (results as { deliverabilityHints: { recommendations: string[] } })
|
||||
{#if diagnosticState.results.deliverabilityHints.recommendations.length > 0}
|
||||
{@const hintsData = (diagnosticState.results as { deliverabilityHints: { recommendations: string[] } })
|
||||
.deliverabilityHints}
|
||||
<div class="recommendations-section">
|
||||
<h5>Deliverability Recommendations</h5>
|
||||
@@ -250,7 +233,7 @@
|
||||
<h4>DMARC Record</h4>
|
||||
<div class="record-display">
|
||||
<div class="record-location">_dmarc.{domain}</div>
|
||||
<code>{results.record}</code>
|
||||
<code>{diagnosticState.results.record}</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -259,19 +242,19 @@
|
||||
<h4>Policy Configuration</h4>
|
||||
<div class="policy-grid">
|
||||
<!-- Main Policy -->
|
||||
<div class="policy-item {getPolicyColor(results.parsed.policy)}">
|
||||
<div class="policy-item {getPolicyColor(diagnosticState.results.parsed.policy)}">
|
||||
<div class="policy-header">
|
||||
<Icon name="shield" size="sm" />
|
||||
<span>Main Policy</span>
|
||||
</div>
|
||||
<div class="policy-value">
|
||||
<span class="policy-text">{results.parsed.policy}</span>
|
||||
<span class="policy-text">{diagnosticState.results.parsed.policy}</span>
|
||||
<span class="policy-description">
|
||||
{#if results.parsed.policy === 'reject'}
|
||||
{#if diagnosticState.results.parsed.policy === 'reject'}
|
||||
Reject non-compliant messages
|
||||
{:else if results.parsed.policy === 'quarantine'}
|
||||
{:else if diagnosticState.results.parsed.policy === 'quarantine'}
|
||||
Quarantine suspicious messages
|
||||
{:else if results.parsed.policy === 'none'}
|
||||
{:else if diagnosticState.results.parsed.policy === 'none'}
|
||||
Monitor only, no action
|
||||
{:else}
|
||||
Unknown policy
|
||||
@@ -281,40 +264,46 @@
|
||||
</div>
|
||||
|
||||
<!-- Subdomain Policy -->
|
||||
{#if results.parsed.subdomainPolicy}
|
||||
<div class="policy-item {getPolicyColor(results.parsed.subdomainPolicy)}">
|
||||
{#if diagnosticState.results.parsed.subdomainPolicy}
|
||||
<div class="policy-item {getPolicyColor(diagnosticState.results.parsed.subdomainPolicy)}">
|
||||
<div class="policy-header">
|
||||
<Icon name="git-branch" size="sm" />
|
||||
<span>Subdomain Policy</span>
|
||||
</div>
|
||||
<div class="policy-value">
|
||||
<span class="policy-text">{results.parsed.subdomainPolicy}</span>
|
||||
<span class="policy-text">{diagnosticState.results.parsed.subdomainPolicy}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Coverage Percentage -->
|
||||
<div class="policy-item {parseInt(results.parsed.percentage) === 100 ? 'success' : 'warning'}">
|
||||
<div
|
||||
class="policy-item {parseInt(diagnosticState.results.parsed.percentage) === 100
|
||||
? 'success'
|
||||
: 'warning'}"
|
||||
>
|
||||
<div class="policy-header">
|
||||
<Icon name="percent" size="sm" />
|
||||
<span>Coverage</span>
|
||||
</div>
|
||||
<div class="policy-value">
|
||||
<span class="policy-text">{results.parsed.percentage}%</span>
|
||||
<span class="policy-text">{diagnosticState.results.parsed.percentage}%</span>
|
||||
<span class="policy-description">of messages affected</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- DKIM Alignment -->
|
||||
<div class="policy-item {getAlignmentColor(results.parsed.alignment.dkim)}">
|
||||
<div class="policy-item {getAlignmentColor(diagnosticState.results.parsed.alignment.dkim)}">
|
||||
<div class="policy-header">
|
||||
<Icon name="key" size="sm" />
|
||||
<span>DKIM Alignment</span>
|
||||
</div>
|
||||
<div class="policy-value">
|
||||
<span class="policy-text">{results.parsed.alignment.dkim === 's' ? 'Strict' : 'Relaxed'}</span>
|
||||
<span class="policy-text"
|
||||
>{diagnosticState.results.parsed.alignment.dkim === 's' ? 'Strict' : 'Relaxed'}</span
|
||||
>
|
||||
<span class="policy-description">
|
||||
{results.parsed.alignment.dkim === 's'
|
||||
{diagnosticState.results.parsed.alignment.dkim === 's'
|
||||
? 'Exact domain match required'
|
||||
: 'Organizational domain match allowed'}
|
||||
</span>
|
||||
@@ -322,15 +311,17 @@
|
||||
</div>
|
||||
|
||||
<!-- SPF Alignment -->
|
||||
<div class="policy-item {getAlignmentColor(results.parsed.alignment.spf)}">
|
||||
<div class="policy-item {getAlignmentColor(diagnosticState.results.parsed.alignment.spf)}">
|
||||
<div class="policy-header">
|
||||
<Icon name="mail" size="sm" />
|
||||
<span>SPF Alignment</span>
|
||||
</div>
|
||||
<div class="policy-value">
|
||||
<span class="policy-text">{results.parsed.alignment.spf === 's' ? 'Strict' : 'Relaxed'}</span>
|
||||
<span class="policy-text"
|
||||
>{diagnosticState.results.parsed.alignment.spf === 's' ? 'Strict' : 'Relaxed'}</span
|
||||
>
|
||||
<span class="policy-description">
|
||||
{results.parsed.alignment.spf === 's'
|
||||
{diagnosticState.results.parsed.alignment.spf === 's'
|
||||
? 'Exact domain match required'
|
||||
: 'Organizational domain match allowed'}
|
||||
</span>
|
||||
@@ -344,15 +335,15 @@
|
||||
<span>Failure Options</span>
|
||||
</div>
|
||||
<div class="policy-value">
|
||||
<span class="policy-text">{results.parsed.reporting.failureOptions}</span>
|
||||
<span class="policy-text">{diagnosticState.results.parsed.reporting.failureOptions}</span>
|
||||
<span class="policy-description">
|
||||
{#if results.parsed.reporting.failureOptions === '0'}
|
||||
{#if diagnosticState.results.parsed.reporting.failureOptions === '0'}
|
||||
DKIM and SPF failure
|
||||
{:else if results.parsed.reporting.failureOptions === '1'}
|
||||
{:else if diagnosticState.results.parsed.reporting.failureOptions === '1'}
|
||||
Any alignment failure
|
||||
{:else if results.parsed.reporting.failureOptions === 'd'}
|
||||
{:else if diagnosticState.results.parsed.reporting.failureOptions === 'd'}
|
||||
DKIM failure only
|
||||
{:else if results.parsed.reporting.failureOptions === 's'}
|
||||
{:else if diagnosticState.results.parsed.reporting.failureOptions === 's'}
|
||||
SPF failure only
|
||||
{:else}
|
||||
Custom configuration
|
||||
@@ -373,8 +364,8 @@
|
||||
<span>Aggregate Reports (RUA)</span>
|
||||
</div>
|
||||
<div class="reporting-value">
|
||||
{#if results.parsed.reporting.aggregate}
|
||||
<span class="email-address">{results.parsed.reporting.aggregate}</span>
|
||||
{#if diagnosticState.results.parsed.reporting.aggregate}
|
||||
<span class="email-address">{diagnosticState.results.parsed.reporting.aggregate}</span>
|
||||
<span class="reporting-description">Daily summaries of DMARC activity</span>
|
||||
{:else}
|
||||
<span class="not-configured">Not configured</span>
|
||||
@@ -389,8 +380,8 @@
|
||||
<span>Forensic Reports (RUF)</span>
|
||||
</div>
|
||||
<div class="reporting-value">
|
||||
{#if results.parsed.reporting.forensic}
|
||||
<span class="email-address">{results.parsed.reporting.forensic}</span>
|
||||
{#if diagnosticState.results.parsed.reporting.forensic}
|
||||
<span class="email-address">{diagnosticState.results.parsed.reporting.forensic}</span>
|
||||
<span class="reporting-description">Real-time failure reports with message samples</span>
|
||||
{:else}
|
||||
<span class="not-configured">Not configured</span>
|
||||
@@ -406,7 +397,7 @@
|
||||
{/if}
|
||||
|
||||
<!-- No Record Found -->
|
||||
{#if results && results.hasRecord === false}
|
||||
{#if diagnosticState.results && diagnosticState.results.hasRecord === false}
|
||||
<div class="card warning-card none-found">
|
||||
<div class="card-content">
|
||||
<div class="warning-content">
|
||||
@@ -429,19 +420,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>DMARC Check Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="DMARC Check Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { greylistContent as content } from '$lib/content/greylist';
|
||||
import { useDiagnosticState } from '$lib/composables';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
interface GreylistAttempt {
|
||||
@@ -27,7 +29,7 @@
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
const examples = [
|
||||
const examplesList = [
|
||||
{ domain: 'mail.protonmail.ch', port: 25, desc: 'ProtonMail (privacy-focused)' },
|
||||
{ domain: 'mail.tutanota.de', port: 25, desc: 'Tutanota (encrypted email)' },
|
||||
{ domain: 'mx01.mail.icloud.com', port: 25, desc: 'iCloud Mail' },
|
||||
@@ -40,11 +42,10 @@
|
||||
let port = $state(25);
|
||||
let attempts = $state(2);
|
||||
let delayBetweenAttempts = $state(5);
|
||||
let loading = $state(false);
|
||||
let results = $state<GreylistTestResult | null>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let selectedExample = $state<string | null>(null);
|
||||
|
||||
const diagnosticState = useDiagnosticState<GreylistTestResult>();
|
||||
|
||||
async function loadExample(exampleDomain: string, examplePort: number) {
|
||||
domain = exampleDomain;
|
||||
port = examplePort;
|
||||
@@ -54,13 +55,11 @@
|
||||
|
||||
async function testGreylist() {
|
||||
if (!domain.trim()) {
|
||||
error = 'Please enter a domain name';
|
||||
diagnosticState.setError('Please enter a domain name');
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/greylist', {
|
||||
@@ -79,11 +78,10 @@
|
||||
throw new Error(errorData.message || 'Greylisting test failed');
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'Unknown error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,12 +101,12 @@
|
||||
const getConfidenceIcon = (c: string) =>
|
||||
c === 'high' ? 'check-circle' : c === 'medium' ? 'alert-triangle' : c === 'low' ? 'info' : 'help-circle';
|
||||
|
||||
const connectedCount = $derived(results?.attempts.filter((a) => a.connected).length ?? 0);
|
||||
const connectedCount = $derived(diagnosticState.results?.attempts.filter((a) => a.connected).length ?? 0);
|
||||
const testDuration = $derived(
|
||||
results
|
||||
diagnosticState.results
|
||||
? Math.round(
|
||||
(new Date(results.attempts[results.attempts.length - 1].timestamp).getTime() -
|
||||
new Date(results.attempts[0].timestamp).getTime()) /
|
||||
(new Date(diagnosticState.results.attempts[diagnosticState.results.attempts.length - 1].timestamp).getTime() -
|
||||
new Date(diagnosticState.results.attempts[0].timestamp).getTime()) /
|
||||
1000,
|
||||
)
|
||||
: 0,
|
||||
@@ -136,35 +134,54 @@
|
||||
bind:value={domain}
|
||||
placeholder="smtp.example.com"
|
||||
onkeydown={(e) => e.key === 'Enter' && testGreylist()}
|
||||
disabled={loading}
|
||||
disabled={diagnosticState.loading}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-group port-group">
|
||||
<label for="port">Port</label>
|
||||
<input type="number" id="port" bind:value={port} placeholder="25" min="1" max="65535" disabled={loading} />
|
||||
<input
|
||||
type="number"
|
||||
id="port"
|
||||
bind:value={port}
|
||||
placeholder="25"
|
||||
min="1"
|
||||
max="65535"
|
||||
disabled={diagnosticState.loading}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="attempts">Connection Attempts</label>
|
||||
<input type="number" id="attempts" bind:value={attempts} min="2" max="5" disabled={loading} />
|
||||
<input type="number" id="attempts" bind:value={attempts} min="2" max="5" disabled={diagnosticState.loading} />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="delay">Delay Between Attempts (seconds)</label>
|
||||
<input type="number" id="delay" bind:value={delayBetweenAttempts} min="1" max="300" disabled={loading} />
|
||||
<input
|
||||
type="number"
|
||||
id="delay"
|
||||
bind:value={delayBetweenAttempts}
|
||||
min="1"
|
||||
max="300"
|
||||
disabled={diagnosticState.loading}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="lookup-btn" onclick={testGreylist} disabled={loading}>
|
||||
<Icon name={loading ? 'loader' : 'play'} size="sm" animate={loading ? 'spin' : undefined} />
|
||||
{loading ? 'Testing...' : 'Test Greylisting'}
|
||||
<button class="lookup-btn" onclick={testGreylist} disabled={diagnosticState.loading}>
|
||||
<Icon
|
||||
name={diagnosticState.loading ? 'loader' : 'play'}
|
||||
size="sm"
|
||||
animate={diagnosticState.loading ? 'spin' : undefined}
|
||||
/>
|
||||
{diagnosticState.loading ? 'Testing...' : 'Test Greylisting'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loading State -->
|
||||
{#if loading}
|
||||
{#if diagnosticState.loading}
|
||||
<div class="card loading-card">
|
||||
<div class="card-content">
|
||||
<div class="loading-state">
|
||||
@@ -184,17 +201,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Error Display -->
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-message">
|
||||
<Icon name="alert-circle" size="md" />
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard error={diagnosticState.error} />
|
||||
|
||||
<!-- Quick Examples -->
|
||||
<div class="card examples-card">
|
||||
@@ -204,12 +211,12 @@
|
||||
<h4>Quick Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example (example.domain)}
|
||||
{#each examplesList as example (example.domain)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExample === `${example.domain}:${example.port}`}
|
||||
onclick={() => loadExample(example.domain, example.port)}
|
||||
disabled={loading}
|
||||
disabled={diagnosticState.loading}
|
||||
>
|
||||
<strong>{example.domain}</strong>
|
||||
<span>Port {example.port}</span>
|
||||
@@ -221,20 +228,20 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>Test Results for {results.domain}:{results.port}</h3>
|
||||
<h3>Test Results for {diagnosticState.results.domain}:{diagnosticState.results.port}</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Greylisting Status -->
|
||||
<div class="status-overview">
|
||||
{#if results.implementsGreylisting}
|
||||
{#if diagnosticState.results.implementsGreylisting}
|
||||
<div class="status-item success">
|
||||
<Icon name="check-circle" size="md" />
|
||||
<div>
|
||||
<h4>Greylisting Detected</h4>
|
||||
<p>Server implements greylisting (Confidence: {results.analysis.confidence})</p>
|
||||
<p>Server implements greylisting (Confidence: {diagnosticState.results.analysis.confidence})</p>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
@@ -247,12 +254,12 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results.analysis.typicalDelay}
|
||||
{#if diagnosticState.results.analysis.typicalDelay}
|
||||
<div class="status-item info">
|
||||
<Icon name="clock" size="md" />
|
||||
<div>
|
||||
<h4>Typical Delay</h4>
|
||||
<p>{results.analysis.typicalDelay} seconds between rejection and acceptance</p>
|
||||
<p>{diagnosticState.results.analysis.typicalDelay} seconds between rejection and acceptance</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -265,7 +272,7 @@
|
||||
Connection Attempts
|
||||
</h4>
|
||||
<div class="attempts-list">
|
||||
{#each results.attempts as attempt (attempt.attemptNumber)}
|
||||
{#each diagnosticState.results.attempts as attempt (attempt.attemptNumber)}
|
||||
<div class="attempt-item">
|
||||
<div class="attempt-header">
|
||||
<span class="attempt-number">#{attempt.attemptNumber}</span>
|
||||
@@ -315,21 +322,21 @@
|
||||
<span class="detail-label">Server:</span>
|
||||
<span class="detail-value">
|
||||
<Icon name="server" size="sm" />
|
||||
{results.domain}:{results.port}
|
||||
{diagnosticState.results.domain}:{diagnosticState.results.port}
|
||||
</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Total Attempts:</span>
|
||||
<span class="detail-value">
|
||||
<Icon name="activity" size="sm" />
|
||||
{results.attempts.length}
|
||||
{diagnosticState.results.attempts.length}
|
||||
</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Successful Connections:</span>
|
||||
<span class="detail-value {connectedCount > 0 ? 'success' : 'error'}">
|
||||
<Icon name={connectedCount > 0 ? 'check-circle' : 'x-circle'} size="sm" />
|
||||
{connectedCount} / {results.attempts.length}
|
||||
{connectedCount} / {diagnosticState.results.attempts.length}
|
||||
</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
@@ -341,32 +348,36 @@
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Initial Connection:</span>
|
||||
<span class="detail-value {results.analysis.initialRejected ? 'warning' : 'success'}">
|
||||
<Icon name={results.analysis.initialRejected ? 'x-circle' : 'check-circle'} size="sm" />
|
||||
{results.analysis.initialRejected ? 'Temporarily rejected' : 'Accepted immediately'}
|
||||
<span class="detail-value {diagnosticState.results.analysis.initialRejected ? 'warning' : 'success'}">
|
||||
<Icon name={diagnosticState.results.analysis.initialRejected ? 'x-circle' : 'check-circle'} size="sm" />
|
||||
{diagnosticState.results.analysis.initialRejected ? 'Temporarily rejected' : 'Accepted immediately'}
|
||||
</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Subsequent Attempts:</span>
|
||||
<span class="detail-value {results.analysis.subsequentAccepted ? 'success' : 'error'}">
|
||||
<Icon name={results.analysis.subsequentAccepted ? 'check-circle' : 'x-circle'} size="sm" />
|
||||
{results.analysis.subsequentAccepted ? 'Accepted after delay' : 'Still rejected'}
|
||||
<span class="detail-value {diagnosticState.results.analysis.subsequentAccepted ? 'success' : 'error'}">
|
||||
<Icon
|
||||
name={diagnosticState.results.analysis.subsequentAccepted ? 'check-circle' : 'x-circle'}
|
||||
size="sm"
|
||||
/>
|
||||
{diagnosticState.results.analysis.subsequentAccepted ? 'Accepted after delay' : 'Still rejected'}
|
||||
</span>
|
||||
</div>
|
||||
{#if results.analysis.typicalDelay}
|
||||
{#if diagnosticState.results.analysis.typicalDelay}
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Delay Duration:</span>
|
||||
<span class="detail-value info">
|
||||
<Icon name="clock" size="sm" />
|
||||
{results.analysis.typicalDelay} seconds
|
||||
{diagnosticState.results.analysis.typicalDelay} seconds
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Confidence Level:</span>
|
||||
<span class="detail-value {getConfidenceBadgeClass(results.analysis.confidence)}">
|
||||
<Icon name={getConfidenceIcon(results.analysis.confidence)} size="sm" />
|
||||
{results.analysis.confidence.charAt(0).toUpperCase() + results.analysis.confidence.slice(1)}
|
||||
<span class="detail-value {getConfidenceBadgeClass(diagnosticState.results.analysis.confidence)}">
|
||||
<Icon name={getConfidenceIcon(diagnosticState.results.analysis.confidence)} size="sm" />
|
||||
{diagnosticState.results.analysis.confidence.charAt(0).toUpperCase() +
|
||||
diagnosticState.results.analysis.confidence.slice(1)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<script lang="ts">
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { mailTLSContent as content } from '$lib/content/mail-tls';
|
||||
import { useDiagnosticState, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
interface CertificateInfo {
|
||||
@@ -26,7 +29,7 @@
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
const examples = [
|
||||
const examplesList = [
|
||||
{ domain: 'gmail.com', port: 587, desc: 'Google Mail STARTTLS' },
|
||||
{ domain: 'outlook.com', port: 587, desc: 'Microsoft Outlook STARTTLS' },
|
||||
{ domain: 'smtp.gmail.com', port: 465, desc: 'Gmail Direct TLS' },
|
||||
@@ -34,27 +37,24 @@
|
||||
|
||||
let domain = $state('');
|
||||
let port = $state(587);
|
||||
let loading = $state(false);
|
||||
let results = $state<TLSCheckResult | null>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let selectedExample = $state<string | null>(null);
|
||||
|
||||
async function loadExample(exampleDomain: string, examplePort: number) {
|
||||
domain = exampleDomain;
|
||||
port = examplePort;
|
||||
selectedExample = `${exampleDomain}:${examplePort}`;
|
||||
const diagnosticState = useDiagnosticState<TLSCheckResult>();
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
async function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
domain = example.domain;
|
||||
port = example.port;
|
||||
examples.select(index);
|
||||
await checkTLS();
|
||||
}
|
||||
|
||||
async function checkTLS() {
|
||||
if (!domain.trim()) {
|
||||
error = 'Please enter a domain name';
|
||||
diagnosticState.setError('Please enter a domain name');
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/mail-tls', {
|
||||
@@ -68,11 +68,10 @@
|
||||
throw new Error(errorData.message || 'TLS check failed');
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'Unknown error occurred');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -95,7 +94,7 @@
|
||||
bind:value={domain}
|
||||
placeholder="mail.example.com"
|
||||
onkeydown={(e) => e.key === 'Enter' && checkTLS()}
|
||||
disabled={loading}
|
||||
disabled={diagnosticState.loading}
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
@@ -104,41 +103,33 @@
|
||||
max="65535"
|
||||
placeholder="Port"
|
||||
class="port-input"
|
||||
disabled={loading}
|
||||
disabled={diagnosticState.loading}
|
||||
/>
|
||||
<button class="lookup-btn" onclick={checkTLS} disabled={loading}>
|
||||
<Icon name={loading ? 'loader' : 'lock'} size="sm" animate={loading ? 'spin' : undefined} />
|
||||
{loading ? 'Checking...' : 'Check TLS'}
|
||||
<button class="lookup-btn" onclick={checkTLS} disabled={diagnosticState.loading}>
|
||||
<Icon
|
||||
name={diagnosticState.loading ? 'loader' : 'lock'}
|
||||
size="sm"
|
||||
animate={diagnosticState.loading ? 'spin' : undefined}
|
||||
/>
|
||||
{diagnosticState.loading ? 'Checking...' : 'Check TLS'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Quick Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="sm" />
|
||||
<h4>Quick Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example (`${example.domain}:${example.port}`)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExample === `${example.domain}:${example.port}`}
|
||||
onclick={() => loadExample(example.domain, example.port)}
|
||||
type="button"
|
||||
>
|
||||
<h5>{example.domain}:{example.port}</h5>
|
||||
<p>{example.desc}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<!-- Examples -->
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Quick Examples"
|
||||
getLabel={(ex) => `${ex.domain}:${ex.port}`}
|
||||
getDescription={(ex) => ex.desc}
|
||||
getTooltip={(ex) => `Check TLS for ${ex.domain} on port ${ex.port}`}
|
||||
/>
|
||||
|
||||
<!-- Loading -->
|
||||
{#if loading}
|
||||
{#if diagnosticState.loading}
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="loading-state">
|
||||
@@ -152,28 +143,18 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Error -->
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-message">
|
||||
<Icon name="alert-circle" size="md" />
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard error={diagnosticState.error} />
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>TLS Check Results for {results.domain}:{results.port}</h3>
|
||||
<h3>TLS Check Results for {diagnosticState.results.domain}:{diagnosticState.results.port}</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- TLS Support Status -->
|
||||
<div class="status-overview">
|
||||
{#if results.supportsSTARTTLS}
|
||||
{#if diagnosticState.results.supportsSTARTTLS}
|
||||
<div class="status-item success">
|
||||
<Icon name="check-circle" size="md" />
|
||||
<div>
|
||||
@@ -182,7 +163,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if results.supportsDirectTLS}
|
||||
{#if diagnosticState.results.supportsDirectTLS}
|
||||
<div class="status-item success">
|
||||
<Icon name="lock" size="md" />
|
||||
<div>
|
||||
@@ -191,7 +172,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if !results.supportsSTARTTLS && !results.supportsDirectTLS}
|
||||
{#if !diagnosticState.results.supportsSTARTTLS && !diagnosticState.results.supportsDirectTLS}
|
||||
<div class="status-item error">
|
||||
<Icon name="x-circle" size="md" />
|
||||
<div>
|
||||
@@ -203,23 +184,23 @@
|
||||
</div>
|
||||
|
||||
<!-- Connection Details -->
|
||||
{#if results.tlsVersion || results.cipherSuite}
|
||||
{#if diagnosticState.results.tlsVersion || diagnosticState.results.cipherSuite}
|
||||
<div class="subsection">
|
||||
<h4>
|
||||
<Icon name="shield" size="sm" />
|
||||
Connection Details
|
||||
</h4>
|
||||
<div class="details-grid">
|
||||
{#if results.tlsVersion}
|
||||
{#if diagnosticState.results.tlsVersion}
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">TLS Version</span>
|
||||
<span class="detail-value">{results.tlsVersion}</span>
|
||||
<span class="detail-value">{diagnosticState.results.tlsVersion}</span>
|
||||
</div>
|
||||
{/if}
|
||||
{#if results.cipherSuite}
|
||||
{#if diagnosticState.results.cipherSuite}
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">Cipher Suite</span>
|
||||
<span class="detail-value mono">{results.cipherSuite}</span>
|
||||
<span class="detail-value mono">{diagnosticState.results.cipherSuite}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -227,7 +208,7 @@
|
||||
{/if}
|
||||
|
||||
<!-- Certificate Information -->
|
||||
{#if results.certificate}
|
||||
{#if diagnosticState.results.certificate}
|
||||
<div class="subsection">
|
||||
<h4>
|
||||
<Icon name="award" size="sm" />
|
||||
@@ -236,38 +217,44 @@
|
||||
<div class="details-grid">
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">Common Name</span>
|
||||
<span class="detail-value">{results.certificate.commonName}</span>
|
||||
<span class="detail-value">{diagnosticState.results.certificate.commonName}</span>
|
||||
</div>
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">Issuer</span>
|
||||
<span class="detail-value">{results.certificate.issuer}</span>
|
||||
<span class="detail-value">{diagnosticState.results.certificate.issuer}</span>
|
||||
</div>
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">Valid From</span>
|
||||
<span class="detail-value">{new Date(results.certificate.validFrom).toLocaleDateString()}</span>
|
||||
<span class="detail-value"
|
||||
>{new Date(diagnosticState.results.certificate.validFrom).toLocaleDateString()}</span
|
||||
>
|
||||
</div>
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">Valid To</span>
|
||||
<span class="detail-value {results.certificate.daysUntilExpiry < 30 ? 'warning' : ''}">
|
||||
{new Date(results.certificate.validTo).toLocaleDateString()}
|
||||
{#if results.certificate.daysUntilExpiry < 30}
|
||||
<span class="badge warning">Expires in {results.certificate.daysUntilExpiry} days</span>
|
||||
<span class="detail-value {diagnosticState.results.certificate.daysUntilExpiry < 30 ? 'warning' : ''}">
|
||||
{new Date(diagnosticState.results.certificate.validTo).toLocaleDateString()}
|
||||
{#if diagnosticState.results.certificate.daysUntilExpiry < 30}
|
||||
<span class="badge warning"
|
||||
>Expires in {diagnosticState.results.certificate.daysUntilExpiry} days</span
|
||||
>
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
<div class="detail-item full-width">
|
||||
<span class="detail-label">Serial Number</span>
|
||||
<span class="detail-value mono">{results.certificate.serialNumber}</span>
|
||||
<span class="detail-value mono">{diagnosticState.results.certificate.serialNumber}</span>
|
||||
</div>
|
||||
<div class="detail-item full-width">
|
||||
<span class="detail-label">Fingerprint</span>
|
||||
<span class="detail-value mono">{results.certificate.fingerprint}</span>
|
||||
<span class="detail-value mono">{diagnosticState.results.certificate.fingerprint}</span>
|
||||
</div>
|
||||
{#if results.certificate.altNames.length > 0}
|
||||
{#if diagnosticState.results.certificate.altNames.length > 0}
|
||||
<div class="detail-item full-width">
|
||||
<span class="detail-label">Alternative Names ({results.certificate.altNames.length})</span>
|
||||
<span class="detail-label"
|
||||
>Alternative Names ({diagnosticState.results.certificate.altNames.length})</span
|
||||
>
|
||||
<div class="alt-names">
|
||||
{#each results.certificate.altNames as altName (altName)}
|
||||
{#each diagnosticState.results.certificate.altNames as altName (altName)}
|
||||
<span class="alt-name-tag">{altName}</span>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -357,14 +344,6 @@
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.error-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
color: var(--color-error);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.subsection {
|
||||
margin-top: var(--spacing-lg);
|
||||
padding-top: var(--spacing-lg);
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let domain = $state('gmail.com');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
let checkPorts = $state(false);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const examplesList = [
|
||||
{ domain: 'gmail.com', description: 'Google Gmail MX infrastructure' },
|
||||
{ domain: 'outlook.com', description: 'Microsoft Outlook mail servers' },
|
||||
{ domain: 'yahoo.com', description: 'Yahoo Mail MX configuration' },
|
||||
@@ -20,10 +20,10 @@
|
||||
{ domain: 'github.com', description: 'GitHub enterprise email setup' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
async function checkMXHealth() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/email', {
|
||||
@@ -40,24 +40,19 @@
|
||||
throw new Error(`MX health check failed: ${response.status}`);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'Unknown error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
domain = example.domain;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
checkMXHealth();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getHealthColor(isHealthy: boolean): string {
|
||||
return isHealthy ? 'success' : 'error';
|
||||
}
|
||||
@@ -81,19 +76,19 @@
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results) return;
|
||||
if (!diagnosticState.results) return;
|
||||
|
||||
let text = `MX Health Check for ${domain}\n`;
|
||||
text += `Generated at: ${new Date().toISOString()}\n\n`;
|
||||
|
||||
text += `Summary:\n`;
|
||||
text += ` Total MX records: ${results.summary.totalMX}\n`;
|
||||
text += ` Healthy MX records: ${results.summary.healthyMX}\n`;
|
||||
if (results.summary.reachableMX !== null) {
|
||||
text += ` Reachable MX records: ${results.summary.reachableMX}\n`;
|
||||
text += ` Total MX records: ${diagnosticState.results.summary.totalMX}\n`;
|
||||
text += ` Healthy MX records: ${diagnosticState.results.summary.healthyMX}\n`;
|
||||
if (diagnosticState.results.summary.reachableMX !== null) {
|
||||
text += ` Reachable MX records: ${diagnosticState.results.summary.reachableMX}\n`;
|
||||
}
|
||||
text += ` Overall health: ${results.summary.healthy ? 'Healthy' : 'Issues detected'}\n`;
|
||||
text += ` Redundancy: ${results.summary.hasRedundancy ? 'Yes' : 'No'}\n\n`;
|
||||
text += ` Overall health: ${diagnosticState.results.summary.healthy ? 'Healthy' : 'Issues detected'}\n`;
|
||||
text += ` Redundancy: ${diagnosticState.results.summary.hasRedundancy ? 'Yes' : 'No'}\n\n`;
|
||||
|
||||
text += `MX Records (by priority):\n`;
|
||||
type MxRecord = {
|
||||
@@ -103,7 +98,7 @@
|
||||
addresses?: { ipv4: string[]; ipv6: string[] };
|
||||
portChecks?: Array<{ port: number; open: boolean; latency?: number }>;
|
||||
};
|
||||
const mxRecords = (results as { mxRecords: MxRecord[] }).mxRecords;
|
||||
const mxRecords = (diagnosticState.results as { mxRecords: MxRecord[] }).mxRecords;
|
||||
mxRecords.forEach((mx, _index) => {
|
||||
text += `${_index + 1}. ${mx.exchange} (Priority: ${mx.priority})\n`;
|
||||
if (mx.error) {
|
||||
@@ -123,9 +118,7 @@
|
||||
text += `\n`;
|
||||
});
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -139,27 +132,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>MX Health Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Check MX health for ${example.domain}`}
|
||||
>
|
||||
<h5>{example.domain}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="MX Health Examples"
|
||||
getLabel={(ex) => ex.domain}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Check MX health for ${ex.domain}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -168,7 +149,7 @@
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-group">
|
||||
<label for="domain" use:tooltip={'Enter the domain to check email server health for'}>
|
||||
<label for="domain">
|
||||
Domain Name
|
||||
<input
|
||||
id="domain"
|
||||
@@ -176,7 +157,7 @@
|
||||
bind:value={domain}
|
||||
placeholder="example.com"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (domain) checkMXHealth();
|
||||
}}
|
||||
/>
|
||||
@@ -191,8 +172,12 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="check-btn lookup-btn" onclick={checkMXHealth} disabled={loading || !domain.trim()}>
|
||||
{#if loading}
|
||||
<button
|
||||
class="check-btn lookup-btn"
|
||||
onclick={checkMXHealth}
|
||||
disabled={diagnosticState.loading || !domain.trim()}
|
||||
>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Checking MX Health...
|
||||
{:else}
|
||||
@@ -205,32 +190,33 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>MX Health Results</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
<button class="copy-btn" onclick={copyResults} disabled={clipboard.isCopied()}>
|
||||
<Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Health Summary -->
|
||||
<div class="summary-section">
|
||||
<div class="health-overview {getHealthColor(results.summary.healthy)}">
|
||||
<Icon name={results.summary.healthy ? 'check-circle' : 'alert-circle'} size="md" />
|
||||
<div class="health-overview {getHealthColor(diagnosticState.results.summary.healthy)}">
|
||||
<Icon name={diagnosticState.results.summary.healthy ? 'check-circle' : 'alert-circle'} size="md" />
|
||||
<div>
|
||||
<h4>
|
||||
{#if results.summary.healthy}
|
||||
{#if diagnosticState.results.summary.healthy}
|
||||
Mail Infrastructure Healthy
|
||||
{:else}
|
||||
Mail Infrastructure Issues
|
||||
{/if}
|
||||
</h4>
|
||||
<p>
|
||||
{results.summary.healthyMX} of {results.summary.totalMX} MX records resolved successfully
|
||||
{#if checkPorts && results.summary.reachableMX !== null}
|
||||
• {results.summary.reachableMX} reachable via SMTP
|
||||
{diagnosticState.results.summary.healthyMX} of {diagnosticState.results.summary.totalMX} MX records resolved
|
||||
successfully
|
||||
{#if checkPorts && diagnosticState.results.summary.reachableMX !== null}
|
||||
• {diagnosticState.results.summary.reachableMX} reachable via SMTP
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
@@ -241,7 +227,7 @@
|
||||
<Icon name="server" size="sm" />
|
||||
<div>
|
||||
<span class="stat-label">MX Records</span>
|
||||
<span class="stat-value">{results.summary.totalMX}</span>
|
||||
<span class="stat-value">{diagnosticState.results.summary.totalMX}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -249,17 +235,19 @@
|
||||
<Icon name="shield-check" size="sm" />
|
||||
<div>
|
||||
<span class="stat-label">Healthy</span>
|
||||
<span class="stat-value {getHealthColor(results.summary.healthy)}">{results.summary.healthyMX}</span>
|
||||
<span class="stat-value {getHealthColor(diagnosticState.results.summary.healthy)}"
|
||||
>{diagnosticState.results.summary.healthyMX}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if checkPorts && results.summary.reachableMX !== null}
|
||||
{#if checkPorts && diagnosticState.results.summary.reachableMX !== null}
|
||||
<div class="stat-item">
|
||||
<Icon name="wifi" size="sm" />
|
||||
<div>
|
||||
<span class="stat-label">Reachable</span>
|
||||
<span class="stat-value {getHealthColor(results.summary.reachableMX > 0)}"
|
||||
>{results.summary.reachableMX}</span
|
||||
<span class="stat-value {getHealthColor(diagnosticState.results.summary.reachableMX > 0)}"
|
||||
>{diagnosticState.results.summary.reachableMX}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
@@ -269,8 +257,8 @@
|
||||
<Icon name="copy" size="sm" />
|
||||
<div>
|
||||
<span class="stat-label">Redundancy</span>
|
||||
<span class="stat-value {getHealthColor(results.summary.hasRedundancy)}"
|
||||
>{results.summary.hasRedundancy ? 'Yes' : 'No'}</span
|
||||
<span class="stat-value {getHealthColor(diagnosticState.results.summary.hasRedundancy)}"
|
||||
>{diagnosticState.results.summary.hasRedundancy ? 'Yes' : 'No'}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
@@ -281,7 +269,7 @@
|
||||
<div class="mx-section">
|
||||
<h4>MX Records (by priority)</h4>
|
||||
<div class="mx-list">
|
||||
{#each (results as { mxRecords: Array<{ error?: string; exchange: string; priority: number; addresses?: { ipv4: string[]; ipv6: string[] }; portChecks?: Array<{ port: number; open: boolean; latency?: number }> }> }).mxRecords as mx, _index (_index)}
|
||||
{#each (diagnosticState.results as { mxRecords: Array<{ error?: string; exchange: string; priority: number; addresses?: { ipv4: string[]; ipv6: string[] }; portChecks?: Array<{ port: number; open: boolean; latency?: number }> }> }).mxRecords as mx, _index (_index)}
|
||||
<div class="mx-record {mx.error ? 'error' : 'success'}">
|
||||
<div class="mx-header">
|
||||
<div class="mx-info">
|
||||
@@ -378,19 +366,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>MX Health Check Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="MX Health Check Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let url = $state('https://example.com');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
|
||||
const examplesList = [
|
||||
{ url: 'https://httpbin.org/gzip', description: 'HTTPBin gzip test' },
|
||||
{ url: 'https://www.google.com', description: 'Google (likely compressed)' },
|
||||
{ url: 'https://github.com', description: 'GitHub (modern compression)' },
|
||||
{ url: 'https://www.cloudflare.com', description: 'Cloudflare (brotli support)' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) return false;
|
||||
@@ -29,13 +31,11 @@
|
||||
|
||||
async function checkCompression() {
|
||||
if (!isInputValid) {
|
||||
error = 'Please enter a valid HTTP/HTTPS URL';
|
||||
diagnosticState.setError('Please enter a valid HTTP/HTTPS URL');
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/http', {
|
||||
@@ -53,24 +53,18 @@
|
||||
throw new Error(data.message || 'Failed to check compression');
|
||||
}
|
||||
|
||||
results = data;
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err) {
|
||||
error = err instanceof Error ? err.message : 'An error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'An error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
url = example.url;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
checkCompression();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
@@ -101,27 +95,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Quick Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Test compression for ${example.url}`}
|
||||
>
|
||||
<h5>{example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Compression Examples"
|
||||
getLabel={(ex) => ex.url}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Test compression for ${ex.url}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -137,12 +119,12 @@
|
||||
type="url"
|
||||
bind:value={url}
|
||||
placeholder="https://example.com"
|
||||
disabled={loading}
|
||||
onchange={() => clearExampleSelection()}
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && checkCompression()}
|
||||
/>
|
||||
<button onclick={checkCompression} disabled={loading || !isInputValid} class="primary">
|
||||
{#if loading}
|
||||
<button onclick={checkCompression} disabled={diagnosticState.loading || !isInputValid} class="primary">
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Testing...
|
||||
{:else}
|
||||
@@ -155,21 +137,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Compression Test Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Compression Test Failed" error={diagnosticState.error} />
|
||||
|
||||
{#if loading}
|
||||
{#if diagnosticState.loading}
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="loading-state">
|
||||
@@ -183,7 +153,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>Compression Results</h3>
|
||||
@@ -198,32 +168,35 @@
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Server Compression</div>
|
||||
<div class="stat-value" class:success={results.serverCompression.enabled}>
|
||||
<Icon name={results.serverCompression.enabled ? 'check-circle' : 'x-circle'} size="sm" />
|
||||
{results.serverCompression.enabled ? 'Enabled' : 'Disabled'}
|
||||
<div class="stat-value" class:success={diagnosticState.results.serverCompression.enabled}>
|
||||
<Icon
|
||||
name={diagnosticState.results.serverCompression.enabled ? 'check-circle' : 'x-circle'}
|
||||
size="sm"
|
||||
/>
|
||||
{diagnosticState.results.serverCompression.enabled ? 'Enabled' : 'Disabled'}
|
||||
</div>
|
||||
{#if results.serverCompression.encoding}
|
||||
<div class="stat-detail">{results.serverCompression.encoding}</div>
|
||||
{#if diagnosticState.results.serverCompression.encoding}
|
||||
<div class="stat-detail">{diagnosticState.results.serverCompression.encoding}</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Best Compression</div>
|
||||
<div class="stat-value">
|
||||
<Icon name={getCompressionIcon(results.bestCompression.encoding)} size="sm" />
|
||||
{results.bestCompression.encoding}
|
||||
<Icon name={getCompressionIcon(diagnosticState.results.bestCompression.encoding)} size="sm" />
|
||||
{diagnosticState.results.bestCompression.encoding}
|
||||
</div>
|
||||
<div class="stat-detail">{results.bestCompression.ratio.toFixed(1)}% reduction</div>
|
||||
<div class="stat-detail">{diagnosticState.results.bestCompression.ratio.toFixed(1)}% reduction</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Uncompressed Size</div>
|
||||
<div class="stat-value">{formatBytes(results.uncompressed.size)}</div>
|
||||
<div class="stat-value">{formatBytes(diagnosticState.results.uncompressed.size)}</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Time Taken</div>
|
||||
<div class="stat-value">{results.timings.total}ms</div>
|
||||
<div class="stat-value">{diagnosticState.results.timings.total}ms</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -236,8 +209,11 @@
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="compression-grid">
|
||||
{#each results.compressionResults as result (result.encoding)}
|
||||
<div class="compression-card" class:best={result.encoding === results.bestCompression.encoding}>
|
||||
{#each diagnosticState.results.compressionResults as result (result.encoding)}
|
||||
<div
|
||||
class="compression-card"
|
||||
class:best={result.encoding === diagnosticState.results.bestCompression.encoding}
|
||||
>
|
||||
<div class="compression-header">
|
||||
<div class="compression-type">
|
||||
<Icon name={getCompressionIcon(result.encoding)} size="sm" />
|
||||
@@ -256,11 +232,11 @@
|
||||
<div class="original-bar"></div>
|
||||
<div
|
||||
class="compressed-bar"
|
||||
style="width: {(result.compressedSize / results.uncompressed.size) * 100}%"
|
||||
style="width: {(result.compressedSize / diagnosticState.results.uncompressed.size) * 100}%"
|
||||
></div>
|
||||
</div>
|
||||
<div class="size-labels">
|
||||
<span class="original-size">{formatBytes(results.uncompressed.size)}</span>
|
||||
<span class="original-size">{formatBytes(diagnosticState.results.uncompressed.size)}</span>
|
||||
<span class="compressed-size">{formatBytes(result.compressedSize)}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -290,7 +266,7 @@
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="headers-grid">
|
||||
{#each Object.entries(results.headers) as [key, value] (key)}
|
||||
{#each Object.entries(diagnosticState.results.headers) as [key, value] (key)}
|
||||
<div class="header-item">
|
||||
<span class="header-key">{key}</span>
|
||||
<span class="header-value">{value}</span>
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let url = $state('https://example.com');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
|
||||
const examplesList = [
|
||||
{ url: 'https://github.com', description: 'Excellent security (Score: 91)' },
|
||||
{ url: 'https://www.cloudflare.com', description: 'Strong security (Score: 90)' },
|
||||
{ url: 'https://www.paypal.com', description: 'Good security (Score: 80)' },
|
||||
@@ -20,6 +20,8 @@
|
||||
{ url: 'https://domain-locker.com', description: 'No cookies found' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) return false;
|
||||
@@ -33,13 +35,11 @@
|
||||
|
||||
async function checkCookieSecurity() {
|
||||
if (!isInputValid) {
|
||||
error = 'Please enter a valid HTTP/HTTPS URL';
|
||||
diagnosticState.setError('Please enter a valid HTTP/HTTPS URL');
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/http', {
|
||||
@@ -65,28 +65,22 @@
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = data;
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
error = err.message;
|
||||
diagnosticState.setError(err.message);
|
||||
} else {
|
||||
error = 'An unexpected error occurred. Please try again.';
|
||||
diagnosticState.setError('An unexpected error occurred. Please try again.');
|
||||
}
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
url = example.url;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
checkCookieSecurity();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getSecurityIcon(level: string): string {
|
||||
switch (level) {
|
||||
case 'secure':
|
||||
@@ -131,27 +125,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Quick Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Inspect cookies for ${example.url}`}
|
||||
>
|
||||
<h5>{example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Cookie Security Examples"
|
||||
getLabel={(ex) => ex.url}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Inspect cookies for ${ex.url}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -167,12 +149,12 @@
|
||||
type="url"
|
||||
bind:value={url}
|
||||
placeholder="https://example.com"
|
||||
disabled={loading}
|
||||
onchange={() => clearExampleSelection()}
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && checkCookieSecurity()}
|
||||
/>
|
||||
<button onclick={checkCookieSecurity} disabled={loading || !isInputValid} class="primary">
|
||||
{#if loading}
|
||||
<button onclick={checkCookieSecurity} disabled={diagnosticState.loading || !isInputValid} class="primary">
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Analyzing...
|
||||
{:else}
|
||||
@@ -185,21 +167,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Cookie Inspection Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Cookie Inspection Failed" error={diagnosticState.error} />
|
||||
|
||||
{#if loading}
|
||||
{#if diagnosticState.loading}
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="loading-state">
|
||||
@@ -213,7 +183,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>Cookie Security Analysis</h3>
|
||||
@@ -226,27 +196,32 @@
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="score-container">
|
||||
<div class="score-circle" style="--score-color: {getSecurityGrade(results.securityScore).color}">
|
||||
<div class="score-value">{getSecurityGrade(results.securityScore).grade}</div>
|
||||
<div
|
||||
class="score-circle"
|
||||
style="--score-color: {getSecurityGrade(diagnosticState.results.securityScore).color}"
|
||||
>
|
||||
<div class="score-value">{getSecurityGrade(diagnosticState.results.securityScore).grade}</div>
|
||||
<div class="score-label">
|
||||
{results.securityScore !== null ? `${results.securityScore}/100` : 'No cookies'}
|
||||
{diagnosticState.results.securityScore !== null
|
||||
? `${diagnosticState.results.securityScore}/100`
|
||||
: 'No cookies'}
|
||||
</div>
|
||||
</div>
|
||||
<div class="score-summary">
|
||||
<h4>Overall Assessment</h4>
|
||||
<p>{results.summary}</p>
|
||||
<p>{diagnosticState.results.summary}</p>
|
||||
<div class="score-stats">
|
||||
<div class="stat">
|
||||
<span class="stat-label">Total Cookies:</span>
|
||||
<span class="stat-value">{results.totalCookies}</span>
|
||||
<span class="stat-value">{diagnosticState.results.totalCookies}</span>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<span class="stat-label">Secure Cookies:</span>
|
||||
<span class="stat-value">{results.secureCookies}</span>
|
||||
<span class="stat-value">{diagnosticState.results.secureCookies}</span>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<span class="stat-label">HttpOnly Cookies:</span>
|
||||
<span class="stat-value">{results.httpOnlyCookies}</span>
|
||||
<span class="stat-value">{diagnosticState.results.httpOnlyCookies}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -255,14 +230,14 @@
|
||||
</div>
|
||||
|
||||
<!-- Cookie Details -->
|
||||
{#if results.cookies && results.cookies.length > 0}
|
||||
{#if diagnosticState.results.cookies && diagnosticState.results.cookies.length > 0}
|
||||
<div class="card cookies-section">
|
||||
<div class="card-header">
|
||||
<h3>Cookie Details</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="cookies-grid">
|
||||
{#each results.cookies as cookie (cookie.id || cookie.name)}
|
||||
{#each diagnosticState.results.cookies as cookie (cookie.id || cookie.name)}
|
||||
<div
|
||||
class="cookie-card"
|
||||
class:secure={cookie.securityLevel === 'secure'}
|
||||
@@ -370,14 +345,14 @@
|
||||
{/if}
|
||||
|
||||
<!-- Security Recommendations -->
|
||||
{#if results.recommendations && results.recommendations.length > 0}
|
||||
{#if diagnosticState.results.recommendations && diagnosticState.results.recommendations.length > 0}
|
||||
<div class="card recommendations-section">
|
||||
<div class="card-header">
|
||||
<h3>Security Recommendations</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="recommendations-list">
|
||||
{#each results.recommendations as recommendation, index (index)}
|
||||
{#each diagnosticState.results.recommendations as recommendation, index (index)}
|
||||
<div class="recommendation-item">
|
||||
<Icon name="lightbulb" size="sm" />
|
||||
<div class="recommendation-content">
|
||||
|
||||
@@ -2,19 +2,23 @@
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ActionButton from '$lib/components/common/ActionButton.svelte';
|
||||
import ResultsCard from '$lib/components/common/ResultsCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let url = $state('https://api.github.com');
|
||||
let origin = $state('https://example.com');
|
||||
let method = $state('GET');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
||||
|
||||
const examples = [
|
||||
const examplesList = [
|
||||
{ url: 'https://api.github.com', origin: 'https://example.com', description: 'GitHub API CORS policy' },
|
||||
{ url: 'https://httpbin.org/get', origin: 'https://test.com', description: 'HTTPBin CORS test' },
|
||||
{
|
||||
@@ -29,6 +33,8 @@
|
||||
},
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
@@ -46,23 +52,19 @@
|
||||
});
|
||||
|
||||
async function checkCORS() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
// Validation
|
||||
const trimmedUrl = url.trim();
|
||||
const trimmedOrigin = origin.trim();
|
||||
|
||||
if (!trimmedUrl) {
|
||||
error = 'URL is required';
|
||||
loading = false;
|
||||
diagnosticState.setError('URL is required');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!trimmedOrigin) {
|
||||
error = 'Origin is required';
|
||||
loading = false;
|
||||
diagnosticState.setError('Origin is required');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -70,8 +72,7 @@
|
||||
new URL(trimmedUrl);
|
||||
new URL(trimmedOrigin);
|
||||
} catch {
|
||||
error = 'Invalid URL or Origin format';
|
||||
loading = false;
|
||||
diagnosticState.setError('Invalid URL or Origin format');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -103,53 +104,51 @@
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(formatDNSError(err));
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0]) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
url = example.url;
|
||||
origin = example.origin;
|
||||
examples.select(index);
|
||||
checkCORS();
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results) return;
|
||||
if (!diagnosticState.results) return;
|
||||
|
||||
let text = `CORS Policy Analysis\nURL: ${url}\nOrigin: ${origin}\nMethod: ${method}\n\n`;
|
||||
|
||||
text += `Preflight Status: ${results.preflight.status}\n`;
|
||||
text += `Origin Allowed: ${results.preflight.allowed ? 'Yes' : 'No'}\n`;
|
||||
text += `CORS Enabled: ${results.analysis.corsEnabled ? 'Yes' : 'No'}\n\n`;
|
||||
text += `Preflight Status: ${diagnosticState.results.preflight.status}\n`;
|
||||
text += `Origin Allowed: ${diagnosticState.results.preflight.allowed ? 'Yes' : 'No'}\n`;
|
||||
text += `CORS Enabled: ${diagnosticState.results.analysis.corsEnabled ? 'Yes' : 'No'}\n\n`;
|
||||
|
||||
if (results.analysis.allowedMethods.length > 0) {
|
||||
text += `Allowed Methods: ${results.analysis.allowedMethods.join(', ')}\n`;
|
||||
if (diagnosticState.results.analysis.allowedMethods.length > 0) {
|
||||
text += `Allowed Methods: ${diagnosticState.results.analysis.allowedMethods.join(', ')}\n`;
|
||||
}
|
||||
|
||||
if (results.analysis.allowedHeaders.length > 0) {
|
||||
text += `Allowed Headers: ${results.analysis.allowedHeaders.join(', ')}\n`;
|
||||
if (diagnosticState.results.analysis.allowedHeaders.length > 0) {
|
||||
text += `Allowed Headers: ${diagnosticState.results.analysis.allowedHeaders.join(', ')}\n`;
|
||||
}
|
||||
|
||||
text += `Credentials Allowed: ${results.analysis.allowsCredentials ? 'Yes' : 'No'}\n`;
|
||||
text += `Credentials Allowed: ${diagnosticState.results.analysis.allowsCredentials ? 'Yes' : 'No'}\n`;
|
||||
|
||||
if (results.analysis.maxAge) {
|
||||
text += `Max Age: ${results.analysis.maxAge} seconds\n`;
|
||||
if (diagnosticState.results.analysis.maxAge) {
|
||||
text += `Max Age: ${diagnosticState.results.analysis.maxAge} seconds\n`;
|
||||
}
|
||||
|
||||
if (Object.keys(results.preflight.headers || {}).length > 0) {
|
||||
if (Object.keys(diagnosticState.results.preflight.headers || {}).length > 0) {
|
||||
text += '\nCORS Headers:\n';
|
||||
Object.entries(results.preflight.headers).forEach(([key, value]) => {
|
||||
Object.entries(diagnosticState.results.preflight.headers).forEach(([key, value]) => {
|
||||
text += `${key}: ${value}\n`;
|
||||
});
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
|
||||
function getAccessClass(allowed: boolean): string {
|
||||
@@ -161,18 +160,18 @@
|
||||
}
|
||||
|
||||
function getCORSStatusText(): string {
|
||||
if (!results?.analysis) return 'Unknown';
|
||||
if (!diagnosticState.results?.analysis) return 'Unknown';
|
||||
|
||||
if (!results.analysis.corsEnabled) return 'No CORS Policy';
|
||||
if (results.analysis.allowsOrigin) return 'Access Allowed';
|
||||
if (!diagnosticState.results.analysis.corsEnabled) return 'No CORS Policy';
|
||||
if (diagnosticState.results.analysis.allowsOrigin) return 'Access Allowed';
|
||||
return 'Access Denied';
|
||||
}
|
||||
|
||||
function getCORSStatusClass(): string {
|
||||
if (!results?.analysis) return '';
|
||||
if (!diagnosticState.results?.analysis) return '';
|
||||
|
||||
if (!results.analysis.corsEnabled) return 'warning';
|
||||
if (results.analysis.allowsOrigin) return 'success';
|
||||
if (!diagnosticState.results.analysis.corsEnabled) return 'warning';
|
||||
if (diagnosticState.results.analysis.allowsOrigin) return 'success';
|
||||
return 'error';
|
||||
}
|
||||
</script>
|
||||
@@ -187,22 +186,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>CORS Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, index (index)}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<h5>{example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="CORS Examples"
|
||||
getLabel={(ex) => ex.url}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Test CORS policy for ${ex.url}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -221,6 +213,7 @@
|
||||
placeholder="https://api.example.com"
|
||||
class:invalid={url && !isInputValid()}
|
||||
onchange={() => {
|
||||
examples.clear();
|
||||
if (isInputValid()) checkCORS();
|
||||
}}
|
||||
/>
|
||||
@@ -240,6 +233,7 @@
|
||||
placeholder="https://yoursite.com"
|
||||
class:invalid={origin && !isInputValid}
|
||||
onchange={() => {
|
||||
examples.clear();
|
||||
if (isInputValid()) checkCORS();
|
||||
}}
|
||||
/>
|
||||
@@ -256,6 +250,7 @@
|
||||
id="method"
|
||||
bind:value={method}
|
||||
onchange={() => {
|
||||
examples.clear();
|
||||
if (isInputValid()) checkCORS();
|
||||
}}
|
||||
>
|
||||
@@ -268,36 +263,32 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={checkCORS} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
Checking CORS...
|
||||
{:else}
|
||||
<Icon name="globe" size="sm" />
|
||||
Check CORS Policy
|
||||
{/if}
|
||||
</button>
|
||||
<ActionButton
|
||||
loading={diagnosticState.loading}
|
||||
disabled={!isInputValid}
|
||||
icon="globe"
|
||||
loadingText="Checking CORS..."
|
||||
onclick={checkCORS}
|
||||
>
|
||||
Check CORS Policy
|
||||
</ActionButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>CORS Policy Analysis</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<span class={copiedState ? 'text-green-500' : ''}
|
||||
><Icon name={copiedState ? 'check' : 'copy'} size="xs" /></span
|
||||
>
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
{#if diagnosticState.results}
|
||||
<ResultsCard title="CORS Policy Analysis" onCopy={copyResults} copied={clipboard.isCopied()}>
|
||||
<div class="card-content">
|
||||
<!-- CORS Overview -->
|
||||
<div class="status-overview">
|
||||
<div class="status-item {getCORSStatusClass()}">
|
||||
<Icon name={getAccessIcon(results.analysis.corsEnabled && results.analysis.allowsOrigin)} size="sm" />
|
||||
<Icon
|
||||
name={getAccessIcon(
|
||||
diagnosticState.results.analysis.corsEnabled && diagnosticState.results.analysis.allowsOrigin,
|
||||
)}
|
||||
size="sm"
|
||||
/>
|
||||
<div>
|
||||
<strong>{getCORSStatusText()}</strong>
|
||||
<div class="status-text">CORS Status</div>
|
||||
@@ -307,16 +298,16 @@
|
||||
<div class="status-item">
|
||||
<Icon name="shield" size="sm" />
|
||||
<div>
|
||||
<strong>{results.preflight.status || 'Failed'}</strong>
|
||||
<strong>{diagnosticState.results.preflight.status || 'Failed'}</strong>
|
||||
<div class="status-text">Preflight Status</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if results.analysis.maxAge}
|
||||
{#if diagnosticState.results.analysis.maxAge}
|
||||
<div class="status-item">
|
||||
<Icon name="clock" size="sm" />
|
||||
<div>
|
||||
<strong>{results.analysis.maxAge}s</strong>
|
||||
<strong>{diagnosticState.results.analysis.maxAge}s</strong>
|
||||
<div class="status-text">Cache Max Age</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -327,24 +318,24 @@
|
||||
<div class="record-section">
|
||||
<h4>CORS Policy Details</h4>
|
||||
<div class="cors-analysis">
|
||||
<div class="cors-item {getAccessClass(results.analysis.corsEnabled)}">
|
||||
<Icon name={results.analysis.corsEnabled ? 'check' : 'x'} size="sm" />
|
||||
<div class="cors-item {getAccessClass(diagnosticState.results.analysis.corsEnabled)}">
|
||||
<Icon name={diagnosticState.results.analysis.corsEnabled ? 'check' : 'x'} size="sm" />
|
||||
<div>
|
||||
<strong>CORS Enabled</strong>
|
||||
<p>
|
||||
{results.analysis.corsEnabled
|
||||
{diagnosticState.results.analysis.corsEnabled
|
||||
? 'Server has CORS headers configured'
|
||||
: 'No CORS headers found - requests will be blocked by browsers'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cors-item {getAccessClass(results.analysis.allowsOrigin)}">
|
||||
<Icon name={getAccessIcon(results.analysis.allowsOrigin)} size="sm" />
|
||||
<div class="cors-item {getAccessClass(diagnosticState.results.analysis.allowsOrigin)}">
|
||||
<Icon name={getAccessIcon(diagnosticState.results.analysis.allowsOrigin)} size="sm" />
|
||||
<div>
|
||||
<strong>Origin Access</strong>
|
||||
<p>
|
||||
{#if results.analysis.allowsOrigin}
|
||||
{#if diagnosticState.results.analysis.allowsOrigin}
|
||||
Origin '{origin}' is allowed to access this resource
|
||||
{:else}
|
||||
Origin '{origin}' is not allowed to access this resource
|
||||
@@ -353,12 +344,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cors-item {getAccessClass(results.analysis.allowsCredentials)}">
|
||||
<Icon name={results.analysis.allowsCredentials ? 'check' : 'x'} size="sm" />
|
||||
<div class="cors-item {getAccessClass(diagnosticState.results.analysis.allowsCredentials)}">
|
||||
<Icon name={diagnosticState.results.analysis.allowsCredentials ? 'check' : 'x'} size="sm" />
|
||||
<div>
|
||||
<strong>Credentials Support</strong>
|
||||
<p>
|
||||
{results.analysis.allowsCredentials
|
||||
{diagnosticState.results.analysis.allowsCredentials
|
||||
? 'Cookies and credentials can be sent'
|
||||
: 'Cookies and credentials cannot be sent'}
|
||||
</p>
|
||||
@@ -368,11 +359,11 @@
|
||||
</div>
|
||||
|
||||
<!-- Allowed Methods -->
|
||||
{#if results.analysis.allowedMethods?.length > 0}
|
||||
{#if diagnosticState.results.analysis.allowedMethods?.length > 0}
|
||||
<div class="record-section">
|
||||
<h4>Allowed Methods</h4>
|
||||
<div class="method-list">
|
||||
{#each results.analysis.allowedMethods as allowedMethod, index (index)}
|
||||
{#each diagnosticState.results.analysis.allowedMethods as allowedMethod, index (index)}
|
||||
<span class="method-badge {method === allowedMethod ? 'active' : ''}">{allowedMethod}</span>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -380,11 +371,11 @@
|
||||
{/if}
|
||||
|
||||
<!-- Allowed Headers -->
|
||||
{#if results.analysis.allowedHeaders?.length > 0}
|
||||
{#if diagnosticState.results.analysis.allowedHeaders?.length > 0}
|
||||
<div class="record-section">
|
||||
<h4>Allowed Headers</h4>
|
||||
<div class="header-list">
|
||||
{#each results.analysis.allowedHeaders as header, index (index)}
|
||||
{#each diagnosticState.results.analysis.allowedHeaders as header, index (index)}
|
||||
<span class="header-badge">{header}</span>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -392,11 +383,11 @@
|
||||
{/if}
|
||||
|
||||
<!-- Raw CORS Headers -->
|
||||
{#if Object.keys(results.preflight.headers || {}).length > 0}
|
||||
{#if Object.keys(diagnosticState.results.preflight.headers || {}).length > 0}
|
||||
<div class="record-section">
|
||||
<h4>CORS Headers</h4>
|
||||
<div class="records-list">
|
||||
{#each Object.entries(results.preflight.headers) as [name, value] (name)}
|
||||
{#each Object.entries(diagnosticState.results.preflight.headers) as [name, value] (name)}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>{name}:</strong>
|
||||
@@ -406,7 +397,7 @@
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{:else if results.analysis.corsEnabled}
|
||||
{:else if diagnosticState.results.analysis.corsEnabled}
|
||||
<div class="no-records">
|
||||
<Icon name="info" size="md" />
|
||||
<p>CORS enabled but no detailed headers available</p>
|
||||
@@ -421,22 +412,10 @@
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</ResultsCard>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>CORS Check Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="CORS Check Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -2,20 +2,23 @@
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ActionButton from '$lib/components/common/ActionButton.svelte';
|
||||
import ResultsCard from '$lib/components/common/ResultsCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let url = $state('https://example.com');
|
||||
let method = $state('GET');
|
||||
let customHeadersText = $state('');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
|
||||
|
||||
const examples = [
|
||||
const examplesList = [
|
||||
{ url: 'https://httpbin.org/get', method: 'GET', description: 'Basic GET request headers' },
|
||||
{ url: 'https://api.github.com', method: 'HEAD', description: 'GitHub API headers (HEAD)' },
|
||||
{ url: 'https://www.cloudflare.com', method: 'GET', description: 'Cloudflare response headers' },
|
||||
@@ -24,6 +27,8 @@
|
||||
{ url: 'https://httpbin.org/gzip', method: 'GET', description: 'Compressed response headers' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
@@ -58,26 +63,22 @@
|
||||
}
|
||||
|
||||
async function checkHeaders() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
|
||||
// Validation
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) {
|
||||
error = 'URL is required';
|
||||
loading = false;
|
||||
diagnosticState.setError('URL is required');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(trimmedUrl);
|
||||
} catch {
|
||||
error = 'Invalid URL format';
|
||||
loading = false;
|
||||
diagnosticState.setError('Invalid URL format');
|
||||
return;
|
||||
}
|
||||
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const customHeaders = parseCustomHeaders();
|
||||
|
||||
@@ -106,41 +107,34 @@
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(formatDNSError(err));
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
url = example.url;
|
||||
method = example.method;
|
||||
customHeadersText = '';
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
checkHeaders();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.headers) return;
|
||||
if (!diagnosticState.results?.headers) return;
|
||||
|
||||
let text = `${method} ${results.url}\nStatus: ${results.status} ${results.statusText}\n\nResponse Headers:\n`;
|
||||
Object.entries(results.headers).forEach(([key, value]) => {
|
||||
let text = `${method} ${diagnosticState.results.url}\nStatus: ${diagnosticState.results.status} ${diagnosticState.results.statusText}\n\nResponse Headers:\n`;
|
||||
Object.entries(diagnosticState.results.headers).forEach(([key, value]) => {
|
||||
text += `${key}: ${value}\n`;
|
||||
});
|
||||
|
||||
if (results.size) {
|
||||
text += `\nContent-Length: ${results.size} bytes`;
|
||||
if (diagnosticState.results.size) {
|
||||
text += `\nContent-Length: ${diagnosticState.results.size} bytes`;
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
@@ -169,27 +163,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Header Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Analyze headers for ${example.url}`}
|
||||
>
|
||||
<h5>{example.method} {example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Header Examples"
|
||||
getLabel={(ex) => `${ex.method} ${ex.url}`}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Analyze headers for ${ex.url}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -208,7 +190,7 @@
|
||||
placeholder="https://example.com"
|
||||
class:invalid={url && !isInputValid()}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) checkHeaders();
|
||||
}}
|
||||
/>
|
||||
@@ -225,7 +207,7 @@
|
||||
id="method"
|
||||
bind:value={method}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) checkHeaders();
|
||||
}}
|
||||
>
|
||||
@@ -246,7 +228,7 @@
|
||||
placeholder="User-Agent: My Custom Agent Authorization: Bearer token123"
|
||||
rows="3"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) checkHeaders();
|
||||
}}
|
||||
></textarea>
|
||||
@@ -254,126 +236,103 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={checkHeaders} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
Analyzing Headers...
|
||||
{:else}
|
||||
<Icon name="globe" size="sm" />
|
||||
Analyze Headers
|
||||
{/if}
|
||||
</button>
|
||||
<ActionButton
|
||||
loading={diagnosticState.loading}
|
||||
disabled={!isInputValid}
|
||||
icon="globe"
|
||||
loadingText="Analyzing Headers..."
|
||||
onclick={checkHeaders}
|
||||
>
|
||||
Analyze Headers
|
||||
</ActionButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>HTTP Response Analysis</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<span class={copiedState ? 'text-green-500' : ''}
|
||||
><Icon name={copiedState ? 'check' : 'copy'} size="xs" /></span
|
||||
>
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Status Overview -->
|
||||
<div class="status-overview">
|
||||
<div class="status-item {getStatusClass(results.status)}">
|
||||
<Icon name="activity" size="sm" />
|
||||
{#if diagnosticState.results}
|
||||
<ResultsCard title="HTTP Response Analysis" onCopy={copyResults} copied={clipboard.isCopied()}>
|
||||
<!-- Status Overview -->
|
||||
<div class="status-overview">
|
||||
<div class="status-item {getStatusClass(diagnosticState.results.status)}">
|
||||
<Icon name="activity" size="sm" />
|
||||
<div>
|
||||
<strong>{diagnosticState.results.status} {diagnosticState.results.statusText}</strong>
|
||||
<div class="status-text">HTTP Status</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if diagnosticState.results.size}
|
||||
<div class="status-item">
|
||||
<Icon name="file" size="sm" />
|
||||
<div>
|
||||
<strong>{results.status} {results.statusText}</strong>
|
||||
<div class="status-text">HTTP Status</div>
|
||||
<strong>{formatBytes(diagnosticState.results.size)}</strong>
|
||||
<div class="status-text">Response Size</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results.size}
|
||||
<div class="status-item">
|
||||
<Icon name="file" size="sm" />
|
||||
<div>
|
||||
<strong>{formatBytes(results.size)}</strong>
|
||||
<div class="status-text">Response Size</div>
|
||||
</div>
|
||||
{#if diagnosticState.results.timings}
|
||||
<div class="status-item">
|
||||
<Icon name="clock" size="sm" />
|
||||
<div>
|
||||
<strong>{diagnosticState.results.timings.total.toFixed(0)}ms</strong>
|
||||
<div class="status-text">Total Time</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results.timings}
|
||||
<div class="status-item">
|
||||
<Icon name="clock" size="sm" />
|
||||
<div>
|
||||
<strong>{results.timings.total.toFixed(0)}ms</strong>
|
||||
<div class="status-text">Total Time</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Response Headers -->
|
||||
<div class="record-section card">
|
||||
<h4>Response Headers</h4>
|
||||
<div class="records-list">
|
||||
{#each Object.entries(results.headers) as [name, value] (name)}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>{name}:</strong>
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if results.timings}
|
||||
<div class="record-section card">
|
||||
<h4>Performance Timing</h4>
|
||||
<div class="records-list">
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>DNS Resolution:</strong> ~{results.timings.dns.toFixed(1)}ms
|
||||
</div>
|
||||
</div>
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>TCP Connect:</strong> ~{results.timings.tcp.toFixed(1)}ms
|
||||
</div>
|
||||
</div>
|
||||
{#if results.timings.tls > 0}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>TLS Handshake:</strong> ~{results.timings.tls.toFixed(1)}ms
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>Time to First Byte:</strong> ~{results.timings.ttfb.toFixed(1)}ms
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-text">* Timing values are approximations when not isolated</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Request Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
<!-- Response Headers -->
|
||||
<div class="record-section card">
|
||||
<h4>Response Headers</h4>
|
||||
<div class="records-list">
|
||||
{#each Object.entries(diagnosticState.results.headers) as [name, value] (name)}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>{name}:</strong>
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if diagnosticState.results.timings}
|
||||
<div class="record-section card">
|
||||
<h4>Performance Timing</h4>
|
||||
<div class="records-list">
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>DNS Resolution:</strong> ~{diagnosticState.results.timings.dns.toFixed(1)}ms
|
||||
</div>
|
||||
</div>
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>TCP Connect:</strong> ~{diagnosticState.results.timings.tcp.toFixed(1)}ms
|
||||
</div>
|
||||
</div>
|
||||
{#if diagnosticState.results.timings.tls > 0}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>TLS Handshake:</strong> ~{diagnosticState.results.timings.tls.toFixed(1)}ms
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>Time to First Byte:</strong> ~{diagnosticState.results.timings.ttfb.toFixed(1)}ms
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-text">* Timing values are approximations when not isolated</p>
|
||||
</div>
|
||||
{/if}
|
||||
</ResultsCard>
|
||||
{/if}
|
||||
|
||||
<ErrorCard title="Request Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
<div class="card-header">
|
||||
|
||||
@@ -2,24 +2,28 @@
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let url = $state('https://www.google.com');
|
||||
let method = $state('GET');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE'];
|
||||
|
||||
const examples = [
|
||||
const examplesList = [
|
||||
{ url: 'https://www.google.com', description: 'Google homepage performance' },
|
||||
{ url: 'https://httpbin.org/delay/2', description: 'Delayed response (2s)' },
|
||||
{ url: 'https://api.github.com', description: 'GitHub API response time' },
|
||||
{ url: 'https://www.cloudflare.com', description: 'Cloudflare CDN performance' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
@@ -33,26 +37,22 @@
|
||||
});
|
||||
|
||||
async function measurePerformance() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
|
||||
// Validation
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) {
|
||||
error = 'URL is required';
|
||||
loading = false;
|
||||
diagnosticState.setError('URL is required');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(trimmedUrl);
|
||||
} catch {
|
||||
error = 'Invalid URL format';
|
||||
loading = false;
|
||||
diagnosticState.setError('Invalid URL format');
|
||||
return;
|
||||
}
|
||||
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/http', {
|
||||
method: 'POST',
|
||||
@@ -78,45 +78,43 @@
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(formatDNSError(err));
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0]) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
url = example.url;
|
||||
examples.select(index);
|
||||
measurePerformance();
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.timings) return;
|
||||
if (!diagnosticState.results?.timings) return;
|
||||
|
||||
let text = `HTTP Performance Analysis\nURL: ${results.url}\nMethod: ${method}\nStatus: ${results.status}\n\n`;
|
||||
let text = `HTTP Performance Analysis\nURL: ${diagnosticState.results.url}\nMethod: ${method}\nStatus: ${diagnosticState.results.status}\n\n`;
|
||||
|
||||
text += `Performance Timing:\n`;
|
||||
text += `DNS Resolution: ${results.timings.dns.toFixed(1)}ms ${results.timings.dns_note ? `(${results.timings.dns_note})` : ''}\n`;
|
||||
text += `TCP Connect: ${results.timings.tcp.toFixed(1)}ms ${results.timings.tcp_note ? `(${results.timings.tcp_note})` : ''}\n`;
|
||||
text += `DNS Resolution: ${diagnosticState.results.timings.dns.toFixed(1)}ms ${diagnosticState.results.timings.dns_note ? `(${diagnosticState.results.timings.dns_note})` : ''}\n`;
|
||||
text += `TCP Connect: ${diagnosticState.results.timings.tcp.toFixed(1)}ms ${diagnosticState.results.timings.tcp_note ? `(${diagnosticState.results.timings.tcp_note})` : ''}\n`;
|
||||
|
||||
if (results.timings.tls > 0) {
|
||||
text += `TLS Handshake: ${results.timings.tls.toFixed(1)}ms ${results.timings.tls_note ? `(${results.timings.tls_note})` : ''}\n`;
|
||||
if (diagnosticState.results.timings.tls > 0) {
|
||||
text += `TLS Handshake: ${diagnosticState.results.timings.tls.toFixed(1)}ms ${diagnosticState.results.timings.tls_note ? `(${diagnosticState.results.timings.tls_note})` : ''}\n`;
|
||||
}
|
||||
|
||||
text += `Time to First Byte: ${results.timings.ttfb.toFixed(1)}ms\n`;
|
||||
text += `Total Time: ${results.timings.total.toFixed(1)}ms\n\n`;
|
||||
text += `Time to First Byte: ${diagnosticState.results.timings.ttfb.toFixed(1)}ms\n`;
|
||||
text += `Total Time: ${diagnosticState.results.timings.total.toFixed(1)}ms\n\n`;
|
||||
|
||||
if (results.size) {
|
||||
text += `Response Size: ${formatBytes(results.size)}\n`;
|
||||
if (diagnosticState.results.size) {
|
||||
text += `Response Size: ${formatBytes(diagnosticState.results.size)}\n`;
|
||||
}
|
||||
|
||||
text += `HTTPS: ${results.performance.isHTTPS ? 'Yes' : 'No'}\n`;
|
||||
text += `Compression: ${results.performance.hasCompression ? 'Yes' : 'No'}\n`;
|
||||
text += `HTTPS: ${diagnosticState.results.performance.isHTTPS ? 'Yes' : 'No'}\n`;
|
||||
text += `Compression: ${diagnosticState.results.performance.hasCompression ? 'Yes' : 'No'}\n`;
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
@@ -159,22 +157,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Performance Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, exampleIndex (exampleIndex)}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<h5>{example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Performance Examples"
|
||||
getLabel={(ex) => ex.url}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Measure performance for ${ex.url}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -221,9 +212,9 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={measurePerformance} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<button class="lookup-btn" onclick={measurePerformance} disabled={diagnosticState.loading || !isInputValid}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Measuring Performance...
|
||||
{:else}
|
||||
<Icon name="activity" size="sm" />
|
||||
@@ -235,16 +226,16 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{@const grade = getPerformanceGrade(results.timings.total)}
|
||||
{#if diagnosticState.results}
|
||||
{@const grade = getPerformanceGrade(diagnosticState.results.timings.total)}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>Performance Analysis</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<span class={copiedState ? 'text-green-500' : ''}
|
||||
><Icon name={copiedState ? 'check' : 'copy'} size="xs" /></span
|
||||
<button class="copy-btn" onclick={copyResults} disabled={clipboard.isCopied()}>
|
||||
<span class={clipboard.isCopied() ? 'text-green-500' : ''}
|
||||
><Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" /></span
|
||||
>
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
@@ -254,33 +245,35 @@
|
||||
<Icon name="zap" size="sm" />
|
||||
<div>
|
||||
<strong>Grade {grade.grade}</strong>
|
||||
<div class="status-text">{results.timings.total.toFixed(0)}ms Total</div>
|
||||
<div class="status-text">{diagnosticState.results.timings.total.toFixed(0)}ms Total</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-item">
|
||||
<Icon name="activity" size="sm" />
|
||||
<div>
|
||||
<strong>{results.status}</strong>
|
||||
<strong>{diagnosticState.results.status}</strong>
|
||||
<div class="status-text">HTTP Status</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if results.size}
|
||||
{#if diagnosticState.results.size}
|
||||
<div class="status-item">
|
||||
<Icon name="file" size="sm" />
|
||||
<div>
|
||||
<strong>{formatBytes(results.size)}</strong>
|
||||
<strong>{formatBytes(diagnosticState.results.size)}</strong>
|
||||
<div class="status-text">Response Size</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results.size && results.timings.total}
|
||||
{#if diagnosticState.results.size && diagnosticState.results.timings.total}
|
||||
<div class="status-item">
|
||||
<Icon name="wifi" size="sm" />
|
||||
<div>
|
||||
<strong>{calculateThroughput(results.size, results.timings.total)}</strong>
|
||||
<strong
|
||||
>{calculateThroughput(diagnosticState.results.size, diagnosticState.results.timings.total)}</strong
|
||||
>
|
||||
<div class="status-text">Throughput</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -291,59 +284,80 @@
|
||||
<div class="record-section">
|
||||
<h4>Performance Timing Breakdown</h4>
|
||||
<div class="timing-chart">
|
||||
<div class="timing-item {getPerformanceClass(results.timings.dns, { good: 20, fair: 100 })}">
|
||||
<div
|
||||
class="timing-item {getPerformanceClass(diagnosticState.results.timings.dns, { good: 20, fair: 100 })}"
|
||||
>
|
||||
<div class="timing-label">
|
||||
<Icon name="globe" size="xs" />
|
||||
<span>DNS Resolution</span>
|
||||
{#if results.timings.dns_note}
|
||||
<span class="timing-note">({results.timings.dns_note})</span>
|
||||
{#if diagnosticState.results.timings.dns_note}
|
||||
<span class="timing-note">({diagnosticState.results.timings.dns_note})</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="timing-bar">
|
||||
<div class="timing-fill" style="width: {(results.timings.dns / results.timings.total) * 100}%"></div>
|
||||
<div
|
||||
class="timing-fill"
|
||||
style="width: {(diagnosticState.results.timings.dns / diagnosticState.results.timings.total) * 100}%"
|
||||
></div>
|
||||
</div>
|
||||
<div class="timing-value">{results.timings.dns.toFixed(1)}ms</div>
|
||||
<div class="timing-value">{diagnosticState.results.timings.dns.toFixed(1)}ms</div>
|
||||
</div>
|
||||
|
||||
<div class="timing-item {getPerformanceClass(results.timings.tcp, { good: 50, fair: 200 })}">
|
||||
<div
|
||||
class="timing-item {getPerformanceClass(diagnosticState.results.timings.tcp, { good: 50, fair: 200 })}"
|
||||
>
|
||||
<div class="timing-label">
|
||||
<Icon name="link" size="xs" />
|
||||
<span>TCP Connect</span>
|
||||
{#if results.timings.tcp_note}
|
||||
<span class="timing-note">({results.timings.tcp_note})</span>
|
||||
{#if diagnosticState.results.timings.tcp_note}
|
||||
<span class="timing-note">({diagnosticState.results.timings.tcp_note})</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="timing-bar">
|
||||
<div class="timing-fill" style="width: {(results.timings.tcp / results.timings.total) * 100}%"></div>
|
||||
<div
|
||||
class="timing-fill"
|
||||
style="width: {(diagnosticState.results.timings.tcp / diagnosticState.results.timings.total) * 100}%"
|
||||
></div>
|
||||
</div>
|
||||
<div class="timing-value">{results.timings.tcp.toFixed(1)}ms</div>
|
||||
<div class="timing-value">{diagnosticState.results.timings.tcp.toFixed(1)}ms</div>
|
||||
</div>
|
||||
|
||||
{#if results.timings.tls > 0}
|
||||
<div class="timing-item {getPerformanceClass(results.timings.tls, { good: 100, fair: 300 })}">
|
||||
{#if diagnosticState.results.timings.tls > 0}
|
||||
<div
|
||||
class="timing-item {getPerformanceClass(diagnosticState.results.timings.tls, { good: 100, fair: 300 })}"
|
||||
>
|
||||
<div class="timing-label">
|
||||
<Icon name="lock" size="xs" />
|
||||
<span>TLS Handshake</span>
|
||||
{#if results.timings.tls_note}
|
||||
<span class="timing-note">({results.timings.tls_note})</span>
|
||||
{#if diagnosticState.results.timings.tls_note}
|
||||
<span class="timing-note">({diagnosticState.results.timings.tls_note})</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="timing-bar">
|
||||
<div class="timing-fill" style="width: {(results.timings.tls / results.timings.total) * 100}%"></div>
|
||||
<div
|
||||
class="timing-fill"
|
||||
style="width: {(diagnosticState.results.timings.tls / diagnosticState.results.timings.total) *
|
||||
100}%"
|
||||
></div>
|
||||
</div>
|
||||
<div class="timing-value">{results.timings.tls.toFixed(1)}ms</div>
|
||||
<div class="timing-value">{diagnosticState.results.timings.tls.toFixed(1)}ms</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="timing-item {getPerformanceClass(results.timings.ttfb, { good: 200, fair: 500 })}">
|
||||
<div
|
||||
class="timing-item {getPerformanceClass(diagnosticState.results.timings.ttfb, { good: 200, fair: 500 })}"
|
||||
>
|
||||
<div class="timing-label">
|
||||
<Icon name="clock" size="xs" />
|
||||
<span>Time to First Byte</span>
|
||||
</div>
|
||||
<div class="timing-bar">
|
||||
<div class="timing-fill" style="width: {(results.timings.ttfb / results.timings.total) * 100}%"></div>
|
||||
<div
|
||||
class="timing-fill"
|
||||
style="width: {(diagnosticState.results.timings.ttfb / diagnosticState.results.timings.total) * 100}%"
|
||||
></div>
|
||||
</div>
|
||||
<div class="timing-value">{results.timings.ttfb.toFixed(1)}ms</div>
|
||||
<div class="timing-value">{diagnosticState.results.timings.ttfb.toFixed(1)}ms</div>
|
||||
</div>
|
||||
|
||||
<div class="timing-item total">
|
||||
@@ -354,7 +368,7 @@
|
||||
<div class="timing-bar">
|
||||
<div class="timing-fill" style="width: 100%"></div>
|
||||
</div>
|
||||
<div class="timing-value">{results.timings.total.toFixed(1)}ms</div>
|
||||
<div class="timing-value">{diagnosticState.results.timings.total.toFixed(1)}ms</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -363,19 +377,23 @@
|
||||
<div class="record-section">
|
||||
<h4>Connection Features</h4>
|
||||
<div class="feature-list">
|
||||
<div class="feature-item {results.performance.isHTTPS ? 'success' : 'warning'}">
|
||||
<Icon name={results.performance.isHTTPS ? 'shield' : 'shield-off'} size="sm" />
|
||||
<div class="feature-item {diagnosticState.results.performance.isHTTPS ? 'success' : 'warning'}">
|
||||
<Icon name={diagnosticState.results.performance.isHTTPS ? 'shield' : 'shield-off'} size="sm" />
|
||||
<div>
|
||||
<strong>HTTPS</strong>
|
||||
<p>{results.performance.isHTTPS ? 'Secure connection' : 'Unencrypted connection'}</p>
|
||||
<p>{diagnosticState.results.performance.isHTTPS ? 'Secure connection' : 'Unencrypted connection'}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="feature-item {results.performance.hasCompression ? 'success' : 'warning'}">
|
||||
<Icon name={results.performance.hasCompression ? 'archive' : 'file'} size="sm" />
|
||||
<div class="feature-item {diagnosticState.results.performance.hasCompression ? 'success' : 'warning'}">
|
||||
<Icon name={diagnosticState.results.performance.hasCompression ? 'archive' : 'file'} size="sm" />
|
||||
<div>
|
||||
<strong>Compression</strong>
|
||||
<p>{results.performance.hasCompression ? 'Response is compressed' : 'No compression detected'}</p>
|
||||
<p>
|
||||
{diagnosticState.results.performance.hasCompression
|
||||
? 'Response is compressed'
|
||||
: 'No compression detected'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -383,7 +401,7 @@
|
||||
<Icon name="server" size="sm" />
|
||||
<div>
|
||||
<strong>HTTP Version</strong>
|
||||
<p>{results.performance.httpVersion}</p>
|
||||
<p>{diagnosticState.results.performance.httpVersion}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -391,7 +409,7 @@
|
||||
<Icon name="repeat" size="sm" />
|
||||
<div>
|
||||
<strong>Connection Reuse</strong>
|
||||
<p>{results.performance.connectionReused}</p>
|
||||
<p>{diagnosticState.results.performance.connectionReused}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -400,19 +418,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Performance Test Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Performance Test Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let url = $state('https://bit.ly/3example');
|
||||
let maxRedirects = $state(10);
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let _selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const examplesList = [
|
||||
{ url: 'https://httpbin.org/redirect/3', description: '3-hop redirect chain' },
|
||||
{ url: 'https://bit.ly/3example', description: 'URL shortener redirect' },
|
||||
{ url: 'https://httpbin.org/absolute-redirect/2', description: 'Absolute redirects' },
|
||||
@@ -21,6 +22,8 @@
|
||||
{ url: 'https://httpbin.org/relative-redirect/2', description: 'Relative path redirects' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
@@ -34,32 +37,27 @@
|
||||
});
|
||||
|
||||
async function traceRedirects() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
|
||||
// Validation
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) {
|
||||
error = 'URL is required';
|
||||
loading = false;
|
||||
diagnosticState.setError('URL is required');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(trimmedUrl);
|
||||
} catch {
|
||||
error = 'Invalid URL format';
|
||||
loading = false;
|
||||
diagnosticState.setError('Invalid URL format');
|
||||
return;
|
||||
}
|
||||
|
||||
if (maxRedirects < 1 || maxRedirects > 50) {
|
||||
error = 'Max redirects must be between 1 and 50';
|
||||
loading = false;
|
||||
diagnosticState.setError('Max redirects must be between 1 and 50');
|
||||
return;
|
||||
}
|
||||
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/http', {
|
||||
method: 'POST',
|
||||
@@ -85,31 +83,28 @@
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(formatDNSError(err));
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
url = example.url;
|
||||
_selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
traceRedirects();
|
||||
}
|
||||
|
||||
function _clearExampleSelection() {
|
||||
_selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.redirectChain) return;
|
||||
if (!diagnosticState.results?.redirectChain) return;
|
||||
|
||||
let text = `Redirect Chain Analysis\nOriginal URL: ${url}\nTotal Redirects: ${results.totalRedirects}\n\n`;
|
||||
let text = `Redirect Chain Analysis\nOriginal URL: ${url}\nTotal Redirects: ${diagnosticState.results.totalRedirects}\n\n`;
|
||||
|
||||
(
|
||||
results as { redirectChain: Array<{ url: string; status: number; location?: string; duration: number }> }
|
||||
diagnosticState.results as {
|
||||
redirectChain: Array<{ url: string; status: number; location?: string; duration: number }>;
|
||||
}
|
||||
).redirectChain.forEach((step, i: number) => {
|
||||
text += `${i + 1}. ${step.url}\n`;
|
||||
text += ` Status: ${step.status}\n`;
|
||||
@@ -119,11 +114,9 @@
|
||||
text += '\n';
|
||||
});
|
||||
|
||||
text += `Final URL: ${results.finalUrl}\nFinal Status: ${results.finalStatus}`;
|
||||
text += `Final URL: ${diagnosticState.results.finalUrl}\nFinal Status: ${diagnosticState.results.finalStatus}`;
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
|
||||
function getStatusClass(status: number): string {
|
||||
@@ -165,22 +158,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Redirect Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, index (index)}
|
||||
<button class="example-card" onclick={() => loadExample(example, index)}>
|
||||
<h5>{example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Redirect Examples"
|
||||
getLabel={(ex) => ex.url}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Trace redirects for ${ex.url}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -226,9 +212,9 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={traceRedirects} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<button class="lookup-btn" onclick={traceRedirects} disabled={diagnosticState.loading || !isInputValid}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Tracing Redirects...
|
||||
{:else}
|
||||
<Icon name="link" size="sm" />
|
||||
@@ -240,15 +226,15 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>Redirect Chain Analysis</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<span class={copiedState ? 'text-green-500' : ''}
|
||||
><Icon name={copiedState ? 'check' : 'copy'} size="xs" /></span
|
||||
<button class="copy-btn" onclick={copyResults} disabled={clipboard.isCopied()}>
|
||||
<span class={clipboard.isCopied() ? 'text-green-500' : ''}
|
||||
><Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" /></span
|
||||
>
|
||||
{copiedState ? 'Copied!' : 'Copy Chain'}
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Chain'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
@@ -257,24 +243,24 @@
|
||||
<div class="status-item">
|
||||
<Icon name="link" size="sm" />
|
||||
<div>
|
||||
<strong>{results.totalRedirects}</strong>
|
||||
<strong>{diagnosticState.results.totalRedirects}</strong>
|
||||
<div class="status-text">Total Redirects</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-item {getStatusClass(results.finalStatus)}">
|
||||
<Icon name={getStatusIcon(results.finalStatus)} size="sm" />
|
||||
<div class="status-item {getStatusClass(diagnosticState.results.finalStatus)}">
|
||||
<Icon name={getStatusIcon(diagnosticState.results.finalStatus)} size="sm" />
|
||||
<div>
|
||||
<strong>{results.finalStatus}</strong>
|
||||
<strong>{diagnosticState.results.finalStatus}</strong>
|
||||
<div class="status-text">Final Status</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if results.timings}
|
||||
{#if diagnosticState.results.timings}
|
||||
<div class="status-item">
|
||||
<Icon name="clock" size="sm" />
|
||||
<div>
|
||||
<strong>{results.timings.total.toFixed(0)}ms</strong>
|
||||
<strong>{diagnosticState.results.timings.total.toFixed(0)}ms</strong>
|
||||
<div class="status-text">Total Time</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -282,11 +268,11 @@
|
||||
</div>
|
||||
|
||||
<!-- Redirect Chain -->
|
||||
{#if results.redirectChain?.length > 0}
|
||||
{#if diagnosticState.results.redirectChain?.length > 0}
|
||||
<div class="record-section">
|
||||
<h4>Redirect Chain</h4>
|
||||
<div class="redirect-chain">
|
||||
{#each results.redirectChain as step, i (i)}
|
||||
{#each diagnosticState.results.redirectChain as step, i (i)}
|
||||
<div class="redirect-step">
|
||||
<div class="step-number">{i + 1}</div>
|
||||
<div class="step-content">
|
||||
@@ -301,7 +287,7 @@
|
||||
HSTS
|
||||
</div>
|
||||
{/if}
|
||||
{#if i < results.redirectChain.length - 1 && isSecureRedirect(step.url, step.location)}
|
||||
{#if i < diagnosticState.results.redirectChain.length - 1 && isSecureRedirect(step.url, step.location)}
|
||||
<div class="security-badge success" use:tooltip={'HTTP to HTTPS upgrade'}>
|
||||
<Icon name="shield-check" size="xs" />
|
||||
Secure Upgrade
|
||||
@@ -318,7 +304,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if i < results.redirectChain.length - 1}
|
||||
{#if i < diagnosticState.results.redirectChain.length - 1}
|
||||
<div class="redirect-arrow">
|
||||
<Icon name="chevron-down" size="sm" />
|
||||
</div>
|
||||
@@ -330,37 +316,25 @@
|
||||
<div class="record-section">
|
||||
<h4>Final Destination</h4>
|
||||
<div class="final-destination">
|
||||
<div class="final-status {getStatusClass(results.finalStatus)}">
|
||||
<Icon name={getStatusIcon(results.finalStatus)} size="sm" />
|
||||
{results.finalStatus}
|
||||
<div class="final-status {getStatusClass(diagnosticState.results.finalStatus)}">
|
||||
<Icon name={getStatusIcon(diagnosticState.results.finalStatus)} size="sm" />
|
||||
{diagnosticState.results.finalStatus}
|
||||
</div>
|
||||
<div class="final-url mono">{results.finalUrl}</div>
|
||||
<div class="final-url mono">{diagnosticState.results.finalUrl}</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="no-records">
|
||||
<Icon name="info" size="md" />
|
||||
<p>No redirects found - URL resolved directly</p>
|
||||
<p class="help-text">Final URL: {results.finalUrl}</p>
|
||||
<p class="help-text">Final URL: {diagnosticState.results.finalUrl}</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Redirect Trace Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Redirect Trace Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let url = $state('https://github.com');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const examplesList = [
|
||||
{ url: 'https://github.com', description: 'GitHub security headers' },
|
||||
{ url: 'https://www.cloudflare.com', description: 'Cloudflare security setup' },
|
||||
{
|
||||
@@ -20,6 +22,8 @@
|
||||
{ url: 'https://example.com', description: 'Basic site (minimal headers)' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
@@ -33,26 +37,22 @@
|
||||
});
|
||||
|
||||
async function analyzeSecurity() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
|
||||
// Validation
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) {
|
||||
error = 'URL is required';
|
||||
loading = false;
|
||||
diagnosticState.setError('URL is required');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(trimmedUrl);
|
||||
} catch {
|
||||
error = 'Invalid URL format';
|
||||
loading = false;
|
||||
diagnosticState.setError('Invalid URL format');
|
||||
return;
|
||||
}
|
||||
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/http', {
|
||||
method: 'POST',
|
||||
@@ -77,42 +77,40 @@
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(formatDNSError(err));
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0]) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
url = example.url;
|
||||
examples.select(index);
|
||||
analyzeSecurity();
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.analysis) return;
|
||||
if (!diagnosticState.results?.analysis) return;
|
||||
|
||||
let text = `Security Headers Analysis\nURL: ${results.url}\nStatus: ${results.status}\n\n`;
|
||||
let text = `Security Headers Analysis\nURL: ${diagnosticState.results.url}\nStatus: ${diagnosticState.results.status}\n\n`;
|
||||
|
||||
text += 'Security Headers Found:\n';
|
||||
Object.entries(results.headers || {}).forEach(([key, value]) => {
|
||||
Object.entries(diagnosticState.results.headers || {}).forEach(([key, value]) => {
|
||||
text += `${key}: ${value}\n`;
|
||||
});
|
||||
|
||||
text += '\nSecurity Analysis:\n';
|
||||
(results as { analysis: Array<{ header: string; message: string; recommendation?: string }> }).analysis.forEach(
|
||||
(item) => {
|
||||
text += `• ${item.header}: ${item.message}\n`;
|
||||
if (item.recommendation) {
|
||||
text += ` Recommendation: ${item.recommendation}\n`;
|
||||
}
|
||||
},
|
||||
);
|
||||
(
|
||||
diagnosticState.results as { analysis: Array<{ header: string; message: string; recommendation?: string }> }
|
||||
).analysis.forEach((item) => {
|
||||
text += `• ${item.header}: ${item.message}\n`;
|
||||
if (item.recommendation) {
|
||||
text += ` Recommendation: ${item.recommendation}\n`;
|
||||
}
|
||||
});
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
|
||||
function getAnalysisClass(status: string): string {
|
||||
@@ -142,13 +140,13 @@
|
||||
}
|
||||
|
||||
function getOverallScore(): { score: number; grade: string; class: string } {
|
||||
if (!results?.analysis) return { score: 0, grade: 'F', class: 'error' };
|
||||
if (!diagnosticState.results?.analysis) return { score: 0, grade: 'F', class: 'error' };
|
||||
|
||||
const total = results.analysis.length;
|
||||
const present = (results as { analysis: Array<{ status: string }> }).analysis.filter(
|
||||
const total = diagnosticState.results.analysis.length;
|
||||
const present = (diagnosticState.results as { analysis: Array<{ status: string }> }).analysis.filter(
|
||||
(a) => a.status === 'present',
|
||||
).length;
|
||||
const weak = (results as { analysis: Array<{ status: string }> }).analysis.filter(
|
||||
const weak = (diagnosticState.results as { analysis: Array<{ status: string }> }).analysis.filter(
|
||||
(a) => a.status === 'weak',
|
||||
).length;
|
||||
|
||||
@@ -188,22 +186,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Security Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, index (index)}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<h5>{example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Security Examples"
|
||||
getLabel={(ex) => ex.url}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Analyze security headers for ${ex.url}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -231,9 +222,9 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={analyzeSecurity} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<button class="lookup-btn" onclick={analyzeSecurity} disabled={diagnosticState.loading || !isInputValid}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Analyzing Security...
|
||||
{:else}
|
||||
<Icon name="shield" size="sm" />
|
||||
@@ -245,16 +236,16 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
{@const overallScore = getOverallScore()}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>Security Headers Analysis</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<span class={copiedState ? 'text-green-500' : ''}
|
||||
><Icon name={copiedState ? 'check' : 'copy'} size="xs" /></span
|
||||
<button class="copy-btn" onclick={copyResults} disabled={clipboard.isCopied()}>
|
||||
<span class={clipboard.isCopied() ? 'text-green-500' : ''}
|
||||
><Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" /></span
|
||||
>
|
||||
{copiedState ? 'Copied!' : 'Copy Analysis'}
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Analysis'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
@@ -272,8 +263,9 @@
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<div>
|
||||
<strong
|
||||
>{(results as { analysis?: Array<{ status: string }> })?.analysis?.filter((a) => a.status === 'present')
|
||||
.length || 0}</strong
|
||||
>{(diagnosticState.results as { analysis?: Array<{ status: string }> })?.analysis?.filter(
|
||||
(a) => a.status === 'present',
|
||||
).length || 0}</strong
|
||||
>
|
||||
<div class="status-text">Headers Present</div>
|
||||
</div>
|
||||
@@ -283,8 +275,9 @@
|
||||
<Icon name="alert-triangle" size="sm" />
|
||||
<div>
|
||||
<strong
|
||||
>{(results as { analysis?: Array<{ status: string }> })?.analysis?.filter((a) => a.status === 'missing')
|
||||
.length || 0}</strong
|
||||
>{(diagnosticState.results as { analysis?: Array<{ status: string }> })?.analysis?.filter(
|
||||
(a) => a.status === 'missing',
|
||||
).length || 0}</strong
|
||||
>
|
||||
<div class="status-text">Headers Missing</div>
|
||||
</div>
|
||||
@@ -295,7 +288,7 @@
|
||||
<div class="record-section">
|
||||
<h4>Security Header Analysis</h4>
|
||||
<div class="security-analysis">
|
||||
{#each results.analysis as analysis, index (index)}
|
||||
{#each diagnosticState.results.analysis as analysis, index (index)}
|
||||
<div class="analysis-item {getAnalysisClass(analysis.status)}">
|
||||
<div class="analysis-header">
|
||||
<div class="analysis-status">
|
||||
@@ -319,11 +312,11 @@
|
||||
</div>
|
||||
|
||||
<!-- Present Headers -->
|
||||
{#if Object.keys(results.headers || {}).length > 0}
|
||||
{#if Object.keys(diagnosticState.results.headers || {}).length > 0}
|
||||
<div class="record-section">
|
||||
<h4>Security Headers Found</h4>
|
||||
<div class="records-list">
|
||||
{#each Object.entries(results.headers) as [name, value], index (index)}
|
||||
{#each Object.entries(diagnosticState.results.headers) as [name, value], index (index)}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>{name}:</strong>
|
||||
@@ -344,19 +337,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Security Analysis Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Security Analysis Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let url = $state('https://google.com');
|
||||
let method = $state('HEAD');
|
||||
let count = $state(5);
|
||||
let timeout = $state(10000);
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const examplesList = [
|
||||
{ url: 'https://google.com', method: 'HEAD', description: 'Google homepage' },
|
||||
{ url: 'https://github.com', method: 'HEAD', description: 'GitHub homepage' },
|
||||
{ url: 'https://api.github.com', method: 'GET', description: 'GitHub API' },
|
||||
@@ -22,6 +23,8 @@
|
||||
{ url: 'https://stackoverflow.com', method: 'HEAD', description: 'Stack Overflow' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
const httpMethods = [
|
||||
{ value: 'HEAD', label: 'HEAD', description: 'Headers only, fastest' },
|
||||
{ value: 'GET', label: 'GET', description: 'Full response, more realistic' },
|
||||
@@ -43,9 +46,7 @@
|
||||
});
|
||||
|
||||
async function httpPing() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/network', {
|
||||
@@ -70,30 +71,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = (err as Error).message;
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError((err as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
url = example.url;
|
||||
method = example.method;
|
||||
count = 5;
|
||||
timeout = 10000;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
httpPing();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function setMethod(newMethod: string) {
|
||||
method = newMethod;
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) httpPing();
|
||||
}
|
||||
|
||||
@@ -112,45 +108,43 @@
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results) return;
|
||||
if (!diagnosticState.results) return;
|
||||
|
||||
let text = `HTTP Ping Results for ${results.url}\n`;
|
||||
let text = `HTTP Ping Results for ${diagnosticState.results.url}\n`;
|
||||
text += `Generated at: ${new Date().toISOString()}\n\n`;
|
||||
text += `Configuration:\n`;
|
||||
text += ` Method: ${results.method}\n`;
|
||||
text += ` Count: ${results.count}\n`;
|
||||
text += ` Method: ${diagnosticState.results.method}\n`;
|
||||
text += ` Count: ${diagnosticState.results.count}\n`;
|
||||
text += ` Timeout: ${timeout}ms\n\n`;
|
||||
text += `Summary:\n`;
|
||||
text += ` Successful: ${results.successful}\n`;
|
||||
text += ` Failed: ${results.failed}\n`;
|
||||
text += ` Success Rate: ${((results.successful / results.count) * 100).toFixed(1)}%\n\n`;
|
||||
text += ` Successful: ${diagnosticState.results.successful}\n`;
|
||||
text += ` Failed: ${diagnosticState.results.failed}\n`;
|
||||
text += ` Success Rate: ${((diagnosticState.results.successful / diagnosticState.results.count) * 100).toFixed(1)}%\n\n`;
|
||||
|
||||
if (results.statistics && results.successful > 0) {
|
||||
if (diagnosticState.results.statistics && diagnosticState.results.successful > 0) {
|
||||
text += `Latency Statistics:\n`;
|
||||
text += ` Min: ${results.statistics.min}ms\n`;
|
||||
text += ` Max: ${results.statistics.max}ms\n`;
|
||||
text += ` Average: ${results.statistics.avg}ms\n`;
|
||||
text += ` Median: ${results.statistics.median}ms\n`;
|
||||
text += ` 95th Percentile: ${results.statistics.p95}ms\n\n`;
|
||||
text += ` Min: ${diagnosticState.results.statistics.min}ms\n`;
|
||||
text += ` Max: ${diagnosticState.results.statistics.max}ms\n`;
|
||||
text += ` Average: ${diagnosticState.results.statistics.avg}ms\n`;
|
||||
text += ` Median: ${diagnosticState.results.statistics.median}ms\n`;
|
||||
text += ` 95th Percentile: ${diagnosticState.results.statistics.p95}ms\n\n`;
|
||||
}
|
||||
|
||||
if (results.latencies?.length > 0) {
|
||||
if (diagnosticState.results.latencies?.length > 0) {
|
||||
text += `Individual Results:\n`;
|
||||
results.latencies.forEach((latency: number, i: number) => {
|
||||
diagnosticState.results.latencies.forEach((latency: number, i: number) => {
|
||||
text += ` Request ${i + 1}: ${latency}ms\n`;
|
||||
});
|
||||
}
|
||||
|
||||
if (results.errors?.length > 0) {
|
||||
if (diagnosticState.results.errors?.length > 0) {
|
||||
text += `\nErrors:\n`;
|
||||
results.errors.forEach((err: string, i: number) => {
|
||||
diagnosticState.results.errors.forEach((err: string, i: number) => {
|
||||
text += ` ${i + 1}: ${err}\n`;
|
||||
});
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -164,30 +158,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>HTTP Ping Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Ping ${example.url} using ${example.method} method`}
|
||||
>
|
||||
<h5>{example.description}</h5>
|
||||
<div class="example-details">
|
||||
<span class="example-url mono">{example.url}</span>
|
||||
<span class="example-method">{example.method}</span>
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="HTTP Ping Examples"
|
||||
getLabel={(ex) => ex.description}
|
||||
getDescription={(ex) => `${ex.url} (${ex.method})`}
|
||||
getTooltip={(ex) => `Ping ${ex.url} using ${ex.method} method`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -206,7 +185,7 @@
|
||||
placeholder="https://example.com"
|
||||
class:invalid={url && !isUrlValid()}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) httpPing();
|
||||
}}
|
||||
/>
|
||||
@@ -248,7 +227,7 @@
|
||||
min="1"
|
||||
max="20"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) httpPing();
|
||||
}}
|
||||
/>
|
||||
@@ -265,7 +244,7 @@
|
||||
max="30000"
|
||||
step="1000"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) httpPing();
|
||||
}}
|
||||
/>
|
||||
@@ -274,8 +253,8 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={httpPing} disabled={loading || !isInputValid()}>
|
||||
{#if loading}
|
||||
<button class="lookup-btn" onclick={httpPing} disabled={diagnosticState.loading || !isInputValid()}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
Pinging...
|
||||
{:else}
|
||||
@@ -288,13 +267,13 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>HTTP Ping Results</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
<button class="copy-btn" onclick={copyResults} disabled={clipboard.isCopied()}>
|
||||
<Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
@@ -303,68 +282,72 @@
|
||||
<div class="status-item success">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<div>
|
||||
<span class="status-title">{results.successful}/{results.count}</span>
|
||||
<span class="status-title">{diagnosticState.results.successful}/{diagnosticState.results.count}</span>
|
||||
<p class="status-desc">Successful requests</p>
|
||||
</div>
|
||||
</div>
|
||||
{#if results.statistics?.avg}
|
||||
<div class="status-item {getLatencyClass(results.statistics.avg)}">
|
||||
{#if diagnosticState.results.statistics?.avg}
|
||||
<div class="status-item {getLatencyClass(diagnosticState.results.statistics.avg)}">
|
||||
<Icon name="zap" size="sm" />
|
||||
<div>
|
||||
<span class="status-title">{results.statistics.avg}ms</span>
|
||||
<p class="status-desc">Average latency ({getLatencyDescription(results.statistics.avg)})</p>
|
||||
<span class="status-title">{diagnosticState.results.statistics.avg}ms</span>
|
||||
<p class="status-desc">
|
||||
Average latency ({getLatencyDescription(diagnosticState.results.statistics.avg)})
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if results.failed > 0}
|
||||
{#if diagnosticState.results.failed > 0}
|
||||
<div class="status-item error">
|
||||
<Icon name="x-circle" size="sm" />
|
||||
<div>
|
||||
<span class="status-title">{results.failed}</span>
|
||||
<span class="status-title">{diagnosticState.results.failed}</span>
|
||||
<p class="status-desc">Failed requests</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if results.statistics && results.successful > 0}
|
||||
{#if diagnosticState.results.statistics && diagnosticState.results.successful > 0}
|
||||
<!-- Statistics -->
|
||||
<div class="stats-section">
|
||||
<h4>Latency Statistics</h4>
|
||||
<div class="stats-grid">
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Minimum:</span>
|
||||
<span class="stat-value">{results.statistics.min}ms</span>
|
||||
<span class="stat-value">{diagnosticState.results.statistics.min}ms</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Maximum:</span>
|
||||
<span class="stat-value">{results.statistics.max}ms</span>
|
||||
<span class="stat-value">{diagnosticState.results.statistics.max}ms</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Average:</span>
|
||||
<span class="stat-value">{results.statistics.avg}ms</span>
|
||||
<span class="stat-value">{diagnosticState.results.statistics.avg}ms</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Median:</span>
|
||||
<span class="stat-value">{results.statistics.median}ms</span>
|
||||
<span class="stat-value">{diagnosticState.results.statistics.median}ms</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">95th Percentile:</span>
|
||||
<span class="stat-value">{results.statistics.p95}ms</span>
|
||||
<span class="stat-value">{diagnosticState.results.statistics.p95}ms</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-label">Range:</span>
|
||||
<span class="stat-value">{results.statistics.max - results.statistics.min}ms</span>
|
||||
<span class="stat-value"
|
||||
>{diagnosticState.results.statistics.max - diagnosticState.results.statistics.min}ms</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Individual Results -->
|
||||
{#if results.latencies?.length > 0}
|
||||
{#if diagnosticState.results.latencies?.length > 0}
|
||||
<div class="results-section">
|
||||
<h4>Individual Request Results</h4>
|
||||
<div class="requests-list">
|
||||
{#each results.latencies as latency, i (i)}
|
||||
{#each diagnosticState.results.latencies as latency, i (i)}
|
||||
<div class="request-item {getLatencyClass(latency)}">
|
||||
<span class="request-number">#{i + 1}</span>
|
||||
<span class="request-latency">{latency}ms</span>
|
||||
@@ -377,13 +360,13 @@
|
||||
{/if}
|
||||
|
||||
<!-- Errors -->
|
||||
{#if results.errors?.length > 0}
|
||||
{#if diagnosticState.results.errors?.length > 0}
|
||||
<div class="errors-section">
|
||||
<h4>Request Errors ({results.errors.length})</h4>
|
||||
<h4>Request Errors ({diagnosticState.results.errors.length})</h4>
|
||||
<div class="errors-list">
|
||||
{#each results.errors as error, i (i)}
|
||||
{#each diagnosticState.results.errors as error, i (i)}
|
||||
<div class="error-item">
|
||||
<span class="error-number">#{i + results.successful + 1}</span>
|
||||
<span class="error-number">#{i + diagnosticState.results.successful + 1}</span>
|
||||
<span class="error-message">{error}</span>
|
||||
</div>
|
||||
{/each}
|
||||
@@ -397,15 +380,17 @@
|
||||
<div class="detail-grid">
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">URL:</span>
|
||||
<span class="detail-value mono">{results.url}</span>
|
||||
<span class="detail-value mono">{diagnosticState.results.url}</span>
|
||||
</div>
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">Method:</span>
|
||||
<span class="detail-value">{results.method}</span>
|
||||
<span class="detail-value">{diagnosticState.results.method}</span>
|
||||
</div>
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">Success Rate:</span>
|
||||
<span class="detail-value">{((results.successful / results.count) * 100).toFixed(1)}%</span>
|
||||
<span class="detail-value"
|
||||
>{((diagnosticState.results.successful / diagnosticState.results.count) * 100).toFixed(1)}%</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -413,19 +398,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>HTTP Ping Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="HTTP Ping Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let targets = $state('google.com:443\ngithub.com:443\nstackoverflow.com:443');
|
||||
let timeout = $state(5000);
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const examplesList = [
|
||||
{
|
||||
targets: 'google.com:443\ngithub.com:443\nstackoverflow.com:443',
|
||||
description: 'Common HTTPS ports',
|
||||
@@ -38,6 +39,8 @@
|
||||
},
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
const commonPorts = [
|
||||
{ port: '22', service: 'SSH', description: 'Secure Shell' },
|
||||
{ port: '80', service: 'HTTP', description: 'Web traffic' },
|
||||
@@ -63,9 +66,7 @@
|
||||
});
|
||||
|
||||
async function checkPorts() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
// Calculate targets list at function call time
|
||||
const currentTargets = targets
|
||||
@@ -96,30 +97,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = (err as Error).message;
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError((err as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
targets = example.targets;
|
||||
timeout = 5000;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
checkPorts();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function addCommonPort(port: string) {
|
||||
const currentTargets = targets.trim();
|
||||
const newTarget = `example.com:${port}`;
|
||||
targets = currentTargets ? `${currentTargets}\n${newTarget}` : newTarget;
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
}
|
||||
|
||||
function getPortStatus(result: { open: boolean; latency?: number; error?: string }): {
|
||||
@@ -143,29 +139,29 @@
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results) return;
|
||||
if (!diagnosticState.results) return;
|
||||
|
||||
let text = `TCP Port Check Results\n`;
|
||||
text += `Generated at: ${new Date().toISOString()}\n\n`;
|
||||
text += `Summary:\n`;
|
||||
text += ` Total ports: ${results.summary.total}\n`;
|
||||
text += ` Open: ${results.summary.open}\n`;
|
||||
text += ` Closed: ${results.summary.closed}\n`;
|
||||
if (results.summary.avgLatency) {
|
||||
text += ` Average latency: ${results.summary.avgLatency}ms\n`;
|
||||
text += ` Total ports: ${diagnosticState.results.summary.total}\n`;
|
||||
text += ` Open: ${diagnosticState.results.summary.open}\n`;
|
||||
text += ` Closed: ${diagnosticState.results.summary.closed}\n`;
|
||||
if (diagnosticState.results.summary.avgLatency) {
|
||||
text += ` Average latency: ${diagnosticState.results.summary.avgLatency}ms\n`;
|
||||
}
|
||||
text += `\nResults:\n`;
|
||||
|
||||
(
|
||||
results as { results: Array<{ host: string; port: number; open: boolean; latency?: number; error?: string }> }
|
||||
diagnosticState.results as {
|
||||
results: Array<{ host: string; port: number; open: boolean; latency?: number; error?: string }>;
|
||||
}
|
||||
).results.forEach((result) => {
|
||||
const status = result.open ? `OPEN (${result.latency}ms)` : `CLOSED${result.error ? ` - ${result.error}` : ''}`;
|
||||
text += ` ${result.host}:${result.port} - ${status}\n`;
|
||||
});
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -179,34 +175,19 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Port Check Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Test ports: ${example.targets.split('\n').join(', ')}`}
|
||||
>
|
||||
<h5>{example.description}</h5>
|
||||
<div class="example-targets">
|
||||
{#each example.targets.split('\n').slice(0, 3) as target, index (index)}
|
||||
<span class="target-item mono">{target}</span>
|
||||
{/each}
|
||||
{#if example.targets.split('\n').length > 3}
|
||||
<span class="more-targets">+{example.targets.split('\n').length - 3} more</span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Port Check Examples"
|
||||
getLabel={(ex) => ex.description}
|
||||
getDescription={(ex) => {
|
||||
const targets = ex.targets.split('\n');
|
||||
const preview = targets.slice(0, 3).join(', ');
|
||||
return targets.length > 3 ? `${preview} (+${targets.length - 3} more)` : preview;
|
||||
}}
|
||||
getTooltip={(ex) => `Test ports: ${ex.targets.split('\n').join(', ')}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -225,7 +206,7 @@
|
||||
rows="6"
|
||||
class:invalid={targets && !isInputValid()}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) checkPorts();
|
||||
}}
|
||||
></textarea>
|
||||
@@ -270,7 +251,7 @@
|
||||
max="30000"
|
||||
step="1000"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) checkPorts();
|
||||
}}
|
||||
/>
|
||||
@@ -279,8 +260,8 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={checkPorts} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<button class="lookup-btn" onclick={checkPorts} disabled={diagnosticState.loading || !isInputValid()}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
Checking Ports...
|
||||
{:else}
|
||||
@@ -293,13 +274,13 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>Port Check Results</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
<button class="copy-btn" onclick={copyResults} disabled={clipboard.isCopied()}>
|
||||
<Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
@@ -308,22 +289,22 @@
|
||||
<div class="status-item success">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<div>
|
||||
<span class="status-title">{results.summary.open} Open</span>
|
||||
<span class="status-title">{diagnosticState.results.summary.open} Open</span>
|
||||
<p class="status-desc">Ports accepting connections</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-item error">
|
||||
<Icon name="x-circle" size="sm" />
|
||||
<div>
|
||||
<span class="status-title">{results.summary.closed} Closed</span>
|
||||
<span class="status-title">{diagnosticState.results.summary.closed} Closed</span>
|
||||
<p class="status-desc">Ports not responding</p>
|
||||
</div>
|
||||
</div>
|
||||
{#if results.summary.avgLatency}
|
||||
{#if diagnosticState.results.summary.avgLatency}
|
||||
<div class="status-item">
|
||||
<Icon name="zap" size="sm" />
|
||||
<div>
|
||||
<span class="status-title">{results.summary.avgLatency}ms</span>
|
||||
<span class="status-title">{diagnosticState.results.summary.avgLatency}ms</span>
|
||||
<p class="status-desc">Average latency</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -332,9 +313,9 @@
|
||||
|
||||
<!-- Detailed Results -->
|
||||
<div class="ports-section">
|
||||
<h4>Port Status ({results.results.length} targets)</h4>
|
||||
<h4>Port Status ({diagnosticState.results.results.length} targets)</h4>
|
||||
<div class="ports-list">
|
||||
{#each results.results as result, index (index)}
|
||||
{#each diagnosticState.results.results as result, index (index)}
|
||||
{@const status = getPortStatus(result)}
|
||||
<div class="port-result {status.class}">
|
||||
<div class="port-header">
|
||||
@@ -357,19 +338,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Port Check Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Port Check Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -162,7 +162,7 @@
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={lookupASN} disabled={loading || !asn.trim()}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Performing RDAP Lookup...
|
||||
{:else}
|
||||
<Icon name="search" size="sm" />
|
||||
|
||||
@@ -153,7 +153,7 @@
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={lookupDomain} disabled={loading || !domain.trim()}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Performing RDAP Lookup...
|
||||
{:else}
|
||||
<Icon name="search" size="sm" />
|
||||
|
||||
@@ -159,7 +159,7 @@
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={lookupIP} disabled={loading || !ip.trim()}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Performing RDAP Lookup...
|
||||
{:else}
|
||||
<Icon name="search" size="sm" />
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let host = $state('google.com:443');
|
||||
let servername = $state('');
|
||||
let useCustomServername = $state(false);
|
||||
let protocols = $state('h2,http/1.1');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const examplesList = [
|
||||
{ host: 'google.com:443', protocols: 'h2,http/1.1', description: 'Google HTTP/2 support' },
|
||||
{ host: 'github.com:443', protocols: 'h2,http/1.1', description: 'GitHub ALPN negotiation' },
|
||||
{ host: 'cloudflare.com:443', protocols: 'h2,http/1.1,h3', description: 'Cloudflare HTTP/3 support' },
|
||||
@@ -22,6 +23,8 @@
|
||||
{ host: 'api.github.com:443', protocols: 'h2,http/1.1', description: 'API server ALPN' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
const commonProtocols = [
|
||||
{ value: 'h2,http/1.1', label: 'HTTP/2 + HTTP/1.1', description: 'Standard web protocols' },
|
||||
{ value: 'h3,h2,http/1.1', label: 'HTTP/3 + HTTP/2 + HTTP/1.1', description: 'Including experimental HTTP/3' },
|
||||
@@ -44,9 +47,7 @@
|
||||
});
|
||||
|
||||
async function probeALPN() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/tls', {
|
||||
@@ -70,30 +71,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'Unknown error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
host = example.host;
|
||||
protocols = example.protocols;
|
||||
servername = '';
|
||||
useCustomServername = false;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
probeALPN();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function setCommonProtocols(protocolSet: string) {
|
||||
protocols = protocolSet;
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) probeALPN();
|
||||
}
|
||||
|
||||
@@ -113,18 +109,18 @@
|
||||
}
|
||||
|
||||
function getNegotiationStatus(): { status: string; icon: string; class: string; description: string } {
|
||||
if (!results)
|
||||
if (!diagnosticState.results)
|
||||
return { status: 'Unknown', icon: 'help-circle', class: 'secondary', description: 'No results available' };
|
||||
|
||||
if (results.success && results.negotiatedProtocol) {
|
||||
const protocol = getProtocolInfo(results.negotiatedProtocol);
|
||||
if (diagnosticState.results.success && diagnosticState.results.negotiatedProtocol) {
|
||||
const protocol = getProtocolInfo(diagnosticState.results.negotiatedProtocol);
|
||||
return {
|
||||
status: 'Successful',
|
||||
icon: 'check-circle',
|
||||
class: 'success',
|
||||
description: `Server selected ${protocol.name}`,
|
||||
};
|
||||
} else if (!results.success) {
|
||||
} else if (!diagnosticState.results.success) {
|
||||
return {
|
||||
status: 'Failed',
|
||||
icon: 'x-circle',
|
||||
@@ -142,29 +138,27 @@
|
||||
}
|
||||
|
||||
async function copyALPNInfo() {
|
||||
if (!results) return;
|
||||
if (!diagnosticState.results) return;
|
||||
|
||||
let text = `ALPN Negotiation Results for ${host}\n`;
|
||||
text += `Generated at: ${new Date().toISOString()}\n\n`;
|
||||
text += `Requested Protocols: ${results.requestedProtocols.join(', ')}\n`;
|
||||
text += `Negotiated Protocol: ${results.negotiatedProtocol || 'None'}\n`;
|
||||
text += `TLS Version: ${results.tlsVersion || 'Unknown'}\n`;
|
||||
text += `Success: ${results.success ? 'Yes' : 'No'}\n`;
|
||||
text += `Requested Protocols: ${diagnosticState.results.requestedProtocols.join(', ')}\n`;
|
||||
text += `Negotiated Protocol: ${diagnosticState.results.negotiatedProtocol || 'None'}\n`;
|
||||
text += `TLS Version: ${diagnosticState.results.tlsVersion || 'Unknown'}\n`;
|
||||
text += `Success: ${diagnosticState.results.success ? 'Yes' : 'No'}\n`;
|
||||
|
||||
const status = getNegotiationStatus();
|
||||
text += `\nNegotiation Status: ${status.status}\n`;
|
||||
text += `Description: ${status.description}\n`;
|
||||
|
||||
if (results.negotiatedProtocol) {
|
||||
const protocolInfo = getProtocolInfo(results.negotiatedProtocol);
|
||||
if (diagnosticState.results.negotiatedProtocol) {
|
||||
const protocolInfo = getProtocolInfo(diagnosticState.results.negotiatedProtocol);
|
||||
text += `\nSelected Protocol Info:\n`;
|
||||
text += ` Name: ${protocolInfo.name}\n`;
|
||||
text += ` Description: ${protocolInfo.description}\n`;
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -178,28 +172,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>ALPN Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Test ALPN for ${example.host} (${example.description})`}
|
||||
>
|
||||
<h5>{example.host}</h5>
|
||||
<p>{example.description}</p>
|
||||
<div class="example-protocols mono">{example.protocols}</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="ALPN Examples"
|
||||
getLabel={(ex) => ex.host}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Test ALPN for ${ex.host} (${ex.description})`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -218,7 +199,7 @@
|
||||
placeholder="google.com:443"
|
||||
class:invalid={host && !isInputValid}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) probeALPN();
|
||||
}}
|
||||
/>
|
||||
@@ -240,7 +221,7 @@
|
||||
bind:value={protocols}
|
||||
placeholder="h2,http/1.1"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) probeALPN();
|
||||
}}
|
||||
/>
|
||||
@@ -268,7 +249,7 @@
|
||||
type="checkbox"
|
||||
bind:checked={useCustomServername}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) probeALPN();
|
||||
}}
|
||||
/>
|
||||
@@ -281,7 +262,7 @@
|
||||
placeholder="example.com"
|
||||
use:tooltip={'Custom servername for SNI (Server Name Indication)'}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) probeALPN();
|
||||
}}
|
||||
/>
|
||||
@@ -290,9 +271,9 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={probeALPN} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<button class="lookup-btn" onclick={probeALPN} disabled={diagnosticState.loading || !isInputValid}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Testing ALPN...
|
||||
{:else}
|
||||
<Icon name="shuffle" size="sm" />
|
||||
@@ -304,18 +285,18 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>ALPN Negotiation Results</h3>
|
||||
<button class="copy-btn" onclick={copyALPNInfo} disabled={copiedState}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
<button class="copy-btn" onclick={copyALPNInfo} disabled={clipboard.isCopied()}>
|
||||
<Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Negotiation Overview -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
{@const status = getNegotiationStatus()}
|
||||
<div class="status-overview">
|
||||
<div class="status-item {status.class}">
|
||||
@@ -325,11 +306,11 @@
|
||||
<p class="status-desc">{status.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
{#if results.tlsVersion}
|
||||
{#if diagnosticState.results.tlsVersion}
|
||||
<div class="status-item success">
|
||||
<Icon name="shield-check" size="sm" />
|
||||
<div>
|
||||
<span class="status-title">TLS Version: {results.tlsVersion}</span>
|
||||
<span class="status-title">TLS Version: {diagnosticState.results.tlsVersion}</span>
|
||||
<p class="status-desc">Connection established successfully</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -345,7 +326,7 @@
|
||||
<div class="detail-section">
|
||||
<h5>Requested Protocols</h5>
|
||||
<div class="protocol-list">
|
||||
{#each results.requestedProtocols as protocol, i (i)}
|
||||
{#each diagnosticState.results.requestedProtocols as protocol, i (i)}
|
||||
{@const protocolInfo = getProtocolInfo(protocol)}
|
||||
<div class="protocol-item requested">
|
||||
<div class="protocol-header">
|
||||
@@ -359,8 +340,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if results.negotiatedProtocol}
|
||||
{@const selectedProtocol = getProtocolInfo(results.negotiatedProtocol)}
|
||||
{#if diagnosticState.results.negotiatedProtocol}
|
||||
{@const selectedProtocol = getProtocolInfo(diagnosticState.results.negotiatedProtocol)}
|
||||
<div class="detail-section">
|
||||
<h5>Selected Protocol</h5>
|
||||
<div class="selected-protocol">
|
||||
@@ -368,7 +349,7 @@
|
||||
<div class="protocol-header">
|
||||
<span class="success-icon"><Icon name="check-circle" size="sm" /></span>
|
||||
<span class="protocol-name">{selectedProtocol.name}</span>
|
||||
<span class="protocol-id mono">({results.negotiatedProtocol})</span>
|
||||
<span class="protocol-id mono">({diagnosticState.results.negotiatedProtocol})</span>
|
||||
</div>
|
||||
<p class="protocol-desc">{selectedProtocol.description}</p>
|
||||
</div>
|
||||
@@ -387,18 +368,18 @@
|
||||
</div>
|
||||
|
||||
<!-- Connection Info -->
|
||||
{#if results.servername || results.tlsVersion}
|
||||
{#if diagnosticState.results.servername || diagnosticState.results.tlsVersion}
|
||||
<div class="connection-section">
|
||||
<h4>Connection Information</h4>
|
||||
<div class="detail-grid">
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">Server Name:</span>
|
||||
<span class="detail-value mono">{results.servername}</span>
|
||||
<span class="detail-value mono">{diagnosticState.results.servername}</span>
|
||||
</div>
|
||||
{#if results.tlsVersion}
|
||||
{#if diagnosticState.results.tlsVersion}
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">TLS Version:</span>
|
||||
<span class="detail-value">{results.tlsVersion}</span>
|
||||
<span class="detail-value">{diagnosticState.results.tlsVersion}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -408,19 +389,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>ALPN Negotiation Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="ALPN Negotiation Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let host = $state('');
|
||||
let port = $state<number | null>(null);
|
||||
let service = $state('custom');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
|
||||
const services = {
|
||||
custom: { port: null, description: 'Custom port' },
|
||||
@@ -34,7 +34,7 @@
|
||||
vnc: { port: 5900, description: 'VNC Remote Desktop' },
|
||||
};
|
||||
|
||||
const examples = [
|
||||
const examplesList = [
|
||||
{ host: 'scanme.nmap.org', port: 22, service: 'ssh', description: 'Nmap SSH Test' },
|
||||
{ host: 'test.rebex.net', port: 21, service: 'ftp', description: 'Rebex FTP Test' },
|
||||
{ host: 'example.com', port: 80, service: 'http', description: 'Example.com HTTP' },
|
||||
@@ -46,6 +46,8 @@
|
||||
{ host: 'whois.verisign-grs.com', port: 43, service: 'whois', description: 'Verisign WHOIS' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
$effect(() => {
|
||||
if (service && service !== 'custom' && services[service as keyof typeof services]) {
|
||||
port = services[service as keyof typeof services].port;
|
||||
@@ -64,13 +66,11 @@
|
||||
|
||||
async function grabBanner() {
|
||||
if (!isInputValid) {
|
||||
error = 'Please enter a valid host and port (1-65535)';
|
||||
diagnosticState.setError('Please enter a valid host and port (1-65535)');
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/tls', {
|
||||
@@ -97,26 +97,20 @@
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = data;
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err) {
|
||||
error = err instanceof Error ? err.message : 'An unexpected error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'An unexpected error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
host = example.host;
|
||||
port = example.port;
|
||||
service = example.service;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
grabBanner();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getProtocolIcon(protocol: string): string {
|
||||
switch (protocol?.toLowerCase()) {
|
||||
case 'ssh':
|
||||
@@ -155,27 +149,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Quick Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Grab banner from ${example.host}:${example.port}`}
|
||||
>
|
||||
<h5>{example.description}</h5>
|
||||
<p>{example.host}:{example.port}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Quick Examples"
|
||||
getLabel={(ex) => ex.description}
|
||||
getDescription={(ex) => `${ex.host}:${ex.port}`}
|
||||
getTooltip={(ex) => `Grab banner from ${ex.host}:${ex.port}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -186,7 +168,12 @@
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="service">Service Type</label>
|
||||
<select id="service" bind:value={service} disabled={loading} onchange={() => clearExampleSelection()}>
|
||||
<select
|
||||
id="service"
|
||||
bind:value={service}
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
>
|
||||
{#each Object.entries(services) as [key, svc] (key)}
|
||||
<option value={key}>{svc.description} {svc.port ? `(${svc.port})` : ''}</option>
|
||||
{/each}
|
||||
@@ -202,8 +189,8 @@
|
||||
type="text"
|
||||
bind:value={host}
|
||||
placeholder="example.com or 192.168.1.1"
|
||||
disabled={loading}
|
||||
onchange={() => clearExampleSelection()}
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && grabBanner()}
|
||||
/>
|
||||
</div>
|
||||
@@ -216,15 +203,15 @@
|
||||
min="1"
|
||||
max="65535"
|
||||
placeholder="1-65535"
|
||||
disabled={loading}
|
||||
onchange={() => clearExampleSelection()}
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && grabBanner()}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button onclick={grabBanner} disabled={loading || !isInputValid} class="primary">
|
||||
{#if loading}
|
||||
<button onclick={grabBanner} disabled={diagnosticState.loading || !isInputValid} class="primary">
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Connecting...
|
||||
{:else}
|
||||
@@ -235,21 +222,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Connection Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Connection Failed" error={diagnosticState.error} />
|
||||
|
||||
{#if loading}
|
||||
{#if diagnosticState.loading}
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="loading-state">
|
||||
@@ -263,7 +238,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>Banner Information</h3>
|
||||
@@ -278,22 +253,22 @@
|
||||
<div class="info-grid">
|
||||
<div class="info-item">
|
||||
<span class="info-label">Host:</span>
|
||||
<span class="info-value">{results.host}</span>
|
||||
<span class="info-value">{diagnosticState.results.host}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Port:</span>
|
||||
<span class="info-value">{results.port}</span>
|
||||
<span class="info-value">{diagnosticState.results.port}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Protocol:</span>
|
||||
<span class="info-value">
|
||||
<Icon name={getProtocolIcon(results.protocol)} size="xs" />
|
||||
{results.protocol || 'Unknown'}
|
||||
<Icon name={getProtocolIcon(diagnosticState.results.protocol)} size="xs" />
|
||||
{diagnosticState.results.protocol || 'Unknown'}
|
||||
</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Response Time:</span>
|
||||
<span class="info-value">{results.responseTime}ms</span>
|
||||
<span class="info-value">{diagnosticState.results.responseTime}ms</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -305,9 +280,9 @@
|
||||
<h3>Service Banner</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
{#if results.banner}
|
||||
{#if diagnosticState.results.banner}
|
||||
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
||||
<pre class="banner-content">{@html formatBanner(results.banner)}</pre>
|
||||
<pre class="banner-content">{@html formatBanner(diagnosticState.results.banner)}</pre>
|
||||
{:else}
|
||||
<div class="no-banner">
|
||||
<Icon name="file-x" size="lg" />
|
||||
@@ -319,47 +294,47 @@
|
||||
</div>
|
||||
|
||||
<!-- Service Analysis -->
|
||||
{#if results.analysis && (results.analysis.software || results.analysis.version || results.analysis.os || (results.analysis.security && results.analysis.security.length > 0))}
|
||||
{#if diagnosticState.results.analysis && (diagnosticState.results.analysis.software || diagnosticState.results.analysis.version || diagnosticState.results.analysis.os || (diagnosticState.results.analysis.security && diagnosticState.results.analysis.security.length > 0))}
|
||||
<div class="card analysis-section">
|
||||
<div class="card-header">
|
||||
<h3>Service Analysis</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="analysis-grid">
|
||||
{#if results.analysis.software}
|
||||
{#if diagnosticState.results.analysis.software}
|
||||
<div class="analysis-item">
|
||||
<Icon name="package" size="sm" />
|
||||
<div>
|
||||
<h4>Software</h4>
|
||||
<p>{results.analysis.software}</p>
|
||||
<p>{diagnosticState.results.analysis.software}</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if results.analysis.version}
|
||||
{#if diagnosticState.results.analysis.version}
|
||||
<div class="analysis-item">
|
||||
<Icon name="tag" size="sm" />
|
||||
<div>
|
||||
<h4>Version</h4>
|
||||
<p>{results.analysis.version}</p>
|
||||
<p>{diagnosticState.results.analysis.version}</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if results.analysis.os}
|
||||
{#if diagnosticState.results.analysis.os}
|
||||
<div class="analysis-item">
|
||||
<Icon name="monitor" size="sm" />
|
||||
<div>
|
||||
<h4>Operating System</h4>
|
||||
<p>{results.analysis.os}</p>
|
||||
<p>{diagnosticState.results.analysis.os}</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if results.analysis.security && results.analysis.security.length > 0}
|
||||
{#if diagnosticState.results.analysis.security && diagnosticState.results.analysis.security.length > 0}
|
||||
<div class="analysis-item full-width">
|
||||
<Icon name="shield" size="sm" />
|
||||
<div>
|
||||
<h4>Security Notes</h4>
|
||||
<ul>
|
||||
{#each results.analysis.security as note, i (i)}
|
||||
{#each diagnosticState.results.analysis.security as note, i (i)}
|
||||
<li>{note}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
@@ -372,7 +347,7 @@
|
||||
{/if}
|
||||
|
||||
<!-- TLS Info (if applicable) -->
|
||||
{#if results.tls}
|
||||
{#if diagnosticState.results.tls}
|
||||
<div class="card tls-section">
|
||||
<div class="card-header">
|
||||
<h3>TLS Information</h3>
|
||||
@@ -381,16 +356,16 @@
|
||||
<div class="tls-info">
|
||||
<div class="tls-item">
|
||||
<span class="tls-label">Protocol:</span>
|
||||
<span class="tls-value">{results.tls.protocol}</span>
|
||||
<span class="tls-value">{diagnosticState.results.tls.protocol}</span>
|
||||
</div>
|
||||
<div class="tls-item">
|
||||
<span class="tls-label">Cipher:</span>
|
||||
<span class="tls-value">{results.tls.cipher}</span>
|
||||
<span class="tls-value">{diagnosticState.results.tls.cipher}</span>
|
||||
</div>
|
||||
{#if results.tls.certificate}
|
||||
{#if diagnosticState.results.tls.certificate}
|
||||
<div class="tls-item">
|
||||
<span class="tls-label">Certificate CN:</span>
|
||||
<span class="tls-value">{results.tls.certificate.cn}</span>
|
||||
<span class="tls-value">{diagnosticState.results.tls.certificate.cn}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let host = $state('google.com:443');
|
||||
let servername = $state('');
|
||||
let useCustomServername = $state(false);
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
|
||||
interface Certificate {
|
||||
isExpired: boolean;
|
||||
daysUntilExpiry: number;
|
||||
}
|
||||
|
||||
const examples = [
|
||||
const examplesList = [
|
||||
{ host: 'google.com:443', description: 'Google TLS certificate' },
|
||||
{ host: 'github.com:443', description: 'GitHub certificate chain' },
|
||||
{ host: 'cloudflare.com:443', description: 'Cloudflare certificate' },
|
||||
@@ -26,6 +27,8 @@
|
||||
{ host: 'microsoft.com:443', description: 'Microsoft certificate' },
|
||||
];
|
||||
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedHost = host.trim();
|
||||
@@ -35,9 +38,7 @@
|
||||
});
|
||||
|
||||
async function analyzeCertificate() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/tls', {
|
||||
@@ -60,26 +61,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
const data = await response.json();
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'Unknown error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
host = example.host;
|
||||
servername = '';
|
||||
useCustomServername = false;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
analyzeCertificate();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getExpiryStatus(cert: Certificate): { status: string; icon: string; class: string } {
|
||||
if (cert.isExpired) {
|
||||
return { status: 'Expired', icon: 'x-circle', class: 'error' };
|
||||
@@ -94,9 +90,9 @@
|
||||
}
|
||||
|
||||
async function copyCertificateInfo() {
|
||||
if (!results?.peerCertificate) return;
|
||||
if (!diagnosticState.results?.peerCertificate) return;
|
||||
|
||||
const cert = results.peerCertificate;
|
||||
const cert = diagnosticState.results.peerCertificate;
|
||||
let text = `TLS Certificate Analysis for ${host}\n`;
|
||||
text += `Generated at: ${new Date().toISOString()}\n\n`;
|
||||
text += `Subject: ${cert.subject.CN}\n`;
|
||||
@@ -115,9 +111,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
await clipboard.copy(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -131,27 +125,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Certificate Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Analyze certificate for ${example.host} (${example.description})`}
|
||||
>
|
||||
<h5>{example.host}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Certificate Examples"
|
||||
getLabel={(example) => example.host}
|
||||
getDescription={(example) => example.description}
|
||||
getTooltip={(example) => `Analyze certificate for ${example.host} (${example.description})`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -161,7 +143,7 @@
|
||||
<div class="card-content">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="host" use:tooltip={'Enter hostname:port (e.g., google.com:443)'}>
|
||||
<label for="host">
|
||||
Host:Port
|
||||
<input
|
||||
id="host"
|
||||
@@ -169,8 +151,9 @@
|
||||
bind:value={host}
|
||||
placeholder="google.com:443"
|
||||
class:invalid={host && !isInputValid}
|
||||
use:tooltip={'Enter hostname:port (e.g., google.com:443)'}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) analyzeCertificate();
|
||||
}}
|
||||
/>
|
||||
@@ -188,7 +171,7 @@
|
||||
type="checkbox"
|
||||
bind:checked={useCustomServername}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) analyzeCertificate();
|
||||
}}
|
||||
/>
|
||||
@@ -201,7 +184,7 @@
|
||||
placeholder="example.com"
|
||||
use:tooltip={'Custom servername for SNI (Server Name Indication)'}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) analyzeCertificate();
|
||||
}}
|
||||
/>
|
||||
@@ -210,8 +193,8 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={analyzeCertificate} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<button class="lookup-btn" onclick={analyzeCertificate} disabled={diagnosticState.loading || !isInputValid}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
Analyzing Certificate...
|
||||
{:else}
|
||||
@@ -224,19 +207,19 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>Certificate Analysis Results</h3>
|
||||
<button class="copy-btn" onclick={copyCertificateInfo} disabled={copiedState}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
{copiedState ? 'Copied!' : 'Copy Certificate Info'}
|
||||
<button class="copy-btn" onclick={copyCertificateInfo} disabled={clipboard.isCopied()}>
|
||||
<Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Certificate Info'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Certificate Overview -->
|
||||
{#if results.peerCertificate}
|
||||
{@const cert = results.peerCertificate}
|
||||
{#if diagnosticState.results.peerCertificate}
|
||||
{@const cert = diagnosticState.results.peerCertificate}
|
||||
{@const expiryStatus = getExpiryStatus(cert)}
|
||||
|
||||
<div class="cert-overview">
|
||||
@@ -314,11 +297,11 @@
|
||||
{/if}
|
||||
|
||||
<!-- Certificate Chain -->
|
||||
{#if results.chain?.length > 0}
|
||||
{#if diagnosticState.results.chain?.length > 0}
|
||||
<div class="chain-section">
|
||||
<h4>Certificate Chain ({results.chain.length} certificates)</h4>
|
||||
<h4>Certificate Chain ({diagnosticState.results.chain.length} certificates)</h4>
|
||||
<div class="chain-list">
|
||||
{#each results.chain as chainCert, i (i)}
|
||||
{#each diagnosticState.results.chain as chainCert, i (i)}
|
||||
<div class="chain-item">
|
||||
<div class="chain-header">
|
||||
<span class="chain-level">Level {i}</span>
|
||||
@@ -335,26 +318,26 @@
|
||||
{/if}
|
||||
|
||||
<!-- Connection Details -->
|
||||
{#if results.protocol || results.cipher || results.alpnProtocol}
|
||||
{#if diagnosticState.results.protocol || diagnosticState.results.cipher || diagnosticState.results.alpnProtocol}
|
||||
<div class="connection-section">
|
||||
<h4>Connection Details</h4>
|
||||
<div class="detail-grid">
|
||||
{#if results.protocol}
|
||||
{#if diagnosticState.results.protocol}
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">TLS Version:</span>
|
||||
<span class="detail-value">{results.protocol}</span>
|
||||
<span class="detail-value">{diagnosticState.results.protocol}</span>
|
||||
</div>
|
||||
{/if}
|
||||
{#if results.cipher}
|
||||
{#if diagnosticState.results.cipher}
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">Cipher Suite:</span>
|
||||
<span class="detail-value">{results.cipher.name}</span>
|
||||
<span class="detail-value">{diagnosticState.results.cipher.name}</span>
|
||||
</div>
|
||||
{/if}
|
||||
{#if results.alpnProtocol}
|
||||
{#if diagnosticState.results.alpnProtocol}
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">ALPN Protocol:</span>
|
||||
<span class="detail-value">{results.alpnProtocol}</span>
|
||||
<span class="detail-value">{diagnosticState.results.alpnProtocol}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -364,19 +347,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Certificate Analysis Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Certificate Analysis Failed" error={diagnosticState.error} />
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let hostname = $state('example.com');
|
||||
let port = $state('443');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const examplesList = [
|
||||
{ host: 'github.com', port: '443', description: 'GitHub cipher support' },
|
||||
{ host: 'cloudflare.com', port: '443', description: 'Cloudflare cipher support' },
|
||||
{ host: 'google.com', port: '443', description: 'Google cipher support' },
|
||||
];
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
async function testCiphers() {
|
||||
if (!hostname?.trim()) {
|
||||
error = 'Please enter a hostname';
|
||||
diagnosticState.setError('Please enter a hostname');
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/tls', {
|
||||
@@ -43,25 +40,19 @@
|
||||
throw new Error(data.message || 'Failed to test cipher presets');
|
||||
}
|
||||
|
||||
results = data;
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err) {
|
||||
error = err instanceof Error ? err.message : 'An error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'An error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
hostname = example.host;
|
||||
port = example.port;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
testCiphers();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getPresetScore(preset: any): number {
|
||||
if (!preset.supported) return 0;
|
||||
const total = preset.ciphers.length;
|
||||
@@ -88,27 +79,14 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Quick Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Test cipher presets for ${example.host}:${example.port}`}
|
||||
>
|
||||
<h5>{example.host}:{example.port}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
getLabel={(ex) => `${ex.host}:${ex.port}`}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Test cipher presets for ${ex.host}:${ex.port}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -124,8 +102,8 @@
|
||||
type="text"
|
||||
bind:value={hostname}
|
||||
placeholder="example.com"
|
||||
disabled={loading}
|
||||
onchange={() => clearExampleSelection()}
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && testCiphers()}
|
||||
class="flex-grow"
|
||||
/>
|
||||
@@ -134,13 +112,13 @@
|
||||
type="text"
|
||||
bind:value={port}
|
||||
placeholder="443"
|
||||
disabled={loading}
|
||||
onchange={() => clearExampleSelection()}
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && testCiphers()}
|
||||
class="port-input"
|
||||
/>
|
||||
<button onclick={testCiphers} disabled={loading} class="primary">
|
||||
{#if loading}
|
||||
<button onclick={testCiphers} disabled={diagnosticState.loading} class="primary">
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Testing...
|
||||
{:else}
|
||||
@@ -153,21 +131,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Cipher Test Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Cipher Test Failed" error={diagnosticState.error} />
|
||||
|
||||
{#if loading}
|
||||
{#if diagnosticState.loading}
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="loading-state">
|
||||
@@ -181,7 +147,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>Cipher Presets Results</h3>
|
||||
@@ -189,7 +155,7 @@
|
||||
<div class="card-content">
|
||||
<div class="results-section">
|
||||
<div class="presets-grid">
|
||||
{#each results.presets as preset (preset.name)}
|
||||
{#each diagnosticState.results.presets as preset (preset.name)}
|
||||
<div class="preset-card {preset.level}" class:supported={preset.supported}>
|
||||
<div class="preset-header">
|
||||
<div class="preset-title">
|
||||
@@ -207,15 +173,11 @@
|
||||
|
||||
<div class="preset-stats">
|
||||
<div class="stat">
|
||||
<span class="stat-label" use:tooltip={'Number of supported ciphers out of total tested'}
|
||||
>Supported:</span
|
||||
>
|
||||
<span class="stat-label">Supported:</span>
|
||||
<span class="stat-value">{preset.supportedCiphers.length}/{preset.ciphers.length}</span>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<span class="stat-label" use:tooltip={'Percentage of ciphers in this preset that are supported'}
|
||||
>Coverage:</span
|
||||
>
|
||||
<span class="stat-label">Coverage:</span>
|
||||
<span class="stat-value">{getPresetScore(preset)}%</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -228,18 +190,10 @@
|
||||
|
||||
{#if preset.protocols}
|
||||
<div class="protocols-section">
|
||||
<span class="protocols-label" use:tooltip={'TLS/SSL protocol versions supported by this preset'}
|
||||
>Protocols:</span
|
||||
>
|
||||
<span class="protocols-label">Protocols:</span>
|
||||
<div class="protocols-list">
|
||||
{#each preset.protocols as protocol (protocol.name)}
|
||||
<span
|
||||
class="protocol-badge"
|
||||
class:supported={protocol.supported}
|
||||
use:tooltip={protocol.supported
|
||||
? 'Supported protocol version'
|
||||
: 'Unsupported protocol version'}
|
||||
>
|
||||
<span class="protocol-badge" class:supported={protocol.supported}>
|
||||
{protocol.name}
|
||||
</span>
|
||||
{/each}
|
||||
@@ -285,25 +239,25 @@
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
{#if results.summary}
|
||||
{#if diagnosticState.results.summary}
|
||||
<div class="summary-section">
|
||||
<h3>Overall Assessment</h3>
|
||||
<div class="summary-content">
|
||||
<div class="summary-score">
|
||||
<div class="score-circle grade-{results.summary.overallGrade.toLowerCase()}">
|
||||
{results.summary.overallGrade}
|
||||
<div class="score-circle grade-{diagnosticState.results.summary.overallGrade.toLowerCase()}">
|
||||
{diagnosticState.results.summary.overallGrade}
|
||||
</div>
|
||||
<div class="score-details">
|
||||
<h4>{results.summary.rating}</h4>
|
||||
<p>{results.summary.description}</p>
|
||||
<h4>{diagnosticState.results.summary.rating}</h4>
|
||||
<p>{diagnosticState.results.summary.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if results.summary.recommendations && results.summary.recommendations.length > 0}
|
||||
{#if diagnosticState.results.summary.recommendations && diagnosticState.results.summary.recommendations.length > 0}
|
||||
<div class="recommendations">
|
||||
<h4>Recommendations</h4>
|
||||
<ul>
|
||||
{#each results.summary.recommendations as rec (rec)}
|
||||
{#each diagnosticState.results.summary.recommendations as rec (rec)}
|
||||
<li>{rec}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<script lang="ts">
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import { ctLogContent as content } from '$lib/content/ct-log-search';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
@@ -31,7 +34,7 @@
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
const examples = [
|
||||
const examplesList = [
|
||||
{ domain: 'as93.net', desc: 'Domain hosting multiple apps' },
|
||||
{ domain: 'github.com', desc: 'Popular tech platform with modern certificate infrastructure' },
|
||||
{ domain: 'google.com', desc: 'Shows historic DigiNotar breach certificate from 2011' },
|
||||
@@ -39,6 +42,7 @@
|
||||
{ domain: 'wikipedia.org', desc: 'Example of wildcard certificate usage' },
|
||||
{ domain: 'twitter.com', desc: 'Shows certificate lifecycle and expiration tracking' },
|
||||
];
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
const statsConfig = [
|
||||
{
|
||||
@@ -87,28 +91,23 @@
|
||||
];
|
||||
|
||||
let domain = $state('');
|
||||
let loading = $state(false);
|
||||
let results = $state<CTLogResponse | null>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
const diagnosticState = useDiagnosticState<CTLogResponse>();
|
||||
const clipboard = useClipboard();
|
||||
let expandedCert = $state<number | null>(null);
|
||||
let selectedExample = $state<string | null>(null);
|
||||
|
||||
async function loadExample(exampleDomain: string) {
|
||||
domain = exampleDomain;
|
||||
selectedExample = exampleDomain;
|
||||
async function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
domain = example.domain;
|
||||
examples.select(index);
|
||||
await searchCTLogs();
|
||||
}
|
||||
|
||||
async function searchCTLogs() {
|
||||
if (!domain.trim()) {
|
||||
error = 'Please enter a domain name';
|
||||
diagnosticState.setError('Please enter a domain name');
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/ct-log-search', {
|
||||
@@ -122,30 +121,26 @@
|
||||
throw new Error(errorData.message || 'Search failed');
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
diagnosticState.setResults(await response.json());
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'Unknown error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results) return;
|
||||
if (!diagnosticState.results) return;
|
||||
|
||||
let text = `Certificate Transparency Log Search\nDomain: ${results.domain}\nGenerated at: ${results.timestamp}\n\n`;
|
||||
text += `Total Certificates: ${results.totalCertificates}\n`;
|
||||
text += `Valid Certificates: ${results.validCertificates}\n`;
|
||||
text += `Expiring Soon (30 days): ${results.expiringSoon}\n`;
|
||||
text += `Wildcard Certificates: ${results.wildcardCertificates}\n\n`;
|
||||
text += `Discovered Hostnames (${results.discoveredHostnames.length}):\n`;
|
||||
results.discoveredHostnames.forEach((h) => (text += ` - ${h}\n`));
|
||||
let text = `Certificate Transparency Log Search\nDomain: ${diagnosticState.results.domain}\nGenerated at: ${diagnosticState.results.timestamp}\n\n`;
|
||||
text += `Total Certificates: ${diagnosticState.results.totalCertificates}\n`;
|
||||
text += `Valid Certificates: ${diagnosticState.results.validCertificates}\n`;
|
||||
text += `Expiring Soon (30 days): ${diagnosticState.results.expiringSoon}\n`;
|
||||
text += `Wildcard Certificates: ${diagnosticState.results.wildcardCertificates}\n\n`;
|
||||
text += `Discovered Hostnames (${diagnosticState.results.discoveredHostnames.length}):\n`;
|
||||
diagnosticState.results.discoveredHostnames.forEach((h) => (text += ` - ${h}\n`));
|
||||
text += `\nTop Issuers:\n`;
|
||||
results.issuers.forEach((i) => (text += ` - ${i.name}: ${i.count} certificates\n`));
|
||||
diagnosticState.results.issuers.forEach((i) => (text += ` - ${i.name}: ${i.count} certificates\n`));
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
clipboard.copy(text);
|
||||
}
|
||||
|
||||
function toggleCert(id: number) {
|
||||
@@ -186,41 +181,31 @@
|
||||
bind:value={domain}
|
||||
placeholder="example.com"
|
||||
onkeydown={(e) => e.key === 'Enter' && searchCTLogs()}
|
||||
disabled={loading}
|
||||
disabled={diagnosticState.loading}
|
||||
/>
|
||||
<button class="lookup-btn" onclick={searchCTLogs} disabled={loading}>
|
||||
<Icon name={loading ? 'loader' : 'search'} size="sm" animate={loading ? 'spin' : undefined} />
|
||||
{loading ? 'Searching...' : 'Search CT Logs'}
|
||||
<button class="lookup-btn" onclick={searchCTLogs} disabled={diagnosticState.loading}>
|
||||
<Icon
|
||||
name={diagnosticState.loading ? 'loader' : 'search'}
|
||||
size="sm"
|
||||
animate={diagnosticState.loading ? 'spin' : undefined}
|
||||
/>
|
||||
{diagnosticState.loading ? 'Searching...' : 'Search CT Logs'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Quick Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="sm" />
|
||||
<h4>Quick Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example (example.domain)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExample === example.domain}
|
||||
onclick={() => loadExample(example.domain)}
|
||||
type="button"
|
||||
>
|
||||
<h5>{example.domain}</h5>
|
||||
<p>{example.desc}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
getLabel={(ex) => ex.domain}
|
||||
getDescription={(ex) => ex.desc}
|
||||
/>
|
||||
|
||||
<!-- Loading -->
|
||||
{#if loading}
|
||||
{#if diagnosticState.loading}
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="loading-state">
|
||||
@@ -234,26 +219,16 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Error -->
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-message">
|
||||
<Icon name="alert-circle" size="md" />
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="CT Log Search Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>CT Log Results for {results.domain}</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
<h3>CT Log Results for {diagnosticState.results.domain}</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={clipboard.isCopied()}>
|
||||
<Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
@@ -262,7 +237,7 @@
|
||||
<div class="status-item info">
|
||||
<Icon name="file" size="md" />
|
||||
<div>
|
||||
<h4>{results.totalCertificates} Total Certificates</h4>
|
||||
<h4>{diagnosticState.results.totalCertificates} Total Certificates</h4>
|
||||
<p>Found in Certificate Transparency logs</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -278,8 +253,8 @@
|
||||
</h4>
|
||||
<div class="stat-value {stat.valueClass}">
|
||||
{stat.isArray
|
||||
? (results[stat.key as keyof CTLogResponse] as any[]).length
|
||||
: results[stat.key as keyof CTLogResponse]}
|
||||
? (diagnosticState.results[stat.key as keyof CTLogResponse] as any[]).length
|
||||
: diagnosticState.results[stat.key as keyof CTLogResponse]}
|
||||
</div>
|
||||
<p class="stat-label">{stat.desc}</p>
|
||||
</div>
|
||||
@@ -287,14 +262,14 @@
|
||||
</div>
|
||||
|
||||
<!-- Discovered Hostnames -->
|
||||
{#if results.discoveredHostnames.length > 0}
|
||||
{#if diagnosticState.results.discoveredHostnames.length > 0}
|
||||
<div class="subsection">
|
||||
<h4>
|
||||
<Icon name="list" size="sm" />
|
||||
Discovered Hostnames ({results.discoveredHostnames.length})
|
||||
Discovered Hostnames ({diagnosticState.results.discoveredHostnames.length})
|
||||
</h4>
|
||||
<div class="hostname-list">
|
||||
{#each results.discoveredHostnames.slice(0, 50) as hostname (hostname)}
|
||||
{#each diagnosticState.results.discoveredHostnames.slice(0, 50) as hostname (hostname)}
|
||||
<span class="hostname-tag {hostname.startsWith('*') ? 'wildcard' : ''}">
|
||||
{#if hostname.startsWith('*')}
|
||||
<Icon name="asterisk" size="xs" />
|
||||
@@ -302,9 +277,9 @@
|
||||
{hostname}
|
||||
</span>
|
||||
{/each}
|
||||
{#if results.discoveredHostnames.length > 50}
|
||||
{#if diagnosticState.results.discoveredHostnames.length > 50}
|
||||
<span class="hostname-tag muted">
|
||||
+{results.discoveredHostnames.length - 50} more
|
||||
+{diagnosticState.results.discoveredHostnames.length - 50} more
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -312,14 +287,14 @@
|
||||
{/if}
|
||||
|
||||
<!-- Top Issuers -->
|
||||
{#if results.issuers.length > 0}
|
||||
{#if diagnosticState.results.issuers.length > 0}
|
||||
<div class="subsection">
|
||||
<h4>
|
||||
<Icon name="building" size="sm" />
|
||||
Certificate Issuers ({results.issuers.length})
|
||||
Certificate Issuers ({diagnosticState.results.issuers.length})
|
||||
</h4>
|
||||
<div class="issuer-list">
|
||||
{#each results.issuers.slice(0, 10) as issuer (issuer.name)}
|
||||
{#each diagnosticState.results.issuers.slice(0, 10) as issuer (issuer.name)}
|
||||
<div class="issuer-item">
|
||||
<span class="issuer-name">{issuer.name}</span>
|
||||
<span class="issuer-count">{issuer.count}</span>
|
||||
@@ -333,10 +308,10 @@
|
||||
<div class="subsection">
|
||||
<h4>
|
||||
<Icon name="file" size="sm" />
|
||||
Certificates ({results.certificates.length})
|
||||
Certificates ({diagnosticState.results.certificates.length})
|
||||
</h4>
|
||||
<div class="cert-list">
|
||||
{#each results.certificates.slice(0, 20) as cert (cert.id)}
|
||||
{#each diagnosticState.results.certificates.slice(0, 20) as cert (cert.id)}
|
||||
<div class="cert-item">
|
||||
<div
|
||||
class="cert-header"
|
||||
@@ -393,9 +368,9 @@
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
{#if results.certificates.length > 20}
|
||||
{#if diagnosticState.results.certificates.length > 20}
|
||||
<div class="cert-item muted-text">
|
||||
Showing first 20 of {results.certificates.length} certificates
|
||||
Showing first 20 of {diagnosticState.results.certificates.length} certificates
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -462,14 +437,6 @@
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.error-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
color: var(--color-error);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import { tlsHandshakeContent } from '$lib/content/tls-handshake';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
@@ -32,13 +34,9 @@
|
||||
|
||||
let hostname = $state('google.com');
|
||||
let port = $state(443);
|
||||
let loading = $state(false);
|
||||
let results = $state<TLSHandshakeResponse | null>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<TLSHandshakeResponse>();
|
||||
const clipboard = useClipboard();
|
||||
const examplesList = [
|
||||
{ hostname: 'as93.net', port: 443, description: 'Alicia Sykes' },
|
||||
{ hostname: 'apple.com', port: 443, description: 'Apple (Fast - 28ms)' },
|
||||
{ hostname: 'cloudflare.com', port: 443, description: 'Cloudflare' },
|
||||
@@ -46,11 +44,10 @@
|
||||
{ hostname: 'baidu.com', port: 443, description: 'Baidu (China - TLS 1.2)' },
|
||||
{ hostname: 'zoom.us', port: 443, description: 'Zoom' },
|
||||
];
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
async function analyzeHandshake() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/tls-handshake', {
|
||||
@@ -64,51 +61,43 @@
|
||||
throw new Error(errorData.message || `Analysis failed: ${response.status}`);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
diagnosticState.setResults(await response.json());
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'Unknown error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
hostname = example.hostname;
|
||||
port = example.port;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
analyzeHandshake();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results) return;
|
||||
if (!diagnosticState.results) return;
|
||||
|
||||
let text = `TLS Handshake Analysis for ${results.hostname}:${results.port}\n`;
|
||||
text += `Generated at: ${results.timestamp}\n\n`;
|
||||
text += `Total Time: ${results.totalTime}ms\n`;
|
||||
text += `TLS Version: ${results.tlsVersion}\n`;
|
||||
text += `Cipher Suite: ${results.cipherSuite}\n`;
|
||||
if (results.alpnProtocol) text += `ALPN Protocol: ${results.alpnProtocol}\n`;
|
||||
let text = `TLS Handshake Analysis for ${diagnosticState.results.hostname}:${diagnosticState.results.port}\n`;
|
||||
text += `Generated at: ${diagnosticState.results.timestamp}\n\n`;
|
||||
text += `Total Time: ${diagnosticState.results.totalTime}ms\n`;
|
||||
text += `TLS Version: ${diagnosticState.results.tlsVersion}\n`;
|
||||
text += `Cipher Suite: ${diagnosticState.results.cipherSuite}\n`;
|
||||
if (diagnosticState.results.alpnProtocol) text += `ALPN Protocol: ${diagnosticState.results.alpnProtocol}\n`;
|
||||
|
||||
text += `\nHandshake Phases:\n`;
|
||||
results.phases.forEach((phase) => {
|
||||
diagnosticState.results.phases.forEach((phase) => {
|
||||
text += ` ${phase.phase}: ${phase.duration}ms (at ${phase.timestamp}ms)\n`;
|
||||
});
|
||||
|
||||
if (results.certificateInfo) {
|
||||
if (diagnosticState.results.certificateInfo) {
|
||||
text += `\nCertificate:\n`;
|
||||
text += ` Subject: ${results.certificateInfo.subject}\n`;
|
||||
text += ` Issuer: ${results.certificateInfo.issuer}\n`;
|
||||
text += ` Valid From: ${results.certificateInfo.validFrom}\n`;
|
||||
text += ` Valid To: ${results.certificateInfo.validTo}\n`;
|
||||
text += ` Subject: ${diagnosticState.results.certificateInfo.subject}\n`;
|
||||
text += ` Issuer: ${diagnosticState.results.certificateInfo.issuer}\n`;
|
||||
text += ` Valid From: ${diagnosticState.results.certificateInfo.validFrom}\n`;
|
||||
text += ` Valid To: ${diagnosticState.results.certificateInfo.validTo}\n`;
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
clipboard.copy(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -119,27 +108,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Example Hosts</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Analyze ${example.hostname}`}
|
||||
>
|
||||
<h5>{example.hostname}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="Example Hosts"
|
||||
getLabel={(ex) => ex.hostname}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Analyze ${ex.hostname}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -149,24 +126,24 @@
|
||||
<div class="card-content">
|
||||
<div class="lookup-form">
|
||||
<div class="input-row">
|
||||
<label for="hostname" use:tooltip={'Enter hostname (e.g., google.com)'}> Hostname </label>
|
||||
<label for="hostname"> Hostname </label>
|
||||
<input
|
||||
id="hostname"
|
||||
type="text"
|
||||
bind:value={hostname}
|
||||
placeholder="google.com"
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (hostname.trim()) analyzeHandshake();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div class="port-row">
|
||||
<label for="port" use:tooltip={'Port number (default: 443)'}> Port </label>
|
||||
<label for="port"> Port </label>
|
||||
<input id="port" type="number" bind:value={port} placeholder="443" min="1" max="65535" />
|
||||
</div>
|
||||
<button class="lookup-btn" onclick={analyzeHandshake} disabled={loading || !hostname.trim()}>
|
||||
{#if loading}
|
||||
<button class="lookup-btn" onclick={analyzeHandshake} disabled={diagnosticState.loading || !hostname.trim()}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Analyzing...
|
||||
{:else}
|
||||
@@ -179,15 +156,15 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>
|
||||
Handshake Results for {results.hostname}:{results.port}
|
||||
Handshake Results for {diagnosticState.results.hostname}:{diagnosticState.results.port}
|
||||
</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
<button class="copy-btn" onclick={copyResults} disabled={clipboard.isCopied()}>
|
||||
<Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
@@ -200,29 +177,29 @@
|
||||
<Icon name="clock" size="sm" />
|
||||
<div class="info-content">
|
||||
<span class="info-label">Total Time</span>
|
||||
<span class="info-value highlight">{results.totalTime}ms</span>
|
||||
<span class="info-value highlight">{diagnosticState.results.totalTime}ms</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<Icon name="shield" size="sm" />
|
||||
<div class="info-content">
|
||||
<span class="info-label">TLS Version</span>
|
||||
<span class="info-value">{results.tlsVersion}</span>
|
||||
<span class="info-value">{diagnosticState.results.tlsVersion}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<Icon name="key" size="sm" />
|
||||
<div class="info-content">
|
||||
<span class="info-label">Cipher Suite</span>
|
||||
<span class="info-value cipher">{results.cipherSuite}</span>
|
||||
<span class="info-value cipher">{diagnosticState.results.cipherSuite}</span>
|
||||
</div>
|
||||
</div>
|
||||
{#if results.alpnProtocol}
|
||||
{#if diagnosticState.results.alpnProtocol}
|
||||
<div class="info-item">
|
||||
<Icon name="layers" size="sm" />
|
||||
<div class="info-content">
|
||||
<span class="info-label">ALPN Protocol</span>
|
||||
<span class="info-value">{results.alpnProtocol}</span>
|
||||
<span class="info-value">{diagnosticState.results.alpnProtocol}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -230,7 +207,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Certificate Card -->
|
||||
{#if results.certificateInfo}
|
||||
{#if diagnosticState.results.certificateInfo}
|
||||
<div class="result-card">
|
||||
<h4>Certificate Information</h4>
|
||||
<div class="info-list">
|
||||
@@ -238,14 +215,14 @@
|
||||
<Icon name="file" size="sm" />
|
||||
<div class="info-content">
|
||||
<span class="info-label">Subject</span>
|
||||
<span class="info-value">{results.certificateInfo.subject}</span>
|
||||
<span class="info-value">{diagnosticState.results.certificateInfo.subject}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<Icon name="building" size="sm" />
|
||||
<div class="info-content">
|
||||
<span class="info-label">Issuer</span>
|
||||
<span class="info-value">{results.certificateInfo.issuer}</span>
|
||||
<span class="info-value">{diagnosticState.results.certificateInfo.issuer}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
@@ -253,17 +230,17 @@
|
||||
<div class="info-content">
|
||||
<span class="info-label">Valid</span>
|
||||
<span class="info-value cert-date">
|
||||
{new Date(results.certificateInfo.validFrom).toLocaleDateString()} →
|
||||
{new Date(results.certificateInfo.validTo).toLocaleDateString()}
|
||||
{new Date(diagnosticState.results.certificateInfo.validFrom).toLocaleDateString()} →
|
||||
{new Date(diagnosticState.results.certificateInfo.validTo).toLocaleDateString()}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{#if results.certificateInfo.san}
|
||||
{#if diagnosticState.results.certificateInfo.san}
|
||||
<div class="info-item">
|
||||
<Icon name="globe" size="sm" />
|
||||
<div class="info-content">
|
||||
<span class="info-label">SANs</span>
|
||||
<span class="info-value">{results.certificateInfo.san.length} domains</span>
|
||||
<span class="info-value">{diagnosticState.results.certificateInfo.san.length} domains</span>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -275,7 +252,7 @@
|
||||
<div class="result-card timeline-card">
|
||||
<h4>Handshake Timeline</h4>
|
||||
<div class="timeline">
|
||||
{#each results.phases as phase (phase.phase)}
|
||||
{#each diagnosticState.results.phases as phase (phase.phase)}
|
||||
<div class="timeline-item">
|
||||
<div class="timeline-marker"></div>
|
||||
<div class="timeline-content">
|
||||
@@ -301,19 +278,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>Analysis Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="Analysis Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let hostname = $state('example.com');
|
||||
let port = $state('443');
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const examplesList = [
|
||||
{ host: 'cloudflare.com', port: '443', description: 'Cloudflare - OCSP stapling enabled' },
|
||||
{ host: 'www.digicert.com', port: '443', description: 'DigiCert - OCSP stapling enabled' },
|
||||
{ host: 'github.com', port: '443', description: 'GitHub - OCSP stapling disabled' },
|
||||
];
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
async function checkOCSP() {
|
||||
if (!hostname?.trim()) {
|
||||
error = 'Please enter a hostname';
|
||||
diagnosticState.setError('Please enter a hostname');
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/tls', {
|
||||
@@ -43,25 +40,19 @@
|
||||
throw new Error(data.message || 'Failed to check OCSP stapling');
|
||||
}
|
||||
|
||||
results = data;
|
||||
diagnosticState.setResults(data);
|
||||
} catch (err) {
|
||||
error = err instanceof Error ? err.message : 'An error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'An error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
hostname = example.host;
|
||||
port = example.port;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
checkOCSP();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function formatDate(dateStr: string): string {
|
||||
const date = new Date(dateStr);
|
||||
return date.toLocaleString();
|
||||
@@ -75,27 +66,14 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>Quick Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Check OCSP stapling for ${example.host}:${example.port}`}
|
||||
>
|
||||
<h5>{example.host}:{example.port}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
getLabel={(ex) => `${ex.host}:${ex.port}`}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Check OCSP stapling for ${ex.host}:${ex.port}`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -111,8 +89,8 @@
|
||||
type="text"
|
||||
bind:value={hostname}
|
||||
placeholder="example.com"
|
||||
disabled={loading}
|
||||
onchange={() => clearExampleSelection()}
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && checkOCSP()}
|
||||
class="flex-grow"
|
||||
/>
|
||||
@@ -121,13 +99,13 @@
|
||||
type="text"
|
||||
bind:value={port}
|
||||
placeholder="443"
|
||||
disabled={loading}
|
||||
onchange={() => clearExampleSelection()}
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && checkOCSP()}
|
||||
class="port-input"
|
||||
/>
|
||||
<button onclick={checkOCSP} disabled={loading} class="primary">
|
||||
{#if loading}
|
||||
<button onclick={checkOCSP} disabled={diagnosticState.loading} class="primary">
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Checking...
|
||||
{:else}
|
||||
@@ -140,21 +118,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>OCSP Check Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="OCSP Check Failed" error={diagnosticState.error} />
|
||||
|
||||
{#if loading}
|
||||
{#if diagnosticState.loading}
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="loading-state">
|
||||
@@ -168,7 +134,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>OCSP Stapling Results</h3>
|
||||
@@ -181,7 +147,7 @@
|
||||
<h3>OCSP Stapling Status</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
{#if results.staplingEnabled}
|
||||
{#if diagnosticState.results.staplingEnabled}
|
||||
<div class="status-card enabled">
|
||||
<Icon name="check-circle" size="lg" />
|
||||
<div class="status-content">
|
||||
@@ -202,7 +168,7 @@
|
||||
</div>
|
||||
|
||||
<!-- OCSP Response Details Section -->
|
||||
{#if results.staplingEnabled && results.ocspResponse}
|
||||
{#if diagnosticState.results.staplingEnabled && diagnosticState.results.ocspResponse}
|
||||
<div class="card response-section">
|
||||
<div class="card-header">
|
||||
<h3>OCSP Response Details</h3>
|
||||
@@ -210,55 +176,51 @@
|
||||
<div class="card-content">
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-label" use:tooltip={'Current status of the certificate according to OCSP'}>
|
||||
Certificate Status
|
||||
</div>
|
||||
<div class="stat-value status-{results.ocspResponse.certStatus.toLowerCase()}">
|
||||
<div class="stat-label">Certificate Status</div>
|
||||
<div class="stat-value status-{diagnosticState.results.ocspResponse.certStatus.toLowerCase()}">
|
||||
<Icon
|
||||
name={results.ocspResponse.certStatus.toLowerCase() === 'good'
|
||||
name={diagnosticState.results.ocspResponse.certStatus.toLowerCase() === 'good'
|
||||
? 'check-circle'
|
||||
: 'alert-circle'}
|
||||
size="sm"
|
||||
/>
|
||||
{results.ocspResponse.certStatus}
|
||||
{diagnosticState.results.ocspResponse.certStatus}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-label" use:tooltip={'Status of the OCSP response itself'}>Response Status</div>
|
||||
<div class="stat-label">Response Status</div>
|
||||
<div class="stat-value">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
{results.ocspResponse.responseStatus}
|
||||
{diagnosticState.results.ocspResponse.responseStatus}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if results.ocspResponse.thisUpdate}
|
||||
{#if diagnosticState.results.ocspResponse.thisUpdate}
|
||||
<div class="stat-card">
|
||||
<div class="stat-label" use:tooltip={'When this OCSP response was issued'}>This Update</div>
|
||||
<div class="stat-value mono">{formatDate(results.ocspResponse.thisUpdate)}</div>
|
||||
<div class="stat-label">This Update</div>
|
||||
<div class="stat-value mono">{formatDate(diagnosticState.results.ocspResponse.thisUpdate)}</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results.ocspResponse.nextUpdate}
|
||||
{#if diagnosticState.results.ocspResponse.nextUpdate}
|
||||
<div class="stat-card">
|
||||
<div class="stat-label" use:tooltip={'When the next OCSP response will be available'}>
|
||||
Next Update
|
||||
</div>
|
||||
<div class="stat-value mono">{formatDate(results.ocspResponse.nextUpdate)}</div>
|
||||
<div class="stat-label">Next Update</div>
|
||||
<div class="stat-value mono">{formatDate(diagnosticState.results.ocspResponse.nextUpdate)}</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results.ocspResponse.producedAt}
|
||||
{#if diagnosticState.results.ocspResponse.producedAt}
|
||||
<div class="stat-card">
|
||||
<div class="stat-label" use:tooltip={'When the OCSP response was generated'}>Produced At</div>
|
||||
<div class="stat-value mono">{formatDate(results.ocspResponse.producedAt)}</div>
|
||||
<div class="stat-label">Produced At</div>
|
||||
<div class="stat-value mono">{formatDate(diagnosticState.results.ocspResponse.producedAt)}</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results.ocspResponse.responderUrl}
|
||||
{#if diagnosticState.results.ocspResponse.responderUrl}
|
||||
<div class="stat-card full-width">
|
||||
<div class="stat-label" use:tooltip={'URL of the OCSP responder service'}>Responder URL</div>
|
||||
<div class="stat-value mono">{results.ocspResponse.responderUrl}</div>
|
||||
<div class="stat-label">Responder URL</div>
|
||||
<div class="stat-value mono">{diagnosticState.results.ocspResponse.responderUrl}</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -266,7 +228,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Response Validity Section -->
|
||||
{#if results.ocspResponse.validity}
|
||||
{#if diagnosticState.results.ocspResponse.validity}
|
||||
<div class="card validity-section">
|
||||
<div class="card-header">
|
||||
<h3>Response Validity</h3>
|
||||
@@ -275,34 +237,42 @@
|
||||
<div class="validity-info">
|
||||
<div class="validity-stats">
|
||||
<div class="stat-card">
|
||||
<div class="stat-label" use:tooltip={'How long this OCSP response is valid for'}>Valid For</div>
|
||||
<div class="stat-value">{results.ocspResponse.validity.validFor}</div>
|
||||
<div class="stat-label">Valid For</div>
|
||||
<div class="stat-value">{diagnosticState.results.ocspResponse.validity.validFor}</div>
|
||||
</div>
|
||||
|
||||
{#if results.ocspResponse.validity.expiresIn}
|
||||
{#if diagnosticState.results.ocspResponse.validity.expiresIn}
|
||||
<div class="stat-card">
|
||||
<div class="stat-label" use:tooltip={'Time remaining until this OCSP response expires'}>
|
||||
Expires In
|
||||
</div>
|
||||
<div class="stat-value" class:expiring={results.ocspResponse.validity.expiringSoon}>
|
||||
<div class="stat-label">Expires In</div>
|
||||
<div
|
||||
class="stat-value"
|
||||
class:expiring={diagnosticState.results.ocspResponse.validity.expiringSoon}
|
||||
>
|
||||
<Icon
|
||||
name={results.ocspResponse.validity.expiringSoon ? 'alert-triangle' : 'check-circle'}
|
||||
name={diagnosticState.results.ocspResponse.validity.expiringSoon
|
||||
? 'alert-triangle'
|
||||
: 'check-circle'}
|
||||
size="sm"
|
||||
/>
|
||||
{results.ocspResponse.validity.expiresIn}
|
||||
{diagnosticState.results.ocspResponse.validity.expiresIn}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if results.ocspResponse.validity.percentage !== undefined}
|
||||
{#if diagnosticState.results.ocspResponse.validity.percentage !== undefined}
|
||||
<div class="validity-progress">
|
||||
<div class="progress-header">
|
||||
<span class="progress-label">Validity Period Progress</span>
|
||||
<span class="progress-percentage">{results.ocspResponse.validity.percentage}%</span>
|
||||
<span class="progress-percentage"
|
||||
>{diagnosticState.results.ocspResponse.validity.percentage}%</span
|
||||
>
|
||||
</div>
|
||||
<div class="progress-bar">
|
||||
<div class="progress-fill" style="width: {results.ocspResponse.validity.percentage}%"></div>
|
||||
<div
|
||||
class="progress-fill"
|
||||
style="width: {diagnosticState.results.ocspResponse.validity.percentage}%"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -313,7 +283,7 @@
|
||||
{/if}
|
||||
|
||||
<!-- Certificate Information Section -->
|
||||
{#if results.certificate}
|
||||
{#if diagnosticState.results.certificate}
|
||||
<div class="card certificate-section">
|
||||
<div class="card-header">
|
||||
<h3>Certificate Information</h3>
|
||||
@@ -321,22 +291,20 @@
|
||||
<div class="card-content">
|
||||
<div class="cert-details">
|
||||
<div class="cert-item">
|
||||
<div class="cert-label" use:tooltip={'Certificate subject (who the certificate was issued to)'}>
|
||||
Subject
|
||||
</div>
|
||||
<div class="cert-value mono">{results.certificate.subject}</div>
|
||||
<div class="cert-label">Subject</div>
|
||||
<div class="cert-value mono">{diagnosticState.results.certificate.subject}</div>
|
||||
</div>
|
||||
|
||||
<div class="cert-item">
|
||||
<div class="cert-label" use:tooltip={'Certificate issuer (who signed the certificate)'}>Issuer</div>
|
||||
<div class="cert-value mono">{results.certificate.issuer}</div>
|
||||
<div class="cert-label">Issuer</div>
|
||||
<div class="cert-value mono">{diagnosticState.results.certificate.issuer}</div>
|
||||
</div>
|
||||
|
||||
{#if results.certificate.ocspUrls && results.certificate.ocspUrls.length > 0}
|
||||
{#if diagnosticState.results.certificate.ocspUrls && diagnosticState.results.certificate.ocspUrls.length > 0}
|
||||
<div class="cert-item">
|
||||
<div class="cert-label" use:tooltip={'OCSP responder URLs from the certificate'}>OCSP URLs</div>
|
||||
<div class="cert-label">OCSP URLs</div>
|
||||
<div class="cert-urls">
|
||||
{#each results.certificate.ocspUrls as url (url)}
|
||||
{#each diagnosticState.results.certificate.ocspUrls as url (url)}
|
||||
<div class="cert-url mono">{url}</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -348,14 +316,14 @@
|
||||
{/if}
|
||||
|
||||
<!-- Recommendations Section -->
|
||||
{#if results.recommendations && results.recommendations.length > 0}
|
||||
{#if diagnosticState.results.recommendations && diagnosticState.results.recommendations.length > 0}
|
||||
<div class="card recommendations-section">
|
||||
<div class="card-header">
|
||||
<h3>Recommendations</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="recommendations-list">
|
||||
{#each results.recommendations as rec (rec)}
|
||||
{#each diagnosticState.results.recommendations as rec (rec)}
|
||||
<div class="recommendation-item">
|
||||
<Icon name="alert-triangle" size="sm" />
|
||||
<span>{rec}</span>
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useDiagnosticState, useClipboard, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let host = $state('google.com:443');
|
||||
let servername = $state('');
|
||||
let useCustomServername = $state(false);
|
||||
let loading = $state(false);
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const examples = [
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const clipboard = useClipboard();
|
||||
const examplesList = [
|
||||
{ host: 'google.com:443', description: 'Google TLS version support' },
|
||||
{ host: 'github.com:443', description: 'GitHub TLS versions' },
|
||||
{ host: 'cloudflare.com:443', description: 'Cloudflare TLS support' },
|
||||
@@ -20,6 +18,7 @@
|
||||
{ host: 'amazon.com:443', description: 'Amazon TLS configuration' },
|
||||
{ host: 'facebook.com:443', description: 'Facebook TLS versions' },
|
||||
];
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
const tlsVersions = [
|
||||
{ version: 'TLSv1', name: 'TLS 1.0', deprecated: true },
|
||||
@@ -36,9 +35,7 @@
|
||||
});
|
||||
|
||||
async function probeTLSVersions() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
diagnosticState.startOperation();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/tls', {
|
||||
@@ -61,26 +58,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
diagnosticState.setResults(await response.json());
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
diagnosticState.setError(err instanceof Error ? err.message : 'Unknown error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: (typeof examples)[0], index: number) {
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
host = example.host;
|
||||
servername = '';
|
||||
useCustomServername = false;
|
||||
selectedExampleIndex = index;
|
||||
examples.select(index);
|
||||
probeTLSVersions();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getVersionStatus(
|
||||
version: string,
|
||||
supported: boolean,
|
||||
@@ -96,10 +87,10 @@
|
||||
}
|
||||
|
||||
function getOverallSecurity(): { level: string; class: string; icon: string; description: string } {
|
||||
if (!results)
|
||||
if (!diagnosticState.results)
|
||||
return { level: 'Unknown', class: 'secondary', icon: 'help-circle', description: 'No results available' };
|
||||
|
||||
const supportedVersions = results.supportedVersions || [];
|
||||
const supportedVersions = diagnosticState.results.supportedVersions || [];
|
||||
const hasDeprecated = supportedVersions.some((v: string) => v === 'TLSv1' || v === 'TLSv1.1');
|
||||
const hasModern = supportedVersions.includes('TLSv1.3');
|
||||
const hasSecure = supportedVersions.includes('TLSv1.2');
|
||||
@@ -130,14 +121,14 @@
|
||||
}
|
||||
|
||||
async function copyVersionsInfo() {
|
||||
if (!results) return;
|
||||
if (!diagnosticState.results) return;
|
||||
|
||||
let text = `TLS Versions Analysis for ${host}\n`;
|
||||
text += `Generated at: ${new Date().toISOString()}\n\n`;
|
||||
text += `Supported Versions (${results.totalSupported}):\n`;
|
||||
text += `Supported Versions (${diagnosticState.results.totalSupported}):\n`;
|
||||
|
||||
tlsVersions.forEach((tlsVer) => {
|
||||
const supported = results.supported[tlsVer.version];
|
||||
const supported = diagnosticState.results.supported[tlsVer.version];
|
||||
text += ` ${tlsVer.name} (${tlsVer.version}): ${supported ? 'Supported' : 'Not Supported'}`;
|
||||
if (supported && tlsVer.deprecated) {
|
||||
text += ' (DEPRECATED)';
|
||||
@@ -149,15 +140,13 @@
|
||||
text += `\nSecurity Level: ${security.level}\n`;
|
||||
text += `Description: ${security.description}\n`;
|
||||
|
||||
if (results.minVersion || results.maxVersion) {
|
||||
if (diagnosticState.results.minVersion || diagnosticState.results.maxVersion) {
|
||||
text += `\nVersion Range:\n`;
|
||||
text += ` Minimum: ${results.minVersion || 'Unknown'}\n`;
|
||||
text += ` Maximum: ${results.maxVersion || 'Unknown'}\n`;
|
||||
text += ` Minimum: ${diagnosticState.results.minVersion || 'Unknown'}\n`;
|
||||
text += ` Maximum: ${diagnosticState.results.maxVersion || 'Unknown'}\n`;
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
clipboard.copy(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -171,27 +160,15 @@
|
||||
</header>
|
||||
|
||||
<!-- Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="xs" />
|
||||
<h4>TLS Version Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i (i)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Probe TLS versions for ${example.host} (${example.description})`}
|
||||
>
|
||||
<h5>{example.host}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<ExamplesCard
|
||||
examples={examplesList}
|
||||
selectedIndex={examples.selectedIndex}
|
||||
onSelect={loadExample}
|
||||
title="TLS Version Examples"
|
||||
getLabel={(ex) => ex.host}
|
||||
getDescription={(ex) => ex.description}
|
||||
getTooltip={(ex) => `Probe TLS versions for ${ex.host} (${ex.description})`}
|
||||
/>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
@@ -201,7 +178,7 @@
|
||||
<div class="card-content">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="host" use:tooltip={'Enter hostname:port (e.g., google.com:443)'}>
|
||||
<label for="host">
|
||||
Host:Port
|
||||
<input
|
||||
id="host"
|
||||
@@ -210,7 +187,7 @@
|
||||
placeholder="google.com:443"
|
||||
class:invalid={host && !isInputValid}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) probeTLSVersions();
|
||||
}}
|
||||
/>
|
||||
@@ -228,7 +205,7 @@
|
||||
type="checkbox"
|
||||
bind:checked={useCustomServername}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) probeTLSVersions();
|
||||
}}
|
||||
/>
|
||||
@@ -239,9 +216,8 @@
|
||||
type="text"
|
||||
bind:value={servername}
|
||||
placeholder="example.com"
|
||||
use:tooltip={'Custom servername for SNI (Server Name Indication)'}
|
||||
onchange={() => {
|
||||
clearExampleSelection();
|
||||
examples.clear();
|
||||
if (isInputValid()) probeTLSVersions();
|
||||
}}
|
||||
/>
|
||||
@@ -250,9 +226,9 @@
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={probeTLSVersions} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" animate="spin" />
|
||||
<button class="lookup-btn" onclick={probeTLSVersions} disabled={diagnosticState.loading || !isInputValid}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Probing TLS Versions...
|
||||
{:else}
|
||||
<Icon name="search" size="sm" />
|
||||
@@ -264,18 +240,18 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if diagnosticState.results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>TLS Versions Probe Results</h3>
|
||||
<button class="copy-btn" onclick={copyVersionsInfo} disabled={copiedState}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
<button class="copy-btn" onclick={copyVersionsInfo} disabled={clipboard.isCopied()}>
|
||||
<Icon name={clipboard.isCopied() ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied() ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Security Overview -->
|
||||
{#if results.supported}
|
||||
{#if diagnosticState.results.supported}
|
||||
{@const security = getOverallSecurity()}
|
||||
|
||||
<div class="security-overview">
|
||||
@@ -290,7 +266,7 @@
|
||||
<div class="status-item success">
|
||||
<Icon name="check-square" size="sm" />
|
||||
<div>
|
||||
<span class="status-title">{results.totalSupported} Versions Supported</span>
|
||||
<span class="status-title">{diagnosticState.results.totalSupported} Versions Supported</span>
|
||||
<p class="status-desc">Out of {tlsVersions.length} tested</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -302,7 +278,7 @@
|
||||
<h4>TLS Version Support</h4>
|
||||
<div class="versions-grid">
|
||||
{#each tlsVersions as tlsVer (tlsVer.version)}
|
||||
{@const supported = results.supported[tlsVer.version]}
|
||||
{@const supported = diagnosticState.results.supported[tlsVer.version]}
|
||||
{@const status = getVersionStatus(tlsVer.version, supported, tlsVer.deprecated)}
|
||||
|
||||
<div class="version-item {status.class}">
|
||||
@@ -317,9 +293,9 @@
|
||||
<span class="version-status">{status.status}</span>
|
||||
</div>
|
||||
|
||||
{#if !supported && results.errors[tlsVer.version]}
|
||||
{#if !supported && diagnosticState.results.errors[tlsVer.version]}
|
||||
<div class="version-error">
|
||||
<span class="error-detail">{results.errors[tlsVer.version]}</span>
|
||||
<span class="error-detail">{diagnosticState.results.errors[tlsVer.version]}</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -335,17 +311,17 @@
|
||||
</div>
|
||||
|
||||
<!-- Version Range Summary -->
|
||||
{#if results.minVersion || results.maxVersion}
|
||||
{#if diagnosticState.results.minVersion || diagnosticState.results.maxVersion}
|
||||
<div class="range-section">
|
||||
<h4>Supported Version Range</h4>
|
||||
<div class="range-info">
|
||||
<div class="range-item">
|
||||
<span class="range-label">Minimum Version:</span>
|
||||
<span class="range-value mono">{results.minVersion || 'Unknown'}</span>
|
||||
<span class="range-value mono">{diagnosticState.results.minVersion || 'Unknown'}</span>
|
||||
</div>
|
||||
<div class="range-item">
|
||||
<span class="range-label">Maximum Version:</span>
|
||||
<span class="range-value mono">{results.maxVersion || 'Unknown'}</span>
|
||||
<span class="range-value mono">{diagnosticState.results.maxVersion || 'Unknown'}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -355,19 +331,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-content">
|
||||
<Icon name="alert-triangle" size="md" />
|
||||
<div>
|
||||
<strong>TLS Versions Probe Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<ErrorCard title="TLS Versions Probe Failed" error={diagnosticState.error} />
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
|
||||
Reference in new issue
Block a user