summary refs log tree commit diff
path: root/demo/start.sh
blob: 55e69685e3c2b074268ffcec67bc44e80549de3f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash

DIR="$( cd "$( dirname "$0" )" && pwd )"

CWD=$(pwd)

cd "$DIR/.." || exit

PYTHONPATH=$(readlink -f "$(pwd)")
export PYTHONPATH


echo "$PYTHONPATH"

for port in 8080 8081 8082; do
    echo "Starting server on port $port... "

    https_port=$((port + 400))
    mkdir -p demo/$port
    pushd demo/$port || exit

    # Generate the configuration for the homeserver at localhost:848x.
    python3 -m synapse.app.homeserver \
        --generate-config \
        --server-name "localhost:$port" \
        --config-path "$port.config" \
        --report-stats no

    if ! grep -F "Customisation made by demo/start.sh" -q "$port.config"; then
        # Generate TLS keys.
        openssl req -x509 -newkey rsa:4096 \
          -keyout "localhost:$port.tls.key" \
          -out "localhost:$port.tls.crt" \
          -days 365 -nodes -subj "/O=matrix"

        # Add customisations to the configuration.
        {
            printf '\n\n# Customisation made by demo/start.sh\n\n'
            echo "public_baseurl: http://localhost:$port/"
            echo 'enable_registration: true'
            echo ''

			# Warning, this heredoc depends on the interaction of tabs and spaces.
			# Please don't accidentaly bork me with your fancy settings.
			listeners=$(cat <<-PORTLISTENERS
			# Configure server to listen on both $https_port and $port
			# This overides some of the default settings above
			listeners:
			  - port: $https_port
			    type: http
			    tls: true
			    resources:
			      - names: [client, federation]

			  - port: $port
			    tls: false
			    bind_addresses: ['::1', '127.0.0.1']
			    type: http
			    x_forwarded: true
			    resources:
			      - names: [client, federation]
			        compress: false
			PORTLISTENERS
			)

            echo "${listeners}"

            # Disable TLS for the servers
            printf '\n\n# Disable TLS for the servers.'
            echo '# DO NOT USE IN PRODUCTION'
            echo 'use_insecure_ssl_client_just_for_testing_do_not_use: true'
            echo 'federation_verify_certificates: false'

            # Set paths for the TLS certificates.
            echo "tls_certificate_path: \"$DIR/$port/localhost:$port.tls.crt\""
            echo "tls_private_key_path: \"$DIR/$port/localhost:$port.tls.key\""

            # Ignore keys from the trusted keys server
            echo '# Ignore keys from the trusted keys server'
            echo 'trusted_key_servers:'
            echo '  - server_name: "matrix.org"'
            echo '    accept_keys_insecurely: true'
            echo ''

			# Allow the servers to communicate over localhost.
			allow_list=$(cat <<-ALLOW_LIST
			# Allow the servers to communicate over localhost.
			ip_range_whitelist:
			  - '127.0.0.1/8'
			  - '::1/128'
			ALLOW_LIST
			)

            echo "${allow_list}"
        } >> "$port.config"
    fi

    # Check script parameters
    if [ $# -eq 1 ]; then
        if [ "$1" = "--no-rate-limit" ]; then

            # Disable any rate limiting
            ratelimiting=$(cat <<-RC
			rc_message:
			  per_second: 1000
			  burst_count: 1000
			rc_registration:
			  per_second: 1000
			  burst_count: 1000
			rc_login:
			  address:
			    per_second: 1000
			    burst_count: 1000
			  account:
			    per_second: 1000
			    burst_count: 1000
			  failed_attempts:
			    per_second: 1000
			    burst_count: 1000
			rc_admin_redaction:
			  per_second: 1000
			  burst_count: 1000
			rc_joins:
			  local:
			    per_second: 1000
			    burst_count: 1000
			  remote:
			    per_second: 1000
			    burst_count: 1000
			rc_3pid_validation:
			  per_second: 1000
			  burst_count: 1000
			rc_invites:
			  per_room:
			    per_second: 1000
			    burst_count: 1000
			  per_user:
			    per_second: 1000
			    burst_count: 1000
			RC
			)
            echo "${ratelimiting}" >> "$port.config"
        fi
    fi

    # Always disable reporting of stats if the option is not there.
    if ! grep -F "report_stats" -q  "$port.config" ; then
        echo "report_stats: false" >> "$port.config"
    fi

    # Run the homeserver in the background.
    python3 -m synapse.app.homeserver \
        --config-path "$port.config" \
        -D \

    popd || exit
done

cd "$CWD" || exit