import { NextResponse } from 'next/server'; import { exec } from 'child_process'; const dhcpConfigPath = '/etc/dhcp/dhcpd.conf'; export async function POST(request) { const { username, password } = await request.json(); try { const command = ` echo '${password}' | sudo -S visudo -c && echo '${username} ALL=(ALL) NOPASSWD: /bin/systemctl restart isc-dhcp-server' | sudo tee -a /etc/sudoers && echo '${password}' | sudo -S chown ${username}:${username} ${dhcpConfigPath} `; exec(command, (error, stdout, stderr) => { if (error) { throw new Error(stderr); } }); return NextResponse.json({ success: true }); } catch (error) { return NextResponse.json({ error: 'Failed to grant sudo rights or set file permissions' }, { status: 500 }); } }