Merge pull request #187 in DNS/adguard-dns from fix/655 to master

* commit '0c973334be33c77e509676d65394d99ead4b26e2':
  * client: if 0.0.0.0 is selected, then redirect to the current IP
This commit is contained in:
Ildar Kamalov 2019-03-29 17:38:02 +03:00
commit d6b83d4a63
6 changed files with 40 additions and 14 deletions

View File

@ -155,3 +155,5 @@ export const UNSAFE_PORTS = [
6668, 6668,
6669, 6669,
]; ];
export const ALL_INTERFACES_IP = '0.0.0.0';

View File

@ -2,12 +2,13 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { getIpList, getDnsAddress, getWebAddress } from '../../helpers/helpers'; import { getIpList, getDnsAddress, getWebAddress } from '../../helpers/helpers';
import { ALL_INTERFACES_IP } from '../../helpers/constants';
const AddressList = (props) => { const AddressList = (props) => {
let webAddress = getWebAddress(props.address, props.port); let webAddress = getWebAddress(props.address, props.port);
let dnsAddress = getDnsAddress(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) => { return getIpList(props.interfaces).map((ip) => {
webAddress = getWebAddress(ip, props.port); webAddress = getWebAddress(ip, props.port);
dnsAddress = getDnsAddress(ip, props.port); dnsAddress = getDnsAddress(ip, props.port);

View File

@ -25,13 +25,22 @@ class Controls extends Component {
} }
renderNextButton(step) { renderNextButton(step) {
const {
nextStep,
invalid,
pristine,
install,
ip,
port,
} = this.props;
switch (step) { switch (step) {
case 1: case 1:
return ( return (
<button <button
type="button" type="button"
className="btn btn-success btn-lg setup__button" className="btn btn-success btn-lg setup__button"
onClick={this.props.nextStep} onClick={nextStep}
> >
<Trans>get_started</Trans> <Trans>get_started</Trans>
</button> </button>
@ -43,9 +52,9 @@ class Controls extends Component {
type="submit" type="submit"
className="btn btn-success btn-lg setup__button" className="btn btn-success btn-lg setup__button"
disabled={ disabled={
this.props.invalid invalid
|| this.props.pristine || pristine
|| this.props.install.processingSubmit || install.processingSubmit
} }
> >
<Trans>next</Trans> <Trans>next</Trans>
@ -56,7 +65,7 @@ class Controls extends Component {
<button <button
type="button" type="button"
className="btn btn-success btn-lg setup__button" className="btn btn-success btn-lg setup__button"
onClick={this.props.nextStep} onClick={nextStep}
> >
<Trans>next</Trans> <Trans>next</Trans>
</button> </button>
@ -66,7 +75,8 @@ class Controls extends Component {
<button <button
type="button" type="button"
className="btn btn-success btn-lg setup__button" className="btn btn-success btn-lg setup__button"
onClick={() => this.props.openDashboard(this.props.address)} onClick={() =>
this.props.openDashboard(ip, port)}
> >
<Trans>open_dashboard</Trans> <Trans>open_dashboard</Trans>
</button> </button>
@ -98,7 +108,8 @@ Controls.propTypes = {
submitting: PropTypes.bool, submitting: PropTypes.bool,
invalid: PropTypes.bool, invalid: PropTypes.bool,
pristine: PropTypes.bool, pristine: PropTypes.bool,
address: PropTypes.string, ip: PropTypes.string,
port: PropTypes.number,
}; };
const mapStateToProps = (state) => { const mapStateToProps = (state) => {

View File

@ -9,6 +9,7 @@ import Controls from './Controls';
import AddressList from './AddressList'; import AddressList from './AddressList';
import renderField from './renderField'; import renderField from './renderField';
import { getInterfaceIp } from '../../helpers/helpers'; import { getInterfaceIp } from '../../helpers/helpers';
import { ALL_INTERFACES_IP } from '../../helpers/constants';
const required = (value) => { const required = (value) => {
if (value || value === 0) { if (value || value === 0) {
@ -75,7 +76,7 @@ let Settings = (props) => {
component="select" component="select"
className="form-control custom-select" className="form-control custom-select"
> >
<option value="0.0.0.0"> <option value={ALL_INTERFACES_IP}>
<Trans>install_settings_all_interfaces</Trans> <Trans>install_settings_all_interfaces</Trans>
</option> </option>
{renderInterfaces(interfaces)} {renderInterfaces(interfaces)}
@ -130,7 +131,7 @@ let Settings = (props) => {
component="select" component="select"
className="form-control custom-select" className="form-control custom-select"
> >
<option value="0.0.0.0"> <option value={ALL_INTERFACES_IP}>
<Trans>install_settings_all_interfaces</Trans> <Trans>install_settings_all_interfaces</Trans>
</option> </option>
{renderInterfaces(interfaces)} {renderInterfaces(interfaces)}

View File

@ -6,7 +6,6 @@ import { Trans, withNamespaces } from 'react-i18next';
import flow from 'lodash/flow'; import flow from 'lodash/flow';
import Controls from './Controls'; import Controls from './Controls';
import { getWebAddress } from '../../helpers/helpers';
let Submit = props => ( let Submit = props => (
<div className="setup__step"> <div className="setup__step">
@ -20,7 +19,8 @@ let Submit = props => (
</div> </div>
<Controls <Controls
openDashboard={props.openDashboard} openDashboard={props.openDashboard}
address={getWebAddress(props.webIp, props.webPort)} ip={props.webIp}
port={props.webPort}
/> />
</div> </div>
); );

View File

@ -3,7 +3,12 @@ import { connect } from 'react-redux';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import * as actionCreators from '../../actions/install'; 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 Loading from '../../components/ui/Loading';
import Greeting from './Greeting'; import Greeting from './Greeting';
@ -29,7 +34,13 @@ class Setup extends Component {
this.props.setAllSettings(values); 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); window.location.replace(address);
} }