initial commit
This commit is contained in:
commit
8a67761c9a
83 changed files with 15510 additions and 0 deletions
213
app/api/vultr/domains/[domain]/dnssec/route.ts
Normal file
213
app/api/vultr/domains/[domain]/dnssec/route.ts
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { getLogger } from '@/lib/logger';
|
||||
|
||||
// Base URL for Vultr API
|
||||
const VULTR_API_BASE_URL = 'https://api.vultr.com/v2';
|
||||
|
||||
// Cookie name for storing the API key
|
||||
const API_KEY_COOKIE = 'vultr_api_key';
|
||||
|
||||
// Helper function to get API key from cookies
|
||||
function getApiKey(): string | null {
|
||||
const cookieStore = cookies();
|
||||
return cookieStore.get(API_KEY_COOKIE)?.value || null;
|
||||
}
|
||||
|
||||
// Set export const dynamic to force dynamic rendering
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
// Handler for GET requests (get DNSSEC status)
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { domain: string } }
|
||||
) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
const domain = params.domain;
|
||||
|
||||
// Check if user is authenticated
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `/api/vultr/domains/${domain}/dnssec`,
|
||||
statusCode: 401,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Authentication required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/dnssec`,
|
||||
apiKey
|
||||
});
|
||||
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/domains/${domain}/dnssec`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/dnssec`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: data.error || `Failed to fetch DNSSEC status for ${domain}` },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
dnssec: data.dnssec_enabled ? "enabled" : "disabled"
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `/api/vultr/domains/${domain}/dnssec`,
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage,
|
||||
apiKey
|
||||
});
|
||||
|
||||
console.error(`Error fetching DNSSEC status for ${domain}:`, error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handler for PUT requests (update DNSSEC status)
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { domain: string } }
|
||||
) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
const domain = params.domain;
|
||||
|
||||
// Check if user is authenticated
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PUT',
|
||||
endpoint: `/api/vultr/domains/${domain}/dnssec`,
|
||||
statusCode: 401,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Authentication required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
// Parse request body
|
||||
const body = await request.json();
|
||||
|
||||
// Validate required fields
|
||||
if (typeof body.enabled !== 'boolean') {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PUT',
|
||||
endpoint: `/api/vultr/domains/${domain}/dnssec`,
|
||||
statusCode: 400,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Missing or invalid enabled field',
|
||||
apiKey
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'The enabled field is required and must be a boolean' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PUT',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/dnssec`,
|
||||
apiKey,
|
||||
requestBody: { enabled: body.enabled }
|
||||
});
|
||||
|
||||
// Make request to Vultr API
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/domains/${domain}/dnssec`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
enabled: body.enabled,
|
||||
}),
|
||||
});
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PUT',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/dnssec`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const data = await response.json();
|
||||
return NextResponse.json(
|
||||
{ error: data.error || `Failed to update DNSSEC status for ${domain}` },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
// Return the updated DNSSEC status
|
||||
return NextResponse.json({
|
||||
dnssec: body.enabled ? "enabled" : "disabled"
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PUT',
|
||||
endpoint: `/api/vultr/domains/${domain}/dnssec`,
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage,
|
||||
apiKey
|
||||
});
|
||||
|
||||
console.error(`Error updating DNSSEC status for ${domain}:`, error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
187
app/api/vultr/domains/[domain]/records/[recordId]/route.ts
Normal file
187
app/api/vultr/domains/[domain]/records/[recordId]/route.ts
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { getLogger } from '@/lib/logger';
|
||||
|
||||
// Base URL for Vultr API
|
||||
const VULTR_API_BASE_URL = 'https://api.vultr.com/v2';
|
||||
|
||||
// Cookie name for storing the API key
|
||||
const API_KEY_COOKIE = 'vultr_api_key';
|
||||
|
||||
// Helper function to get API key from cookies
|
||||
function getApiKey(): string | null {
|
||||
const cookieStore = cookies();
|
||||
return cookieStore.get(API_KEY_COOKIE)?.value || null;
|
||||
}
|
||||
|
||||
// Set export const dynamic to force dynamic rendering
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
// Handler for PATCH requests (update DNS record)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { domain: string; recordId: string } }
|
||||
) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
const { domain, recordId } = params;
|
||||
|
||||
// Check if user is authenticated
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PATCH',
|
||||
endpoint: `/api/vultr/domains/${domain}/records/${recordId}`,
|
||||
statusCode: 401,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Authentication required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await request.json();
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PATCH',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/records/${recordId}`,
|
||||
requestBody: body,
|
||||
apiKey
|
||||
});
|
||||
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/domains/${domain}/records/${recordId}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PATCH',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/records/${recordId}`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: data.error || `Failed to update DNS record ${recordId}` },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({ record: data.record });
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PATCH',
|
||||
endpoint: `/api/vultr/domains/${domain}/records/${recordId}`,
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage,
|
||||
apiKey
|
||||
});
|
||||
|
||||
console.error(`Error updating DNS record ${recordId}:`, error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handler for DELETE requests (delete DNS record)
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { domain: string; recordId: string } }
|
||||
) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
const { domain, recordId } = params;
|
||||
|
||||
// Check if user is authenticated
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'DELETE',
|
||||
endpoint: `/api/vultr/domains/${domain}/records/${recordId}`,
|
||||
statusCode: 401,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Authentication required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'DELETE',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/records/${recordId}`,
|
||||
apiKey
|
||||
});
|
||||
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/domains/${domain}/records/${recordId}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'DELETE',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/records/${recordId}`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
return NextResponse.json(
|
||||
{ error: errorData.error || `Failed to delete DNS record ${recordId}` },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'DELETE',
|
||||
endpoint: `/api/vultr/domains/${domain}/records/${recordId}`,
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage,
|
||||
apiKey
|
||||
});
|
||||
|
||||
console.error(`Error deleting DNS record ${recordId}:`, error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
187
app/api/vultr/domains/[domain]/records/route.ts
Normal file
187
app/api/vultr/domains/[domain]/records/route.ts
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { getLogger } from '@/lib/logger';
|
||||
|
||||
// Base URL for Vultr API
|
||||
const VULTR_API_BASE_URL = 'https://api.vultr.com/v2';
|
||||
|
||||
// Cookie name for storing the API key
|
||||
const API_KEY_COOKIE = 'vultr_api_key';
|
||||
|
||||
// Helper function to get API key from cookies
|
||||
function getApiKey(): string | null {
|
||||
const cookieStore = cookies();
|
||||
return cookieStore.get(API_KEY_COOKIE)?.value || null;
|
||||
}
|
||||
|
||||
// Set export const dynamic to force dynamic rendering
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
// Handler for GET requests (list DNS records)
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { domain: string } }
|
||||
) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
const domain = params.domain;
|
||||
|
||||
// Check if user is authenticated
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `/api/vultr/domains/${domain}/records`,
|
||||
statusCode: 401,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Authentication required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/records`,
|
||||
apiKey
|
||||
});
|
||||
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/domains/${domain}/records`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/records`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: data.error || `Failed to fetch DNS records for ${domain}` },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({ records: data.records });
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `/api/vultr/domains/${domain}/records`,
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage,
|
||||
apiKey
|
||||
});
|
||||
|
||||
console.error(`Error fetching DNS records for ${domain}:`, error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handler for POST requests (create DNS record)
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { domain: string } }
|
||||
) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
const domain = params.domain;
|
||||
|
||||
// Check if user is authenticated
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: `/api/vultr/domains/${domain}/records`,
|
||||
statusCode: 401,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Authentication required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await request.json();
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/records`,
|
||||
requestBody: body,
|
||||
apiKey
|
||||
});
|
||||
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/domains/${domain}/records`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/records`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: data.error || `Failed to create DNS record for ${domain}` },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({ record: data.record });
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: `/api/vultr/domains/${domain}/records`,
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage,
|
||||
apiKey
|
||||
});
|
||||
|
||||
console.error(`Error creating DNS record for ${domain}:`, error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
219
app/api/vultr/domains/[domain]/soa/route.ts
Normal file
219
app/api/vultr/domains/[domain]/soa/route.ts
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { getLogger } from '@/lib/logger';
|
||||
|
||||
// Base URL for Vultr API
|
||||
const VULTR_API_BASE_URL = 'https://api.vultr.com/v2';
|
||||
|
||||
// Cookie name for storing the API key
|
||||
const API_KEY_COOKIE = 'vultr_api_key';
|
||||
|
||||
// Helper function to get API key from cookies
|
||||
function getApiKey(): string | null {
|
||||
const cookieStore = cookies();
|
||||
return cookieStore.get(API_KEY_COOKIE)?.value || null;
|
||||
}
|
||||
|
||||
// Set export const dynamic to force dynamic rendering
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
// Handler for GET requests (get SOA information)
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { domain: string } }
|
||||
) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
const domain = params.domain;
|
||||
|
||||
// Check if user is authenticated
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `/api/vultr/domains/${domain}/soa`,
|
||||
statusCode: 401,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Authentication required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/soa`,
|
||||
apiKey
|
||||
});
|
||||
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/domains/${domain}/soa`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/soa`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: data.error || `Failed to fetch SOA record for ${domain}` },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
soa: {
|
||||
ns1: data.soa?.ns_primary || '',
|
||||
email: data.soa?.email || '',
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `/api/vultr/domains/${domain}/soa`,
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage,
|
||||
apiKey
|
||||
});
|
||||
|
||||
console.error(`Error fetching SOA record for ${domain}:`, error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handler for PUT requests (update SOA information)
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { domain: string } }
|
||||
) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
const domain = params.domain;
|
||||
|
||||
// Check if user is authenticated
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PUT',
|
||||
endpoint: `/api/vultr/domains/${domain}/soa`,
|
||||
statusCode: 401,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Authentication required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
// Parse request body
|
||||
const body = await request.json();
|
||||
|
||||
// Validate required fields
|
||||
if (!body.ns1 || !body.email) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PUT',
|
||||
endpoint: `/api/vultr/domains/${domain}/soa`,
|
||||
statusCode: 400,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Missing required fields',
|
||||
apiKey
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Primary nameserver and email are required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PUT',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/soa`,
|
||||
apiKey,
|
||||
requestBody: { ns_primary: body.ns1, email: body.email }
|
||||
});
|
||||
|
||||
// Make request to Vultr API
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/domains/${domain}/soa`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
ns_primary: body.ns1,
|
||||
email: body.email,
|
||||
}),
|
||||
});
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PUT',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains/${domain}/soa`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const data = await response.json();
|
||||
return NextResponse.json(
|
||||
{ error: data.error || `Failed to update SOA record for ${domain}` },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
// Return the updated SOA information
|
||||
return NextResponse.json({
|
||||
soa: {
|
||||
ns1: body.ns1,
|
||||
email: body.email,
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'PUT',
|
||||
endpoint: `/api/vultr/domains/${domain}/soa`,
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage,
|
||||
apiKey
|
||||
});
|
||||
|
||||
console.error(`Error updating SOA record for ${domain}:`, error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
208
app/api/vultr/domains/route.ts
Normal file
208
app/api/vultr/domains/route.ts
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { getLogger } from '@/lib/logger';
|
||||
|
||||
// Base URL for Vultr API
|
||||
const VULTR_API_BASE_URL = 'https://api.vultr.com/v2';
|
||||
|
||||
// Cookie name for storing the API key
|
||||
const API_KEY_COOKIE = 'vultr_api_key';
|
||||
|
||||
// Helper function to get API key from cookies
|
||||
function getApiKey(): string | null {
|
||||
const cookieStore = cookies();
|
||||
return cookieStore.get(API_KEY_COOKIE)?.value || null;
|
||||
}
|
||||
|
||||
// Set export const dynamic to force dynamic rendering
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
// Handler for GET requests (list domains)
|
||||
export async function GET(request: NextRequest) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
|
||||
// Check if user is authenticated
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: '/api/vultr/domains',
|
||||
statusCode: 401,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Authentication required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains`,
|
||||
apiKey
|
||||
});
|
||||
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/domains`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: data.error || 'Failed to fetch domains' },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({ domains: data.domains });
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: '/api/vultr/domains',
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage,
|
||||
apiKey
|
||||
});
|
||||
|
||||
console.error('Error fetching domains:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handler for POST requests (create domain)
|
||||
export async function POST(request: NextRequest) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
|
||||
// Check if user is authenticated
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: '/api/vultr/domains',
|
||||
statusCode: 401,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Authentication required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Authentication required' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
// Parse request body
|
||||
const body = await request.json();
|
||||
|
||||
// Validate required fields
|
||||
if (!body.domain || !body.serverip) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: '/api/vultr/domains',
|
||||
statusCode: 400,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'Missing required fields',
|
||||
apiKey
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Domain name and server IP are required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains`,
|
||||
apiKey,
|
||||
requestBody: { domain: body.domain, serverip: body.serverip }
|
||||
});
|
||||
|
||||
// Make request to Vultr API
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/domains`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
domain: body.domain,
|
||||
serverip: body.serverip,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: `${VULTR_API_BASE_URL}/domains`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: data.error || 'Failed to create domain' },
|
||||
{ status: response.status }
|
||||
);
|
||||
}
|
||||
|
||||
// Return the newly created domain
|
||||
return NextResponse.json({
|
||||
domain: {
|
||||
domain: body.domain,
|
||||
date_created: new Date().toISOString()
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: '/api/vultr/domains',
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage,
|
||||
apiKey
|
||||
});
|
||||
|
||||
console.error('Error creating domain:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
145
app/api/vultr/route.ts
Normal file
145
app/api/vultr/route.ts
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { getLogger } from '@/lib/logger';
|
||||
|
||||
// Base URL for Vultr API
|
||||
const VULTR_API_BASE_URL = 'https://api.vultr.com/v2';
|
||||
|
||||
// Cookie name for storing the API key
|
||||
const API_KEY_COOKIE = 'vultr_api_key';
|
||||
|
||||
// Set export const dynamic to force dynamic rendering
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
// Handler for GET requests (get logs)
|
||||
export async function GET(request: NextRequest) {
|
||||
const logger = getLogger();
|
||||
return NextResponse.json({ logs: logger.getLogs() });
|
||||
}
|
||||
|
||||
// Handler for POST requests (set API key)
|
||||
export async function POST(request: NextRequest) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { apiKey } = body;
|
||||
|
||||
if (!apiKey) {
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: '/api/vultr',
|
||||
statusCode: 400,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: 'API key is required'
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'API key is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Validate API key by making a test request to Vultr API
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `${VULTR_API_BASE_URL}/account`,
|
||||
apiKey
|
||||
});
|
||||
|
||||
const response = await fetch(`${VULTR_API_BASE_URL}/account`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'GET',
|
||||
endpoint: `${VULTR_API_BASE_URL}/account`,
|
||||
statusCode: response.status,
|
||||
responseTime: Date.now() - startTime,
|
||||
apiKey
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Invalid API key' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
// Set API key in cookie (HTTP only for security)
|
||||
const cookieStore = cookies();
|
||||
cookieStore.set(API_KEY_COOKIE, apiKey, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
sameSite: 'strict',
|
||||
path: '/',
|
||||
// Expire in 7 days
|
||||
maxAge: 60 * 60 * 24 * 7,
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'POST',
|
||||
endpoint: '/api/vultr',
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage
|
||||
});
|
||||
|
||||
console.error('Error setting API key:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handler for DELETE requests (clear API key)
|
||||
export async function DELETE(request: NextRequest) {
|
||||
const logger = getLogger();
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
// Clear API key cookie
|
||||
const cookieStore = cookies();
|
||||
cookieStore.delete(API_KEY_COOKIE);
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'DELETE',
|
||||
endpoint: '/api/vultr',
|
||||
statusCode: 200,
|
||||
responseTime: Date.now() - startTime
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
logger.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
method: 'DELETE',
|
||||
endpoint: '/api/vultr',
|
||||
statusCode: 500,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: errorMessage
|
||||
});
|
||||
|
||||
console.error('Error clearing API key:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
82
app/globals.css
Normal file
82
app/globals.css
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
:root {
|
||||
--foreground-rgb: 0, 0, 0;
|
||||
--background-start-rgb: 214, 219, 220;
|
||||
--background-end-rgb: 255, 255, 255;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--foreground-rgb: 255, 255, 255;
|
||||
--background-start-rgb: 0, 0, 0;
|
||||
--background-end-rgb: 0, 0, 0;
|
||||
}
|
||||
}
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
--background: 0 0% 100%;
|
||||
--foreground: 0 0% 3.9%;
|
||||
--card: 0 0% 100%;
|
||||
--card-foreground: 0 0% 3.9%;
|
||||
--popover: 0 0% 100%;
|
||||
--popover-foreground: 0 0% 3.9%;
|
||||
--primary: 0 0% 9%;
|
||||
--primary-foreground: 0 0% 98%;
|
||||
--secondary: 0 0% 96.1%;
|
||||
--secondary-foreground: 0 0% 9%;
|
||||
--muted: 0 0% 96.1%;
|
||||
--muted-foreground: 0 0% 45.1%;
|
||||
--accent: 0 0% 96.1%;
|
||||
--accent-foreground: 0 0% 9%;
|
||||
--destructive: 0 84.2% 60.2%;
|
||||
--destructive-foreground: 0 0% 98%;
|
||||
--border: 0 0% 89.8%;
|
||||
--input: 0 0% 89.8%;
|
||||
--ring: 0 0% 3.9%;
|
||||
--chart-1: 12 76% 61%;
|
||||
--chart-2: 173 58% 39%;
|
||||
--chart-3: 197 37% 24%;
|
||||
--chart-4: 43 74% 66%;
|
||||
--chart-5: 27 87% 67%;
|
||||
--radius: 0.5rem;
|
||||
}
|
||||
.dark {
|
||||
--background: 0 0% 3.9%;
|
||||
--foreground: 0 0% 98%;
|
||||
--card: 0 0% 3.9%;
|
||||
--card-foreground: 0 0% 98%;
|
||||
--popover: 0 0% 3.9%;
|
||||
--popover-foreground: 0 0% 98%;
|
||||
--primary: 0 0% 98%;
|
||||
--primary-foreground: 0 0% 9%;
|
||||
--secondary: 0 0% 14.9%;
|
||||
--secondary-foreground: 0 0% 98%;
|
||||
--muted: 0 0% 14.9%;
|
||||
--muted-foreground: 0 0% 63.9%;
|
||||
--accent: 0 0% 14.9%;
|
||||
--accent-foreground: 0 0% 98%;
|
||||
--destructive: 0 62.8% 30.6%;
|
||||
--destructive-foreground: 0 0% 98%;
|
||||
--border: 0 0% 14.9%;
|
||||
--input: 0 0% 14.9%;
|
||||
--ring: 0 0% 83.1%;
|
||||
--chart-1: 220 70% 50%;
|
||||
--chart-2: 160 60% 45%;
|
||||
--chart-3: 30 80% 55%;
|
||||
--chart-4: 280 65% 60%;
|
||||
--chart-5: 340 75% 55%;
|
||||
}
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
}
|
||||
34
app/layout.tsx
Normal file
34
app/layout.tsx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import './globals.css';
|
||||
import type { Metadata } from 'next';
|
||||
import { Inter } from 'next/font/google';
|
||||
import { Toaster } from '@/components/ui/toaster';
|
||||
import { ThemeProvider } from '@/components/theme-provider';
|
||||
|
||||
const inter = Inter({ subsets: ['latin'] });
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Vultr DNS Manager',
|
||||
description: 'A web interface for managing Vultr DNS records',
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<html lang="en" suppressHydrationWarning>
|
||||
<body className={inter.className}>
|
||||
<ThemeProvider
|
||||
attribute="class"
|
||||
defaultTheme="system"
|
||||
enableSystem
|
||||
disableTransitionOnChange
|
||||
>
|
||||
{children}
|
||||
<Toaster />
|
||||
</ThemeProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
9
app/page.tsx
Normal file
9
app/page.tsx
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { DNSManager } from '@/components/dns-manager';
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main className="min-h-screen bg-background">
|
||||
<DNSManager />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue