-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge: + DNS: new settings (ratelimit, blocking mode, edns_client_sub…
…net) Close #1091 Close #1154 Close #1022 * commit '97e77cab643d6784067ce97c0f03ec3e4612c2c9': + client: handle EDNS Client Subnet setting + dns: add "edns_client_subnet" setting + client: handle DNS config * DNS: remove /enable_protection and /disable_protection + openapi: /dns_info, /dns_config * /control/set_upstreams_config: allow empty upstream list + dns: support blocking_mode=custom_ip + DNS: Get/Set DNS general settings
- Loading branch information
Showing
19 changed files
with
611 additions
and
49 deletions.
There are no files selected for viewing
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
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,35 @@ | ||
import { createAction } from 'redux-actions'; | ||
|
||
import apiClient from '../api/Api'; | ||
import { addErrorToast, addSuccessToast } from './index'; | ||
|
||
export const getDnsConfigRequest = createAction('GET_DNS_CONFIG_REQUEST'); | ||
export const getDnsConfigFailure = createAction('GET_DNS_CONFIG_FAILURE'); | ||
export const getDnsConfigSuccess = createAction('GET_DNS_CONFIG_SUCCESS'); | ||
|
||
export const getDnsConfig = () => async (dispatch) => { | ||
dispatch(getDnsConfigRequest()); | ||
try { | ||
const data = await apiClient.getDnsConfig(); | ||
dispatch(getDnsConfigSuccess(data)); | ||
} catch (error) { | ||
dispatch(addErrorToast({ error })); | ||
dispatch(getDnsConfigFailure()); | ||
} | ||
}; | ||
|
||
export const setDnsConfigRequest = createAction('SET_DNS_CONFIG_REQUEST'); | ||
export const setDnsConfigFailure = createAction('SET_DNS_CONFIG_FAILURE'); | ||
export const setDnsConfigSuccess = createAction('SET_DNS_CONFIG_SUCCESS'); | ||
|
||
export const setDnsConfig = config => async (dispatch) => { | ||
dispatch(setDnsConfigRequest()); | ||
try { | ||
await apiClient.setDnsConfig(config); | ||
dispatch(addSuccessToast('config_successfully_saved')); | ||
dispatch(setDnsConfigSuccess(config)); | ||
} catch (error) { | ||
dispatch(addErrorToast({ error })); | ||
dispatch(setDnsConfigFailure()); | ||
} | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import React, { Fragment } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { Field, reduxForm, formValueSelector } from 'redux-form'; | ||
import { Trans, withNamespaces } from 'react-i18next'; | ||
import flow from 'lodash/flow'; | ||
|
||
import { | ||
renderField, | ||
renderRadioField, | ||
renderSelectField, | ||
required, | ||
ipv4, | ||
ipv6, | ||
biggerOrEqualZero, | ||
toNumber, | ||
} from '../../../../helpers/form'; | ||
import { BLOCKING_MODES } from '../../../../helpers/constants'; | ||
|
||
const getFields = (processing, t) => Object.values(BLOCKING_MODES).map(mode => ( | ||
<Field | ||
key={mode} | ||
name="blocking_mode" | ||
type="radio" | ||
component={renderRadioField} | ||
value={mode} | ||
placeholder={t(mode)} | ||
disabled={processing} | ||
/> | ||
)); | ||
|
||
let Form = ({ | ||
handleSubmit, submitting, invalid, processing, blockingMode, t, | ||
}) => ( | ||
<form onSubmit={handleSubmit}> | ||
<div className="row"> | ||
<div className="col-12 col-sm-6"> | ||
<div className="form__group form__group--settings"> | ||
<label htmlFor="ratelimit" className="form__label form__label--with-desc"> | ||
<Trans>rate_limit</Trans> | ||
</label> | ||
<div className="form__desc form__desc--top"> | ||
<Trans>rate_limit_desc</Trans> | ||
</div> | ||
<Field | ||
name="ratelimit" | ||
type="number" | ||
component={renderField} | ||
className="form-control" | ||
placeholder={t('form_enter_rate_limit')} | ||
normalize={toNumber} | ||
validate={[required, biggerOrEqualZero]} | ||
/> | ||
</div> | ||
</div> | ||
<div className="col-12"> | ||
<div className="form__group form__group--settings"> | ||
<Field | ||
name="edns_cs_enabled" | ||
type="checkbox" | ||
component={renderSelectField} | ||
placeholder={t('edns_enable')} | ||
disabled={processing} | ||
subtitle={t('edns_cs_desc')} | ||
/> | ||
</div> | ||
</div> | ||
<div className="col-12"> | ||
<div className="form__group form__group--settings mb-4"> | ||
<label className="form__label form__label--with-desc"> | ||
<Trans>blocking_mode</Trans> | ||
</label> | ||
<div className="form__desc form__desc--top"> | ||
<Trans components={[<div key="0">text</div>]}>blocking_mode_desc</Trans> | ||
</div> | ||
<div className="custom-controls-stacked"> | ||
{getFields(processing, t)} | ||
</div> | ||
</div> | ||
</div> | ||
{blockingMode === BLOCKING_MODES.custom_ip && ( | ||
<Fragment> | ||
<div className="col-12 col-sm-6"> | ||
<div className="form__group form__group--settings"> | ||
<label htmlFor="blocking_ipv4" className="form__label form__label--with-desc"> | ||
<Trans>blocking_ipv4</Trans> | ||
</label> | ||
<div className="form__desc form__desc--top"> | ||
<Trans>blocking_ipv4_desc</Trans> | ||
</div> | ||
<Field | ||
name="blocking_ipv4" | ||
component={renderField} | ||
className="form-control" | ||
placeholder={t('form_enter_ip')} | ||
validate={[ipv4, required]} | ||
/> | ||
</div> | ||
</div> | ||
<div className="col-12 col-sm-6"> | ||
<div className="form__group form__group--settings"> | ||
<label htmlFor="ip_address" className="form__label form__label--with-desc"> | ||
<Trans>blocking_ipv6</Trans> | ||
</label> | ||
<div className="form__desc form__desc--top"> | ||
<Trans>blocking_ipv6_desc</Trans> | ||
</div> | ||
<Field | ||
name="blocking_ipv6" | ||
component={renderField} | ||
className="form-control" | ||
placeholder={t('form_enter_ip')} | ||
validate={[ipv6, required]} | ||
/> | ||
</div> | ||
</div> | ||
</Fragment> | ||
)} | ||
</div> | ||
<button | ||
type="submit" | ||
className="btn btn-success btn-standard btn-large" | ||
disabled={submitting || invalid || processing} | ||
> | ||
<Trans>save_btn</Trans> | ||
</button> | ||
</form> | ||
); | ||
|
||
Form.propTypes = { | ||
blockingMode: PropTypes.string.isRequired, | ||
handleSubmit: PropTypes.func.isRequired, | ||
submitting: PropTypes.bool.isRequired, | ||
invalid: PropTypes.bool.isRequired, | ||
processing: PropTypes.bool.isRequired, | ||
t: PropTypes.func.isRequired, | ||
}; | ||
|
||
const selector = formValueSelector('blockingModeForm'); | ||
|
||
Form = connect((state) => { | ||
const blockingMode = selector(state, 'blocking_mode'); | ||
return { | ||
blockingMode, | ||
}; | ||
})(Form); | ||
|
||
export default flow([ | ||
withNamespaces(), | ||
reduxForm({ | ||
form: 'blockingModeForm', | ||
}), | ||
])(Form); |
Oops, something went wrong.