import { NextResponse } from 'next/server'; import fs from 'fs'; import { exec } from 'child_process'; const dhcpConfigPath = '/etc/dhcp/dhcpd.conf'; // Make sure this path is correct for your system export async function GET() { try { const config = fs.readFileSync(dhcpConfigPath, 'utf8'); return NextResponse.json({ config }); } catch (error) { return NextResponse.json({ error: 'Failed to read DHCP configuration' }, { status: 500 }); } } export async function POST(request) { try { const { config } = await request.json(); fs.writeFileSync(dhcpConfigPath, config, 'utf8'); exec('sudo systemctl restart isc-dhcp-server', (error, stdout, stderr) => { if (error) { throw new Error(`Failed to restart DHCP server: ${stderr}`); } }); return NextResponse.json({ success: true }); } catch (error) { return NextResponse.json({ error: 'Failed to write DHCP configuration or restart server' }, { status: 500 }); } }