1
0

Finished templates, database config, and started converting options to synapse yaml.

This commit is contained in:
Jorik Schellekens
2019-08-07 16:32:35 +01:00
parent 3ae448a183
commit a8cc43dfac
28 changed files with 341 additions and 104 deletions

View File

@@ -16,4 +16,9 @@ export const TLS_TYPES = {
ACME: "ACME",
TLS: "TLS",
REVERSE_PROXY: "REVERSE_PROXY",
}
export const DATABASE_TYPES = {
SQLITE3: "SQLITE3",
POSTGRES: "POSTGRES",
}

View File

@@ -20,6 +20,7 @@ import {
TESTING_SYNAPSE_PORTS,
SET_SYNAPSE_PORTS,
SET_SYNAPSE_PORTS_FREE,
SET_DATABASE,
} from './types';
import {
@@ -219,4 +220,9 @@ export const update_ports_free = (synapse_federation_port_free, synapse_client_p
export const testing_synapse_ports = verifying => ({
type: TESTING_SYNAPSE_PORTS,
verifying,
})
export const set_database = database => ({
type: SET_DATABASE,
database,
})

View File

@@ -18,4 +18,5 @@ export const SET_TLS_CERT_PATHS_VALIDITY = 'SET_TLS_CERT_PATHS_VALIDITY';
export const SET_TLS_CERT_FILES = 'SET_TLS_CERT_FILES';
export const TESTING_SYNAPSE_PORTS = 'TESTING_SYNAPSE_PORTS';
export const SET_SYNAPSE_PORTS = 'SET_SYNAPSE_PORTS';
export const SET_SYNAPSE_PORTS_FREE = 'SET_SYNAPSE_PORTS_IN_USE';
export const SET_SYNAPSE_PORTS_FREE = 'SET_SYNAPSE_PORTS_IN_USE';
export const SET_DATABASE = 'SET_DATABASE';

View File

@@ -0,0 +1,28 @@
import React, { useState } from 'react';
import ContentWrapper from '../containers/ContentWrapper';
import {
DATABASE_TYPES
} from '../actions/constants'
import ButtonDisplay from './ButtonDisplay';
export default ({
onClick,
}) => {
const defaultDatabase = DATABASE_TYPES.POSTGRES;
const [database, setDatabase] = useState(defaultDatabase)
return <ContentWrapper>
<h1>Database</h1>
<p>Synapse can use either SQLite3 or Postgres as it's databse.</p>
<p>If you don't have one of those two installed Postgres is the recommended database to use.</p>
<select defaultValue={defaultDatabase} onChange={event => setDatabase(event.target.value)}>
<option value={DATABASE_TYPES.POSTGRES}>PostgreSQL</option>
<option value={DATABASE_TYPES.SQLITE3}>SQLite3</option>
</select>
<ButtonDisplay>
<button onClick={() => onClick(database)}>Continue</button>
</ButtonDisplay>
</ContentWrapper>
}

View File

@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import ContentWrapper from './ContentWrapper';
import ContentWrapper from '../containers/ContentWrapper';
import style from '../../less/main.less';

View File

@@ -3,24 +3,64 @@ import React from 'react';
import ContentWrapper from '../containers/ContentWrapper';
import ButtonDisplay from './ButtonDisplay';
import DownloadOrCopy from './DownloadOrCopy';
import { REVERSE_PROXY_TYPES, DELEGATION_TYPES } from '../actions/constants';
import { DELEGATION_TYPES } from '../actions/constants';
export default (delegationType, serverConfig, clientConfig, fileName, serverName, onClick) => {
const delegationExplanation = delegationType == DELEGATION_TYPES.DNS ?
"You will need to add the following SRV record to your DNS zone." :
`You'll need to host the following at https://${serverName}/.well-known/matrix/server`
return <ContentWrapper>
<h1>Configure delegation</h1>
<p>
The delegation configuration needs to take place outside the installer.
</p>
{delegationExplanation}
<code>
{sampleConfig}
</code>
<DownloadOrCopy content={sampleConfig} fileName={fileName} />
<ButtonDisplay>
<button onClick={onClick}>Continue</button>
</ButtonDisplay>
</ContentWrapper>;
export default ({
delegationType,
serverConfig,
clientConfig,
serverConfigFileName,
clientConfigFileName,
serverName,
onClick
}) => {
if (delegationType == DELEGATION_TYPES.DNS) {
return <ContentWrapper>
<h1>ConfigureDelegation</h1>
<p>
You will need to add the following SRV record to your DNS zone.
</p>
<pre>
<code>
{clientConfig}
</code>
</pre>
<DownloadOrCopy content={clientConfig} fileName={clientConfigFileName} />
<ButtonDisplay>
<button onClick={onClick}>Continue</button>
</ButtonDisplay>
</ContentWrapper>
} else {
return <ContentWrapper>
<h1>Configure delegation</h1>
<p>
The delegation configuration needs to take place outside the installer.
</p>
<p>
You'll need to host the following at https://{serverName}/.well-known/matrix/server
</p>
<pre>
<code>
{serverConfig}
</code>
</pre>
<DownloadOrCopy content={serverConfig} fileName={serverConfigFileName} />
<p>
You'll also need to host the following at https://{serverName}/.well-known/matrix/client
</p>
<pre>
<code>
{clientConfig}
</code>
</pre>
<DownloadOrCopy content={clientConfig} fileName={clientConfigFileName} />
<ButtonDisplay>
<button onClick={onClick}>Continue</button>
</ButtonDisplay>
</ContentWrapper>;
}
}

View File

@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import ContentWrapper from './ContentWrapper';
import ContentWrapper from '../containers/ContentWrapper';
export default ({ onClick }) => {
const [servername, setServerName] = useState("");

View File

@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import ContentWrapper from './ContentWrapper';
import ContentWrapper from '../containers/ContentWrapper';
import style from '../../less/main.less';

View File

@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import ContentWrapper from './ContentWrapper';
import ContentWrapper from '../containers/ContentWrapper';
import {
REVERSE_PROXY_TYPES

View File

@@ -5,7 +5,10 @@ import ButtonDisplay from './ButtonDisplay';
import DownloadOrCopy from './DownloadOrCopy';
import { REVERSE_PROXY_TYPES } from '../actions/constants';
export default (proxyType, sampleConfig, fileName, onClick) => {
export default ({ proxyType, sampleConfig, fileName, onClick }) => {
console.log("SFSFD")
console.log(sampleConfig)
console.log("SFSFD")
return <ContentWrapper>
<h1>Configure the ReverseProxy</h1>
<p>
@@ -23,9 +26,11 @@ export default (proxyType, sampleConfig, fileName, onClick) => {
but here's the sample configuration for your {proxyType} proxy.
</p>
}
<code>
{sampleConfig}
</code>
<pre>
<code>
{sampleConfig}
</code>
</pre>
<DownloadOrCopy content={sampleConfig} fileName={fileName} />
<ButtonDisplay>
<button onClick={onClick}>Continue</button>

View File

@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import ContentWrapper from './ContentWrapper';
import ContentWrapper from '../containers/ContentWrapper';
export default ({ onClick }) => {
const [servername, setServerName] = useState("");

View File

@@ -20,6 +20,8 @@ import {
DELEGATION_SERVER_NAME_UI,
TLS_CERTPATH_UI,
DELEGATION_PORT_SELECTION_UI,
DELEGATION_TEMPLATE_UI,
DATABASE_UI,
} from '../reducers/ui_constants';
import Error from '../components/Error';
@@ -36,6 +38,9 @@ import TLS from '../containers/TLS';
import TLSCertPath from '../containers/TLSCertPath';
import DelegationPortSelection from '../containers/DelegationPortSelection';
import PortSelection from '../containers/PortSelection';
import ReverseProxySampleConfig from '../containers/ReverseProxySampleConfig';
import DelegationSampleConfig from '../containers/DelegationSampleConfig';
import Database from '../containers/Database';
export default ({ active_ui, dispatch }) => {
console.log(`switching to ui ${active_ui}`)
@@ -66,9 +71,12 @@ export default ({ active_ui, dispatch }) => {
return <TLSCertPath />
case PORT_SELECTION_UI:
return <PortSelection />
case WELL_KNOWN_UI:
case DNS_UI:
case REVERSE_PROXY_TEMPLATE_UI:
return <ReverseProxySampleConfig />
case DELEGATION_TEMPLATE_UI:
return <DelegationSampleConfig />
case DATABASE_UI:
return <Database />
default:
return <h1>how did i get here?</h1>
}

View File

@@ -2,14 +2,10 @@ import { connect } from 'react-redux';
import ContentWrapper from '../components/ContentWrapper';
const mapStateToProps = (state, { children }) => {
const servername = state.base_config.servername;
console.log(state)
return {
servername,
children,
}
}
const mapStateToProps = (state, { children }) => ({
servername: state.base_config.servername,
children,
})
const mapDispatchToProps = (dispatch) => ({

View File

@@ -0,0 +1,20 @@
import { connect } from 'react-redux';
import Database from '../components/Database';
import { set_database, advance_ui } from '../actions';
const mapStateToProps = (state) => {
}
const mapDispatchToProps = (dispatch) => ({
onClick: database => {
dispatch(set_database(database));
dispatch(advance_ui());
}
});
export default connect(
null,
mapDispatchToProps,
)(Database);

View File

@@ -0,0 +1,56 @@
import { connect } from 'react-redux';
import DelegationSampleConfig from '../components/DelegationSampleConfig';
import { advance_ui } from '../actions';
import DNSConfig from '../templates/dns-srv';
import FedWellKnownConfig from '../templates/federation-well-known'
import ClientWellKnownConfig from '../templates/client-well-known'
import { DELEGATION_TYPES } from '../actions/constants';
// synapseServerName: state.base_config.delegation_server_name ? state.base_config.delegation_server_name : state.base_config.servername,
const serverConfig = state => {
if (state.delegation_type == DELEGATION_TYPES.DNS) {
return undefined;
} else {
return FedWellKnownConfig({
synapseServerName: state.delegation_servername,
delegationSynapsePort: state.delegation_federation_port ? state.delegation_federation_port : 8448,
});
}
}
const clientConfig = state => {
if (state.delegation_type == DELEGATION_TYPES.WELL_KNOWN) {
return ClientWellKnownConfig({
synapseServerName: state.delegation_servername,
delegationClientPort: state.delegation_client_port ? state.delegation_client_port : 443,
});
} else {
return DNSConfig({
serverName: state.servername,
synapseServerName: state.delegation_servername,
delegationClientPort: state.delegation_client_port ? state.delegation_client_port : 443,
})
}
}
const mapStateToProps = state => ({
delegationType: state.base_config.delegation_type,
serverConfig: serverConfig(state.base_config),
clientConfig: clientConfig(state.base_config),
serverConfigFileName: `${state.base_config.servername}_delegation.conf`,
clientConfigFileName: `${state.base_config.servername}_client_delegation.conf`,
serverName: state.base_config.servername,
});
const mapDispatchToProps = dispatch => ({
onClick: () => dispatch(advance_ui()),
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(DelegationSampleConfig);

View File

@@ -2,8 +2,9 @@ import { combineReducers } from 'redux';
import ui from './reducer-ui';
import base_config from './reducer-base-config';
import { get_server_setup } from '../api';
import { LOADING_UI } from './ui_constants';
export default combineReducers({
ui,
base_config
export default (state = { ui: { active_ui: LOADING_UI }, base_config: {} }, action) => ({
ui: ui(state, action),
base_config: base_config(state.base_config, action)
});

View File

@@ -15,18 +15,20 @@ import {
REVERSE_PROXY_TEMPLATE_UI,
TLS_CERTPATH_UI,
DELEGATION_PORT_SELECTION_UI,
DELEGATION_TEMPLATE_UI,
DATABASE_UI,
} from './ui_constants';
import {
DELEGATION_TYPES, TLS_TYPES
} from '../actions/constants';
export default (state, action) => {
export default ({ ui, base_config }, action) => {
switch (action.type) {
case BASE_CONFIG_CHECKED:
return BASE_INTRO_UI;
case ADVANCE_UI:
switch (state) {
switch (ui.active_ui) {
case BASE_INTRO_UI:
return SERVER_NAME_UI;
case SERVER_NAME_UI:
@@ -64,17 +66,27 @@ export default (state, action) => {
return PORT_SELECTION_UI;
case TLS_CERTPATH_UI:
return PORT_SELECTION_UI;
case PORT_SELECTION_UI:
return base_config.tls == TLS_TYPES.REVERSE_PROXY ?
REVERSE_PROXY_TEMPLATE_UI :
base_config.delegation_type != DELEGATION_TYPES.LOCAL ?
DELEGATION_TEMPLATE_UI :
DATABASE_UI;
case REVERSE_PROXY_TEMPLATE_UI:
return base_config.delegation_type != DELEGATION_TYPES.LOCAL ?
DELEGATION_TEMPLATE_UI :
DATABASE_UI;
case DELEGATION_TEMPLATE_UI:
return DATABASE_UI;
case WELL_KNOWN_UI:
case DNS_UI:
case PORT_SELECTION_UI:
return REVERSE_PROXY_TEMPLATE_UI;
default:
return BASE_INTRO_UI;
}
// TODO: Think about how back should work..
case BACK_UI:
switch (state) {
switch (ui.active_ui) {
case STATS_REPORT_UI:
return SERVER_NAME_UI;
case KEY_EXPORT_UI:
@@ -89,6 +101,6 @@ export default (state, action) => {
BASE_INTRO_UI;
}
default:
return state;
return ui.active_ui;
}
}

View File

@@ -15,6 +15,7 @@ import {
TESTING_SYNAPSE_PORTS,
SET_SYNAPSE_PORTS,
SET_SYNAPSE_PORTS_FREE,
SET_DATABASE,
} from "../actions/types";
export default (state = { servername: undefined }, action) => {
@@ -111,7 +112,11 @@ export default (state = { servername: undefined }, action) => {
synapse_federation_port_free: action.synapse_federation_port_free,
synapse_client_port_free: action.synapse_client_port_free,
}
case SET_DATABASE:
return {
...state,
database: action.database,
}
default:
return state;
}

View File

@@ -4,33 +4,34 @@ import { LOADING_UI, ERROR_UI } from './ui_constants';
import { BASE_CONFIG_CHECKED, FAIL } from '../actions/types';
export default (state = { active_ui: LOADING_UI }, action) => {
export default (state, action) => {
console.log(state)
console.log(action)
switch (action.type) {
case FAIL:
return {
...state,
...state.ui,
active_ui: ERROR_UI
}
case BASE_CONFIG_CHECKED:
if (action.base_config_done) {
return {
base_config_done: true,
active_ui: advanced_config_ui(state.active_ui, action),
active_ui: advanced_config_ui(state, action),
}
} else {
return {
base_config_done: false,
active_ui: base_config_ui(state.active_ui, action),
active_ui: base_config_ui(state, action),
}
}
default:
const newstate = { ...state };
if ('base_config_done' in state) {
if (state.base_config_done) {
newstate.active_ui = advanced_ui(state.active_ui, action);
const newstate = { ...state.ui };
if ('base_config_done' in state.ui) {
if (state.ui.base_config_done) {
newstate.active_ui = advanced_ui(state, action);
} else {
newstate.active_ui = base_config_ui(state.active_ui, action);
newstate.active_ui = base_config_ui(state, action);
}
}
return newstate;

View File

@@ -13,6 +13,8 @@ export const TLS_CERTPATH_UI = "tls_certpath_ui";
export const REVERSE_PROXY_UI = "reverse_proxy_ui";
export const PORT_SELECTION_UI = "port_selection_ui";
export const REVERSE_PROXY_TEMPLATE_UI = "reverse_proxy_tamplate_ui";
export const DELEGATION_TEMPLATE_UI = "delegation_tamplate_ui";
export const DATABASE_UI = "database_ui";
// Advanced Config
export const CONFIG_SELECTION_UI = "config_selection_ui";

View File

@@ -1,4 +1,4 @@
export default config = ({
export default ({
delegationFedPort,
delegationClientPort,
fedPort,

View File

@@ -1,11 +1,10 @@
export default config = ({
export default ({
delegationFedPort,
delegationClientPort,
fedPort,
clientPort,
synapseServerName,
}) => `
${synapseServerName}:${delegationClientPort} {
}) => `${synapseServerName}:${delegationClientPort} {
proxy /_matrix http://localhost:${clientPort} {
transparent
}
@@ -15,5 +14,4 @@ ${synapseServerName}:${delegationFedPort} {
proxy / http://localhost:${fedPort} {
transparent
}
}
`
}`

View File

@@ -1,13 +1,11 @@
export default config = ({
export default ({
synapseServerName,
delegationClientPort,
}) => `
{
}) => `{
"m.homeserver": {
"base_url": "https://${synapseServerName}${delegationClientPort ? `:${delegationClientPort}` : ""}"
},
}
`
}`
// TODO: Maybe include this?
// "m.identity_server": {
// "base_url": "https://identity.example.com"

View File

@@ -1,10 +1,8 @@
export default config = ({
export default ({
delegationFedPort,
delegationClientPort,
fedPort,
clientPort,
serverName,
synapseServerName,
}) => `
_matrix._tcp.${serverName} 3600 IN SRV 10 5 ${delegationClientPort} ${synapseServerName}
`
}) => `_matrix._tcp.${serverName} 3600 IN SRV 10 5 ${delegationClientPort} ${synapseServerName}`

View File

@@ -1,8 +1,6 @@
export const config = (
export default ({
synapseServerName,
delegationSynapsePort,
) => `
{
}) => `{
"m.server": "${synapseServerName}:${delegationSynapsePort}"
}
`
}`

View File

@@ -1,4 +1,4 @@
export default config = ({
export default ({
delegationFedPort,
delegationClientPort,
fedPort,
@@ -6,8 +6,7 @@ export default config = ({
synapseServerName,
}) => {
if (fedPort == clientPort) {
return `
frontend https
return `frontend https
bind :::${delegationClientPort} v4v6 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2,http/1.1
# Matrix client traffic
@@ -24,8 +23,7 @@ backend matrix
server matrix 127.0.0.1:${fedPort}
`
} else {
return `
frontend https
return `frontend https
bind:::${delegationClientPort} v4v6 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2, http / 1.1
# Matrix client traffic
@@ -41,7 +39,6 @@ default_backend matrix
backend matrix
server matrix 127.0.0.1:${fedPort}
backend matrix-client 127.0.0.1:${clientPort}
`
backend matrix-client 127.0.0.1:${clientPort}`
}
}

View File

@@ -1,29 +1,27 @@
export default config = ({
import React from 'react';
export default ({
delegationFedPort,
delegationClientPort,
fedPort,
clientPort,
synapseServerName,
}) => `
server {
listen ${delegationClientPort} ssl;
listen [::]:${delegationClientPort} ssl;
server_name ${synapseServerName};
}) => `listen {delegationClientPort} ssl;
listen [::]:${delegationClientPort} ssl;
server_name ${synapseServerName};
location /_matrix {
proxy_pass http://localhost:${clientPort};
proxy_set_header X-Forwarded-For $remote_addr;
}
location /_matrix {
proxy_pass http://localhost:${clientPort};
proxy_set_header X-Forwarded-For $remote_addr;
}
}
server {
listen ${delegationFedPort} ssl default_server;
listen [::]:${delegationFedPort} ssl default_server;
server_name example.com;
listen ${delegationFedPort} ssl default_server;
listen [::]:${delegationFedPort} ssl default_server;
server_name ${synapseServerName};
location / {
proxy_pass http://localhost:${fedPort};
proxy_set_header X-Forwarded-For $remote_addr;
}
}
`
location / {
proxy_pass http://localhost:${fedPort};
proxy_set_header X-Forwarded-For $remote_addr;
}
}`

View File

@@ -0,0 +1,64 @@
import yaml from 'yaml';
import { TLS_TYPES } from '../actions/constants';
const listeners = conf => {
const listeners = [];
if (conf.tls == TLS_TYPES.TLS) {
listeners.append({
port: conf.synapse_federation_port,
tls: true,
bind_addresses: ['::1', '127.0.0.1'],
type: "http",
x_forwarded: true,
resources: [{
names: ["federation"],
compress: false,
}],
});
} else {
listeners.append({
port: conf.synapse_federation_port,
tls: true,
type: "http",
resources: [{
names: ["federation"],
}],
});
}
if (conf.synapse_client_port == conf.synapse_federation_port) {
listeners[0].resources[0].names.append("client");
} else if (conf.tls == TLS_TYPES.TLS) {
listeners.append({
port: conf.synapse_client_port,
tls: true,
bind_addresses: ['::1', '127.0.0.1'],
type: "http",
x_forwarded: true,
resources: [{
names: ["client"],
compress: false,
}],
});
} else {
listeners.append({
port: conf.synapse_client_port,
tls: true,
type: "http",
resources: [{
names: ["client"],
}],
});
}
return listeners;
}
const base_config_to_yaml = conf => ({
server_name: conf.servername,
listeners: listeners(conf),
})