Skip to content

Commit

Permalink
fix: fix case sensitivity of app domain resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Nov 7, 2024
1 parent 84383de commit 6d7066d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lib/dns/server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
/**
* The Weird DNS server implementation.
*/

import { env } from '$env/dynamic/private';
import { env as pubenv } from '$env/dynamic/public';
import { createClient } from 'redis';
import dns, { type AnyRecord } from 'node:dns';

import * as server from 'dinodns/common/server';
import * as network from 'dinodns/common/network';
import type { SupportedAnswer } from 'dinodns/types/dns';
import { DefaultStore } from 'dinodns/plugins/storage';
import { dev } from '$app/environment';
import { AUTHORITATIVE_ANSWER, type SoaAnswer } from 'dns-packet';
import { z } from 'zod';
import { RCode } from 'dinodns/common/core/utils';
import { redis } from '$lib/redis';

const REDIS_USER_PREFIX = 'weird:users:';
const REDIS_DNS_RECORD_PREFIX = 'weird:dns:records:';
Expand All @@ -37,6 +40,7 @@ const VALID_DOMAIN_REGEX =

const DNS_PORT = parseInt(env.DNS_PORT || '53');
const APP_IPS = env.APP_IPS.split(',');
const APP_DOMAIN = pubenv.PUBLIC_DOMAIN.split(':')[0].toLowerCase();
const DNS_MASTER = env.DNS_SOA_MASTER;
const soaSplit = env.DNS_SOA_EMAIL.split('@');
const DNS_EMAIL = soaSplit[0].replace('.', '\\.') + '.' + soaSplit[1];
Expand Down Expand Up @@ -69,10 +73,6 @@ const makeNsAnswers = (name: string): SupportedAnswer[] => {
* Start the Weird DNS server and return the `Redis` store with the mapping from username
*/
export async function startDnsServer() {
const redis = await createClient({ url: env.REDIS_URL })
.on('error', (err) => console.error('Redis client error', err))
.connect();

const makeSoaAnswer = async (name: string): Promise<SoaAnswer> => {
const serial = await redis.get('weird:dns:serial');
return {
Expand Down Expand Up @@ -132,7 +132,7 @@ export async function startDnsServer() {
if (res.finished) return next();
const question = req.packet.questions[0];

if (question.name == pubenv.PUBLIC_DOMAIN.split(':')[0] && question.type == 'A') {
if (question.name.toLowerCase() == APP_DOMAIN && question.type == 'A') {
res.answer(
APP_IPS.map((ip) => ({
name: question.name,
Expand Down
7 changes: 7 additions & 0 deletions src/lib/redis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { env } from '$env/dynamic/private';
import { createClient } from 'redis';

/** The global redis client used by the Weird server. */
export const redis = await createClient({ url: env.REDIS_URL })
.on('error', (err) => console.error('Redis client error', err))
.connect();

0 comments on commit 6d7066d

Please sign in to comment.