feat: dns server

This commit is contained in:
Shahrad Elahi
2024-05-29 18:59:49 +03:30
parent ae787625b9
commit 06a0a3008b
24 changed files with 386 additions and 165 deletions

View File

@@ -1,11 +1,12 @@
import type { RequestHandler } from '@sveltejs/kit';
import logger from '@lib/logger';
import { getServers, WGServer } from '@lib/wireguard';
import { errorBox } from '@lib/logger';
import { WG_STORE } from '@lib/storage';
import { WGServer } from '@lib/wireguard';
export const GET: RequestHandler = async () => {
try {
for (const { id } of await getServers()) {
for (const { id } of await WG_STORE.listServers()) {
const wg = new WGServer(id);
const server = await wg.get();
const hasInterface = await wg.isUp();
@@ -20,7 +21,7 @@ export const GET: RequestHandler = async () => {
}
}
} catch (e) {
logger.error('APIFailed: HealthCheck:', e);
errorBox(e);
return new Response('FAILED', { status: 500, headers: { 'Content-Type': 'text/plain' } });
}

View File

@@ -1,13 +0,0 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { execa } from 'execa';
export const GET: RequestHandler = async ({ params }) => {
try {
const { stdout } = await execa('screen', ['-ls'], { shell: true });
const isRunning = stdout.includes(params.serviceName!);
return json({ healthy: isRunning });
} catch (e) {
return json({ healthy: false });
}
};

View File

@@ -0,0 +1,19 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { errorBox } from '@lib/logger';
import { getService } from '@lib/services';
export const GET: RequestHandler = async ({ params }) => {
try {
const service = getService(params.service);
if (!service) {
return json({ healthy: false });
}
const healthy = await service.health();
return json({ healthy });
} catch (e) {
errorBox(e);
return json({ healthy: false });
}
};