mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 20:06:22 -05:00
Controller: move hotspot settings to controller.yaml with WiFi device dropdown.
Hotspot was reported as "not supported" on x86 machines (Ubuntu/Debian PCs) because the Controller only watched the hardcoded default wlan0 device, while predictable interface naming produces names like wlp2s0. The Settings page saved hotspot_device to wrolpi.yaml, which the Controller never read. The Controller now owns hotspot settings in controller.yaml: * New endpoints: GET/POST /api/hotspot/settings, GET /api/hotspot/devices (WiFi interfaces discovered via nmcli). * Legacy hotspot_* values in wrolpi.yaml are migrated into controller.yaml once on startup, unless controller.yaml already sets them. * The Hotspot SSID/password/device fields moved from the Settings page to the Control page next to the Hotspot toggle; the device is now a dropdown of the WiFi devices found on the machine. * The Controller fallback UI gets the same hotspot settings form for parity. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
ebbc60992c
commit
0d2c13e4e7
12 changed files with 586 additions and 89 deletions
|
|
@ -11,6 +11,8 @@ import {
|
|||
enableService,
|
||||
getDisks,
|
||||
getFstabEntries,
|
||||
getHotspotDevices,
|
||||
getHotspotSettings,
|
||||
getSambaStatus,
|
||||
getServiceLogs,
|
||||
getServices,
|
||||
|
|
@ -23,7 +25,9 @@ import {
|
|||
startService,
|
||||
stopService,
|
||||
unmountDisk,
|
||||
updateHotspotSettings,
|
||||
} from "../../api/controller";
|
||||
import QRCode from "react-qr-code";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
import {RestartButton, ShutdownButton} from "./Settings";
|
||||
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
||||
|
|
@ -1345,6 +1349,100 @@ function SambaSection() {
|
|||
}
|
||||
|
||||
|
||||
function HotspotSettingsForm() {
|
||||
const dockerized = useDockerized();
|
||||
const [devices, setDevices] = React.useState([]);
|
||||
const [form, setForm] = React.useState({device: '', ssid: '', password: ''});
|
||||
const [loading, setLoading] = React.useState(true);
|
||||
const [saving, setSaving] = React.useState(false);
|
||||
const [qrOpen, setQrOpen] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
const fetchSettings = async () => {
|
||||
try {
|
||||
const [settings, devicesResponse] = await Promise.all([getHotspotSettings(), getHotspotDevices()]);
|
||||
setForm({device: settings.device, ssid: settings.ssid, password: settings.password});
|
||||
setDevices(devicesResponse.devices || []);
|
||||
} catch (e) {
|
||||
console.error('Failed to fetch hotspot settings', e);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
fetchSettings();
|
||||
}, []);
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true);
|
||||
try {
|
||||
const settings = await updateHotspotSettings(form);
|
||||
setForm(settings);
|
||||
toast({type: 'success', title: 'Hotspot settings saved', time: 3000});
|
||||
} catch (e) {
|
||||
toast({type: 'error', title: 'Failed to save hotspot settings', description: e.message, time: 5000});
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return <Loader active inline size='small'/>;
|
||||
}
|
||||
|
||||
// Keep the saved device selectable even if it is not currently present
|
||||
// (e.g. a USB WiFi dongle is unplugged).
|
||||
const deviceOptions = [...new Set([...devices, form.device].filter(Boolean))]
|
||||
.map(device => ({key: device, value: device, text: device}));
|
||||
|
||||
// Special string which allows a mobile device to connect to a specific Wi-Fi.
|
||||
const qrCodeValue = `WIFI:S:${form.ssid};T:WPA;P:${form.password};;`;
|
||||
|
||||
return <Form style={{marginLeft: '1em', marginBottom: '1em'}}>
|
||||
<Form.Group widths='equal'>
|
||||
<Form.Input
|
||||
label='Hotspot SSID'
|
||||
value={form.ssid}
|
||||
disabled={dockerized || saving}
|
||||
onChange={(e, {value}) => setForm({...form, ssid: value})}
|
||||
/>
|
||||
<Form.Input
|
||||
label='Hotspot Password'
|
||||
value={form.password}
|
||||
disabled={dockerized || saving}
|
||||
onChange={(e, {value}) => setForm({...form, password: value})}
|
||||
/>
|
||||
<Form.Dropdown
|
||||
selection
|
||||
label='Hotspot Device'
|
||||
placeholder='No WiFi devices found'
|
||||
options={deviceOptions}
|
||||
value={form.device}
|
||||
disabled={dockerized || saving}
|
||||
onChange={(e, {value}) => setForm({...form, device: value})}
|
||||
/>
|
||||
</Form.Group>
|
||||
<Button
|
||||
color='violet'
|
||||
disabled={dockerized}
|
||||
loading={saving}
|
||||
onClick={handleSave}
|
||||
>Save</Button>
|
||||
<Modal closeIcon
|
||||
onClose={() => setQrOpen(false)}
|
||||
onOpen={() => setQrOpen(true)}
|
||||
open={qrOpen}
|
||||
trigger={<Button icon='qrcode' color='violet'/>}
|
||||
>
|
||||
<Modal.Header>Scan this code to join the hotspot</Modal.Header>
|
||||
<Modal.Content>
|
||||
<div style={{display: 'inline-block', backgroundColor: '#ffffff', padding: '1em'}}>
|
||||
<QRCode value={qrCodeValue} size={300}/>
|
||||
</div>
|
||||
</Modal.Content>
|
||||
</Modal>
|
||||
</Form>;
|
||||
}
|
||||
|
||||
function AdminControlsSection() {
|
||||
const dockerized = useDockerized();
|
||||
|
||||
|
|
@ -1356,6 +1454,7 @@ function AdminControlsSection() {
|
|||
</Header>
|
||||
|
||||
<HotspotToggle/>
|
||||
<HotspotSettingsForm/>
|
||||
<BluetoothToggle/>
|
||||
<ThrottleToggle/>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue