Merge in DNS/adguard-home from 1383-client-id to master Updates #1383. Squashed commit of the following: commit ebe2678bfa9bf651a2cb1e64499b38edcf19a7ad Author: Ildar Kamalov <ik@adguard.com> Date: Wed Jan 27 17:51:59 2021 +0300 - client: check if IP is valid commit 0c330585a170ea149ee75e43dfa65211e057299c Author: Ildar Kamalov <ik@adguard.com> Date: Wed Jan 27 17:07:50 2021 +0300 - client: find clients by client_id commit 71c9593ee35d996846f061e114b7867c3aa3c978 Merge: 9104f1613e9edd9eAuthor: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Jan 27 16:09:45 2021 +0300 Merge branch 'master' into 1383-client-id commit 9104f1615d2d462606c52017df25a422df872cea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Jan 27 13:28:50 2021 +0300 dnsforward: imp tests commit ed47f26e611ade625a2cc2c2f71a291b796bbf8f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Jan 27 12:39:52 2021 +0300 dnsforward: fix address commit 98b222ba69a5d265f620c180c960d01c84a1fb3b Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Jan 26 19:50:31 2021 +0300 home: imp code commit 4f3966548a2d8437d0b68207dd108dd1a6cb7d20 Merge: 199fdc05c215b820Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Jan 26 19:45:13 2021 +0300 Merge branch 'master' into 1383-client-id commit 199fdc056f8a8be5500584f3aaee32865188aedc Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Jan 26 19:20:37 2021 +0300 all: imp tests, logging, etc commit 35ff14f4d534251aecb2ea60baba225f3eed8a3e Author: Ildar Kamalov <ik@adguard.com> Date: Tue Jan 26 18:55:19 2021 +0300 + client: remove block button from clients with client_id commit 32991a0b4c56583a02fb5e00bba95d96000bce20 Author: Ildar Kamalov <ik@adguard.com> Date: Tue Jan 26 18:54:25 2021 +0300 + client: add requests count for client_id commit 2d68df4d2eac4a296d7469923e601dad4575c1a1 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Jan 26 15:49:50 2021 +0300 stats: handle client ids commit 4e14ab3590328f93a8cd6e9cbe1665baf74f220b Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Jan 26 13:45:25 2021 +0300 openapi: fix example commit ca9cf3f744fe197cace2c28ddc5bc68f71dad1f3 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Jan 26 13:37:10 2021 +0300 openapi: improve clients find api docs commit f79876e550c424558b704bc316a4cd04f25db011 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Jan 26 13:18:52 2021 +0300 home: accept ids in clients find commit 5b72595122aa0bd64debadfd753ed8a0e0840629 Merge: 607e241fabf8f65fAuthor: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Jan 25 18:34:56 2021 +0300 Merge branch 'master' into 1383-client-id commit 607e241f1c339dd6397218f70b8301e3de6a1ee0 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Jan 25 18:30:39 2021 +0300 dnsforward: fix quic commit f046352fef93e46234c2bbe8ae316d21034260e5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Jan 25 16:53:09 2021 +0300 all: remove wildcard requirement commit 3b679489bae82c54177372be453fe184d8f0bab6 Author: Andrey Meshkov <am@adguard.com> Date: Mon Jan 25 16:02:28 2021 +0300 workDir now supports symlinks commit 0647ab4f113de2223f6949df001f42ecab05c995 Author: Ildar Kamalov <ik@adguard.com> Date: Mon Jan 25 14:59:46 2021 +0300 - client: remove wildcard from domain validation commit b1aec04a4ecadc9d65648ed6d284188fecce01c3 Author: Ildar Kamalov <ik@adguard.com> Date: Mon Jan 25 14:55:39 2021 +0300 + client: add form to download mobileconfig ... and 12 more commits
455 lines
18 KiB
JavaScript
455 lines
18 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,
|
|
} 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,
|
|
} 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, 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,
|
|
};
|
|
// eslint-disable-next-line no-alert
|
|
if (window.confirm(t('encryption_reset'))) {
|
|
Object.keys(fields)
|
|
.forEach((field) => change(field, fields[field]));
|
|
setTlsConfig(fields);
|
|
}
|
|
};
|
|
|
|
let Form = (props) => {
|
|
const {
|
|
t,
|
|
handleSubmit,
|
|
handleChange,
|
|
isEnabled,
|
|
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,
|
|
certificateSource,
|
|
privateKeySource,
|
|
} = props;
|
|
|
|
const isSavingDisabled = invalid
|
|
|| submitting
|
|
|| processingConfig
|
|
|| processingValidate
|
|
|| !valid_key
|
|
|| !valid_cert
|
|
|| !valid_pair;
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit}>
|
|
<div className="row">
|
|
<div className="col-12">
|
|
<div className="form__group form__group--settings">
|
|
<Field
|
|
name="enabled"
|
|
type="checkbox"
|
|
component={CheckboxField}
|
|
placeholder={t('encryption_enable')}
|
|
onChange={handleChange}
|
|
/>
|
|
</div>
|
|
<div className="form__desc">
|
|
<Trans>encryption_enable_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>
|
|
|
|
<span className="text-lowercase">(<Trans>experimental</Trans>)</span>
|
|
</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 === '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 === '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="path"
|
|
placeholder={t('encryption_key_source_path')}
|
|
disabled={!isEnabled}
|
|
/>
|
|
<Field
|
|
name="key_source"
|
|
component={renderRadioField}
|
|
type="radio"
|
|
className="form-control mr-2"
|
|
value="content"
|
|
placeholder={t('encryption_key_source_content')}
|
|
disabled={!isEnabled}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{privateKeySource === 'content' && (
|
|
<Field
|
|
id="private_key"
|
|
name="private_key"
|
|
component="textarea"
|
|
type="text"
|
|
className="form-control form-control--textarea"
|
|
placeholder={t('encryption_key_input')}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
/>
|
|
)}
|
|
{privateKeySource === 'path' && (
|
|
<Field
|
|
id="private_key_path"
|
|
name="private_key_path"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t('encryption_private_key_path')}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
/>
|
|
)}
|
|
</div>
|
|
<div className="form__status">
|
|
{(privateKey || privateKeyPath) && (
|
|
<KeyStatus validKey={valid_key} keyType={key_type} />
|
|
)}
|
|
</div>
|
|
</div>
|
|
{warning_validation && (
|
|
<div className="col-12">
|
|
<p className="text-danger">{warning_validation}</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="btn-list mt-2">
|
|
<button
|
|
type="submit"
|
|
className="btn btn-success btn-standart"
|
|
disabled={isSavingDisabled}
|
|
>
|
|
<Trans>save_config</Trans>
|
|
</button>
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary btn-standart"
|
|
disabled={submitting || processingConfig}
|
|
onClick={() => clearFields(change, setTlsConfig, t)}
|
|
>
|
|
<Trans>reset_settings</Trans>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
);
|
|
};
|
|
|
|
Form.propTypes = {
|
|
handleSubmit: PropTypes.func.isRequired,
|
|
handleChange: PropTypes.func,
|
|
isEnabled: 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,
|
|
certificateSource: PropTypes.string,
|
|
privateKeySource: PropTypes.string,
|
|
};
|
|
|
|
const selector = formValueSelector(FORM_NAME.ENCRYPTION);
|
|
|
|
Form = connect((state) => {
|
|
const isEnabled = selector(state, 'enabled');
|
|
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');
|
|
return {
|
|
isEnabled,
|
|
certificateChain,
|
|
privateKey,
|
|
certificatePath,
|
|
privateKeyPath,
|
|
certificateSource,
|
|
privateKeySource,
|
|
};
|
|
})(Form);
|
|
|
|
export default flow([
|
|
withTranslation(),
|
|
reduxForm({
|
|
form: FORM_NAME.ENCRYPTION,
|
|
validate,
|
|
}),
|
|
])(Form);
|