From 0c973334be33c77e509676d65394d99ead4b26e2 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Fri, 29 Mar 2019 16:24:59 +0300 Subject: [PATCH] * client: if 0.0.0.0 is selected, then redirect to the current IP Closes #655 --- client/src/helpers/constants.js | 2 ++ client/src/install/Setup/AddressList.js | 3 ++- client/src/install/Setup/Controls.js | 25 ++++++++++++++++++------- client/src/install/Setup/Settings.js | 5 +++-- client/src/install/Setup/Submit.js | 4 ++-- client/src/install/Setup/index.js | 15 +++++++++++++-- 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/client/src/helpers/constants.js b/client/src/helpers/constants.js index 7d1553f6..79deabdb 100644 --- a/client/src/helpers/constants.js +++ b/client/src/helpers/constants.js @@ -155,3 +155,5 @@ export const UNSAFE_PORTS = [ 6668, 6669, ]; + +export const ALL_INTERFACES_IP = '0.0.0.0'; diff --git a/client/src/install/Setup/AddressList.js b/client/src/install/Setup/AddressList.js index 425d6504..aeeed246 100644 --- a/client/src/install/Setup/AddressList.js +++ b/client/src/install/Setup/AddressList.js @@ -2,12 +2,13 @@ import React from 'react'; import PropTypes from 'prop-types'; import { getIpList, getDnsAddress, getWebAddress } from '../../helpers/helpers'; +import { ALL_INTERFACES_IP } from '../../helpers/constants'; const AddressList = (props) => { let webAddress = getWebAddress(props.address, props.port); let dnsAddress = getDnsAddress(props.address, props.port); - if (props.address === '0.0.0.0') { + if (props.address === ALL_INTERFACES_IP) { return getIpList(props.interfaces).map((ip) => { webAddress = getWebAddress(ip, props.port); dnsAddress = getDnsAddress(ip, props.port); diff --git a/client/src/install/Setup/Controls.js b/client/src/install/Setup/Controls.js index aa5a2a42..5560c511 100644 --- a/client/src/install/Setup/Controls.js +++ b/client/src/install/Setup/Controls.js @@ -25,13 +25,22 @@ class Controls extends Component { } renderNextButton(step) { + const { + nextStep, + invalid, + pristine, + install, + ip, + port, + } = this.props; + switch (step) { case 1: return ( @@ -43,9 +52,9 @@ class Controls extends Component { type="submit" className="btn btn-success btn-lg setup__button" disabled={ - this.props.invalid - || this.props.pristine - || this.props.install.processingSubmit + invalid + || pristine + || install.processingSubmit } > next @@ -56,7 +65,7 @@ class Controls extends Component { @@ -66,7 +75,8 @@ class Controls extends Component { @@ -98,7 +108,8 @@ Controls.propTypes = { submitting: PropTypes.bool, invalid: PropTypes.bool, pristine: PropTypes.bool, - address: PropTypes.string, + ip: PropTypes.string, + port: PropTypes.number, }; const mapStateToProps = (state) => { diff --git a/client/src/install/Setup/Settings.js b/client/src/install/Setup/Settings.js index cc127117..25fd2d76 100644 --- a/client/src/install/Setup/Settings.js +++ b/client/src/install/Setup/Settings.js @@ -9,6 +9,7 @@ import Controls from './Controls'; import AddressList from './AddressList'; import renderField from './renderField'; import { getInterfaceIp } from '../../helpers/helpers'; +import { ALL_INTERFACES_IP } from '../../helpers/constants'; const required = (value) => { if (value || value === 0) { @@ -75,7 +76,7 @@ let Settings = (props) => { component="select" className="form-control custom-select" > - {renderInterfaces(interfaces)} @@ -130,7 +131,7 @@ let Settings = (props) => { component="select" className="form-control custom-select" > - {renderInterfaces(interfaces)} diff --git a/client/src/install/Setup/Submit.js b/client/src/install/Setup/Submit.js index 8456909a..27e80bbf 100644 --- a/client/src/install/Setup/Submit.js +++ b/client/src/install/Setup/Submit.js @@ -6,7 +6,6 @@ import { Trans, withNamespaces } from 'react-i18next'; import flow from 'lodash/flow'; import Controls from './Controls'; -import { getWebAddress } from '../../helpers/helpers'; let Submit = props => (
@@ -20,7 +19,8 @@ let Submit = props => (
); diff --git a/client/src/install/Setup/index.js b/client/src/install/Setup/index.js index b1501536..ed901e46 100644 --- a/client/src/install/Setup/index.js +++ b/client/src/install/Setup/index.js @@ -3,7 +3,12 @@ import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import * as actionCreators from '../../actions/install'; -import { INSTALL_FIRST_STEP, INSTALL_TOTAL_STEPS } from '../../helpers/constants'; +import { getWebAddress } from '../../helpers/helpers'; +import { + INSTALL_FIRST_STEP, + INSTALL_TOTAL_STEPS, + ALL_INTERFACES_IP, +} from '../../helpers/constants'; import Loading from '../../components/ui/Loading'; import Greeting from './Greeting'; @@ -29,7 +34,13 @@ class Setup extends Component { this.props.setAllSettings(values); }; - openDashboard = (address) => { + openDashboard = (ip, port) => { + let address = getWebAddress(ip, port); + + if (ip === ALL_INTERFACES_IP) { + address = getWebAddress(window.location.hostname, port); + } + window.location.replace(address); }