Close #1597 Squashed commit of the following: commit 1eb89586dd71260e561420fe669abc8b56a506a1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed May 20 14:54:10 2020 +0300 Fix translation in install options commit 1ebdc9ebfe12a609f978e47db6505c7095b10f7e Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed May 20 13:11:34 2020 +0300 Remove commented code commit 2a8302c65a2a3cf7b6b1596115d1153dac32a794 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 19:02:49 2020 +0300 Update i18n packages, add development browserlist, downgrade eslint to match peerDepencancies version commit 3fcf73fb14cd9da508522d1a300b66af24da95e5 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 17:30:37 2020 +0300 Remove all unused dependencies commit e761810e3e54e188ada41245bdce7414cd0f03e8 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 16:35:24 2020 +0300 Remove unused dependencies commit d89d27da6befcaabcdc12bf5e7e94cbb24140010 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 16:14:09 2020 +0300 Update regular dependencies commit d2dfd01233d059870d5173ffd748cf61a477936f Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 15:34:10 2020 +0300 Update all dev dependancies commit 02b6fb480e9d310039fbe9b7aae062a41128f070 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 14:14:44 2020 +0300 Update all postcss packages commit 5e1fa5f99ad75f77e5e429b28ee1ca0b5e65a9a0 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 12:45:02 2020 +0300 Prevent git from converting linebreaks in .js files commit 0b9b3b0dccd47cfa50c9531fb61729e6b5a04523 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 12:43:01 2020 +0300 Prevent git from converting linebreaks in .js files commit 18b7495e9ef7130b1ac4dbba84c54127d16c6350 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue May 19 12:24:47 2020 +0300 Remove linebreak-style eslint rule commit df893dec53adebb1d662fe805fab508fd4ed5e06 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon May 18 20:55:47 2020 +0300 Add prop types commit 36178ecfc5c7fa11a6ee08d7705ca8560941af40 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon May 18 18:52:07 2020 +0300 Update eslint and babel, fix eslint warnings commit f045b4a2e6b9b78f7e88e3b5d1419c29966a8230 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon May 18 16:45:49 2020 +0300 Update css loading webpack rules commit 247fa1ed548ef0706a03fdada8309c1454d191f8 Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 16:13:49 2020 +0300 Suppress linebreak-style eslint error for Windows commit d6499aac507100d6918c849c06d739d80f2229f0 Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 14:55:07 2020 +0300 Suppress eslint exit code commit ae2d6c614ea23a90d515168f8752e959298894ef Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 14:05:18 2020 +0300 Edit css file warnings commit 60675050f2a5baebc679fc05da7e033e5c740d90 Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 13:10:26 2020 +0300 Remove uglifyjs plugin commit a27806434dd8672e71a26c7a2e810d77e5e229fa Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 01:29:17 2020 +0300 Fix DefinePlugin value commit 8f2966ca59195c2f70bca5072d20515d536f42a6 Author: ArtemBaskal <a.baskal@adguard.com> Date: Sat May 16 01:05:03 2020 +0300 Update webpack
425 lines
16 KiB
JavaScript
425 lines
16 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,
|
|
renderSelectField,
|
|
renderRadioField,
|
|
toNumber,
|
|
port,
|
|
portTLS,
|
|
isSafePort,
|
|
} from '../../../helpers/form';
|
|
import i18n from '../../../i18n';
|
|
import KeyStatus from './KeyStatus';
|
|
import CertificateStatus from './CertificateStatus';
|
|
|
|
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: 443,
|
|
port_dns_over_tls: 853,
|
|
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={renderSelectField}
|
|
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}
|
|
/>
|
|
<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={renderSelectField}
|
|
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={[port, isSafePort]}
|
|
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={[portTLS]}
|
|
normalize={toNumber}
|
|
onChange={handleChange}
|
|
disabled={!isEnabled}
|
|
/>
|
|
<div className="form__desc">
|
|
<Trans>encryption_dot_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 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.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('encryptionForm');
|
|
|
|
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: 'encryptionForm',
|
|
validate,
|
|
}),
|
|
])(Form);
|