mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 13:19:58 -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/>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import {
|
|||
useMessageDismissal,
|
||||
WROLModeMessage
|
||||
} from "../Common";
|
||||
import QRCode from "react-qr-code";
|
||||
import {useConfigs, useDockerized} from "../../hooks/customHooks";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
|
|
@ -296,8 +295,6 @@ function WROLModeSection() {
|
|||
export function SettingsPage() {
|
||||
const [disabled, setDisabled] = React.useState(false);
|
||||
const [editSpecialDirectories, setEditSpecialDirectories] = React.useState(false);
|
||||
const [qrCodeValue, setQrCodeValue] = React.useState('');
|
||||
const [qrOpen, setQrOpen] = React.useState(false);
|
||||
const [ready, setReady] = React.useState(false);
|
||||
const [pendingSave, setPendingSave] = React.useState(false);
|
||||
const {clearAll} = useMessageDismissal();
|
||||
|
|
@ -446,12 +443,6 @@ export function SettingsPage() {
|
|||
setTraceModalOpen(false);
|
||||
}
|
||||
|
||||
const handleHotspotChange = async () => {
|
||||
let {hotspot_ssid, hotspot_encryption, hotspot_password} = state;
|
||||
// Special string which allows a mobile device to connect to a specific Wi-Fi.
|
||||
setQrCodeValue(`WIFI:S:${hotspot_ssid};T:${hotspot_encryption};P:${hotspot_password};;`);
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
console.debug('settings changed, replacing state...');
|
||||
setReady(settings ? true : undefined);
|
||||
|
|
@ -468,10 +459,6 @@ export function SettingsPage() {
|
|||
download_window_start: settings.download_window_start || '',
|
||||
download_window_end: settings.download_window_end || '',
|
||||
timezone: settings.timezone || '',
|
||||
hotspot_device: settings.hotspot_device,
|
||||
hotspot_on_startup: settings.hotspot_on_startup,
|
||||
hotspot_password: settings.hotspot_password,
|
||||
hotspot_ssid: settings.hotspot_ssid,
|
||||
check_for_upgrades: settings.check_for_upgrades,
|
||||
ignore_outdated_zims: settings.ignore_outdated_zims,
|
||||
log_level: fromApiLogLevel(settings.log_level),
|
||||
|
|
@ -487,10 +474,6 @@ export function SettingsPage() {
|
|||
});
|
||||
}, [JSON.stringify(settings)]);
|
||||
|
||||
React.useEffect(() => {
|
||||
handleHotspotChange();
|
||||
}, [state.hotspot_ssid, state.hotspot_password, state.hotspot_device]);
|
||||
|
||||
const handleInputChange = async (e, name, value) => {
|
||||
if (e) {
|
||||
e.preventDefault()
|
||||
|
|
@ -507,15 +490,6 @@ export function SettingsPage() {
|
|||
setState({...state, [name]: value});
|
||||
}
|
||||
|
||||
const handleQrOpen = async (e) => {
|
||||
e.preventDefault();
|
||||
setQrOpen(true);
|
||||
}
|
||||
|
||||
const qrButton = <Button icon color='violet' style={{marginBottom: '1em'}}>
|
||||
<Icon name='qrcode' size='big'/>
|
||||
</Button>;
|
||||
|
||||
const timezoneOptions = Intl.supportedValuesOf('timeZone').map(tz => (
|
||||
{key: tz, value: tz, text: tz}
|
||||
));
|
||||
|
|
@ -619,54 +593,6 @@ export function SettingsPage() {
|
|||
</ButtonGroup>
|
||||
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
<Segment>
|
||||
<Header as='h3'>Hotspot Settings</Header>
|
||||
|
||||
<Form.Input
|
||||
label='Hotspot SSID'
|
||||
value={state.hotspot_ssid}
|
||||
disabled={disabled || state.hotspot_ssid === null}
|
||||
onChange={(e, i) => setState({...state, hotspot_ssid: i.value})}
|
||||
style={{marginBottom: '0.5em'}}
|
||||
/>
|
||||
<Form.Input
|
||||
label='Hotspot Password'
|
||||
disabled={disabled || state.hotspot_password === null}
|
||||
value={state.hotspot_password}
|
||||
onChange={(e, i) => setState({...state, hotspot_password: i.value})}
|
||||
style={{marginBottom: '0.5em'}}
|
||||
/>
|
||||
<Form.Input
|
||||
label='Hotspot Device'
|
||||
disabled={disabled || state.hotspot_password === null}
|
||||
value={state.hotspot_device}
|
||||
onChange={(e, i) => handleInputChange(e, 'hotspot_device', i.value)}
|
||||
style={{marginBottom: '0.5em'}}
|
||||
/>
|
||||
|
||||
<Modal closeIcon
|
||||
onClose={() => setQrOpen(false)}
|
||||
onOpen={handleQrOpen}
|
||||
open={qrOpen}
|
||||
trigger={qrButton}
|
||||
>
|
||||
<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>
|
||||
|
||||
</Segment>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue