mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-12-03 01:59:29 +03:00
wip, http diagnostics
This commit is contained in:
1 parent
357d9da594
commit
41ca0cfa0a
18 files changed
+3672
-630
No files matched your search
@@ -527,7 +527,8 @@
|
||||
'/cidr': 'CIDR Tools',
|
||||
'/ip-address-convertor': 'IP Tools',
|
||||
'/reference': 'Reference',
|
||||
'/dns': 'DNS'
|
||||
'/dns': 'DNS',
|
||||
'/diagnostics': 'Diagnostics'
|
||||
};
|
||||
return titleMap[sectionKey] || sectionKey.replace('/', '').replace('-', ' ');
|
||||
}
|
||||
|
||||
@@ -625,6 +625,46 @@ export const SUB_NAV: Record<string, (NavItem | NavGroup)[]> = {
|
||||
keywords: ['ns', 'soa', 'nameserver', 'consistency', 'check', 'resolution', 'parameters', 'health', 'serial']
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
title: 'HTTP Diagnostics',
|
||||
items: [
|
||||
{
|
||||
href: '/diagnostics/http/headers',
|
||||
label: 'HTTP Headers Analyzer',
|
||||
description: 'Analyze HTTP headers and response metadata with custom method and header support',
|
||||
icon: 'http-headers',
|
||||
keywords: ['http', 'headers', 'analyzer', 'response', 'metadata', 'custom', 'method', 'request']
|
||||
},
|
||||
{
|
||||
href: '/diagnostics/http/redirect-trace',
|
||||
label: 'Redirect Trace',
|
||||
description: 'Follow HTTP redirects and trace the full chain with security upgrade detection',
|
||||
icon: 'redirect-trace',
|
||||
keywords: ['http', 'redirect', 'trace', 'chain', 'hsts', 'security', 'upgrade', 'follow']
|
||||
},
|
||||
{
|
||||
href: '/diagnostics/http/security',
|
||||
label: 'Security Headers Analyzer',
|
||||
description: 'Analyze security headers (HSTS, CSP, X-Frame-Options) with grading and recommendations',
|
||||
icon: 'security-headers',
|
||||
keywords: ['http', 'security', 'headers', 'hsts', 'csp', 'x-frame-options', 'analyzer', 'grade']
|
||||
},
|
||||
{
|
||||
href: '/diagnostics/http/cors-check',
|
||||
label: 'CORS Policy Checker',
|
||||
description: 'Test CORS policies with preflight requests and origin validation',
|
||||
icon: 'cors-check',
|
||||
keywords: ['cors', 'policy', 'check', 'preflight', 'origin', 'validation', 'cross-origin', 'options']
|
||||
},
|
||||
{
|
||||
href: '/diagnostics/http/perf',
|
||||
label: 'HTTP Performance Analyzer',
|
||||
description: 'Measure HTTP performance timing including DNS, TCP, TLS, and TTFB metrics',
|
||||
icon: 'http-perf',
|
||||
keywords: ['http', 'performance', 'timing', 'dns', 'tcp', 'tls', 'ttfb', 'metrics', 'analyzer']
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
'/reference': [
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
Networking Toolbox is a collection of free, open-source networking utilities designed to simplify common network-related tasks for system administrators and network engineers.
|
||||
<i>Because copy-pasting IPs into random websites is soooo 2010</i>
|
||||
</p>
|
||||
<p>
|
||||
This page contains all the relevant information about this project, how to use it, deploy it, edit it, contribute to it, and more.
|
||||
</p>
|
||||
<!-- Links #1: GitHub -->
|
||||
<!-- Links #1: Live Demo, DockerHub, CodeBerg Mirror, Sponsor, More Apps -->
|
||||
<h3>On this page</h3>
|
||||
@@ -140,10 +143,15 @@
|
||||
<!-- Section 5: Actual About -->
|
||||
<section id="about">
|
||||
<h2>About Networking Toolbox</h2>
|
||||
<h3>Motive</h3>
|
||||
<h3>What</h3>
|
||||
<p>
|
||||
I built this, because these are basic networking tasks that I find myself doing frequently, yet nothing existing on the web quite fit my use case.
|
||||
|
||||
Networking Toolbox is an all-in-one suite of 100+ networking utilities,
|
||||
designed to make common network-related tasks easier and more efficient.
|
||||
</p>
|
||||
<h3>Why</h3>
|
||||
<p>
|
||||
My motive for building this, is that these are basic networking tasks that
|
||||
I find myself doing frequently, yet nothing existing on the web quite fit my use case.
|
||||
<br><br>
|
||||
Some websites came close, but I dislike ads, paywalls, tracking, and clunky UIs. And most importantly, I wanted a single place with all the tools I needed.
|
||||
And often when I needed these utilities, it was because I was working on a server without internet access, so I needed something with offline functionality.
|
||||
@@ -152,6 +160,21 @@
|
||||
Then, I wanted to help make life <i>slightly</i> easier for sysadmins, so I've polished, tested, documented and open sourced this project.
|
||||
It can now be used by anyone, anywhere, anytime. Totally free either at <a href="#-">networking-toolbox.net</a> or self-hosted.
|
||||
</p>
|
||||
<h3>Where</h3>
|
||||
<p>
|
||||
I am running a free, public instance at <a href="https://networking-toolbox.net" target="_blank" rel="noopener noreferrer">networking-toolbox.net</a>,
|
||||
which you're free to use (for commercial and personal use), however you like. There's no tracking, no ads, no paywall, no bs.
|
||||
<br><br>
|
||||
You can also self-host it on your own server, using Docker or any static hosting provider
|
||||
</p>
|
||||
<h3>How</h3>
|
||||
<p>
|
||||
This project is built with <a href="https://svelte.dev" target="_blank" rel="noopener noreferrer">SvelteKit</a> and
|
||||
<a href="https://www.typescriptlang.org" target="_blank" rel="noopener noreferrer">TypeScript</a>.
|
||||
It's a static web app, that can be deployed anywhere, including serverless platforms like Vercel or Netlify.
|
||||
It can also be self-hosted using Docker or any static hosting provider.
|
||||
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<!-- Section 6: Author -->
|
||||
@@ -173,6 +196,12 @@
|
||||
</div>
|
||||
<img class="profile-photo" src="{author.avatar}" alt="{author.name}" width="128" />
|
||||
</div>
|
||||
<p>
|
||||
Pretty much everything I build is free to use, open source, and without ads, tracking or paywalls.
|
||||
But running these projects does cost money. And maintaining them takes time.
|
||||
So, if you've found this app useful, please consider <a href="{author.sponsor}" target="_blank" rel="noopener noreferrer">sponsoring me</a>.
|
||||
My sponsors mean the world to me, and it helps cover my hosting costs.
|
||||
</p>
|
||||
<!-- About, more apps, sponsor -->
|
||||
</section>
|
||||
|
||||
|
||||
@@ -271,7 +271,13 @@ async function performNativeDNSLookup(name: string, type: keyof typeof DNS_TYPES
|
||||
throw new Error(`Domain not found: ${name}`);
|
||||
}
|
||||
if (err.code === 'ENODATA') {
|
||||
throw new Error(`No ${type} records found for ${name}`);
|
||||
// Return structured response for no records found (will be handled as 404)
|
||||
return {
|
||||
noRecords: true,
|
||||
message: `No ${type} records found for ${name}`,
|
||||
name,
|
||||
type
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error(`DNS lookup failed: ${err.message}`);
|
||||
@@ -342,7 +348,11 @@ async function checkDMARC(domain: string): Promise<any> {
|
||||
const dmarcRecord = result.Answer?.find((record: any) => record.data.startsWith('v=DMARC1'));
|
||||
|
||||
if (!dmarcRecord) {
|
||||
return { error: 'No DMARC record found' };
|
||||
return {
|
||||
hasRecord: false,
|
||||
message: 'No DMARC record found',
|
||||
domain: dmarcDomain
|
||||
};
|
||||
}
|
||||
|
||||
const policy = dmarcRecord.data;
|
||||
@@ -366,9 +376,17 @@ async function checkDMARC(domain: string): Promise<any> {
|
||||
if (!parsed.reporting.aggregate) issues.push('No aggregate reporting address specified');
|
||||
if (parsed.percentage !== '100') issues.push(`Only ${parsed.percentage}% of messages are subject to DMARC policy`);
|
||||
|
||||
return { record: policy, parsed, issues };
|
||||
return {
|
||||
hasRecord: true,
|
||||
record: policy,
|
||||
parsed,
|
||||
issues
|
||||
};
|
||||
} catch (err: any) {
|
||||
return { error: err.message };
|
||||
return {
|
||||
error: `Error determining DMARC records: ${err.message}`,
|
||||
domain: `_dmarc.${domain}`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,6 +455,12 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
case 'lookup': {
|
||||
const { name, type = 'A', resolverOpts } = body as LookupReq;
|
||||
const result = await performDNSLookup(name, type, resolverOpts);
|
||||
|
||||
// Handle "no records found" as 404
|
||||
if (result.noRecords) {
|
||||
return json(result, { status: 404 });
|
||||
}
|
||||
|
||||
return json(result);
|
||||
}
|
||||
|
||||
@@ -444,6 +468,12 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
const { ip, resolverOpts } = body as ReverseLookupReq;
|
||||
const reverseName = createReverseZone(ip);
|
||||
const result = await performDNSLookup(reverseName, 'PTR', resolverOpts);
|
||||
|
||||
// Handle "no records found" as 404
|
||||
if (result.noRecords) {
|
||||
return json({ ...result, reverseName }, { status: 404 });
|
||||
}
|
||||
|
||||
return json({ ...result, reverseName });
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,432 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { performance } from 'perf_hooks';
|
||||
|
||||
interface HTTPTimings {
|
||||
dns: number;
|
||||
tcp: number;
|
||||
tls: number;
|
||||
ttfb: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
interface SecurityHeaders {
|
||||
'strict-transport-security'?: string;
|
||||
'content-security-policy'?: string;
|
||||
'x-frame-options'?: string;
|
||||
'x-content-type-options'?: string;
|
||||
'referrer-policy'?: string;
|
||||
'x-xss-protection'?: string;
|
||||
'permissions-policy'?: string;
|
||||
'cross-origin-embedder-policy'?: string;
|
||||
'cross-origin-opener-policy'?: string;
|
||||
'cross-origin-resource-policy'?: string;
|
||||
}
|
||||
|
||||
function validateURL(url: string): { isValid: boolean; error?: string; parsed?: URL } {
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
if (!['http:', 'https:'].includes(parsed.protocol)) {
|
||||
return { isValid: false, error: 'URL must use HTTP or HTTPS protocol' };
|
||||
}
|
||||
return { isValid: true, parsed };
|
||||
} catch {
|
||||
return { isValid: false, error: 'Invalid URL format' };
|
||||
}
|
||||
}
|
||||
|
||||
async function performHTTPRequest(
|
||||
url: string,
|
||||
method: string = 'GET',
|
||||
customHeaders: Record<string, string> = {},
|
||||
followRedirects: boolean = true,
|
||||
maxRedirects: number = 10,
|
||||
timeout: number = 10000
|
||||
): Promise<{
|
||||
response: Response;
|
||||
timings: HTTPTimings;
|
||||
redirectChain?: Array<{ url: string; status: number; location?: string; headers: Record<string, string> }>;
|
||||
}> {
|
||||
const startTime = performance.now();
|
||||
let dns = 0, tcp = 0, tls = 0, ttfb = 0;
|
||||
|
||||
const redirectChain: Array<{ url: string; status: number; location?: string; headers: Record<string, string> }> = [];
|
||||
let currentUrl = url;
|
||||
let redirectCount = 0;
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
||||
|
||||
try {
|
||||
while (redirectCount <= maxRedirects) {
|
||||
const requestStart = performance.now();
|
||||
|
||||
const response = await fetch(currentUrl, {
|
||||
method,
|
||||
headers: customHeaders,
|
||||
redirect: 'manual',
|
||||
signal: controller.signal
|
||||
});
|
||||
|
||||
const requestEnd = performance.now();
|
||||
if (redirectCount === 0) {
|
||||
// Approximate timings for first request
|
||||
const totalTime = requestEnd - requestStart;
|
||||
dns = totalTime * 0.1; // ~10% DNS (approximation)
|
||||
tcp = totalTime * 0.2; // ~20% TCP connect
|
||||
tls = currentUrl.startsWith('https:') ? totalTime * 0.3 : 0; // ~30% TLS if HTTPS
|
||||
ttfb = totalTime * 0.4; // ~40% TTFB
|
||||
}
|
||||
|
||||
const responseHeaders: Record<string, string> = {};
|
||||
response.headers.forEach((value, key) => {
|
||||
responseHeaders[key.toLowerCase()] = value;
|
||||
});
|
||||
|
||||
if ([301, 302, 303, 307, 308].includes(response.status)) {
|
||||
const location = response.headers.get('location');
|
||||
redirectChain.push({
|
||||
url: currentUrl,
|
||||
status: response.status,
|
||||
location: location || undefined,
|
||||
headers: responseHeaders
|
||||
});
|
||||
|
||||
if (!location) {
|
||||
throw new Error(`Redirect response (${response.status}) missing Location header`);
|
||||
}
|
||||
|
||||
if (!followRedirects) {
|
||||
const total = performance.now() - startTime;
|
||||
return {
|
||||
response,
|
||||
timings: { dns, tcp, tls, ttfb, total },
|
||||
redirectChain
|
||||
};
|
||||
}
|
||||
|
||||
currentUrl = new URL(location, currentUrl).href;
|
||||
redirectCount++;
|
||||
|
||||
if (redirectCount > maxRedirects) {
|
||||
throw new Error(`Too many redirects (>${maxRedirects})`);
|
||||
}
|
||||
} else {
|
||||
// Final response
|
||||
const total = performance.now() - startTime;
|
||||
if (redirectChain.length > 0) {
|
||||
redirectChain.push({
|
||||
url: currentUrl,
|
||||
status: response.status,
|
||||
headers: responseHeaders
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
response,
|
||||
timings: { dns, tcp, tls, ttfb, total },
|
||||
redirectChain: redirectChain.length > 0 ? redirectChain : undefined
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Maximum redirects (${maxRedirects}) exceeded`);
|
||||
} finally {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
|
||||
function analyzeSecurityHeaders(headers: Headers): {
|
||||
headers: SecurityHeaders;
|
||||
analysis: Array<{ header: string; status: 'present' | 'missing' | 'weak'; message: string; recommendation?: string }>;
|
||||
} {
|
||||
const securityHeaders: SecurityHeaders = {};
|
||||
const analysis: Array<{ header: string; status: 'present' | 'missing' | 'weak'; message: string; recommendation?: string }> = [];
|
||||
|
||||
// Check HSTS
|
||||
const hsts = headers.get('strict-transport-security');
|
||||
if (hsts) {
|
||||
securityHeaders['strict-transport-security'] = hsts;
|
||||
const maxAge = hsts.match(/max-age=(\d+)/)?.[1];
|
||||
if (maxAge && parseInt(maxAge) < 31536000) {
|
||||
analysis.push({
|
||||
header: 'Strict-Transport-Security',
|
||||
status: 'weak',
|
||||
message: 'HSTS max-age is less than 1 year',
|
||||
recommendation: 'Set max-age to at least 31536000 (1 year)'
|
||||
});
|
||||
} else {
|
||||
analysis.push({
|
||||
header: 'Strict-Transport-Security',
|
||||
status: 'present',
|
||||
message: 'HSTS properly configured'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
analysis.push({
|
||||
header: 'Strict-Transport-Security',
|
||||
status: 'missing',
|
||||
message: 'HSTS header not present',
|
||||
recommendation: 'Add "Strict-Transport-Security: max-age=31536000; includeSubDomains"'
|
||||
});
|
||||
}
|
||||
|
||||
// Check CSP
|
||||
const csp = headers.get('content-security-policy');
|
||||
if (csp) {
|
||||
securityHeaders['content-security-policy'] = csp;
|
||||
if (csp.includes("'unsafe-inline'") || csp.includes("'unsafe-eval'")) {
|
||||
analysis.push({
|
||||
header: 'Content-Security-Policy',
|
||||
status: 'weak',
|
||||
message: 'CSP contains unsafe directives',
|
||||
recommendation: 'Remove unsafe-inline and unsafe-eval directives'
|
||||
});
|
||||
} else {
|
||||
analysis.push({
|
||||
header: 'Content-Security-Policy',
|
||||
status: 'present',
|
||||
message: 'CSP configured (review directives)'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
analysis.push({
|
||||
header: 'Content-Security-Policy',
|
||||
status: 'missing',
|
||||
message: 'CSP header not present',
|
||||
recommendation: 'Add a Content-Security-Policy header'
|
||||
});
|
||||
}
|
||||
|
||||
// Check X-Frame-Options
|
||||
const xFrame = headers.get('x-frame-options');
|
||||
if (xFrame) {
|
||||
securityHeaders['x-frame-options'] = xFrame;
|
||||
analysis.push({
|
||||
header: 'X-Frame-Options',
|
||||
status: 'present',
|
||||
message: `Clickjacking protection: ${xFrame}`
|
||||
});
|
||||
} else {
|
||||
analysis.push({
|
||||
header: 'X-Frame-Options',
|
||||
status: 'missing',
|
||||
message: 'X-Frame-Options header not present',
|
||||
recommendation: 'Add "X-Frame-Options: DENY" or use CSP frame-ancestors'
|
||||
});
|
||||
}
|
||||
|
||||
// Check X-Content-Type-Options
|
||||
const xContentType = headers.get('x-content-type-options');
|
||||
if (xContentType === 'nosniff') {
|
||||
securityHeaders['x-content-type-options'] = xContentType;
|
||||
analysis.push({
|
||||
header: 'X-Content-Type-Options',
|
||||
status: 'present',
|
||||
message: 'MIME type sniffing protection enabled'
|
||||
});
|
||||
} else {
|
||||
analysis.push({
|
||||
header: 'X-Content-Type-Options',
|
||||
status: 'missing',
|
||||
message: 'X-Content-Type-Options header not present',
|
||||
recommendation: 'Add "X-Content-Type-Options: nosniff"'
|
||||
});
|
||||
}
|
||||
|
||||
// Check Referrer-Policy
|
||||
const referrerPolicy = headers.get('referrer-policy');
|
||||
if (referrerPolicy) {
|
||||
securityHeaders['referrer-policy'] = referrerPolicy;
|
||||
analysis.push({
|
||||
header: 'Referrer-Policy',
|
||||
status: 'present',
|
||||
message: `Referrer policy: ${referrerPolicy}`
|
||||
});
|
||||
} else {
|
||||
analysis.push({
|
||||
header: 'Referrer-Policy',
|
||||
status: 'missing',
|
||||
message: 'Referrer-Policy header not present',
|
||||
recommendation: 'Add "Referrer-Policy: strict-origin-when-cross-origin"'
|
||||
});
|
||||
}
|
||||
|
||||
return { headers: securityHeaders, analysis };
|
||||
}
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
try {
|
||||
const { action, url, method = 'GET', headers: customHeaders = {}, maxRedirects = 10, timeout = 10000 } = await request.json();
|
||||
|
||||
if (!action || !url) {
|
||||
throw error(400, 'Missing required parameters: action and url');
|
||||
}
|
||||
|
||||
const urlValidation = validateURL(url);
|
||||
if (!urlValidation.isValid) {
|
||||
throw error(400, urlValidation.error || 'Invalid URL');
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case 'headers': {
|
||||
const { response, timings } = await performHTTPRequest(url, method, customHeaders, true, maxRedirects, timeout);
|
||||
|
||||
const responseHeaders: Record<string, string> = {};
|
||||
response.headers.forEach((value, key) => {
|
||||
responseHeaders[key.toLowerCase()] = value;
|
||||
});
|
||||
|
||||
const contentLength = response.headers.get('content-length');
|
||||
const size = contentLength ? parseInt(contentLength) : null;
|
||||
|
||||
return json({
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: responseHeaders,
|
||||
size,
|
||||
timings,
|
||||
url: response.url
|
||||
});
|
||||
}
|
||||
|
||||
case 'redirect-trace': {
|
||||
const { response, timings, redirectChain } = await performHTTPRequest(url, method, customHeaders, true, maxRedirects, timeout);
|
||||
|
||||
return json({
|
||||
finalStatus: response.status,
|
||||
finalUrl: response.url,
|
||||
redirectChain: redirectChain || [],
|
||||
totalRedirects: redirectChain ? redirectChain.length - 1 : 0,
|
||||
timings
|
||||
});
|
||||
}
|
||||
|
||||
case 'security': {
|
||||
const { response, timings } = await performHTTPRequest(url, method, customHeaders, true, maxRedirects, timeout);
|
||||
const { headers: securityHeaders, analysis } = analyzeSecurityHeaders(response.headers);
|
||||
|
||||
return json({
|
||||
url: response.url,
|
||||
status: response.status,
|
||||
headers: securityHeaders,
|
||||
analysis,
|
||||
timings
|
||||
});
|
||||
}
|
||||
|
||||
case 'cors-check': {
|
||||
const origin = customHeaders.origin || 'https://example.com';
|
||||
|
||||
// First try OPTIONS preflight
|
||||
const preflightHeaders = {
|
||||
'Origin': origin,
|
||||
'Access-Control-Request-Method': method,
|
||||
'Access-Control-Request-Headers': 'content-type,authorization'
|
||||
};
|
||||
|
||||
try {
|
||||
const preflightResponse = await fetch(url, {
|
||||
method: 'OPTIONS',
|
||||
headers: preflightHeaders,
|
||||
signal: AbortSignal.timeout(timeout)
|
||||
});
|
||||
|
||||
const corsHeaders: Record<string, string> = {};
|
||||
preflightResponse.headers.forEach((value, key) => {
|
||||
if (key.toLowerCase().startsWith('access-control-')) {
|
||||
corsHeaders[key.toLowerCase()] = value;
|
||||
}
|
||||
});
|
||||
|
||||
const allowsOrigin = corsHeaders['access-control-allow-origin'] === '*' ||
|
||||
corsHeaders['access-control-allow-origin'] === origin;
|
||||
|
||||
return json({
|
||||
preflight: {
|
||||
status: preflightResponse.status,
|
||||
allowed: allowsOrigin,
|
||||
headers: corsHeaders
|
||||
},
|
||||
origin,
|
||||
analysis: {
|
||||
corsEnabled: Object.keys(corsHeaders).length > 0,
|
||||
allowsOrigin,
|
||||
allowsCredentials: corsHeaders['access-control-allow-credentials'] === 'true',
|
||||
allowedMethods: corsHeaders['access-control-allow-methods']?.split(',').map(m => m.trim()) || [],
|
||||
allowedHeaders: corsHeaders['access-control-allow-headers']?.split(',').map(h => h.trim()) || [],
|
||||
maxAge: corsHeaders['access-control-max-age'] ? parseInt(corsHeaders['access-control-max-age']) : null
|
||||
}
|
||||
});
|
||||
} catch (err: any) {
|
||||
return json({
|
||||
preflight: {
|
||||
status: 0,
|
||||
allowed: false,
|
||||
error: err.message
|
||||
},
|
||||
origin,
|
||||
analysis: {
|
||||
corsEnabled: false,
|
||||
allowsOrigin: false,
|
||||
allowsCredentials: false,
|
||||
allowedMethods: [],
|
||||
allowedHeaders: [],
|
||||
maxAge: null
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
case 'perf': {
|
||||
const { response, timings } = await performHTTPRequest(url, method, customHeaders, true, maxRedirects, timeout);
|
||||
|
||||
// Additional performance metrics
|
||||
const contentLength = response.headers.get('content-length');
|
||||
const size = contentLength ? parseInt(contentLength) : null;
|
||||
const isHTTPS = url.startsWith('https:');
|
||||
|
||||
return json({
|
||||
url: response.url,
|
||||
status: response.status,
|
||||
timings: {
|
||||
...timings,
|
||||
dns_note: 'approximation',
|
||||
tcp_note: 'approximation',
|
||||
tls_note: isHTTPS ? 'approximation' : 'not_applicable'
|
||||
},
|
||||
size,
|
||||
performance: {
|
||||
isHTTPS,
|
||||
hasCompression: !!response.headers.get('content-encoding'),
|
||||
httpVersion: 'unknown', // Not easily accessible in Node.js fetch
|
||||
connectionReused: 'unknown'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
default:
|
||||
throw error(400, `Unknown action: ${action}`);
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error('HTTP API error:', err);
|
||||
|
||||
if (err.status) {
|
||||
throw err; // Re-throw SvelteKit errors
|
||||
}
|
||||
|
||||
if (err.name === 'AbortError') {
|
||||
throw error(408, 'Request timeout');
|
||||
}
|
||||
|
||||
if (err.code === 'ENOTFOUND') {
|
||||
throw error(400, 'Host not found');
|
||||
}
|
||||
|
||||
if (err.code === 'ECONNREFUSED') {
|
||||
throw error(400, 'Connection refused');
|
||||
}
|
||||
|
||||
throw error(500, err.message || 'HTTP request failed');
|
||||
}
|
||||
};
|
||||
@@ -2,12 +2,14 @@
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { isValidDomainName, formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let domainName = $state('github.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);
|
||||
|
||||
// Reactive validation state
|
||||
const isInputValid = $derived(() => {
|
||||
@@ -19,7 +21,9 @@
|
||||
{ domain: 'github.com', description: 'GitHub CAA configuration' },
|
||||
{ domain: 'www.google.com', description: 'Google subdomain CAA inheritance' },
|
||||
{ domain: 'api.stripe.com', description: 'Stripe API subdomain CAA' },
|
||||
{ domain: 'blog.cloudflare.com', description: 'Cloudflare blog CAA setup' }
|
||||
{ domain: 'blog.cloudflare.com', description: 'Cloudflare blog CAA setup' },
|
||||
{ domain: 'microsoft.com', description: 'Microsoft CAA settings' },
|
||||
{ domain: 'amazon.com', description: 'Amazon CAA implementation' }
|
||||
];
|
||||
|
||||
async function checkCAA() {
|
||||
@@ -80,11 +84,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0]) {
|
||||
function loadExample(example: typeof examples[0], index: number) {
|
||||
domainName = example.domain;
|
||||
selectedExampleIndex = index;
|
||||
checkCAA();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function parseCAA(record: string): { flag: number, tag: string, value: string } | null {
|
||||
// CAA format: flag tag "value"
|
||||
const match = record.match(/^(\d+)\s+(\w+)\s+["]?([^"]+)["]?$/);
|
||||
@@ -180,7 +189,12 @@
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Check CAA policy for ${example.domain}`}
|
||||
>
|
||||
<h5>{example.domain}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
@@ -204,7 +218,7 @@
|
||||
bind:value={domainName}
|
||||
placeholder="example.com"
|
||||
class:invalid={domainName && !isValidDomainName(domainName.trim())}
|
||||
onchange={() => { if (isInputValid) checkCAA(); }}
|
||||
onchange={() => { clearExampleSelection(); if (isInputValid) checkCAA(); }}
|
||||
/>
|
||||
{#if domainName && !isValidDomainName(domainName.trim())}
|
||||
<span class="error-text">Invalid domain name format</span>
|
||||
@@ -431,6 +445,7 @@
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
// Page-specific styles - shared styles removed
|
||||
// Use shared .lookup-btn instead of .check-btn
|
||||
|
||||
@@ -737,19 +752,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Animation and utility classes
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.text-green-500 {
|
||||
color: var(--color-success);
|
||||
}
|
||||
// Shared utilities moved to diagnostics-pages.scss
|
||||
|
||||
.text-success {
|
||||
color: var(--color-success);
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let domain = $state('google.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 = [
|
||||
{ domain: 'google.com', description: 'Google DMARC policy' },
|
||||
{ domain: 'github.com', description: 'GitHub enterprise DMARC' },
|
||||
{ domain: 'microsoft.com', description: 'Microsoft DMARC configuration' },
|
||||
{ domain: 'paypal.com', description: 'PayPal strict DMARC policy' }
|
||||
{ domain: 'paypal.com', description: 'PayPal strict DMARC policy' },
|
||||
{ domain: 'amazon.com', description: 'Amazon DMARC implementation' },
|
||||
{ domain: 'salesforce.com', description: 'Salesforce DMARC setup' }
|
||||
];
|
||||
|
||||
async function checkDMARC() {
|
||||
@@ -42,11 +46,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0]) {
|
||||
function loadExample(example: typeof examples[0], index: number) {
|
||||
domain = example.domain;
|
||||
selectedExampleIndex = index;
|
||||
checkDMARC();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getPolicyColor(policy: string): string {
|
||||
switch (policy) {
|
||||
case 'reject': return 'success';
|
||||
@@ -183,7 +192,12 @@
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Check DMARC policy for ${example.domain} (${example.description})`}
|
||||
>
|
||||
<h5>{example.domain}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
@@ -206,7 +220,7 @@
|
||||
type="text"
|
||||
bind:value={domain}
|
||||
placeholder="example.com"
|
||||
onchange={() => { if (domain) checkDMARC(); }}
|
||||
onchange={() => { clearExampleSelection(); if (domain) checkDMARC(); }}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
@@ -226,7 +240,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results && !results.error}
|
||||
{#if results && results.hasRecord}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>DMARC Policy Analysis</h3>
|
||||
@@ -236,10 +250,10 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Status Overview -->
|
||||
<div class="status-overview">
|
||||
{#if results && !results.error}
|
||||
{@const issues = getIssues()}
|
||||
{#if results && results.hasRecord}
|
||||
{@const issues = getIssues()}
|
||||
<!-- Status Overview -->
|
||||
<div class="status-overview">
|
||||
<div class="status-item {issues.length === 0 ? 'success' : issues.some(i => i.severity === 'high') ? 'error' : 'warning'}">
|
||||
<Icon name={issues.length === 0 ? 'shield-check' : issues.some(i => i.severity === 'high') ? 'shield-x' : 'shield-alert'} size="md" />
|
||||
<div>
|
||||
@@ -261,8 +275,8 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Original Record -->
|
||||
{#if results.record}
|
||||
@@ -415,29 +429,45 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Issues -->
|
||||
{#if issues.length > 0}
|
||||
<div class="issues-section">
|
||||
<h4>Issues & Recommendations</h4>
|
||||
<div class="issues-list">
|
||||
{#each issues as issue}
|
||||
<div class="issue-item {getSeverityColor(issue.severity)}">
|
||||
<Icon name={issue.severity === 'high' ? 'alert-triangle' : issue.severity === 'medium' ? 'alert-circle' : 'info'} size="sm" />
|
||||
<div class="issue-content">
|
||||
<span class="issue-severity">{issue.severity.toUpperCase()}</span>
|
||||
<span class="issue-message">{issue.message}</span>
|
||||
|
||||
<!-- Issues -->
|
||||
{#if issues.length > 0}
|
||||
<div class="issues-section">
|
||||
<h4>Issues & Recommendations</h4>
|
||||
<div class="issues-list">
|
||||
{#each issues as issue}
|
||||
<div class="issue-item {getSeverityColor(issue.severity)}">
|
||||
<Icon name={issue.severity === 'high' ? 'alert-triangle' : issue.severity === 'medium' ? 'alert-circle' : 'info'} size="sm" />
|
||||
<div class="issue-content">
|
||||
<span class="issue-severity">{issue.severity.toUpperCase()}</span>
|
||||
<span class="issue-message">{issue.message}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- No Record Found (but not an error) -->
|
||||
{#if results && results.hasRecord === false}
|
||||
<div class="card warning-card">
|
||||
<div class="card-content">
|
||||
<div class="warning-content">
|
||||
<Icon name="info" size="md" />
|
||||
<div>
|
||||
<strong>No DMARC Record Found</strong>
|
||||
<p>Domain <code>{domain}</code> does not have a DMARC policy configured at <code>{results.domain}</code>.</p>
|
||||
<p class="help-text">This means the domain is not protected by DMARC. Consider implementing a DMARC policy to prevent email spoofing.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error || (results?.error)}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
@@ -714,17 +744,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Animation and utility classes
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.text-green-500 {
|
||||
color: var(--color-success);
|
||||
}
|
||||
// Page-specific styles (shared styles moved to diagnostics-pages.scss)
|
||||
</style>
|
||||
@@ -13,6 +13,7 @@
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
// Reactive validation state
|
||||
const isInputValid = $derived(() => {
|
||||
@@ -78,23 +79,41 @@
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
let errorMessage = `Lookup failed (${response.status})`;
|
||||
|
||||
try {
|
||||
const errorData = JSON.parse(errorText);
|
||||
if (errorData.error) {
|
||||
errorMessage = errorData.error;
|
||||
const responseData = JSON.parse(errorText);
|
||||
|
||||
// Handle 404 as "no records found" (warning, not error)
|
||||
if (response.status === 404 && responseData.noRecords) {
|
||||
results = {
|
||||
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
|
||||
}
|
||||
} catch {
|
||||
|
||||
// Handle other structured errors
|
||||
if (responseData.error) {
|
||||
throw new Error(responseData.error);
|
||||
}
|
||||
|
||||
// Use API message if available
|
||||
if (responseData.message) {
|
||||
throw new Error(responseData.message);
|
||||
}
|
||||
} catch (parseError) {
|
||||
// If not JSON, use status-based message
|
||||
if (response.status === 400) {
|
||||
errorMessage = 'Invalid request. Please check your input values.';
|
||||
throw new Error('Invalid request. Please check your input values.');
|
||||
} else if (response.status === 500) {
|
||||
errorMessage = 'DNS lookup service temporarily unavailable. Please try again.';
|
||||
throw new Error('DNS lookup service temporarily unavailable. Please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
throw new Error(`Lookup failed (${response.status})`);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
@@ -106,12 +125,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0]) {
|
||||
function loadExample(example: typeof examples[0], index: number) {
|
||||
domainName = example.domain;
|
||||
recordType = example.type;
|
||||
selectedExampleIndex = index;
|
||||
performLookup();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.Answer?.length) return;
|
||||
|
||||
@@ -137,7 +161,12 @@
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<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>
|
||||
@@ -152,7 +181,8 @@
|
||||
<h3>Lookup Configuration</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-grid">
|
||||
<!-- First Row: Domain Name -->
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="domain" use:tooltip={"Enter the domain name to query"}>
|
||||
Domain Name
|
||||
@@ -162,50 +192,51 @@
|
||||
type="text"
|
||||
bind:value={domainName}
|
||||
placeholder="example.com"
|
||||
onchange={() => { if (domainName) performLookup(); }}
|
||||
onchange={() => { clearExampleSelection(); if (domainName) performLookup(); }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Second Row: Record Type and DNS Resolver -->
|
||||
<div class="form-row two-columns">
|
||||
<div class="form-group">
|
||||
<label for="type" use:tooltip={"Select the DNS record type to query"}>
|
||||
Record Type
|
||||
</label>
|
||||
<select id="type" bind:value={recordType} onchange={() => { if (domainName) performLookup(); }}>
|
||||
<select id="type" bind:value={recordType} onchange={() => { clearExampleSelection(); if (domainName) performLookup(); }}>
|
||||
{#each recordTypes as type}
|
||||
<option value={type.value} title={type.description}>{type.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group resolver-group">
|
||||
<div class="form-group">
|
||||
<label use:tooltip={"Choose a DNS resolver to use for the query"}>
|
||||
DNS Resolver
|
||||
</label>
|
||||
<div class="resolver-options">
|
||||
{#if !useCustomResolver}
|
||||
<select bind:value={resolver} onchange={() => { if (domainName) performLookup(); }}>
|
||||
{#each resolvers as res}
|
||||
<option value={res.value}>{res.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
{/if}
|
||||
{#if useCustomResolver}
|
||||
<input
|
||||
type="text"
|
||||
bind:value={customResolver}
|
||||
placeholder="8.8.8.8 or custom IP"
|
||||
onchange={() => { if (domainName) performLookup(); }}
|
||||
/>
|
||||
{/if}
|
||||
<label class="checkbox-group">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={useCustomResolver}
|
||||
onchange={() => { if (domainName) performLookup(); }}
|
||||
/>
|
||||
Use custom resolver
|
||||
</label>
|
||||
</div>
|
||||
{#if !useCustomResolver}
|
||||
<select bind:value={resolver} onchange={() => { clearExampleSelection(); if (domainName) performLookup(); }}>
|
||||
{#each resolvers as res}
|
||||
<option value={res.value}>{res.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
{/if}
|
||||
{#if useCustomResolver}
|
||||
<input
|
||||
type="text"
|
||||
bind:value={customResolver}
|
||||
placeholder="8.8.8.8 or custom IP"
|
||||
onchange={() => { clearExampleSelection(); if (domainName) performLookup(); }}
|
||||
/>
|
||||
{/if}
|
||||
<label class="checkbox-group">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={useCustomResolver}
|
||||
onchange={() => { clearExampleSelection(); if (domainName) performLookup(); }}
|
||||
/>
|
||||
Use custom resolver
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -225,7 +256,7 @@
|
||||
|
||||
<!-- Warnings -->
|
||||
{#if results?.warnings?.length > 0}
|
||||
<div class="card warning-card">
|
||||
<div class="card warning-card warns">
|
||||
<div class="card-content">
|
||||
<div class="warning-content">
|
||||
<Icon name="alert-triangle" size="sm" />
|
||||
@@ -239,10 +270,26 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- No Records Warning -->
|
||||
{#if 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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{#if results && !results.noRecords}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<div class="card-header row">
|
||||
<h3>DNS Records Found</h3>
|
||||
{#if results.Answer?.length > 0}
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
@@ -266,9 +313,11 @@
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="no-records">
|
||||
<Icon name="alert-circle" size="md" />
|
||||
<p>No records found for <code>{domainName}</code> ({recordType})</p>
|
||||
<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>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -291,28 +340,17 @@
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
// Page-specific styles - shared styles now handled by diagnostics-pages.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);
|
||||
}
|
||||
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.text-green-500 {
|
||||
color: var(--color-success);
|
||||
}
|
||||
</style>
|
||||
@@ -1,18 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let domain = $state('google.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 = [
|
||||
{ domain: 'google.com', description: 'Google DNS infrastructure check' },
|
||||
{ domain: 'github.com', description: 'GitHub nameserver configuration' },
|
||||
{ domain: 'cloudflare.com', description: 'Cloudflare NS/SOA setup' },
|
||||
{ domain: 'stackoverflow.com', description: 'Stack Overflow DNS consistency' }
|
||||
{ domain: 'stackoverflow.com', description: 'Stack Overflow DNS consistency' },
|
||||
{ domain: 'microsoft.com', description: 'Microsoft nameserver analysis' },
|
||||
{ domain: 'aws.amazon.com', description: 'AWS subdomain NS/SOA check' }
|
||||
];
|
||||
|
||||
async function checkNSSOA() {
|
||||
@@ -42,11 +46,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0]) {
|
||||
function loadExample(example: typeof examples[0], index: number) {
|
||||
domain = example.domain;
|
||||
selectedExampleIndex = index;
|
||||
checkNSSOA();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function parseSOA(soaString: string): any {
|
||||
// SOA format: primary-ns admin serial refresh retry expire minimum
|
||||
const parts = soaString.trim().split(/\s+/);
|
||||
@@ -152,7 +161,12 @@
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Check NS/SOA consistency for ${example.domain}`}
|
||||
>
|
||||
<h5>{example.domain}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
@@ -175,7 +189,7 @@
|
||||
type="text"
|
||||
bind:value={domain}
|
||||
placeholder="example.com"
|
||||
onchange={() => { if (domain) checkNSSOA(); }}
|
||||
onchange={() => { clearExampleSelection(); if (domain) checkNSSOA(); }}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
@@ -337,80 +351,78 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Configuration Analysis -->
|
||||
<div class="recommendations-section">
|
||||
<h5>Configuration Analysis</h5>
|
||||
<div class="recommendation-list">
|
||||
<!-- Serial number check -->
|
||||
{#if parsed.serial.toString().length === 10 && parsed.serial.toString().startsWith('202')}
|
||||
<div class="recommendation-item success">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<span>Serial number appears to use YYYYMMDDNN format (recommended)</span>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="recommendation-item warning">
|
||||
<Icon name="alert-circle" size="sm" />
|
||||
<span>Consider using YYYYMMDDNN format for serial numbers for easier tracking</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Refresh interval check -->
|
||||
{#if parsed.refresh >= 3600 && parsed.refresh <= 86400}
|
||||
<div class="recommendation-item success">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<span>Refresh interval ({formatTime(parsed.refresh)}) is within recommended range</span>
|
||||
</div>
|
||||
{:else if parsed.refresh < 3600}
|
||||
<div class="recommendation-item warning">
|
||||
<Icon name="alert-circle" size="sm" />
|
||||
<span>Refresh interval ({formatTime(parsed.refresh)}) is quite frequent - consider increasing</span>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="recommendation-item warning">
|
||||
<Icon name="alert-circle" size="sm" />
|
||||
<span>Refresh interval ({formatTime(parsed.refresh)}) is quite long - consider reducing</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Retry interval check -->
|
||||
{#if parsed.retry >= 600 && parsed.retry < parsed.refresh}
|
||||
<div class="recommendation-item success">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<span>Retry interval is properly configured</span>
|
||||
</div>
|
||||
{:else if parsed.retry >= parsed.refresh}
|
||||
<div class="recommendation-item error">
|
||||
<Icon name="x-circle" size="sm" />
|
||||
<span>Retry interval should be less than refresh interval</span>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="recommendation-item warning">
|
||||
<Icon name="alert-circle" size="sm" />
|
||||
<span>Retry interval ({formatTime(parsed.retry)}) might be too short</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Expire check -->
|
||||
{#if parsed.expire >= 604800}
|
||||
<div class="recommendation-item success">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<span>Expire time ({formatTime(parsed.expire)}) provides good resilience</span>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="recommendation-item warning">
|
||||
<Icon name="alert-circle" size="sm" />
|
||||
<span>Expire time ({formatTime(parsed.expire)}) is quite short - consider at least 1 week</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Recommendations -->
|
||||
{#if parsed}
|
||||
<div class="recommendations-section">
|
||||
<h4>Configuration Analysis</h4>
|
||||
<div class="recommendation-list">
|
||||
<!-- Serial number check -->
|
||||
{#if parsed.serial.toString().length === 10 && parsed.serial.toString().startsWith('202')}
|
||||
<div class="recommendation-item success">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<span>Serial number appears to use YYYYMMDDNN format (recommended)</span>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="recommendation-item warning">
|
||||
<Icon name="alert-circle" size="sm" />
|
||||
<span>Consider using YYYYMMDDNN format for serial numbers for easier tracking</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Refresh interval check -->
|
||||
{#if parsed.refresh >= 3600 && parsed.refresh <= 86400}
|
||||
<div class="recommendation-item success">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<span>Refresh interval ({formatTime(parsed.refresh)}) is within recommended range</span>
|
||||
</div>
|
||||
{:else if parsed.refresh < 3600}
|
||||
<div class="recommendation-item warning">
|
||||
<Icon name="alert-circle" size="sm" />
|
||||
<span>Refresh interval ({formatTime(parsed.refresh)}) is quite frequent - consider increasing</span>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="recommendation-item warning">
|
||||
<Icon name="alert-circle" size="sm" />
|
||||
<span>Refresh interval ({formatTime(parsed.refresh)}) is quite long - consider reducing</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Retry interval check -->
|
||||
{#if parsed.retry >= 600 && parsed.retry < parsed.refresh}
|
||||
<div class="recommendation-item success">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<span>Retry interval is properly configured</span>
|
||||
</div>
|
||||
{:else if parsed.retry >= parsed.refresh}
|
||||
<div class="recommendation-item error">
|
||||
<Icon name="x-circle" size="sm" />
|
||||
<span>Retry interval should be less than refresh interval</span>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="recommendation-item warning">
|
||||
<Icon name="alert-circle" size="sm" />
|
||||
<span>Retry interval ({formatTime(parsed.retry)}) might be too short</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Expire check -->
|
||||
{#if parsed.expire >= 604800}
|
||||
<div class="recommendation-item success">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<span>Expire time ({formatTime(parsed.expire)}) provides good resilience</span>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="recommendation-item warning">
|
||||
<Icon name="alert-circle" size="sm" />
|
||||
<span>Expire time ({formatTime(parsed.expire)}) is quite short - consider at least 1 week</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -706,17 +718,6 @@
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
// Animation and utility classes
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.text-green-500 {
|
||||
color: var(--color-success);
|
||||
}
|
||||
// Page-specific styles only (common utilities moved to diagnostics-pages.scss)
|
||||
</style>
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
// import '../../../styles/diagnostics-pages.scss';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let domainName = $state('example.com');
|
||||
let recordType = $state('A');
|
||||
@@ -10,6 +10,7 @@
|
||||
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 recordTypes = [
|
||||
{ value: 'A', label: 'A', description: 'IPv4 address records' },
|
||||
@@ -64,12 +65,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0]) {
|
||||
function loadExample(example: typeof examples[0], index: number) {
|
||||
domainName = example.domain;
|
||||
recordType = example.type;
|
||||
selectedExampleIndex = index;
|
||||
checkPropagation();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getStatusColor(result: any): string {
|
||||
if (result.error) return 'error';
|
||||
if (!result.result?.Answer?.length) return 'warning';
|
||||
@@ -138,7 +144,12 @@
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<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>
|
||||
@@ -153,7 +164,7 @@
|
||||
<h3>Propagation Check Configuration</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-grid">
|
||||
<div class="form-row two-columns">
|
||||
<div class="form-group">
|
||||
<label for="domain" use:tooltip={"Enter the domain name to check propagation for"}>
|
||||
Domain Name
|
||||
@@ -162,7 +173,7 @@
|
||||
type="text"
|
||||
bind:value={domainName}
|
||||
placeholder="example.com"
|
||||
onchange={() => { if (domainName) checkPropagation(); }}
|
||||
onchange={() => { clearExampleSelection(); if (domainName) checkPropagation(); }}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
@@ -170,7 +181,7 @@
|
||||
<div class="form-group">
|
||||
<label for="type" use:tooltip={"Select the DNS record type to check"}>
|
||||
Record Type
|
||||
<select id="type" bind:value={recordType} onchange={() => { if (domainName) checkPropagation(); }}>
|
||||
<select id="type" bind:value={recordType} onchange={() => { clearExampleSelection(); if (domainName) checkPropagation(); }}>
|
||||
{#each recordTypes as type}
|
||||
<option value={type.value} title={type.description}>{type.label}</option>
|
||||
{/each}
|
||||
@@ -196,21 +207,27 @@
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<div class="card-header row">
|
||||
<div>
|
||||
<h3>Propagation Results</h3>
|
||||
<div class="consistency-status">
|
||||
{#if areResultsConsistent()}
|
||||
<Icon name="check-circle" size="xs" class="text-green-500" />
|
||||
<span class="status-text success">Fully Propagated</span>
|
||||
<div class="status-success">
|
||||
<Icon name="check-circle" size="xs" />
|
||||
<span class="status-text">Fully Propagated</span>
|
||||
</div>
|
||||
{:else}
|
||||
<Icon name="alert-circle" size="xs" class="text-orange-500" />
|
||||
<span class="status-text warning">Inconsistent Results</span>
|
||||
<div class="status-warning">
|
||||
<Icon name="alert-circle" size="xs" />
|
||||
<span class="status-text">Inconsistent Results</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<button class="copy-btn" onclick={copyAllResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? "check" : "copy"} size="xs" class={copiedState ? "text-green-500" : ""} />
|
||||
<div class={copiedState ? "status-success" : ""}>
|
||||
<Icon name={copiedState ? "check" : "copy"} size="xs" />
|
||||
</div>
|
||||
{copiedState ? "Copied!" : "Copy All Results"}
|
||||
</button>
|
||||
</div>
|
||||
@@ -221,7 +238,7 @@
|
||||
{@const status = getStatusColor(result)}
|
||||
{@const icon = getStatusIcon(result)}
|
||||
|
||||
<div class="resolver-card {status}">
|
||||
<div class="resolver-card card {status}">
|
||||
<div class="resolver-header">
|
||||
<div class="resolver-info">
|
||||
<Icon name={icon} size="sm" />
|
||||
@@ -309,15 +326,21 @@
|
||||
<h4>Interpreting Results</h4>
|
||||
<div class="status-legend">
|
||||
<div class="legend-item">
|
||||
<Icon name="check-circle" size="xs" class="text-green-500" />
|
||||
<div class="status-success">
|
||||
<Icon name="check-circle" size="xs" />
|
||||
</div>
|
||||
<span><strong>Fully Propagated:</strong> All resolvers return identical results</span>
|
||||
</div>
|
||||
<div class="legend-item">
|
||||
<Icon name="alert-circle" size="xs" class="text-orange-500" />
|
||||
<div class="status-warning">
|
||||
<Icon name="alert-circle" size="xs" />
|
||||
</div>
|
||||
<span><strong>Inconsistent:</strong> Different resolvers return different results</span>
|
||||
</div>
|
||||
<div class="legend-item">
|
||||
<Icon name="x-circle" size="xs" class="text-red-500" />
|
||||
<div class="status-error">
|
||||
<Icon name="x-circle" size="xs" />
|
||||
</div>
|
||||
<span><strong>Error:</strong> Resolver failed to respond or returned an error</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -342,6 +365,19 @@
|
||||
<style lang="scss">
|
||||
// Page-specific styles not covered by shared diagnostics-pages.scss
|
||||
|
||||
|
||||
.resolvers-grid {
|
||||
gap: var(--spacing-md);
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
|
||||
.resolver-card {
|
||||
width: 100%;
|
||||
padding: var(--spacing-sm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
.form-group {
|
||||
label {
|
||||
display: flex;
|
||||
@@ -388,6 +424,35 @@
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
// Status color classes
|
||||
.status-success {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
.status-warning {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
color: var(--color-warning);
|
||||
}
|
||||
|
||||
.status-error {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
color: var(--color-error);
|
||||
}
|
||||
|
||||
.status-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.resolver-header {
|
||||
padding: var(--spacing-md);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
@@ -479,24 +544,5 @@
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.text-green-500 {
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
.text-orange-500 {
|
||||
color: var(--color-warning);
|
||||
}
|
||||
|
||||
.text-red-500 {
|
||||
color: var(--color-error);
|
||||
}
|
||||
</style>
|
||||
@@ -11,6 +11,7 @@
|
||||
let results = $state<any>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let selectedExampleIndex = $state<number | null>(null);
|
||||
|
||||
const resolvers = [
|
||||
{ value: 'cloudflare', label: 'Cloudflare (1.1.1.1)' },
|
||||
@@ -27,12 +28,54 @@
|
||||
];
|
||||
|
||||
function isValidIP(ip: string): boolean {
|
||||
// Basic IPv4/IPv6 validation
|
||||
// Basic IPv4 validation
|
||||
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
||||
const ipv6Regex = /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::1$|^::$/;
|
||||
const ipv6CompressedRegex = /^(?:[0-9a-fA-F]{1,4}:)*::(?:[0-9a-fA-F]{1,4}:)*[0-9a-fA-F]{1,4}$|^(?:[0-9a-fA-F]{1,4}:)*::[0-9a-fA-F]{1,4}$|^(?:[0-9a-fA-F]{1,4}:)*::$/;
|
||||
|
||||
return ipv4Regex.test(ip) || ipv6Regex.test(ip) || ipv6CompressedRegex.test(ip);
|
||||
if (ipv4Regex.test(ip)) return true;
|
||||
|
||||
// IPv6 validation - comprehensive approach
|
||||
try {
|
||||
// Remove any zone identifier (e.g., %eth0)
|
||||
const cleanIp = ip.split('%')[0].toLowerCase();
|
||||
|
||||
// Special cases
|
||||
if (cleanIp === '::' || cleanIp === '::1') return true;
|
||||
|
||||
// Check for invalid characters
|
||||
if (!/^[0-9a-f:]+$/.test(cleanIp)) return false;
|
||||
|
||||
// Check for double colon (can only appear once)
|
||||
const doubleColonCount = (cleanIp.match(/::/g) || []).length;
|
||||
if (doubleColonCount > 1) return false;
|
||||
|
||||
// Split by double colon if present
|
||||
const parts = cleanIp.split('::');
|
||||
|
||||
if (parts.length === 1) {
|
||||
// No compression - must be full format with exactly 8 groups
|
||||
const groups = cleanIp.split(':');
|
||||
if (groups.length !== 8) return false;
|
||||
|
||||
// Each group must be 1-4 hex digits
|
||||
return groups.every(group => /^[0-9a-f]{1,4}$/.test(group));
|
||||
|
||||
} else if (parts.length === 2) {
|
||||
// Has compression
|
||||
const leftGroups = parts[0] ? parts[0].split(':').filter(g => g !== '') : [];
|
||||
const rightGroups = parts[1] ? parts[1].split(':').filter(g => g !== '') : [];
|
||||
|
||||
// Total groups must be less than 8 (compression fills the gap)
|
||||
if (leftGroups.length + rightGroups.length >= 8) return false;
|
||||
|
||||
// Each group must be 1-4 hex digits
|
||||
const allGroups = [...leftGroups, ...rightGroups];
|
||||
return allGroups.every(group => /^[0-9a-f]{1,4}$/.test(group));
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function performReverseLookup() {
|
||||
@@ -71,11 +114,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0]) {
|
||||
function loadExample(example: typeof examples[0], index: number) {
|
||||
ipAddress = example.ip;
|
||||
selectedExampleIndex = index;
|
||||
performReverseLookup();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.Answer?.length) return;
|
||||
|
||||
@@ -101,7 +149,12 @@
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Perform reverse lookup for ${example.ip} (${example.description})`}
|
||||
>
|
||||
<h5>{example.ip}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
@@ -126,7 +179,7 @@
|
||||
bind:value={ipAddress}
|
||||
placeholder="8.8.8.8 or 2001:db8::1"
|
||||
class:invalid={ipAddress && !isValidIP(ipAddress.trim())}
|
||||
onchange={() => { if (ipAddress && isValidIP(ipAddress.trim())) performReverseLookup(); }}
|
||||
onchange={() => { clearExampleSelection(); if (ipAddress && isValidIP(ipAddress.trim())) performReverseLookup(); }}
|
||||
/>
|
||||
{#if ipAddress && !isValidIP(ipAddress.trim())}
|
||||
<span class="error-text">Invalid IP address format</span>
|
||||
@@ -143,7 +196,7 @@
|
||||
type="text"
|
||||
bind:value={customResolver}
|
||||
placeholder="8.8.8.8 or custom IP"
|
||||
onchange={() => { if (ipAddress && isValidIP(ipAddress.trim())) performReverseLookup(); }}
|
||||
onchange={() => { clearExampleSelection(); if (ipAddress && isValidIP(ipAddress.trim())) performReverseLookup(); }}
|
||||
/>
|
||||
{:else}
|
||||
<select bind:value={resolver} onchange={() => { if (ipAddress && isValidIP(ipAddress.trim())) performReverseLookup(); }}>
|
||||
@@ -156,7 +209,7 @@
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={useCustomResolver}
|
||||
onchange={() => { if (ipAddress && isValidIP(ipAddress.trim())) performReverseLookup(); }}
|
||||
onchange={() => { clearExampleSelection(); if (ipAddress && isValidIP(ipAddress.trim())) performReverseLookup(); }}
|
||||
/>
|
||||
Use custom resolver
|
||||
</label>
|
||||
@@ -198,7 +251,7 @@
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<div class="card-header row">
|
||||
<h3>Reverse DNS Results</h3>
|
||||
{#if results.Answer?.length > 0}
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
@@ -431,16 +484,5 @@
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.text-green-500 {
|
||||
color: var(--color-success);
|
||||
}
|
||||
// Shared utilities moved to diagnostics-pages.scss
|
||||
</style>
|
||||
@@ -1,19 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
// import '../../../styles/diagnostics-pages.scss';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let domain = $state('google.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 = [
|
||||
{ domain: 'google.com', description: 'Google SPF with multiple includes' },
|
||||
{ domain: 'github.com', description: 'GitHub SPF record structure' },
|
||||
{ domain: 'mailchimp.com', description: 'MailChimp complex SPF policy' },
|
||||
{ domain: 'salesforce.com', description: 'Salesforce enterprise SPF' }
|
||||
{ domain: 'salesforce.com', description: 'Salesforce enterprise SPF' },
|
||||
{ domain: 'microsoft.com', description: 'Microsoft Office 365 SPF' },
|
||||
{ domain: 'atlassian.com', description: 'Atlassian SPF configuration' }
|
||||
];
|
||||
|
||||
async function evaluateSPF() {
|
||||
@@ -43,11 +46,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0]) {
|
||||
function loadExample(example: typeof examples[0], index: number) {
|
||||
domain = example.domain;
|
||||
selectedExampleIndex = index;
|
||||
evaluateSPF();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
function getMechanismType(mechanism: string): { type: string, color: string, icon: string } {
|
||||
if (mechanism.startsWith('v=spf1')) return { type: 'version', color: 'primary', icon: 'shield' };
|
||||
if (mechanism.startsWith('+all') || mechanism === 'all') return { type: 'pass all', color: 'error', icon: 'shield-off' };
|
||||
@@ -158,7 +166,12 @@
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example, i}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExampleIndex === i}
|
||||
onclick={() => loadExample(example, i)}
|
||||
use:tooltip={`Evaluate SPF record for ${example.domain} (${example.description})`}
|
||||
>
|
||||
<h5>{example.domain}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
@@ -181,7 +194,7 @@
|
||||
type="text"
|
||||
bind:value={domain}
|
||||
placeholder="example.com"
|
||||
onchange={() => { if (domain) evaluateSPF(); }}
|
||||
onchange={() => { clearExampleSelection(); if (domain) evaluateSPF(); }}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
@@ -420,6 +433,7 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
// SPF-specific mechanism styles
|
||||
.mechanisms-section {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
@@ -595,17 +609,5 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Animation and utility classes
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.text-green-500 {
|
||||
color: var(--color-success);
|
||||
}
|
||||
// Shared utilities moved to diagnostics-pages.scss
|
||||
</style>
|
||||
@@ -0,0 +1,510 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
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 methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
||||
|
||||
const examples = [
|
||||
{ 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' },
|
||||
{ url: 'https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41¤t=temperature_2m', origin: 'https://weather-app.com', description: 'Open weather API' },
|
||||
{ url: 'https://jsonplaceholder.typicode.com/posts/1', origin: 'https://example.org', description: 'JSON Placeholder API' }
|
||||
];
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
const trimmedOrigin = origin.trim();
|
||||
|
||||
if (!trimmedUrl || !trimmedOrigin) return false;
|
||||
|
||||
try {
|
||||
const parsedUrl = new URL(trimmedUrl);
|
||||
const parsedOrigin = new URL(trimmedOrigin);
|
||||
return ['http:', 'https:'].includes(parsedUrl.protocol) &&
|
||||
['http:', 'https:'].includes(parsedOrigin.protocol);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
async function checkCORS() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
|
||||
// Validation
|
||||
const trimmedUrl = url.trim();
|
||||
const trimmedOrigin = origin.trim();
|
||||
|
||||
if (!trimmedUrl) {
|
||||
error = 'URL is required';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!trimmedOrigin) {
|
||||
error = 'Origin is required';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(trimmedUrl);
|
||||
new URL(trimmedOrigin);
|
||||
} catch {
|
||||
error = 'Invalid URL or Origin format';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/http', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
action: 'cors-check',
|
||||
url: trimmedUrl,
|
||||
method,
|
||||
headers: {
|
||||
origin: trimmedOrigin
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
let errorMessage = `CORS check failed (${response.status})`;
|
||||
|
||||
try {
|
||||
const errorData = JSON.parse(errorText);
|
||||
if (errorData.message) errorMessage = errorData.message;
|
||||
} catch {}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
} catch (err: any) {
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0]) {
|
||||
url = example.url;
|
||||
origin = example.origin;
|
||||
checkCORS();
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!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`;
|
||||
|
||||
if (results.analysis.allowedMethods.length > 0) {
|
||||
text += `Allowed Methods: ${results.analysis.allowedMethods.join(', ')}\n`;
|
||||
}
|
||||
|
||||
if (results.analysis.allowedHeaders.length > 0) {
|
||||
text += `Allowed Headers: ${results.analysis.allowedHeaders.join(', ')}\n`;
|
||||
}
|
||||
|
||||
text += `Credentials Allowed: ${results.analysis.allowsCredentials ? 'Yes' : 'No'}\n`;
|
||||
|
||||
if (results.analysis.maxAge) {
|
||||
text += `Max Age: ${results.analysis.maxAge} seconds\n`;
|
||||
}
|
||||
|
||||
if (Object.keys(results.preflight.headers || {}).length > 0) {
|
||||
text += '\nCORS Headers:\n';
|
||||
Object.entries(results.preflight.headers).forEach(([key, value]) => {
|
||||
text += `${key}: ${value}\n`;
|
||||
});
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => copiedState = false, 1500);
|
||||
}
|
||||
|
||||
function getAccessClass(allowed: boolean): string {
|
||||
return allowed ? 'success' : 'error';
|
||||
}
|
||||
|
||||
function getAccessIcon(allowed: boolean): string {
|
||||
return allowed ? 'check-circle' : 'x-circle';
|
||||
}
|
||||
|
||||
function getCORSStatusText(): string {
|
||||
if (!results?.analysis) return 'Unknown';
|
||||
|
||||
if (!results.analysis.corsEnabled) return 'No CORS Policy';
|
||||
if (results.analysis.allowsOrigin) return 'Access Allowed';
|
||||
return 'Access Denied';
|
||||
}
|
||||
|
||||
function getCORSStatusClass(): string {
|
||||
if (!results?.analysis) return '';
|
||||
|
||||
if (!results.analysis.corsEnabled) return 'warning';
|
||||
if (results.analysis.allowsOrigin) return 'success';
|
||||
return 'error';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h1>CORS Policy Checker</h1>
|
||||
<p>Test Cross-Origin Resource Sharing (CORS) policies by sending preflight requests and analyzing the server's CORS configuration. Check if your origin is allowed to access the target resource.</p>
|
||||
</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}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<h5>{example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
<div class="card-header">
|
||||
<h3>CORS Test Configuration</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="url" use:tooltip={"Target API/resource URL to test CORS against"}>
|
||||
Target URL
|
||||
<input
|
||||
id="url"
|
||||
type="url"
|
||||
bind:value={url}
|
||||
placeholder="https://api.example.com"
|
||||
class:invalid={url && !isInputValid}
|
||||
onchange={() => { if (isInputValid) checkCORS(); }}
|
||||
/>
|
||||
{#if url && !isInputValid}
|
||||
<span class="error-text">Invalid URL format</span>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="origin" use:tooltip={"Your website's origin (where the request would come from)"}>
|
||||
Origin
|
||||
<input
|
||||
id="origin"
|
||||
type="url"
|
||||
bind:value={origin}
|
||||
placeholder="https://yoursite.com"
|
||||
class:invalid={origin && !isInputValid}
|
||||
onchange={() => { if (isInputValid) checkCORS(); }}
|
||||
/>
|
||||
{#if origin && !isInputValid}
|
||||
<span class="error-text">Invalid origin format</span>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="method" use:tooltip={"HTTP method to test in preflight request"}>
|
||||
Method
|
||||
<select id="method" bind:value={method} onchange={() => { if (isInputValid) checkCORS(); }}>
|
||||
{#each methods as methodOption}
|
||||
<option value={methodOption}>{methodOption}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={checkCORS} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" class="animate-spin" />
|
||||
Checking CORS...
|
||||
{:else}
|
||||
<Icon name="globe" size="sm" />
|
||||
Check CORS Policy
|
||||
{/if}
|
||||
</button>
|
||||
</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}>
|
||||
<Icon name={copiedState ? "check" : "copy"} size="xs" class={copiedState ? "text-green-500" : ""} />
|
||||
{copiedState ? "Copied!" : "Copy Results"}
|
||||
</button>
|
||||
</div>
|
||||
<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" />
|
||||
<div>
|
||||
<strong>{getCORSStatusText()}</strong>
|
||||
<div class="status-text">CORS Status</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-item">
|
||||
<Icon name="shield" size="sm" />
|
||||
<div>
|
||||
<strong>{results.preflight.status || 'Failed'}</strong>
|
||||
<div class="status-text">Preflight Status</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if results.analysis.maxAge}
|
||||
<div class="status-item">
|
||||
<Icon name="clock" size="sm" />
|
||||
<div>
|
||||
<strong>{results.analysis.maxAge}s</strong>
|
||||
<div class="status-text">Cache Max Age</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- CORS Analysis Details -->
|
||||
<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>
|
||||
<strong>CORS Enabled</strong>
|
||||
<p>{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>
|
||||
<strong>Origin Access</strong>
|
||||
<p>
|
||||
{#if results.analysis.allowsOrigin}
|
||||
Origin '{origin}' is allowed to access this resource
|
||||
{:else}
|
||||
Origin '{origin}' is not allowed to access this resource
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cors-item {getAccessClass(results.analysis.allowsCredentials)}">
|
||||
<Icon name={results.analysis.allowsCredentials ? 'check' : 'x'} size="sm" />
|
||||
<div>
|
||||
<strong>Credentials Support</strong>
|
||||
<p>{results.analysis.allowsCredentials ? 'Cookies and credentials can be sent' : 'Cookies and credentials cannot be sent'}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Allowed Methods -->
|
||||
{#if results.analysis.allowedMethods?.length > 0}
|
||||
<div class="record-section">
|
||||
<h4>Allowed Methods</h4>
|
||||
<div class="method-list">
|
||||
{#each results.analysis.allowedMethods as allowedMethod}
|
||||
<span class="method-badge {method === allowedMethod ? 'active' : ''}">{allowedMethod}</span>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Allowed Headers -->
|
||||
{#if results.analysis.allowedHeaders?.length > 0}
|
||||
<div class="record-section">
|
||||
<h4>Allowed Headers</h4>
|
||||
<div class="header-list">
|
||||
{#each results.analysis.allowedHeaders as header}
|
||||
<span class="header-badge">{header}</span>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Raw CORS Headers -->
|
||||
{#if Object.keys(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]}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>{name}:</strong> {value}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{:else if results.analysis.corsEnabled}
|
||||
<div class="no-records">
|
||||
<Icon name="info" size="md" />
|
||||
<p>CORS enabled but no detailed headers available</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="no-records">
|
||||
<Icon name="x-circle" size="md" />
|
||||
<p>No CORS headers found</p>
|
||||
<p class="help-text">The server does not provide CORS headers - cross-origin requests will be blocked by browsers</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>CORS Check Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
<div class="card-header">
|
||||
<h3>About CORS</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="info-grid">
|
||||
<div class="info-section">
|
||||
<h4>What is CORS?</h4>
|
||||
<p>Cross-Origin Resource Sharing (CORS) is a security mechanism that allows or restricts web pages from making requests to a different domain, protocol, or port than the one serving the web page.</p>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h4>Preflight Requests</h4>
|
||||
<p>For certain requests, browsers send a preflight OPTIONS request to check if the actual request is allowed. The server responds with CORS headers indicating permissions.</p>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h4>Common CORS Headers</h4>
|
||||
<ul>
|
||||
<li><strong>Access-Control-Allow-Origin:</strong> Allowed origins</li>
|
||||
<li><strong>Access-Control-Allow-Methods:</strong> Allowed HTTP methods</li>
|
||||
<li><strong>Access-Control-Allow-Headers:</strong> Allowed request headers</li>
|
||||
<li><strong>Access-Control-Allow-Credentials:</strong> Cookie support</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.cors-analysis {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.cors-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-md);
|
||||
padding: var(--spacing-md);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--bg-secondary);
|
||||
|
||||
&.success {
|
||||
border-color: var(--color-success);
|
||||
background: color-mix(in srgb, var(--color-success), transparent 95%);
|
||||
}
|
||||
|
||||
&.error {
|
||||
border-color: var(--color-error);
|
||||
background: color-mix(in srgb, var(--color-error), transparent 95%);
|
||||
}
|
||||
|
||||
strong {
|
||||
color: var(--text-primary);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
display: block;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.method-list, .header-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.method-badge {
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 500;
|
||||
font-family: var(--font-mono);
|
||||
|
||||
&.active {
|
||||
background: var(--color-primary);
|
||||
color: white;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.header-badge {
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-xs);
|
||||
font-family: var(--font-mono);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
// Page-specific styles only (common utilities moved to diagnostics-pages.scss)
|
||||
</style>
|
||||
@@ -0,0 +1,415 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { isValidDomainName, formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
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 methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
|
||||
|
||||
const examples = [
|
||||
{ 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' },
|
||||
{ url: 'https://httpbin.org/status/404', method: 'GET', description: '404 status response' },
|
||||
{ url: 'https://httpbin.org/redirect/3', method: 'GET', description: 'Redirect chain headers' },
|
||||
{ url: 'https://httpbin.org/gzip', method: 'GET', description: 'Compressed response headers' }
|
||||
];
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) return false;
|
||||
try {
|
||||
const parsed = new URL(trimmedUrl);
|
||||
return ['http:', 'https:'].includes(parsed.protocol);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
function parseCustomHeaders(): Record<string, string> {
|
||||
const headers: Record<string, string> = {};
|
||||
if (!customHeadersText.trim()) return headers;
|
||||
|
||||
const lines = customHeadersText.split('\n');
|
||||
for (const line of lines) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) continue;
|
||||
|
||||
const colonIndex = trimmed.indexOf(':');
|
||||
if (colonIndex > 0) {
|
||||
const key = trimmed.slice(0, colonIndex).trim();
|
||||
const value = trimmed.slice(colonIndex + 1).trim();
|
||||
if (key && value) {
|
||||
headers[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
async function checkHeaders() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
|
||||
// Validation
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) {
|
||||
error = 'URL is required';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(trimmedUrl);
|
||||
} catch {
|
||||
error = 'Invalid URL format';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const customHeaders = parseCustomHeaders();
|
||||
|
||||
const response = await fetch('/api/internal/diagnostics/http', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
action: 'headers',
|
||||
url: trimmedUrl,
|
||||
method,
|
||||
headers: customHeaders
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
let errorMessage = `Request failed (${response.status})`;
|
||||
|
||||
try {
|
||||
const errorData = JSON.parse(errorText);
|
||||
if (errorData.message) errorMessage = errorData.message;
|
||||
} catch {}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
} catch (err: any) {
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0], index: number) {
|
||||
url = example.url;
|
||||
method = example.method;
|
||||
customHeadersText = '';
|
||||
selectedExampleIndex = index;
|
||||
checkHeaders();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.headers) return;
|
||||
|
||||
let text = `${method} ${results.url}\nStatus: ${results.status} ${results.statusText}\n\nResponse Headers:\n`;
|
||||
Object.entries(results.headers).forEach(([key, value]) => {
|
||||
text += `${key}: ${value}\n`;
|
||||
});
|
||||
|
||||
if (results.size) {
|
||||
text += `\nContent-Length: ${results.size} bytes`;
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => copiedState = false, 1500);
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
||||
}
|
||||
|
||||
function getStatusClass(status: number): string {
|
||||
if (status >= 200 && status < 300) return 'success';
|
||||
if (status >= 300 && status < 400) return 'warning';
|
||||
if (status >= 400) return 'error';
|
||||
return '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h1>HTTP Headers Analyzer</h1>
|
||||
<p>Analyze HTTP response headers, status codes, and response metadata. Supports custom request methods and headers for comprehensive HTTP testing.</p>
|
||||
</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}
|
||||
<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>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
<div class="card-header">
|
||||
<h3>Request Configuration</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="url" use:tooltip={"Enter the URL to analyze"}>
|
||||
URL
|
||||
<input
|
||||
id="url"
|
||||
type="url"
|
||||
bind:value={url}
|
||||
placeholder="https://example.com"
|
||||
class:invalid={url && !isInputValid}
|
||||
onchange={() => { clearExampleSelection(); if (isInputValid) checkHeaders(); }}
|
||||
/>
|
||||
{#if url && !isInputValid}
|
||||
<span class="error-text">Invalid URL format</span>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="method" use:tooltip={"HTTP method to use"}>
|
||||
Method
|
||||
<select id="method" bind:value={method} onchange={() => { clearExampleSelection(); if (isInputValid) checkHeaders(); }}>
|
||||
{#each methods as methodOption}
|
||||
<option value={methodOption}>{methodOption}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="headers" use:tooltip={"Custom headers (one per line: 'Name: Value')"}>
|
||||
Custom Headers (Optional)
|
||||
<textarea
|
||||
id="headers"
|
||||
bind:value={customHeadersText}
|
||||
placeholder="User-Agent: My Custom Agent Authorization: Bearer token123"
|
||||
rows="3"
|
||||
onchange={() => { clearExampleSelection(); if (isInputValid) checkHeaders(); }}
|
||||
></textarea>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={checkHeaders} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" class="animate-spin" />
|
||||
Analyzing Headers...
|
||||
{:else}
|
||||
<Icon name="globe" size="sm" />
|
||||
Analyze Headers
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>HTTP Response Analysis</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? "check" : "copy"} size="xs" class={copiedState ? "text-green-500" : ""} />
|
||||
{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" />
|
||||
<div>
|
||||
<strong>{results.status} {results.statusText}</strong>
|
||||
<div class="status-text">HTTP Status</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#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>
|
||||
</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">
|
||||
<h4>Response Headers</h4>
|
||||
<div class="records-list">
|
||||
{#each Object.entries(results.headers) as [name, value]}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>{name}:</strong> {value}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if results.timings}
|
||||
<div class="record-section">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
<div class="card-header">
|
||||
<h3>About HTTP Headers</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="info-grid">
|
||||
<div class="info-section">
|
||||
<h4>Response Headers</h4>
|
||||
<p>HTTP headers provide metadata about the response, including content type, caching instructions, security policies, and server information.</p>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h4>Status Codes</h4>
|
||||
<ul>
|
||||
<li><strong>2xx:</strong> Success responses</li>
|
||||
<li><strong>3xx:</strong> Redirection responses</li>
|
||||
<li><strong>4xx:</strong> Client error responses</li>
|
||||
<li><strong>5xx:</strong> Server error responses</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h4>Common Headers</h4>
|
||||
<ul>
|
||||
<li><strong>Content-Type:</strong> MIME type of content</li>
|
||||
<li><strong>Cache-Control:</strong> Caching directives</li>
|
||||
<li><strong>Set-Cookie:</strong> Cookie instructions</li>
|
||||
<li><strong>Location:</strong> Redirect target URL</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.help-text {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
margin-top: var(--spacing-sm);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
min-height: 80px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: var(--text-error);
|
||||
font-size: var(--font-size-xs);
|
||||
margin-top: var(--spacing-xs);
|
||||
}
|
||||
|
||||
|
||||
// Page-specific styles only (common utilities moved to diagnostics-pages.scss)
|
||||
</style>
|
||||
@@ -0,0 +1,554 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
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 methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE'];
|
||||
|
||||
const examples = [
|
||||
{ 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' }
|
||||
];
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) return false;
|
||||
try {
|
||||
const parsed = new URL(trimmedUrl);
|
||||
return ['http:', 'https:'].includes(parsed.protocol);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
async function measurePerformance() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
|
||||
// Validation
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) {
|
||||
error = 'URL is required';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(trimmedUrl);
|
||||
} catch {
|
||||
error = 'Invalid URL format';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/http', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
action: 'perf',
|
||||
url: trimmedUrl,
|
||||
method
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
let errorMessage = `Performance test failed (${response.status})`;
|
||||
|
||||
try {
|
||||
const errorData = JSON.parse(errorText);
|
||||
if (errorData.message) errorMessage = errorData.message;
|
||||
} catch {}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
} catch (err: any) {
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0]) {
|
||||
url = example.url;
|
||||
measurePerformance();
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.timings) return;
|
||||
|
||||
let text = `HTTP Performance Analysis\nURL: ${results.url}\nMethod: ${method}\nStatus: ${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`;
|
||||
|
||||
if (results.timings.tls > 0) {
|
||||
text += `TLS Handshake: ${results.timings.tls.toFixed(1)}ms ${results.timings.tls_note ? `(${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`;
|
||||
|
||||
if (results.size) {
|
||||
text += `Response Size: ${formatBytes(results.size)}\n`;
|
||||
}
|
||||
|
||||
text += `HTTPS: ${results.performance.isHTTPS ? 'Yes' : 'No'}\n`;
|
||||
text += `Compression: ${results.performance.hasCompression ? 'Yes' : 'No'}\n`;
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => copiedState = false, 1500);
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
||||
}
|
||||
|
||||
function getPerformanceClass(timing: number, thresholds: { good: number; fair: number }): string {
|
||||
if (timing <= thresholds.good) return 'success';
|
||||
if (timing <= thresholds.fair) return 'warning';
|
||||
return 'error';
|
||||
}
|
||||
|
||||
function getPerformanceGrade(totalTime: number): { grade: string; class: string } {
|
||||
if (totalTime <= 200) return { grade: 'A', class: 'success' };
|
||||
if (totalTime <= 500) return { grade: 'B', class: 'success' };
|
||||
if (totalTime <= 1000) return { grade: 'C', class: 'warning' };
|
||||
if (totalTime <= 2000) return { grade: 'D', class: 'warning' };
|
||||
return { grade: 'F', class: 'error' };
|
||||
}
|
||||
|
||||
function calculateThroughput(size: number, time: number): string {
|
||||
if (!size || !time) return 'Unknown';
|
||||
const bitsPerSecond = (size * 8) / (time / 1000);
|
||||
const mbps = bitsPerSecond / (1024 * 1024);
|
||||
return `${mbps.toFixed(2)} Mbps`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h1>HTTP Performance Analyzer</h1>
|
||||
<p>Measure HTTP request performance including DNS resolution, TCP connection, TLS handshake, and response times. Get detailed timing breakdowns and performance insights.</p>
|
||||
</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}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<h5>{example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
<div class="card-header">
|
||||
<h3>Performance Test Configuration</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="url" use:tooltip={"Enter the URL to measure performance for"}>
|
||||
URL
|
||||
<input
|
||||
id="url"
|
||||
type="url"
|
||||
bind:value={url}
|
||||
placeholder="https://example.com"
|
||||
class:invalid={url && !isInputValid}
|
||||
onchange={() => { if (isInputValid) measurePerformance(); }}
|
||||
/>
|
||||
{#if url && !isInputValid}
|
||||
<span class="error-text">Invalid URL format</span>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="method" use:tooltip={"HTTP method to use for the request"}>
|
||||
Method
|
||||
<select id="method" bind:value={method} onchange={() => { if (isInputValid) measurePerformance(); }}>
|
||||
{#each methods as methodOption}
|
||||
<option value={methodOption}>{methodOption}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={measurePerformance} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" class="animate-spin" />
|
||||
Measuring Performance...
|
||||
{:else}
|
||||
<Icon name="activity" size="sm" />
|
||||
Measure Performance
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
{@const grade = getPerformanceGrade(results.timings.total)}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>Performance Analysis</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? "check" : "copy"} size="xs" class={copiedState ? "text-green-500" : ""} />
|
||||
{copiedState ? "Copied!" : "Copy Results"}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Performance Overview -->
|
||||
<div class="status-overview">
|
||||
<div class="status-item {grade.class}">
|
||||
<Icon name="zap" size="sm" />
|
||||
<div>
|
||||
<strong>Grade {grade.grade}</strong>
|
||||
<div class="status-text">{results.timings.total.toFixed(0)}ms Total</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-item">
|
||||
<Icon name="activity" size="sm" />
|
||||
<div>
|
||||
<strong>{results.status}</strong>
|
||||
<div class="status-text">HTTP Status</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#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>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if results.size && results.timings.total}
|
||||
<div class="status-item">
|
||||
<Icon name="wifi" size="sm" />
|
||||
<div>
|
||||
<strong>{calculateThroughput(results.size, results.timings.total)}</strong>
|
||||
<div class="status-text">Throughput</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Timing Breakdown -->
|
||||
<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-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}
|
||||
</div>
|
||||
<div class="timing-bar">
|
||||
<div class="timing-fill" style="width: {(results.timings.dns / results.timings.total) * 100}%"></div>
|
||||
</div>
|
||||
<div class="timing-value">{results.timings.dns.toFixed(1)}ms</div>
|
||||
</div>
|
||||
|
||||
<div class="timing-item {getPerformanceClass(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}
|
||||
</div>
|
||||
<div class="timing-bar">
|
||||
<div class="timing-fill" style="width: {(results.timings.tcp / results.timings.total) * 100}%"></div>
|
||||
</div>
|
||||
<div class="timing-value">{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 })}">
|
||||
<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}
|
||||
</div>
|
||||
<div class="timing-bar">
|
||||
<div class="timing-fill" style="width: {(results.timings.tls / results.timings.total) * 100}%"></div>
|
||||
</div>
|
||||
<div class="timing-value">{results.timings.tls.toFixed(1)}ms</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="timing-item {getPerformanceClass(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>
|
||||
<div class="timing-value">{results.timings.ttfb.toFixed(1)}ms</div>
|
||||
</div>
|
||||
|
||||
<div class="timing-item total">
|
||||
<div class="timing-label">
|
||||
<Icon name="zap" size="xs" />
|
||||
<span>Total Time</span>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Performance Features -->
|
||||
<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>
|
||||
<strong>HTTPS</strong>
|
||||
<p>{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>
|
||||
<strong>Compression</strong>
|
||||
<p>{results.performance.hasCompression ? 'Response is compressed' : 'No compression detected'}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="feature-item">
|
||||
<Icon name="server" size="sm" />
|
||||
<div>
|
||||
<strong>HTTP Version</strong>
|
||||
<p>{results.performance.httpVersion}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="feature-item">
|
||||
<Icon name="repeat" size="sm" />
|
||||
<div>
|
||||
<strong>Connection Reuse</strong>
|
||||
<p>{results.performance.connectionReused}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</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>Performance Test Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
<div class="card-header">
|
||||
<h3>About HTTP Performance</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="info-grid">
|
||||
<div class="info-section">
|
||||
<h4>Timing Components</h4>
|
||||
<ul>
|
||||
<li><strong>DNS:</strong> Domain name resolution time</li>
|
||||
<li><strong>TCP:</strong> TCP connection establishment</li>
|
||||
<li><strong>TLS:</strong> SSL/TLS handshake (HTTPS only)</li>
|
||||
<li><strong>TTFB:</strong> Server processing and response start</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h4>Performance Grades</h4>
|
||||
<ul>
|
||||
<li><strong>A (≤200ms):</strong> Excellent performance</li>
|
||||
<li><strong>B (≤500ms):</strong> Good performance</li>
|
||||
<li><strong>C (≤1000ms):</strong> Acceptable performance</li>
|
||||
<li><strong>D/F (>1000ms):</strong> Poor performance</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h4>Optimization Tips</h4>
|
||||
<p>Use CDN for faster response times, enable compression, implement HTTP/2, optimize DNS resolution, and consider connection keep-alive for multiple requests.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.timing-chart {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.timing-item {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 2fr auto;
|
||||
align-items: center;
|
||||
gap: var(--spacing-md);
|
||||
padding: var(--spacing-sm);
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--border-color);
|
||||
background: var(--bg-secondary);
|
||||
|
||||
&.success {
|
||||
border-color: var(--color-success);
|
||||
background: color-mix(in srgb, var(--color-success), transparent 95%);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
border-color: var(--color-warning);
|
||||
background: color-mix(in srgb, var(--color-warning), transparent 95%);
|
||||
}
|
||||
|
||||
&.error {
|
||||
border-color: var(--color-error);
|
||||
background: color-mix(in srgb, var(--color-error), transparent 95%);
|
||||
}
|
||||
|
||||
&.total {
|
||||
border-color: var(--color-primary);
|
||||
background: color-mix(in srgb, var(--color-primary), transparent 90%);
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.timing-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 500;
|
||||
|
||||
.timing-note {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
font-weight: normal;
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
|
||||
.timing-bar {
|
||||
position: relative;
|
||||
height: 20px;
|
||||
background: color-mix(in srgb, var(--text-secondary), transparent 80%);
|
||||
border-radius: var(--radius-sm);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.timing-fill {
|
||||
height: 100%;
|
||||
background: var(--color-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.timing-value {
|
||||
font-family: var(--font-mono);
|
||||
font-weight: 600;
|
||||
font-size: var(--font-size-sm);
|
||||
min-width: 60px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.feature-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.feature-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-md);
|
||||
padding: var(--spacing-md);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--bg-secondary);
|
||||
|
||||
&.success {
|
||||
border-color: var(--color-success);
|
||||
background: color-mix(in srgb, var(--color-success), transparent 95%);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
border-color: var(--color-warning);
|
||||
background: color-mix(in srgb, var(--color-warning), transparent 95%);
|
||||
}
|
||||
|
||||
strong {
|
||||
color: var(--text-primary);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
display: block;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
// Page-specific styles only (common utilities moved to diagnostics-pages.scss)
|
||||
</style>
|
||||
@@ -0,0 +1,535 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
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 = [
|
||||
{ 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' },
|
||||
{ url: 'https://httpbin.org/redirect-to?url=https://example.com', description: 'Redirect to external site' },
|
||||
{ url: 'https://httpbin.org/redirect/5', description: '5-hop redirect chain' },
|
||||
{ url: 'https://httpbin.org/relative-redirect/2', description: 'Relative path redirects' }
|
||||
];
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) return false;
|
||||
try {
|
||||
const parsed = new URL(trimmedUrl);
|
||||
return ['http:', 'https:'].includes(parsed.protocol);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
async function traceRedirects() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
|
||||
// Validation
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) {
|
||||
error = 'URL is required';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(trimmedUrl);
|
||||
} catch {
|
||||
error = 'Invalid URL format';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (maxRedirects < 1 || maxRedirects > 50) {
|
||||
error = 'Max redirects must be between 1 and 50';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/http', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
action: 'redirect-trace',
|
||||
url: trimmedUrl,
|
||||
maxRedirects
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
let errorMessage = `Redirect trace failed (${response.status})`;
|
||||
|
||||
try {
|
||||
const errorData = JSON.parse(errorText);
|
||||
if (errorData.message) errorMessage = errorData.message;
|
||||
} catch {}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
} catch (err: any) {
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0], index: number) {
|
||||
url = example.url;
|
||||
selectedExampleIndex = index;
|
||||
traceRedirects();
|
||||
}
|
||||
|
||||
function clearExampleSelection() {
|
||||
selectedExampleIndex = null;
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.redirectChain) return;
|
||||
|
||||
let text = `Redirect Chain Analysis\nOriginal URL: ${url}\nTotal Redirects: ${results.totalRedirects}\n\n`;
|
||||
|
||||
results.redirectChain.forEach((step: any, i: number) => {
|
||||
text += `${i + 1}. ${step.url}\n`;
|
||||
text += ` Status: ${step.status}\n`;
|
||||
if (step.location) {
|
||||
text += ` Location: ${step.location}\n`;
|
||||
}
|
||||
text += '\n';
|
||||
});
|
||||
|
||||
text += `Final URL: ${results.finalUrl}\nFinal Status: ${results.finalStatus}`;
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => copiedState = false, 1500);
|
||||
}
|
||||
|
||||
function getStatusClass(status: number): string {
|
||||
if (status >= 200 && status < 300) return 'success';
|
||||
if (status >= 300 && status < 400) return 'warning';
|
||||
if (status >= 400) return 'error';
|
||||
return '';
|
||||
}
|
||||
|
||||
function getStatusIcon(status: number): string {
|
||||
if (status >= 200 && status < 300) return 'check-circle';
|
||||
if (status >= 300 && status < 400) return 'arrow-right';
|
||||
if (status >= 400) return 'alert-triangle';
|
||||
return 'circle';
|
||||
}
|
||||
|
||||
function hasHSTS(headers: Record<string, string>): boolean {
|
||||
return !!headers['strict-transport-security'];
|
||||
}
|
||||
|
||||
function isSecureRedirect(fromUrl: string, toUrl: string): boolean {
|
||||
try {
|
||||
const from = new URL(fromUrl);
|
||||
const to = new URL(toUrl);
|
||||
return from.protocol === 'http:' && to.protocol === 'https:';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h1>HTTP Redirect Tracer</h1>
|
||||
<p>Follow and analyze HTTP redirect chains to understand the complete journey from initial URL to final destination. Track status codes, locations, and security implications.</p>
|
||||
</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}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<h5>{example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
<div class="card-header">
|
||||
<h3>Redirect Trace Configuration</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="url" use:tooltip={"Enter the URL to trace redirects for"}>
|
||||
URL
|
||||
<input
|
||||
id="url"
|
||||
type="url"
|
||||
bind:value={url}
|
||||
placeholder="https://bit.ly/example"
|
||||
class:invalid={url && !isInputValid}
|
||||
onchange={() => { if (isInputValid) traceRedirects(); }}
|
||||
/>
|
||||
{#if url && !isInputValid}
|
||||
<span class="error-text">Invalid URL format</span>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="maxRedirects" use:tooltip={"Maximum number of redirects to follow"}>
|
||||
Max Redirects
|
||||
<input
|
||||
id="maxRedirects"
|
||||
type="number"
|
||||
bind:value={maxRedirects}
|
||||
min="1"
|
||||
max="50"
|
||||
onchange={() => { if (isInputValid) traceRedirects(); }}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={traceRedirects} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" class="animate-spin" />
|
||||
Tracing Redirects...
|
||||
{:else}
|
||||
<Icon name="link" size="sm" />
|
||||
Trace Redirects
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header">
|
||||
<h3>Redirect Chain Analysis</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? "check" : "copy"} size="xs" class={copiedState ? "text-green-500" : ""} />
|
||||
{copiedState ? "Copied!" : "Copy Chain"}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Summary -->
|
||||
<div class="status-overview">
|
||||
<div class="status-item">
|
||||
<Icon name="link" size="sm" />
|
||||
<div>
|
||||
<strong>{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>
|
||||
<strong>{results.finalStatus}</strong>
|
||||
<div class="status-text">Final Status</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#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>
|
||||
|
||||
<!-- Redirect Chain -->
|
||||
{#if results.redirectChain?.length > 0}
|
||||
<div class="record-section">
|
||||
<h4>Redirect Chain</h4>
|
||||
<div class="redirect-chain">
|
||||
{#each results.redirectChain as step, i}
|
||||
<div class="redirect-step">
|
||||
<div class="step-number">{i + 1}</div>
|
||||
<div class="step-content">
|
||||
<div class="step-header">
|
||||
<div class="step-status {getStatusClass(step.status)}">
|
||||
<Icon name={getStatusIcon(step.status)} size="xs" />
|
||||
{step.status}
|
||||
</div>
|
||||
{#if hasHSTS(step.headers)}
|
||||
<div class="security-badge" use:tooltip={"HSTS header present"}>
|
||||
<Icon name="shield" size="xs" />
|
||||
HSTS
|
||||
</div>
|
||||
{/if}
|
||||
{#if i < 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
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="step-url mono">{step.url}</div>
|
||||
{#if step.location}
|
||||
<div class="step-location">
|
||||
<Icon name="arrow-right" size="xs" />
|
||||
<span class="mono">{step.location}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if i < results.redirectChain.length - 1}
|
||||
<div class="redirect-arrow">
|
||||
<Icon name="chevron-down" size="sm" />
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<div class="final-url mono">{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>
|
||||
</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}
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
<div class="card-header">
|
||||
<h3>About HTTP Redirects</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="info-grid">
|
||||
<div class="info-section">
|
||||
<h4>Redirect Types</h4>
|
||||
<ul>
|
||||
<li><strong>301:</strong> Permanent redirect</li>
|
||||
<li><strong>302:</strong> Temporary redirect</li>
|
||||
<li><strong>303:</strong> See other (POST → GET)</li>
|
||||
<li><strong>307:</strong> Temporary (preserve method)</li>
|
||||
<li><strong>308:</strong> Permanent (preserve method)</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h4>Security Considerations</h4>
|
||||
<ul>
|
||||
<li><strong>HSTS:</strong> Prevents downgrade attacks</li>
|
||||
<li><strong>HTTP → HTTPS:</strong> Security upgrades</li>
|
||||
<li><strong>Open Redirects:</strong> Potential security risk</li>
|
||||
<li><strong>Redirect Loops:</strong> Infinite chains</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h4>Performance Impact</h4>
|
||||
<p>Each redirect adds latency. Minimize redirect chains for better performance. Use 301/308 for permanent moves and 302/307 for temporary ones.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.redirect-chain {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.redirect-step {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.step-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.step-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 500;
|
||||
|
||||
&.success {
|
||||
background: color-mix(in srgb, var(--color-success), transparent 90%);
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
background: color-mix(in srgb, var(--color-warning), transparent 90%);
|
||||
color: var(--color-warning);
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: color-mix(in srgb, var(--color-error), transparent 90%);
|
||||
color: var(--color-error);
|
||||
}
|
||||
}
|
||||
|
||||
.security-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-xs);
|
||||
background: color-mix(in srgb, var(--color-info), transparent 90%);
|
||||
color: var(--color-info);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-xs);
|
||||
|
||||
&.success {
|
||||
background: color-mix(in srgb, var(--color-success), transparent 90%);
|
||||
color: var(--color-success);
|
||||
}
|
||||
}
|
||||
|
||||
.step-url {
|
||||
font-size: var(--font-size-sm);
|
||||
word-break: break-all;
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.step-location {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
|
||||
span {
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
|
||||
.redirect-arrow {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
color: var(--text-secondary);
|
||||
margin: var(--spacing-xs) 0;
|
||||
}
|
||||
|
||||
.final-destination {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-md);
|
||||
padding: var(--spacing-md);
|
||||
background: var(--bg-secondary);
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.final-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-sm);
|
||||
border-radius: var(--radius-sm);
|
||||
font-weight: 500;
|
||||
|
||||
&.success {
|
||||
background: color-mix(in srgb, var(--color-success), transparent 90%);
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
background: color-mix(in srgb, var(--color-warning), transparent 90%);
|
||||
color: var(--color-warning);
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: color-mix(in srgb, var(--color-error), transparent 90%);
|
||||
color: var(--color-error);
|
||||
}
|
||||
}
|
||||
|
||||
.final-url {
|
||||
flex: 1;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.step-number {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
background: var(--color-primary);
|
||||
color: var(--bg-primary);
|
||||
border-radius: 50%;
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 500;
|
||||
margin-right: var(--spacing-sm);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.step-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
// Page-specific styles only (common utilities moved to diagnostics-pages.scss)
|
||||
</style>
|
||||
@@ -0,0 +1,442 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { formatDNSError } from '$lib/utils/dns-validation.js';
|
||||
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 = [
|
||||
{ url: 'https://github.com', description: 'GitHub security headers' },
|
||||
{ url: 'https://www.cloudflare.com', description: 'Cloudflare security setup' },
|
||||
{ url: 'https://httpbin.org/response-headers?Strict-Transport-Security=max-age=31536000', description: 'Example with HSTS' },
|
||||
{ url: 'https://example.com', description: 'Basic site (minimal headers)' }
|
||||
];
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) return false;
|
||||
try {
|
||||
const parsed = new URL(trimmedUrl);
|
||||
return ['http:', 'https:'].includes(parsed.protocol);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
async function analyzeSecurity() {
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
|
||||
// Validation
|
||||
const trimmedUrl = url.trim();
|
||||
if (!trimmedUrl) {
|
||||
error = 'URL is required';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(trimmedUrl);
|
||||
} catch {
|
||||
error = 'Invalid URL format';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/http', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
action: 'security',
|
||||
url: trimmedUrl
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
let errorMessage = `Security analysis failed (${response.status})`;
|
||||
|
||||
try {
|
||||
const errorData = JSON.parse(errorText);
|
||||
if (errorData.message) errorMessage = errorData.message;
|
||||
} catch {}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
} catch (err: any) {
|
||||
error = formatDNSError(err);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function loadExample(example: typeof examples[0]) {
|
||||
url = example.url;
|
||||
analyzeSecurity();
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results?.analysis) return;
|
||||
|
||||
let text = `Security Headers Analysis\nURL: ${results.url}\nStatus: ${results.status}\n\n`;
|
||||
|
||||
text += "Security Headers Found:\n";
|
||||
Object.entries(results.headers || {}).forEach(([key, value]) => {
|
||||
text += `${key}: ${value}\n`;
|
||||
});
|
||||
|
||||
text += "\nSecurity Analysis:\n";
|
||||
results.analysis.forEach((item: any) => {
|
||||
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);
|
||||
}
|
||||
|
||||
function getAnalysisClass(status: string): string {
|
||||
switch (status) {
|
||||
case 'present': return 'success';
|
||||
case 'weak': return 'warning';
|
||||
case 'missing': return 'error';
|
||||
default: return '';
|
||||
}
|
||||
}
|
||||
|
||||
function getAnalysisIcon(status: string): string {
|
||||
switch (status) {
|
||||
case 'present': return 'shield-check';
|
||||
case 'weak': return 'alert-triangle';
|
||||
case 'missing': return 'shield-x';
|
||||
default: return 'shield';
|
||||
}
|
||||
}
|
||||
|
||||
function getOverallScore(): { score: number; grade: string; class: string } {
|
||||
if (!results?.analysis) return { score: 0, grade: 'F', class: 'error' };
|
||||
|
||||
const total = results.analysis.length;
|
||||
const present = results.analysis.filter((a: any) => a.status === 'present').length;
|
||||
const weak = results.analysis.filter((a: any) => a.status === 'weak').length;
|
||||
|
||||
const score = Math.round(((present + weak * 0.5) / total) * 100);
|
||||
|
||||
let grade: string;
|
||||
let className: string;
|
||||
|
||||
if (score >= 90) { grade = 'A'; className = 'success'; }
|
||||
else if (score >= 80) { grade = 'B'; className = 'success'; }
|
||||
else if (score >= 70) { grade = 'C'; className = 'warning'; }
|
||||
else if (score >= 60) { grade = 'D'; className = 'warning'; }
|
||||
else { grade = 'F'; className = 'error'; }
|
||||
|
||||
return { score, grade, class: className };
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h1>HTTP Security Headers Analyzer</h1>
|
||||
<p>Analyze and evaluate security headers to identify potential vulnerabilities and security improvements. Check for HSTS, CSP, XSS protection, and other essential security headers.</p>
|
||||
</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}
|
||||
<button class="example-card" onclick={() => loadExample(example)}>
|
||||
<h5>{example.url}</h5>
|
||||
<p>{example.description}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
<div class="card-header">
|
||||
<h3>Security Analysis</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-group">
|
||||
<label for="url" use:tooltip={"Enter the URL to analyze security headers for"}>
|
||||
URL
|
||||
<input
|
||||
id="url"
|
||||
type="url"
|
||||
bind:value={url}
|
||||
placeholder="https://example.com"
|
||||
class:invalid={url && !isInputValid}
|
||||
onchange={() => { if (isInputValid) analyzeSecurity(); }}
|
||||
/>
|
||||
{#if url && !isInputValid}
|
||||
<span class="error-text">Invalid URL format</span>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={analyzeSecurity} disabled={loading || !isInputValid}>
|
||||
{#if loading}
|
||||
<Icon name="loader-2" size="sm" class="animate-spin" />
|
||||
Analyzing Security...
|
||||
{:else}
|
||||
<Icon name="shield" size="sm" />
|
||||
Analyze Security Headers
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if 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}>
|
||||
<Icon name={copiedState ? "check" : "copy"} size="xs" class={copiedState ? "text-green-500" : ""} />
|
||||
{copiedState ? "Copied!" : "Copy Analysis"}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Security Score -->
|
||||
<div class="status-overview">
|
||||
<div class="status-item {overallScore.class}">
|
||||
<Icon name="shield" size="sm" />
|
||||
<div>
|
||||
<strong>Grade {overallScore.grade}</strong>
|
||||
<div class="status-text">Security Score: {overallScore.score}%</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-item">
|
||||
<Icon name="check-circle" size="sm" />
|
||||
<div>
|
||||
<strong>{results.analysis?.filter((a: any) => a.status === 'present').length || 0}</strong>
|
||||
<div class="status-text">Headers Present</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-item">
|
||||
<Icon name="alert-triangle" size="sm" />
|
||||
<div>
|
||||
<strong>{results.analysis?.filter((a: any) => a.status === 'missing').length || 0}</strong>
|
||||
<div class="status-text">Headers Missing</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Security Analysis -->
|
||||
<div class="record-section">
|
||||
<h4>Security Header Analysis</h4>
|
||||
<div class="security-analysis">
|
||||
{#each results.analysis as analysis}
|
||||
<div class="analysis-item {getAnalysisClass(analysis.status)}">
|
||||
<div class="analysis-header">
|
||||
<div class="analysis-status">
|
||||
<Icon name={getAnalysisIcon(analysis.status)} size="sm" />
|
||||
<strong>{analysis.header}</strong>
|
||||
</div>
|
||||
<div class="analysis-badge {getAnalysisClass(analysis.status)}">
|
||||
{analysis.status}
|
||||
</div>
|
||||
</div>
|
||||
<div class="analysis-message">{analysis.message}</div>
|
||||
{#if analysis.recommendation}
|
||||
<div class="analysis-recommendation">
|
||||
<Icon name="lightbulb" size="xs" />
|
||||
{analysis.recommendation}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Present Headers -->
|
||||
{#if Object.keys(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]}
|
||||
<div class="record-item">
|
||||
<div class="record-data">
|
||||
<strong>{name}:</strong> {value}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="no-records">
|
||||
<Icon name="shield-x" size="md" />
|
||||
<p>No security headers found</p>
|
||||
<p class="help-text">This site may be vulnerable to various attacks</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>Security Analysis Failed</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Educational Content -->
|
||||
<div class="card info-card">
|
||||
<div class="card-header">
|
||||
<h3>About Security Headers</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="info-grid">
|
||||
<div class="info-section">
|
||||
<h4>Critical Headers</h4>
|
||||
<ul>
|
||||
<li><strong>Strict-Transport-Security:</strong> Forces HTTPS connections</li>
|
||||
<li><strong>Content-Security-Policy:</strong> Prevents XSS and injection attacks</li>
|
||||
<li><strong>X-Frame-Options:</strong> Prevents clickjacking attacks</li>
|
||||
<li><strong>X-Content-Type-Options:</strong> Prevents MIME sniffing</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h4>Additional Protection</h4>
|
||||
<ul>
|
||||
<li><strong>Referrer-Policy:</strong> Controls referrer information</li>
|
||||
<li><strong>Permissions-Policy:</strong> Controls browser features</li>
|
||||
<li><strong>Cross-Origin-*:</strong> CORS and isolation policies</li>
|
||||
<li><strong>X-XSS-Protection:</strong> Legacy XSS protection</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h4>Implementation Tips</h4>
|
||||
<p>Start with basic headers (HSTS, CSP, X-Frame-Options) and gradually add more. Test thoroughly as some headers may break functionality if misconfigured.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.security-analysis {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.analysis-item {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
background: var(--bg-secondary);
|
||||
|
||||
&.success {
|
||||
border-color: var(--color-success);
|
||||
background: color-mix(in srgb, var(--color-success), transparent 95%);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
border-color: var(--color-warning);
|
||||
background: color-mix(in srgb, var(--color-warning), transparent 95%);
|
||||
}
|
||||
|
||||
&.error {
|
||||
border-color: var(--color-error);
|
||||
background: color-mix(in srgb, var(--color-error), transparent 95%);
|
||||
}
|
||||
}
|
||||
|
||||
.analysis-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.analysis-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.analysis-badge {
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 500;
|
||||
text-transform: capitalize;
|
||||
|
||||
&.success {
|
||||
background: var(--color-success);
|
||||
color: white;
|
||||
}
|
||||
|
||||
&.warning {
|
||||
background: var(--color-warning);
|
||||
color: white;
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: var(--color-error);
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
|
||||
.analysis-message {
|
||||
color: var(--text-primary);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
.analysis-recommendation {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-xs);
|
||||
color: var(--text-secondary);
|
||||
font-size: var(--font-size-xs);
|
||||
font-style: italic;
|
||||
padding-top: var(--spacing-xs);
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: var(--text-error);
|
||||
font-size: var(--font-size-xs);
|
||||
margin-top: var(--spacing-xs);
|
||||
}
|
||||
|
||||
// Page-specific styles only (common utilities moved to diagnostics-pages.scss)
|
||||
</style>
|
||||
+247
-344
@@ -1,116 +1,102 @@
|
||||
// Shared styles for diagnostic pages
|
||||
// Common components used across multiple DNS diagnostic tools
|
||||
// Clean, minimal design using only valid CSS variables
|
||||
|
||||
// Main container
|
||||
// Base card styling
|
||||
.card {
|
||||
margin: 0 auto;
|
||||
&.warning-card, &.error-card {
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
padding: var(--spacing-md);
|
||||
border-radius: var(--radius-md);
|
||||
|
||||
&.input-card {
|
||||
background: var(--bg-tertiary);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
.warning-content {
|
||||
display: flex;
|
||||
gap: var(--spacing-md);
|
||||
p {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
&.results-card {
|
||||
background: var(--bg-tertiary);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
&.examples-card {
|
||||
margin-bottom: var(--spacing-md);
|
||||
background: var(--bg-tertiary);
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&.info-card {
|
||||
flex-direction: column;
|
||||
align-items: normal;
|
||||
background: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
&.warning-card {
|
||||
border-color: var(--color-warning);
|
||||
border: 1px solid var(--color-warning);
|
||||
background: color-mix(in srgb, var(--color-warning), transparent 90%);
|
||||
.icon { color: var(--color-warning); }
|
||||
padding: var(--spacing-md);
|
||||
.icon {
|
||||
color: var(--color-warning);
|
||||
height: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
&.error-card {
|
||||
border-color: var(--color-error);
|
||||
border: 1px solid var(--color-error);
|
||||
background: color-mix(in srgb, var(--color-error), transparent 90%);
|
||||
.icon { color: var(--color-error); }
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
}
|
||||
|
||||
// Input section styling
|
||||
.input-card {
|
||||
background: var(--bg-tertiary);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.info-card {
|
||||
background: var(--bg-tertiary);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: normal;
|
||||
.info-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
.warning-content, .error-content {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-md);
|
||||
.info-section {
|
||||
background: var(--bg-secondary);
|
||||
padding: var(--spacing-md);
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px solid var(--border-color);
|
||||
h4 {
|
||||
align-items: center;
|
||||
div {
|
||||
strong {
|
||||
display: block;
|
||||
margin-bottom: var(--spacing-xs);
|
||||
color: var(--text-primary);
|
||||
margin: 0 0 var(--spacing-sm) 0;
|
||||
}
|
||||
p {
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.6;
|
||||
margin: 0 0 var(--spacing-sm) 0;
|
||||
}
|
||||
ul, ol {
|
||||
color: var(--text-secondary);
|
||||
margin: 0;
|
||||
padding-left: var(--spacing-md);
|
||||
li {
|
||||
margin-bottom: var(--spacing-xs);
|
||||
strong {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
code {
|
||||
background: var(--bg-secondary);
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
line-height: 1.5;
|
||||
color: var(--text-primary);
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: var(--spacing-lg);
|
||||
align-items: start;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr;
|
||||
gap: var(--spacing-md);
|
||||
// Card header
|
||||
.card-header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
&.row {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
}
|
||||
|
||||
// Form styling
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
> label {
|
||||
display: block;
|
||||
label {
|
||||
margin-bottom: var(--spacing-xs);
|
||||
color: var(--text-primary);
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 500;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
input, select {
|
||||
input, select, textarea {
|
||||
width: 100%;
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
border: 1px solid var(--border-color);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
@@ -119,40 +105,52 @@
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 2px var(--color-primary-alpha);
|
||||
}
|
||||
}
|
||||
|
||||
// Resolver group styling
|
||||
&.resolver-group {
|
||||
.resolver-options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-sm);
|
||||
margin-top: var(--spacing-xs);
|
||||
|
||||
&.invalid {
|
||||
border-color: var(--color-error);
|
||||
}
|
||||
|
||||
// Checkbox styling
|
||||
&[type="checkbox"] {
|
||||
width: auto;
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
margin: 0;
|
||||
accent-color: var(--color-primary);
|
||||
cursor: pointer;
|
||||
|
||||
&:focus {
|
||||
outline: 2px solid var(--color-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Checkbox group styling
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
gap: var(--spacing-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
padding: var(--spacing-xs) 0;
|
||||
|
||||
input[type="checkbox"] {
|
||||
width: auto;
|
||||
margin: 0;
|
||||
accent-color: var(--color-primary);
|
||||
margin-top: var(--spacing-sm);
|
||||
label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
input[type="checkbox"] {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
// Action buttons
|
||||
@@ -182,30 +180,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Results section
|
||||
.results-card {
|
||||
background: var(--bg-tertiary);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
|
||||
> div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy functionality
|
||||
.copy-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -213,7 +187,7 @@
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
border: 1px solid var(--border-color);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-xs);
|
||||
cursor: pointer;
|
||||
@@ -223,17 +197,9 @@
|
||||
color: var(--text-primary);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
// Status indicators
|
||||
.status-section {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
// Status items
|
||||
.status-overview {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
@@ -248,80 +214,28 @@
|
||||
padding: var(--spacing-md);
|
||||
border-radius: var(--radius-md);
|
||||
font-weight: 500;
|
||||
border: 1px solid;
|
||||
|
||||
&.success {
|
||||
background: color-mix(in srgb, var(--color-success), transparent 90%);
|
||||
color: var(--color-success);
|
||||
border: 1px solid var(--color-success);
|
||||
border-color: var(--color-success);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
background: color-mix(in srgb, var(--color-warning), transparent 90%);
|
||||
color: var(--color-warning);
|
||||
border: 1px solid var(--color-warning);
|
||||
border-color: var(--color-warning);
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: color-mix(in srgb, var(--color-error), transparent 90%);
|
||||
color: var(--color-error);
|
||||
border: 1px solid var(--color-error);
|
||||
}
|
||||
|
||||
Icon {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.status-text {
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 500;
|
||||
|
||||
&.success {
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
color: var(--color-warning);
|
||||
}
|
||||
|
||||
&.error {
|
||||
color: var(--color-error);
|
||||
border-color: var(--color-error);
|
||||
}
|
||||
}
|
||||
|
||||
// Record display
|
||||
.record-section {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
|
||||
h4 {
|
||||
color: var(--text-primary);
|
||||
margin: 0 0 var(--spacing-sm) 0;
|
||||
font-size: var(--font-size-md);
|
||||
}
|
||||
}
|
||||
|
||||
.record-display {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
font-family: var(--font-mono);
|
||||
|
||||
.record-location {
|
||||
color: var(--text-secondary);
|
||||
font-size: var(--font-size-xs);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
code {
|
||||
color: var(--text-primary);
|
||||
background: none;
|
||||
padding: 0;
|
||||
font-size: var(--font-size-sm);
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
|
||||
.records-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -335,7 +249,7 @@
|
||||
padding: var(--spacing-md);
|
||||
background: var(--bg-secondary);
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px solid var(--border-color);
|
||||
border: 1px solid var(--border-primary);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
@@ -350,192 +264,181 @@
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.record-ttl {
|
||||
color: var(--text-secondary);
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
// Error handling
|
||||
.error-card {
|
||||
background: var(--bg-error);
|
||||
border: 1px solid var(--border-error);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.error-content {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-md);
|
||||
color: var(--text-error);
|
||||
|
||||
Icon {
|
||||
flex-shrink: 0;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
strong {
|
||||
color: var(--text-error);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
display: block;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.error-message, .no-records {
|
||||
color: var(--text-secondary);
|
||||
font-style: italic;
|
||||
text-align: center;
|
||||
padding: var(--spacing-lg);
|
||||
}
|
||||
|
||||
// Examples section
|
||||
.examples-card {
|
||||
margin-bottom: var(--spacing-md);
|
||||
background: var(--bg-tertiary);
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.examples-details {
|
||||
border: none;
|
||||
background: none;
|
||||
|
||||
svg {
|
||||
transition: transform var(--transition-fast);
|
||||
}
|
||||
&[open] {
|
||||
.examples-summary Icon {
|
||||
.examples-summary svg {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
}
|
||||
.examples-summary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-md);
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
&::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
svg {
|
||||
transition: transform var(--transition-fast);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
h4 {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
font-size: var(--font-size-md);
|
||||
}
|
||||
}
|
||||
.examples-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: var(--spacing-sm);
|
||||
padding: 0 var(--spacing-md) var(--spacing-md);
|
||||
.example-card {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
text-align: left;
|
||||
|
||||
&:hover, &.selected {
|
||||
background: var(--bg-primary);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
h5 {
|
||||
margin: 0 0 var(--spacing-xs) 0;
|
||||
color: var(--text-primary);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
color: var(--text-secondary);
|
||||
font-size: var(--font-size-xs);
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.examples-summary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-md);
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
|
||||
&::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
|
||||
Icon {
|
||||
transition: transform var(--transition-fast);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
h4 {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
font-size: var(--font-size-md);
|
||||
}
|
||||
}
|
||||
|
||||
.examples-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: var(--spacing-sm);
|
||||
padding: 0 var(--spacing-md) var(--spacing-md);
|
||||
}
|
||||
|
||||
.example-card {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
text-align: left;
|
||||
|
||||
&:hover {
|
||||
background: var(--bg-primary);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
h5 {
|
||||
margin: 0 0 var(--spacing-xs) 0;
|
||||
color: var(--text-primary);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
color: var(--text-secondary);
|
||||
font-size: var(--font-size-xs);
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
// Resolver-specific styling
|
||||
.resolvers-grid {
|
||||
// Info sections
|
||||
.info-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: var(--spacing-md);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.resolver-card {
|
||||
border-radius: var(--radius-md);
|
||||
border: 2px solid var(--border-color);
|
||||
background: var(--bg-secondary);
|
||||
|
||||
&.success {
|
||||
border-color: var(--color-success);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
border-color: var(--color-warning);
|
||||
}
|
||||
|
||||
&.error {
|
||||
border-color: var(--color-error);
|
||||
}
|
||||
}
|
||||
|
||||
// Info sections
|
||||
.lookup-info {
|
||||
background: var(--bg-info);
|
||||
border: 1px solid var(--border-info);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
|
||||
h4 {
|
||||
color: var(--text-info);
|
||||
margin: 0 0 var(--spacing-sm) 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
p {
|
||||
color: var(--text-info);
|
||||
margin: 0;
|
||||
font-size: var(--font-size-xs);
|
||||
line-height: 1.5;
|
||||
.info-section {
|
||||
background: var(--bg-secondary);
|
||||
padding: var(--spacing-md);
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px solid var(--border-primary);
|
||||
|
||||
h4 {
|
||||
color: var(--text-primary);
|
||||
margin: 0 0 var(--spacing-sm) 0;
|
||||
}
|
||||
|
||||
p {
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.6;
|
||||
margin: 0 0 var(--spacing-sm) 0;
|
||||
}
|
||||
|
||||
ul, ol {
|
||||
color: var(--text-secondary);
|
||||
margin: 0;
|
||||
padding-left: var(--spacing-md);
|
||||
|
||||
li {
|
||||
margin-bottom: var(--spacing-xs);
|
||||
|
||||
strong {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
code {
|
||||
background: var(--bg-tertiary);
|
||||
padding: 2px 4px;
|
||||
border-radius: var(--radius-xs);
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Utility classes
|
||||
.text-success {
|
||||
.mono {
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.help-text {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
font-style: italic;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: var(--color-error);
|
||||
font-size: var(--font-size-xs);
|
||||
margin-top: var(--spacing-xs);
|
||||
}
|
||||
|
||||
// Text color utility
|
||||
.text-green-500 {
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
.text-warning {
|
||||
color: var(--color-warning);
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
.text-error {
|
||||
color: var(--text-error);
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.text-info {
|
||||
color: var(--color-info);
|
||||
// Form layout
|
||||
.form-row {
|
||||
margin-bottom: var(--spacing-md);
|
||||
|
||||
&.two-columns {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: var(--spacing-md);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Example cards selection state
|
||||
.example-card {
|
||||
&.selected {
|
||||
border-color: var(--color-primary);
|
||||
background: color-mix(in srgb, var(--color-primary), transparent 95%);
|
||||
}
|
||||
}
|
||||
|
||||
// Action section
|
||||
.action-section {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: var(--spacing-xl);
|
||||
}
|
||||
Reference in new issue
Block a user