Added https redirect

This commit is contained in:
Ildar Kamalov 2019-02-19 15:43:36 +03:00
parent 3c374b5940
commit cca6998efe
5 changed files with 30 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import { createAction } from 'redux-actions';
import Api from '../api/Api';
import { addErrorToast, addSuccessToast } from './index';
import { redirectToCurrentProtocol } from '../helpers/helpers';
const apiClient = new Api();
@ -40,6 +41,7 @@ export const setTlsConfig = config => async (dispatch) => {
response.private_key = atob(response.private_key);
dispatch(setTlsConfigSuccess(response));
dispatch(addSuccessToast('encryption_config_saved'));
redirectToCurrentProtocol(response);
} catch (error) {
dispatch(addErrorToast({ error }));
dispatch(setTlsConfigFailure());

View File

@ -48,9 +48,11 @@ let Form = (props) => {
invalid,
submitting,
processing,
processingValidate,
not_after,
valid_chain,
valid_key,
valid_cert,
dns_names,
key_type,
issuer,
@ -260,7 +262,11 @@ let Form = (props) => {
</div>
<div className="col-12">
<p className="text-danger">
{warning_validation && warning_validation}
{
(certificateChain || privateKey)
&& warning_validation
&& warning_validation
}
</p>
</div>
</div>
@ -273,7 +279,9 @@ let Form = (props) => {
invalid
|| submitting
|| processing
|| !valid_key
|| processingValidate
|| (privateKey && !valid_key)
|| (certificateChain && !valid_cert)
}
>
<Trans>save_config</Trans>
@ -302,11 +310,13 @@ Form.propTypes = {
invalid: PropTypes.bool.isRequired,
initialValues: PropTypes.object.isRequired,
processing: 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,
dns_names: PropTypes.string,
key_type: PropTypes.string,
issuer: PropTypes.string,

View File

@ -46,6 +46,7 @@ class Encryption extends Component {
private_key,
}}
processing={encryption.processingConfig}
processingValidate={encryption.processingValidate}
onSubmit={this.handleFormSubmit}
onChange={this.handleFormChange}
{...this.props.encryption}

View File

@ -140,3 +140,15 @@ export const getWebAddress = (ip, port = '') => {
return address;
};
export const redirectToCurrentProtocol = (values) => {
const { protocol, hostname, hash } = window.location;
const { enabled, port_https } = values;
if (protocol !== 'https:' && enabled && port_https) {
const port = port_https !== 443 ? `:${port_https}` : '';
window.location.replace(`https://${hostname}${port}/${hash}`);
} else if (protocol === 'https:' && (!enabled || !port_https)) {
window.location.replace(`http://${hostname}/${hash}`);
}
};

View File

@ -46,11 +46,12 @@ const encryption = handleActions({
key_type: '',
not_after: '',
not_before: '',
port_dns_over_tls: 853,
port_https: 443,
port_dns_over_tls: '',
port_https: '',
subject: '',
valid_chain: false,
valid_key: false,
valid_cert: false,
status_cert: '',
status_key: '',
certificate_chain: '',