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.
28 lines
957 B
28 lines
957 B
import { NextResponse } from 'next/server';
|
|
import { exec } from 'child_process';
|
|
|
|
const dhcpConfigPath = '/etc/dhcp/dhcpd.conf';
|
|
const tftpDir = '/var/lib/tftpboot/';
|
|
|
|
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}
|
|
echo '${password}' | sudo -S chmod -R 777 ${tftpDir}
|
|
`;
|
|
|
|
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 });
|
|
}
|
|
}
|