From e1fafbe1e42e20eade421f88bb6026708b999c0f Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 21 Sep 2025 22:09:00 +0100 Subject: [PATCH] Format --- src/lib/utils/ipv6-normalize.ts | 6 ++--- src/lib/utils/nth-ip.ts | 6 ++--- src/lib/utils/random-ip.ts | 4 ++-- src/lib/utils/reverse-dns.ts | 4 ++-- src/lib/utils/ula.ts | 23 ++++++++++--------- src/lib/utils/wildcard-mask.ts | 6 ++--- src/lib/utils/zone-parser.ts | 5 ++-- .../api/internal/diagnostics/dns/+server.ts | 20 +++------------- .../diagnostics/dns/soa-serial/+page.svelte | 5 ++-- .../diagnostics/email/spf-check/+page.svelte | 4 +++- src/routes/dns/generators/+page.svelte | 4 ++-- 11 files changed, 36 insertions(+), 51 deletions(-) diff --git a/src/lib/utils/ipv6-normalize.ts b/src/lib/utils/ipv6-normalize.ts index a2374ea..397588d 100644 --- a/src/lib/utils/ipv6-normalize.ts +++ b/src/lib/utils/ipv6-normalize.ts @@ -47,7 +47,7 @@ function isValidIPv6(ip: string): boolean { if (parts.length === 1) { // No compression groups = cleanIP.split(':'); - + // Check for IPv4-mapped addresses const lastGroup = groups[groups.length - 1]; let ipv4Groups = 0; @@ -64,7 +64,7 @@ function isValidIPv6(ip: string): boolean { groups.pop(); // Remove IPv4 part from groups for validation } } - + // Should have 8 groups total (or 6 + IPv4 which counts as 2) const expectedGroups = ipv4Groups > 0 ? 6 : 8; if (groups.length !== expectedGroups) return false; @@ -130,7 +130,7 @@ function expandIPv6(ip: string): string { // Already expanded, just pad with zeros const groups = cleanIP.split(':'); const expandedGroups: string[] = []; - + for (let i = 0; i < groups.length; i++) { const group = groups[i]; if (group.includes('.')) { diff --git a/src/lib/utils/nth-ip.ts b/src/lib/utils/nth-ip.ts index 2522caf..2bde8a4 100644 --- a/src/lib/utils/nth-ip.ts +++ b/src/lib/utils/nth-ip.ts @@ -78,7 +78,7 @@ function expandIPv6(ip: string): string { function compressIPv6(ip: string): string { // Simple IPv6 compression - find longest sequence of consecutive zeros const groups = ip.split(':'); - + // Find longest sequence of '0' groups let longestStart = -1; let longestLength = 0; @@ -138,7 +138,7 @@ function bigIntToIPv6(num: bigint): string { } const uncompressed = groups.join(':'); - + // Apply IPv6 compression using our normalize function try { const result = normalizeIPv6Addresses([uncompressed]); @@ -148,7 +148,7 @@ function bigIntToIPv6(num: bigint): string { } catch { // Fallback to manual compression if normalize fails } - + // Manual compression fallback return compressIPv6(uncompressed); } diff --git a/src/lib/utils/random-ip.ts b/src/lib/utils/random-ip.ts index a33566f..ef3d689 100644 --- a/src/lib/utils/random-ip.ts +++ b/src/lib/utils/random-ip.ts @@ -367,12 +367,12 @@ function parseInputLine(line: string): { if (match) { const countStr = match[2].trim(); const count = parseInt(countStr, 10); - + // Check if the count is a valid number if (isNaN(count) || count < 0) { throw new Error(`Invalid count format: "${countStr}"`); } - + return { network: match[1].trim(), count: count, diff --git a/src/lib/utils/reverse-dns.ts b/src/lib/utils/reverse-dns.ts index a3c2ed7..3cbeaac 100644 --- a/src/lib/utils/reverse-dns.ts +++ b/src/lib/utils/reverse-dns.ts @@ -36,7 +36,7 @@ function isValidIPv4(ip: string): boolean { function isValidIPv6(ip: string): boolean { // Check for triple colons (invalid) if (ip.includes(':::')) return false; - + // Handle zone identifiers (e.g., fe80::1%eth0) let cleanIP = ip; if (ip.includes('%')) { @@ -46,7 +46,7 @@ function isValidIPv6(ip: string): boolean { // Zone identifier part should not be empty if (!parts[1]) return false; } - + // Basic IPv6 validation - handles compressed notation if (cleanIP.includes('::')) { const parts = cleanIP.split('::'); diff --git a/src/lib/utils/ula.ts b/src/lib/utils/ula.ts index 9f6b4e4..97d6893 100644 --- a/src/lib/utils/ula.ts +++ b/src/lib/utils/ula.ts @@ -90,7 +90,7 @@ function generateULA(subnetId?: string): ULAGeneration { const hash = generateHash(hashInput); // Global ID is 40 bits = 10 hex chars for RFC compliance const fullGlobalIDHex = hash.substring(hash.length - 10); // Last 10 hex chars (40 bits) - + // For ULA format, we use 8 hex chars in the address format const globalIDHex = fullGlobalIDHex.substring(2); // Take 8 chars for address format @@ -268,7 +268,7 @@ export function parseULA(ula: string): { // Split into groups const groups = addressPart.split(':'); - + if (groups.length < 3) { return { isValid: false, @@ -281,20 +281,21 @@ export function parseULA(ula: string): { // Detect format type based on first group length if (firstGroup.length > 8) { // Compressed format: fd12345678:abcd::1 (our generated format) - if (firstGroup.length < 10) { // fd + 8 hex chars + if (firstGroup.length < 10) { + // fd + 8 hex chars return { isValid: false, error: 'Invalid ULA format - first group too short for compressed format', }; } - + // Extract global ID from first group (remove fd prefix) const globalIDHex = firstGroup.substring(2); // Remove 'fd' const globalID = globalIDHex.match(/.{4}/g)?.join(':') || ''; - + // Subnet ID is the second group const subnetID = groups[1]; - + // Interface ID is remaining groups let interfaceID = ''; if (groups.length > 2) { @@ -311,7 +312,7 @@ export function parseULA(ula: string): { }; } else { // Standard IPv6 format: fd12:3456:789a:bcde:... or compressed fd12:3456:789a::1 - + // Handle compressed notation by expanding first let expandedULA = cleanULA; if (cleanULA.includes('::')) { @@ -327,7 +328,7 @@ export function parseULA(ula: string): { const leftGroups = parts[0] ? parts[0].split(':') : []; const rightGroups = parts[1] ? parts[1].split(':') : []; const missingGroups = 8 - leftGroups.length - rightGroups.length; - + if (missingGroups < 0) { return { isValid: false, @@ -342,7 +343,7 @@ export function parseULA(ula: string): { // Split expanded ULA into groups const expandedGroups = expandedULA.split(':'); - + if (expandedGroups.length !== 8) { return { isValid: false, @@ -351,7 +352,7 @@ export function parseULA(ula: string): { } // Pad groups to 4 characters for consistent processing - const paddedGroups = expandedGroups.map(group => group.padStart(4, '0')); + const paddedGroups = expandedGroups.map((group) => group.padStart(4, '0')); const globalIDPart1 = paddedGroups[0].substring(2); // '00' from 'fd00' const globalIDPart2 = paddedGroups[1]; // '1234' @@ -367,7 +368,7 @@ export function parseULA(ula: string): { const fourthGroupRemainder = paddedGroups[3].substring(2); // 'bc' from '9abc' const remainingGroups = paddedGroups.slice(4); // everything after 4th group const interfaceHexString = fourthGroupRemainder + remainingGroups.join(''); - + // Handle special cases for interface ID let interfaceID: string; if (cleanULA.includes('::')) { diff --git a/src/lib/utils/wildcard-mask.ts b/src/lib/utils/wildcard-mask.ts index 0a116eb..f1fcf7b 100644 --- a/src/lib/utils/wildcard-mask.ts +++ b/src/lib/utils/wildcard-mask.ts @@ -73,8 +73,7 @@ function isValidSubnetMask(mask: string): boolean { // Valid subnet mask has contiguous 1s followed by contiguous 0s // Special cases: 0.0.0.0 (all zeros) and 255.255.255.255 (all ones) are valid - if (maskBinary === '00000000000000000000000000000000' || - maskBinary === '11111111111111111111111111111111') { + if (maskBinary === '00000000000000000000000000000000' || maskBinary === '11111111111111111111111111111111') { return true; } @@ -113,8 +112,7 @@ function isValidWildcardMask(mask: string): boolean { // Valid wildcard mask has contiguous 0s followed by contiguous 1s // Special cases: 0.0.0.0 (all zeros) and 255.255.255.255 (all ones) are valid - if (maskBinary === '00000000000000000000000000000000' || - maskBinary === '11111111111111111111111111111111') { + if (maskBinary === '00000000000000000000000000000000' || maskBinary === '11111111111111111111111111111111') { return true; } diff --git a/src/lib/utils/zone-parser.ts b/src/lib/utils/zone-parser.ts index 368d5bc..07828c9 100644 --- a/src/lib/utils/zone-parser.ts +++ b/src/lib/utils/zone-parser.ts @@ -154,14 +154,14 @@ function isValidIPv6(ip: string): boolean { // Validate all groups const allGroups = [...left, ...right]; - return allGroups.every(group => /^[0-9a-fA-F]{0,4}$/.test(group)); + return allGroups.every((group) => /^[0-9a-fA-F]{0,4}$/.test(group)); } else { // No compression - must have exactly 8 groups const groups = ip.split(':'); if (groups.length !== 8) return false; // All groups must be valid hex (1-4 characters) - return groups.every(group => /^[0-9a-fA-F]{1,4}$/.test(group)); + return groups.every((group) => /^[0-9a-fA-F]{1,4}$/.test(group)); } } @@ -331,7 +331,6 @@ export function parseZoneFile(content: string): ParsedZone { } for (const { line, lineNum, startsWithWhitespace } of processedLines) { - try { // Handle $ORIGIN directive if (line.startsWith('$ORIGIN')) { diff --git a/src/routes/api/internal/diagnostics/dns/+server.ts b/src/routes/api/internal/diagnostics/dns/+server.ts index 2fa360b..d0b5305 100644 --- a/src/routes/api/internal/diagnostics/dns/+server.ts +++ b/src/routes/api/internal/diagnostics/dns/+server.ts @@ -373,11 +373,7 @@ function createReverseZone(ip: string): string { } } -async function parseSPFRecord( - domain: string, - visited = new Set(), - lookupCount = { count: 0 }, -): Promise { +async function parseSPFRecord(domain: string, visited = new Set(), lookupCount = { count: 0 }): Promise { if (visited.has(domain) || lookupCount.count > 10) { return { error: 'SPF lookup limit exceeded or circular reference' }; } @@ -531,11 +527,7 @@ async function checkNSandSOA(domain: string): Promise { } } -async function checkDNSSECADFlag( - name: string, - type: keyof typeof DNS_TYPES, - opts: ResolverOpts = {}, -): Promise { +async function checkDNSSECADFlag(name: string, type: keyof typeof DNS_TYPES, opts: ResolverOpts = {}): Promise { const { doh = 'cloudflare', timeoutMs = 3500 } = opts; try { @@ -710,13 +702,7 @@ function formatDuration(seconds: number): string { return `${Math.floor(seconds / 86400)}d ${Math.floor((seconds % 86400) / 3600)}h`; } -function getSOARecommendations( - refresh: number, - retry: number, - expire: number, - minimum: number, - ttl: number, -): any[] { +function getSOARecommendations(refresh: number, retry: number, expire: number, minimum: number, ttl: number): any[] { const recommendations = []; if (refresh < 3600) { diff --git a/src/routes/diagnostics/dns/soa-serial/+page.svelte b/src/routes/diagnostics/dns/soa-serial/+page.svelte index 64c6307..a6553ac 100644 --- a/src/routes/diagnostics/dns/soa-serial/+page.svelte +++ b/src/routes/diagnostics/dns/soa-serial/+page.svelte @@ -205,9 +205,8 @@ } ).serialAnalysis} {@const soaData = (results as { soa?: { mname?: string; rname?: string; ttl?: number } }).soa} - {@const timingData = ( - results as { soa?: { refresh?: number; retry?: number; expire?: number; minimum?: number } } - ).soa} + {@const timingData = (results as { soa?: { refresh?: number; retry?: number; expire?: number; minimum?: number } }) + .soa}

SOA Analysis for {results.name}

diff --git a/src/routes/diagnostics/email/spf-check/+page.svelte b/src/routes/diagnostics/email/spf-check/+page.svelte index c75cf10..a56cdc1 100644 --- a/src/routes/diagnostics/email/spf-check/+page.svelte +++ b/src/routes/diagnostics/email/spf-check/+page.svelte @@ -360,7 +360,9 @@ {#if results.expanded.includes.length > 0} {@const spfIncludes = ( - results as { expanded: { includes: Array<{ domain: string; result: { record?: string; error?: string } }> } } + results as { + expanded: { includes: Array<{ domain: string; result: { record?: string; error?: string } }> }; + } ).expanded}
Included SPF Policies
diff --git a/src/routes/dns/generators/+page.svelte b/src/routes/dns/generators/+page.svelte index 56ae647..d8a7156 100644 --- a/src/routes/dns/generators/+page.svelte +++ b/src/routes/dns/generators/+page.svelte @@ -17,11 +17,11 @@ } const dnsGenerators = extractNavItems( - ( + (( SUB_NAV['/dns']?.find((section) => 'title' in section && section.title === 'Record Generators') as { items?: unknown[]; } - )?.items as (NavItem | NavGroup)[] || [], + )?.items as (NavItem | NavGroup)[]) || [], );