mirror of
https://git.vectorsigma.ru/public/AdGuardHome.git
synced 2026-07-30 15:19:20 +00:00
Merge in DNS/adguard-home from AG-28194-plain-dns to master Squashed commit of the following: commit a033982b949217d46a8ea609f63198916f779a61 Merge: 03fc2821179d7a1ef4Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Dec 12 12:07:39 2023 +0200 Merge remote-tracking branch 'origin/master' into AG-28194-plain-dns commit 03fc282119a6372fcb4ce17a5d89779ad84589f5 Merge: e31a6593134a34dc05Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Dec 12 11:07:46 2023 +0200 Merge remote-tracking branch 'origin/master' into AG-28194-plain-dns # Conflicts: # CHANGELOG.md commit e31a659312fffe0cd5f57710843c8a6818515502 Merge: 0b735eb427b5cce517Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Dec 11 11:09:07 2023 +0200 Merge remote-tracking branch 'origin/master' into AG-28194-plain-dns # Conflicts: # CHANGELOG.md commit 0b735eb4261883961058aed562c1e72ad1a20915 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Dec 8 15:22:27 2023 +0200 Revert "safesearch: imp docs" This reverts commit bab6bf3467f8914a34413bbbcdc37e89ff0401a5. commit bab6bf3467f8914a34413bbbcdc37e89ff0401a5 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Dec 8 15:21:23 2023 +0200 safesearch: imp docs commit aa5e6e30e01bf947d645ac4a9578eeac09c92a19 Merge: 503888447 2b62901fe Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Dec 8 14:48:13 2023 +0200 Merge remote-tracking branch 'origin/AG-28194-plain-dns' into AG-28194-plain-dns commit 503888447aaf30d48c3fb9a414e8a65beb1a4e23 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Dec 8 14:47:23 2023 +0200 home: imp code commit 2b62901feb29c9613ae648fa5e83598157207a17 Author: Ildar Kamalov <ik@adguard.com> Date: Fri Dec 8 11:55:25 2023 +0300 client: add plain dns description commit 3d51fc8ea1955e599953070a4b330dd4e2fd44bc Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Dec 8 10:15:53 2023 +0200 all: changelog commit 59697b5f1ab049bd2259ffe42cef7223531ef7aa Merge: 81a15d081b668c04eaAuthor: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Dec 8 10:11:59 2023 +0200 Merge remote-tracking branch 'origin/master' into AG-28194-plain-dns commit 81a15d0818b18f99e651311a8502082b4a539e4b Author: Natalia Sokolova <n.sokolova@adguard.com> Date: Thu Dec 7 17:30:05 2023 +0300 client/src/__locales/en.json edited online with Bitbucket commit 0cf2f880fbd1592c02e6df42319cba357f0d7bc8 Author: Natalia Sokolova <n.sokolova@adguard.com> Date: Thu Dec 7 17:29:51 2023 +0300 client/src/__locales/en.json edited online with Bitbucket commit 2f32c59b8b1d764d060a69c35787566cf5210063 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Dec 7 13:14:04 2023 +0200 home: imp code commit 01e21a26bdd13c42c55c8ea3b5bbe84933bf0c04 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Dec 7 12:14:02 2023 +0200 all: imp docs commit b6beec6df7c2a9077ddce018656c701b7e875b53 Author: Ildar Kamalov <ik@adguard.com> Date: Thu Dec 7 12:42:21 2023 +0300 client: fix reset settings commit 93448500d56a4652a3a060b274936c40015ac8ec Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Dec 7 10:55:25 2023 +0200 home: imp code commit eb32f8268bee097a81463ba29f7ea52be6e7d88b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Dec 7 10:42:23 2023 +0200 home: imp code commit 873d1412cf7c07ed985985a47325779bcfbf650a Merge: 627659680214175eb4Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Dec 7 10:22:25 2023 +0200 Merge remote-tracking branch 'origin/master' into AG-28194-plain-dns commit 627659680da8e973a3878d1722b276d30c7a27bb Author: Ildar Kamalov <ik@adguard.com> Date: Wed Dec 6 17:39:14 2023 +0300 client: handle plain dns setting commit ffdbf05fede721d271a84482a5759284d18eb189 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Dec 1 15:12:50 2023 +0200 home: http dns plain ... and 1 more commit
517 lines
21 KiB
JavaScript
517 lines
21 KiB
JavaScript
import React from 'react';
|
|
import { connect } from 'react-redux';
|
|
import PropTypes from 'prop-types';
|
|
import { Field, reduxForm, formValueSelector } from 'redux-form';
|
|
import { Trans, withTranslation } from 'react-i18next';
|
|
import flow from 'lodash/flow';
|
|
|
|
import {
|
|
renderInputField,
|
|
CheckboxField,
|
|
renderRadioField,
|
|
toNumber,
|
|
} from '../../../helpers/form';
|
|
import {
|
|
validateServerName, validateIsSafePort, validatePort, validatePortQuic, validatePortTLS, validatePlainDns,
|
|
} from '../../../helpers/validators';
|
|
import i18n from '../../../i18n';
|
|
import KeyStatus from './KeyStatus';
|
|
import CertificateStatus from './CertificateStatus';
|
|
import {
|
|
DNS_OVER_QUIC_PORT, DNS_OVER_TLS_PORT, FORM_NAME, STANDARD_HTTPS_PORT, ENCRYPTION_SOURCE,
|
|
} from '../../../helpers/constants';
|
|
|
|
const validate = (values) => {
|
|
const errors = {};
|
|
|
|
if (values.port_dns_over_tls && values.port_https) {
|
|
if (values.port_dns_over_tls === values.port_https) {
|
|
errors.port_dns_over_tls = i18n.t('form_error_equal');
|
|
errors.port_https = i18n.t('form_error_equal');
|
|
}
|
|
}
|
|
|
|
return errors;
|
|
};
|
|
|
|
const clearFields = (change, setTlsConfig, validateTlsConfig, t) => {
|
|
const fields = {
|
|
private_key: '',
|
|
certificate_chain: '',
|
|
private_key_path: '',
|
|
certificate_path: '',
|
|
port_https: STANDARD_HTTPS_PORT,
|
|
port_dns_over_tls: DNS_OVER_TLS_PORT,
|
|
port_dns_over_quic: DNS_OVER_QUIC_PORT,
|
|
server_name: '',
|
|
force_https: false,
|
|
enabled: false,
|
|
private_key_saved: false,
|
|
serve_plain_dns: true,
|
|
};
|
|
// eslint-disable-next-line no-alert
|
|
if (window.confirm(t('encryption_reset'))) {
|
|
Object.keys(fields)
|
|
.forEach((field) => change(field, fields[field]));
|
|
setTlsConfig(fields);
|
|
validateTlsConfig(fields);
|
|
}
|
|
};
|
|
|
|
const validationMessage = (warningValidation, isWarning) => {
|
|
if (!warningValidation) {
|
|
return null;
|
|
}
|
|
|
|
if (isWarning) {
|
|
return (
|
|
<div className="col-12">
|
|
<p><Trans>encryption_warning</Trans>: {warningValidation}</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="col-12">
|
|
<p className="text-danger">{warningValidation}</p>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
let Form = (props) => {
|
|
const {
|
|
t,
|
|
handleSubmit,
|
|
handleChange,
|
|
isEnabled,
|
|
servePlainDns,
|
|
certificateChain,
|
|
privateKey,
|
|
certificatePath,
|
|
privateKeyPath,
|
|
change,
|
|
invalid,
|
|
submitting,
|
|
processingConfig,
|
|
processingValidate,
|
|
not_after,
|
|
valid_chain,
|
|
valid_key,
|
|
valid_cert,
|
|
valid_pair,
|
|
dns_names,
|
|
key_type,
|
|
issuer,
|
|
subject,
|
|
warning_validation,
|
|
setTlsConfig,
|
|
validateTlsConfig,
|
|
certificateSource,
|
|
privateKeySource,
|
|
privateKeySaved,
|
|
} = props;
|
|
|
|
const isSavingDisabled = () => {
|
|
const processing = submitting || processingConfig || processingValidate;
|
|
|
|
if (servePlainDns && !isEnabled) {
|
|
return invalid || processing;
|
|
}
|
|
|
|
return invalid || processing || !valid_key || !valid_cert || !valid_pair;
|
|
};
|
|
|
|
const isDisabled = isSavingDisabled();
|
|
const isWarning = valid_key && valid_cert && valid_pair;
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit}>
|
|
<div className="row">
|
|
<div className="col-12">
|
|
<div className="form__group form__group--settings mb-3">
|
|
<Field
|
|
name="enabled"
|
|
type="checkbox"
|
|
component={CheckboxField}
|
|
placeholder={t('encryption_enable')}
|
|
onChange={handleChange}
|
|
/>
|
|
</div>
|
|
<div className="form__desc">
|
|
<Trans>encryption_enable_desc</Trans>
|
|
</div>
|
|
<div className="form__group mb-3 mt-5">
|
|
<Field
|
|
name="serve_plain_dns"
|
|
type="checkbox"
|
|
component={CheckboxField}
|
|
placeholder={t('encryption_plain_dns_enable')}
|
|
onChange={handleChange}
|
|
validate={validatePlainDns}
|
|
/>
|
|
</div>
|
|
<div className="form__desc">
|
|
<Trans>encryption_plain_dns_desc</Trans>
|
|
</div>
|
|
<hr />
|
|
</div>
|
|
<div className="col-12">
|
|
<label className="form__label" htmlFor="server_name">
|
|
<Trans>encryption_server</Trans>
|
|
</label>
|
|
</div>
|
|
<div className="col-lg-6">
|
|
<div className="form__group form__group--settings">
|
|
<Field
|
|
id="server_name"
|
|
name="server_name"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t('encryption_server_enter')}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
validate={validateServerName}
|
|
/>
|
|
<div className="form__desc">
|
|
<Trans>encryption_server_desc</Trans>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="col-lg-6">
|
|
<div className="form__group form__group--settings">
|
|
<Field
|
|
name="force_https"
|
|
type="checkbox"
|
|
component={CheckboxField}
|
|
placeholder={t('encryption_redirect')}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
/>
|
|
<div className="form__desc">
|
|
<Trans>encryption_redirect_desc</Trans>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="row">
|
|
<div className="col-lg-6">
|
|
<div className="form__group form__group--settings">
|
|
<label className="form__label" htmlFor="port_https">
|
|
<Trans>encryption_https</Trans>
|
|
</label>
|
|
<Field
|
|
id="port_https"
|
|
name="port_https"
|
|
component={renderInputField}
|
|
type="number"
|
|
className="form-control"
|
|
placeholder={t('encryption_https')}
|
|
validate={[validatePort, validateIsSafePort]}
|
|
normalize={toNumber}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
/>
|
|
<div className="form__desc">
|
|
<Trans>encryption_https_desc</Trans>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="col-lg-6">
|
|
<div className="form__group form__group--settings">
|
|
<label className="form__label" htmlFor="port_dns_over_tls">
|
|
<Trans>encryption_dot</Trans>
|
|
</label>
|
|
<Field
|
|
id="port_dns_over_tls"
|
|
name="port_dns_over_tls"
|
|
component={renderInputField}
|
|
type="number"
|
|
className="form-control"
|
|
placeholder={t('encryption_dot')}
|
|
validate={[validatePortTLS]}
|
|
normalize={toNumber}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
/>
|
|
<div className="form__desc">
|
|
<Trans>encryption_dot_desc</Trans>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="col-lg-6">
|
|
<div className="form__group form__group--settings">
|
|
<label className="form__label" htmlFor="port_dns_over_quic">
|
|
<Trans>encryption_doq</Trans>
|
|
</label>
|
|
<Field
|
|
id="port_dns_over_quic"
|
|
name="port_dns_over_quic"
|
|
component={renderInputField}
|
|
type="number"
|
|
className="form-control"
|
|
placeholder={t('encryption_doq')}
|
|
validate={[validatePortQuic]}
|
|
normalize={toNumber}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
/>
|
|
<div className="form__desc">
|
|
<Trans>encryption_doq_desc</Trans>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="row">
|
|
<div className="col-12">
|
|
<div className="form__group form__group--settings">
|
|
<label
|
|
className="form__label form__label--with-desc form__label--bold"
|
|
htmlFor="certificate_chain"
|
|
>
|
|
<Trans>encryption_certificates</Trans>
|
|
</label>
|
|
<div className="form__desc form__desc--top">
|
|
<Trans
|
|
values={{ link: 'letsencrypt.org' }}
|
|
components={[
|
|
<a target="_blank" rel="noopener noreferrer" href="https://letsencrypt.org/" key="0">
|
|
link
|
|
</a>,
|
|
]}
|
|
>
|
|
encryption_certificates_desc
|
|
</Trans>
|
|
</div>
|
|
|
|
<div className="form__inline mb-2">
|
|
<div className="custom-controls-stacked">
|
|
<Field
|
|
name="certificate_source"
|
|
component={renderRadioField}
|
|
type="radio"
|
|
className="form-control mr-2"
|
|
value="path"
|
|
placeholder={t('encryption_certificates_source_path')}
|
|
disabled={!isEnabled}
|
|
/>
|
|
<Field
|
|
name="certificate_source"
|
|
component={renderRadioField}
|
|
type="radio"
|
|
className="form-control mr-2"
|
|
value="content"
|
|
placeholder={t('encryption_certificates_source_content')}
|
|
disabled={!isEnabled}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{certificateSource === ENCRYPTION_SOURCE.CONTENT && (
|
|
<Field
|
|
id="certificate_chain"
|
|
name="certificate_chain"
|
|
component="textarea"
|
|
type="text"
|
|
className="form-control form-control--textarea"
|
|
placeholder={t('encryption_certificates_input')}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
/>
|
|
)}
|
|
{certificateSource === ENCRYPTION_SOURCE.PATH && (
|
|
<Field
|
|
id="certificate_path"
|
|
name="certificate_path"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t('encryption_certificate_path')}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
/>
|
|
)}
|
|
</div>
|
|
<div className="form__status">
|
|
{(certificateChain || certificatePath) && (
|
|
<CertificateStatus
|
|
validChain={valid_chain}
|
|
validCert={valid_cert}
|
|
subject={subject}
|
|
issuer={issuer}
|
|
notAfter={not_after}
|
|
dnsNames={dns_names}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="row">
|
|
<div className="col-12">
|
|
<div className="form__group form__group--settings mt-3">
|
|
<label className="form__label form__label--bold" htmlFor="private_key">
|
|
<Trans>encryption_key</Trans>
|
|
</label>
|
|
|
|
<div className="form__inline mb-2">
|
|
<div className="custom-controls-stacked">
|
|
<Field
|
|
name="key_source"
|
|
component={renderRadioField}
|
|
type="radio"
|
|
className="form-control mr-2"
|
|
value={ENCRYPTION_SOURCE.PATH}
|
|
placeholder={t('encryption_key_source_path')}
|
|
disabled={!isEnabled}
|
|
/>
|
|
<Field
|
|
name="key_source"
|
|
component={renderRadioField}
|
|
type="radio"
|
|
className="form-control mr-2"
|
|
value={ENCRYPTION_SOURCE.CONTENT}
|
|
placeholder={t('encryption_key_source_content')}
|
|
disabled={!isEnabled}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{privateKeySource === ENCRYPTION_SOURCE.PATH && (
|
|
<Field
|
|
name="private_key_path"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t('encryption_private_key_path')}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
/>
|
|
)}
|
|
{privateKeySource === ENCRYPTION_SOURCE.CONTENT && [
|
|
<Field
|
|
key="private_key_saved"
|
|
name="private_key_saved"
|
|
type="checkbox"
|
|
className="form__group form__group--settings mb-2"
|
|
component={CheckboxField}
|
|
disabled={!isEnabled}
|
|
placeholder={t('use_saved_key')}
|
|
onChange={(event) => {
|
|
if (event.target.checked) {
|
|
change('private_key', '');
|
|
}
|
|
if (handleChange) {
|
|
handleChange(event);
|
|
}
|
|
}}
|
|
/>,
|
|
<Field
|
|
id="private_key"
|
|
key="private_key"
|
|
name="private_key"
|
|
component="textarea"
|
|
type="text"
|
|
className="form-control form-control--textarea"
|
|
placeholder={t('encryption_key_input')}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled || privateKeySaved}
|
|
/>,
|
|
]}
|
|
</div>
|
|
<div className="form__status">
|
|
{(privateKey || privateKeyPath) && (
|
|
<KeyStatus validKey={valid_key} keyType={key_type} />
|
|
)}
|
|
</div>
|
|
</div>
|
|
{validationMessage(warning_validation, isWarning)}
|
|
</div>
|
|
|
|
<div className="btn-list mt-2">
|
|
<button
|
|
type="submit"
|
|
disabled={isDisabled}
|
|
className="btn btn-success btn-standart"
|
|
>
|
|
<Trans>save_config</Trans>
|
|
</button>
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary btn-standart"
|
|
disabled={submitting || processingConfig}
|
|
onClick={() => clearFields(change, setTlsConfig, validateTlsConfig, t)}
|
|
>
|
|
<Trans>reset_settings</Trans>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
);
|
|
};
|
|
|
|
Form.propTypes = {
|
|
handleSubmit: PropTypes.func.isRequired,
|
|
handleChange: PropTypes.func,
|
|
isEnabled: PropTypes.bool.isRequired,
|
|
servePlainDns: PropTypes.bool.isRequired,
|
|
certificateChain: PropTypes.string.isRequired,
|
|
privateKey: PropTypes.string.isRequired,
|
|
certificatePath: PropTypes.string.isRequired,
|
|
privateKeyPath: PropTypes.string.isRequired,
|
|
change: PropTypes.func.isRequired,
|
|
submitting: PropTypes.bool.isRequired,
|
|
invalid: PropTypes.bool.isRequired,
|
|
initialValues: PropTypes.object.isRequired,
|
|
processingConfig: PropTypes.bool.isRequired,
|
|
processingValidate: PropTypes.bool.isRequired,
|
|
status_key: PropTypes.string,
|
|
not_after: PropTypes.string,
|
|
warning_validation: PropTypes.string,
|
|
valid_chain: PropTypes.bool,
|
|
valid_key: PropTypes.bool,
|
|
valid_cert: PropTypes.bool,
|
|
valid_pair: PropTypes.bool,
|
|
dns_names: PropTypes.arrayOf(PropTypes.string),
|
|
key_type: PropTypes.string,
|
|
issuer: PropTypes.string,
|
|
subject: PropTypes.string,
|
|
t: PropTypes.func.isRequired,
|
|
setTlsConfig: PropTypes.func.isRequired,
|
|
validateTlsConfig: PropTypes.func.isRequired,
|
|
certificateSource: PropTypes.string,
|
|
privateKeySource: PropTypes.string,
|
|
privateKeySaved: PropTypes.bool,
|
|
};
|
|
|
|
const selector = formValueSelector(FORM_NAME.ENCRYPTION);
|
|
|
|
Form = connect((state) => {
|
|
const isEnabled = selector(state, 'enabled');
|
|
const servePlainDns = selector(state, 'serve_plain_dns');
|
|
const certificateChain = selector(state, 'certificate_chain');
|
|
const privateKey = selector(state, 'private_key');
|
|
const certificatePath = selector(state, 'certificate_path');
|
|
const privateKeyPath = selector(state, 'private_key_path');
|
|
const certificateSource = selector(state, 'certificate_source');
|
|
const privateKeySource = selector(state, 'key_source');
|
|
const privateKeySaved = selector(state, 'private_key_saved');
|
|
return {
|
|
isEnabled,
|
|
servePlainDns,
|
|
certificateChain,
|
|
privateKey,
|
|
certificatePath,
|
|
privateKeyPath,
|
|
certificateSource,
|
|
privateKeySource,
|
|
privateKeySaved,
|
|
};
|
|
})(Form);
|
|
|
|
export default flow([
|
|
withTranslation(),
|
|
reduxForm({
|
|
form: FORM_NAME.ENCRYPTION,
|
|
validate,
|
|
}),
|
|
])(Form);
|