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

View File

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

View File

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

View File

@ -140,3 +140,15 @@ export const getWebAddress = (ip, port = '') => {
return address; 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: '', key_type: '',
not_after: '', not_after: '',
not_before: '', not_before: '',
port_dns_over_tls: 853, port_dns_over_tls: '',
port_https: 443, port_https: '',
subject: '', subject: '',
valid_chain: false, valid_chain: false,
valid_key: false, valid_key: false,
valid_cert: false,
status_cert: '', status_cert: '',
status_key: '', status_key: '',
certificate_chain: '', certificate_chain: '',