-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from stephb9959/main
[WIFI-13534] Captive portal configuration schema fixes
- Loading branch information
Showing
11 changed files
with
340 additions
and
166 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 0 additions & 102 deletions
102
...rationCard/ConfigurationSectionsCard/InterfaceSection/SingleInterface/Captive/Captive.tsx
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
...gurationCard/ConfigurationSectionsCard/InterfaceSection/SingleInterface/Captive/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
...d/ConfigurationSectionsCard/InterfaceSection/SingleInterface/SsidList/Captive/Captive.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import React from 'react'; | ||
import { Heading, Select, SimpleGrid, Text } from '@chakra-ui/react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { object, string } from 'yup'; | ||
import CreatableSelectField from 'components/FormFields/CreatableSelectField'; | ||
import FileInputFieldModal from 'components/FormFields/FileInputFieldModal'; | ||
import NumberField from 'components/FormFields/NumberField'; | ||
import ObjectArrayFieldModal from 'components/FormFields/ObjectArrayFieldModal'; | ||
import SelectField from 'components/FormFields/SelectField'; | ||
import StringField from 'components/FormFields/StringField'; | ||
|
||
const CREDENTIALS_SCHEMA = (t: (str: string) => string, useDefault = false) => { | ||
const shape = object().shape({ | ||
username: string().required(t('form.required')).default(''), | ||
password: string().required(t('form.required')).default(''), | ||
}); | ||
|
||
return useDefault ? shape : shape.nullable().default(undefined); | ||
}; | ||
|
||
interface Props { | ||
isDisabled?: boolean; | ||
namePrefix: string; | ||
onAuthModeChange?: (e: React.ChangeEvent<HTMLSelectElement>) => void; | ||
authMode?: string; | ||
} | ||
|
||
const CaptiveForm = ({ isDisabled, namePrefix, onAuthModeChange, authMode }: Props) => { | ||
const fieldProps = (suffix: string) => ({ | ||
name: `${namePrefix}.${suffix}`, | ||
label: suffix, | ||
definitionKey: `interface.ssid.pass-point.${suffix}`, | ||
isDisabled, | ||
}); | ||
const { t } = useTranslation(); | ||
|
||
const credFields = React.useMemo( | ||
() => ( | ||
<SimpleGrid minChildWidth="300px" gap={4}> | ||
<StringField name="username" label="username" isRequired /> | ||
<StringField name="password" label="password" isRequired /> | ||
</SimpleGrid> | ||
), | ||
[], | ||
); | ||
const credCols = React.useMemo( | ||
() => [ | ||
{ | ||
id: 'username', | ||
Header: 'username', | ||
Footer: '', | ||
accessor: 'username', | ||
}, | ||
{ | ||
id: 'password', | ||
Header: 'password', | ||
Footer: '', | ||
accessor: 'password', | ||
}, | ||
], | ||
[], | ||
); | ||
|
||
return ( | ||
<> | ||
<Heading size="md" display="flex" alignItems="center" mt={2}> | ||
<Text pt={1}>Captive Portal</Text> | ||
<Select w="max-content" ml={2} value={authMode} onChange={onAuthModeChange} isDisabled={isDisabled}> | ||
<option value="none">None</option> | ||
<option value="click">Click</option> | ||
<option value="radius">Radius</option> | ||
<option value="credentials">Credentials</option> | ||
<option value="uam">UAM</option> | ||
</Select> | ||
</Heading> | ||
{authMode !== undefined && ( | ||
<SimpleGrid minChildWidth="300px" spacing="20px" mb={8} mt={2} w="100%"> | ||
<CreatableSelectField | ||
{...fieldProps('walled-garden-fqdn')} | ||
placeholder="Example: *.google.com" | ||
emptyIsUndefined={authMode !== 'uam'} | ||
isRequired={authMode === 'uam'} | ||
/> | ||
<CreatableSelectField | ||
{...fieldProps('walled-garden-ipaddr')} | ||
placeholder="Example: 192.168.0.1" | ||
emptyIsUndefined | ||
/> | ||
<FileInputFieldModal | ||
{...fieldProps('web-root')} | ||
fileName="configuration.captive.web-root-filename" | ||
definitionKey="service.captive.web-root" | ||
explanation={t('form.captive_web_root_explanation')} | ||
test={() => true} | ||
acceptedFileTypes=".tar" | ||
isDisabled={isDisabled} | ||
canDelete | ||
isRequired | ||
wantBase64 | ||
/> | ||
<NumberField {...fieldProps('idle-timeout')} isRequired w="100px" /> | ||
<NumberField {...fieldProps('session-timeout')} emptyIsUndefined acceptEmptyValue w="100px" /> | ||
{authMode === 'credentials' && ( | ||
<ObjectArrayFieldModal | ||
{...fieldProps('credentials')} | ||
fields={credFields} | ||
columns={credCols} | ||
schema={CREDENTIALS_SCHEMA} | ||
isDisabled={isDisabled} | ||
isRequired | ||
/> | ||
)} | ||
{authMode === 'uam' && ( | ||
<> | ||
<StringField {...fieldProps('uam-server')} isRequired /> | ||
<StringField {...fieldProps('uam-secret')} isRequired hideButton /> | ||
<NumberField {...fieldProps('uam-port')} isRequired /> | ||
<StringField {...fieldProps('nasid')} isRequired /> | ||
<StringField {...fieldProps('nasmac')} emptyIsUndefined /> | ||
<SelectField | ||
{...fieldProps('mac-format')} | ||
options={[ | ||
{ value: 'aabbccddeeff', label: 'aabbccddeeff' }, | ||
{ value: 'aa-bb-cc-dd-ee-ff', label: 'aa-bb-cc-dd-ee-ff' }, | ||
{ value: 'aa:bb:cc:dd:ee:ff', label: 'aa:bb:cc:dd:ee:ff' }, | ||
{ value: 'AABBCCDDEEFF', label: 'AABBCCDDEEFF' }, | ||
{ value: 'AA:BB:CC:DD:EE:FF', label: 'AA:BB:CC:DD:EE:FF' }, | ||
{ value: 'AA-BB-CC-DD-EE-FF', label: 'AA-BB-CC-DD-EE-FF' }, | ||
]} | ||
isRequired | ||
/> | ||
<StringField {...fieldProps('ssid')} emptyIsUndefined /> | ||
</> | ||
)} | ||
{(authMode === 'radius' || authMode === 'uam') && ( | ||
<> | ||
<StringField {...fieldProps('auth-server')} isRequired /> | ||
<StringField {...fieldProps('auth-secret')} isRequired hideButton /> | ||
<NumberField {...fieldProps('auth-port')} isRequired /> | ||
<StringField {...fieldProps('acct-server')} emptyIsUndefined /> | ||
<StringField {...fieldProps('acct-secret')} emptyIsUndefined hideButton /> | ||
<NumberField {...fieldProps('acct-port')} emptyIsUndefined acceptEmptyValue /> | ||
<NumberField {...fieldProps('acct-interval')} emptyIsUndefined acceptEmptyValue /> | ||
</> | ||
)} | ||
</SimpleGrid> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default React.memo(CaptiveForm); |
File renamed without changes.
Oops, something went wrong.