You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.0 KiB
30 lines
1.0 KiB
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 });
|
|
}
|
|
}
|