Skip to content

Commit 0f1c788

Browse files
authored
CNAME Overrides #patch (#377)
## v1.0.2 **Improvements** - Introduces CNAME Support for DNS Overrides **Fixes** - dns:family policy fix in UI
1 parent e0c2463 commit 0f1c788

File tree

5 files changed

+67
-16
lines changed

5 files changed

+67
-16
lines changed

RELEASE-NOTES.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Secure Programmable Router (SPR) Release Notes
22

3+
## v1.0.2
4+
**Improvements**
5+
- Introduces CNAME Support for DNS Overrides
6+
**Fixes**
7+
- dns:family policy fix in UI
8+
39
## v1.0.1
410
**Improvements**
511
- Emoji support for ssids in wifi uplink, dashboard

frontend/src/__tests__/DNS.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ describe('DNS Blocklist', () => {
6060
expect(screen.getByText('New Tag...')).toBeTruthy()
6161
expect(screen.getByText('Set Category...')).toBeTruthy()
6262

63-
let numEnabled = screen.getAllByText('Enabled').length
63+
let numEnabled = screen.getAllByText('Block Enabled').length
6464

6565
fireEvent.press(screen.getByText('Disable'))
6666

6767
await waitFor(() =>
68-
expect(screen.getAllByText('Enabled').length).toBeLessThan(numEnabled)
68+
expect(screen.getAllByText('Block Enabled').length).toBeLessThan(numEnabled)
6969
)
7070
})
7171
})

frontend/src/components/DNS/DNSAddOverride.js

+55-10
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import {
3131
export default class DNSAddOverride extends React.Component {
3232
state = {
3333
Type: '',
34+
ReturnType: 'IP',
3435
Domain: '',
35-
ResultIP: '0.0.0.0',
36+
ResultIP: '',
37+
ResultCNAME: '',
3638
ClientIP: '*',
3739
Expiration: 0,
3840
check: {}
@@ -53,11 +55,13 @@ export default class DNSAddOverride extends React.Component {
5355
this.state.Type = props.type
5456
this.state.Domain = props.domain || ''
5557
this.state.ResultIP = props.ResultIP || ''
58+
this.state.ResultCNAME = props.ResultCNAME || ''
5659
this.state.ClientIP = props.clientip || '*'
5760
this.state.check = {
5861
Type: '',
5962
Domain: '',
6063
ResultIP: '',
64+
ResultCNAME: '',
6165
ClientIP: ''
6266
}
6367

@@ -67,7 +71,7 @@ export default class DNSAddOverride extends React.Component {
6771
}
6872

6973
validateField(name, value) {
70-
let check = { Type: '', Domain: '', ResultIP: '', ClientIP: '' }
74+
let check = { Type: '', Domain: '', ResultIP: '', ResultCNAME: '', ClientIP: '' }
7175

7276
if (name == 'Type' && !['block', 'permit'].includes(value)) {
7377
check.Type = 'has-danger'
@@ -103,10 +107,21 @@ export default class DNSAddOverride extends React.Component {
103107
return
104108
}
105109

110+
if (this.state.ReturnType == 'CNAME') {
111+
if (this.state.ResultCNAME != '' && !this.state.ResultCNAME.endsWith('.')) {
112+
this.state.ResultCNAME += '.'
113+
}
114+
this.state.ResultIP = ''
115+
} else if (this.state.ReturnType == 'IP') {
116+
this.state.ResultCNAME = ''
117+
}
118+
119+
106120
let override = {
107121
Type: this.state.Type,
108122
Domain: this.state.Domain,
109123
ResultIP: this.state.ResultIP,
124+
ResultCNAME: this.state.ResultCNAME,
110125
ClientIP: this.state.ClientIP,
111126
Expiration: this.state.Expiration
112127
}
@@ -203,36 +218,66 @@ export default class DNSAddOverride extends React.Component {
203218
)}
204219
</FormControl>
205220

206-
<FormControl isInvalid={this.state.check.ResultIP == 'has-danger'}>
221+
222+
<FormControl
223+
isInvalid={this.state.check.ResultIP == 'has-danger' || this.state.check.ReturnCNAME == 'has-danger'}
224+
>
207225
<FormControlLabel>
208-
<FormControlLabelText>Result IP</FormControlLabelText>
226+
<FormControlLabelText>Result Type</FormControlLabelText>
209227
</FormControlLabel>
210228

211-
<Input>
229+
<RadioGroup
230+
flex={1}
231+
defaultValue={this.state.ReturnType}
232+
accessibilityLabel="Select Return Type"
233+
onChange={(type) => {
234+
this.handleChange('ReturnType', type)
235+
}}
236+
>
237+
<HStack py="1" space="md">
238+
<Radio key="block" value="IP" size="md">
239+
<RadioIndicator mr="$2">
240+
<RadioIcon as={CircleIcon} strokeWidth={1} />
241+
</RadioIndicator>
242+
<RadioLabel>IP</RadioLabel>
243+
</Radio>
244+
245+
<Radio key="permit" value="CNAME" size="md">
246+
<RadioIndicator mr="$2">
247+
<RadioIcon as={CircleIcon} strokeWidth={1} />
248+
</RadioIndicator>
249+
<RadioLabel>CNAME</RadioLabel>
250+
</Radio>
251+
</HStack>
252+
</RadioGroup>
253+
254+
255+
<Input py="1">
212256
<InputField
213257
type="text"
214258
name="ResultIP"
215-
value={this.state.ResultIP}
216-
onChangeText={(value) => this.handleChange('ResultIP', value)}
259+
value={this.state.ReturnType == 'IP' ? this.state.ResultIP : this.state.ResultCNAME}
260+
onChangeText={(value) => this.handleChange('Result' + this.state.ReturnType, value)}
217261
/>
218262
</Input>
219263

220-
{this.state.check.ResultIP == 'has-danger' ? (
264+
{(this.state.check.ResultIP == 'has-danger' || this.state.check.ResultCNAME == 'has-danger') ? (
221265
<FormControlError>
222266
<FormControlErrorText>
223-
Please enter a valid IP or leave empty
267+
Please enter a valid {this.state.ReturnType} or leave empty
224268
</FormControlErrorText>
225269
</FormControlError>
226270
) : (
227271
<FormControlHelper>
228272
<FormControlHelperText>
229-
Optional. Set a custom IP address to return for domain name
273+
Optional. Set a custom {this.state.ReturnType} address to return for domain name
230274
lookup
231275
</FormControlHelperText>
232276
</FormControlHelper>
233277
)}
234278
</FormControl>
235279

280+
236281
<FormControl isInvalid={this.state.check.ClientIP == 'has-danger'}>
237282
<FormControlLabel>
238283
<FormControlLabelText>Client IP</FormControlLabelText>

frontend/src/components/DNS/DNSOverrideListItem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const DNSOverrideListItem = ({ item, deleteListItem, ...props }) => {
3636
>
3737
=
3838
</Text>
39-
<Text>{item.ResultIP || '0.0.0.0'}</Text>
39+
<Text>{item.ResultIP || item.ResultCNAME || '0.0.0.0'}</Text>
4040
</HStack>
4141
</VStack>
4242

frontend/src/components/Devices/EditDevice.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const EditDevice = ({ device, notifyChange, ...props }) => {
7171
const [modalType, setModalType] = useState('')
7272

7373
// for adding
74-
let defaultPolicies = ['wan', 'dns', 'dns_family', 'lan']
74+
let defaultPolicies = ['wan', 'dns', 'dns:family', 'lan']
7575

7676
if (!isSimpleMode) {
7777
defaultPolicies.push(...['lan_upstream', 'disabled', 'quarantine'])
@@ -84,7 +84,7 @@ const EditDevice = ({ device, notifyChange, ...props }) => {
8484
lan_upstream: 'Upstream Private Networks',
8585
quarantine: 'Quarantine',
8686
disabled: 'Disabled',
87-
dns_family: "Use Family DNS"
87+
"dns:family": "Use Family DNS"
8888
}
8989
const policyTips = {
9090
wan: 'Allow Internet Access',
@@ -93,7 +93,7 @@ const EditDevice = ({ device, notifyChange, ...props }) => {
9393
lan_upstream: 'Allow device to reach private LANs upstream',
9494
quarantine: 'Send all Traffic, DNS, to Quarantine Host if set else drop traffic',
9595
disabled: 'Override all policies and groups, to disconnect device',
96-
dns_family: 'Use family friendly DNS resolver'
96+
"dns:family": 'Use family friendly DNS resolver'
9797
}
9898
const defaultGroups = props.groups || []
9999
const defaultTags = props.tags || []

0 commit comments

Comments
 (0)