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.
84 lines
2.8 KiB
84 lines
2.8 KiB
'use client';
|
|
|
|
import { useState, useEffect } from 'react';
|
|
import { useNotification } from '@/app/context/NotificationContext';
|
|
import GrantSudoLink from '@/app/components/GrantSudoLink';
|
|
|
|
export default function ConfigurePage() {
|
|
const [config, setConfig] = useState('');
|
|
const { showNotification } = useNotification();
|
|
const [showDialog, setShowDialog] = useState(false);
|
|
const [username, setUsername] = useState('');
|
|
const [password, setPassword] = useState('');
|
|
|
|
// Function to fetch the DHCP configuration
|
|
const fetchConfig = async () => {
|
|
try {
|
|
const response = await fetch('/api/dhcp/config');
|
|
const data = await response.json();
|
|
if (response.ok) {
|
|
setConfig(data.config);
|
|
showNotification('DHCP configuration loaded successfully.', 'success');
|
|
} else {
|
|
showNotification(data.error, 'error');
|
|
}
|
|
} catch (error) {
|
|
showNotification('Error loading DHCP configuration', 'error');
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
// Initial load of the DHCP configuration
|
|
fetchConfig();
|
|
}, []);
|
|
|
|
const handleConfigChange = (event) => {
|
|
setConfig(event.target.value);
|
|
};
|
|
|
|
const handleSave = async () => {
|
|
try {
|
|
const response = await fetch('/api/dhcp/config', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ config }),
|
|
});
|
|
const data = await response.json();
|
|
if (response.ok) {
|
|
showNotification('DHCP configuration updated and server restarted successfully.', 'success');
|
|
} else {
|
|
showNotification(data.error, 'error');
|
|
}
|
|
} catch (error) {
|
|
showNotification('Error updating configuration or restarting server', 'error');
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="container mt-5">
|
|
<h1 className="mb-4">Configure DHCP Options</h1>
|
|
<div className="form-group">
|
|
<label htmlFor="dhcpConfig">DHCP Configuration</label>
|
|
<textarea
|
|
id="dhcpConfig"
|
|
className="form-control"
|
|
rows="20"
|
|
value={config}
|
|
onChange={handleConfigChange}
|
|
/>
|
|
</div>
|
|
<button className="btn btn-secondary mt-3 mr-2" onClick={fetchConfig}>
|
|
Refresh
|
|
</button>
|
|
<button className="btn btn-primary mt-3" onClick={handleSave}>
|
|
Save and Restart DHCP Server
|
|
</button>
|
|
|
|
<div className="mt-4">
|
|
<GrantSudoLink text="Grant Sudo Rights"/>
|
|
</div>
|
|
|
|
</div>
|
|
);
|
|
}
|