|
@@ -36,8 +36,12 @@ IN_DEFAULT_INSTALL=0
|
36
|
36
|
SHOW_ON_ABOUT=1
|
37
|
37
|
|
38
|
38
|
MATRIX_DATA_DIR='/var/lib/matrix'
|
|
39
|
+MATRIX_HTTP_PORT=8558
|
|
40
|
+MATRIX_ID_HTTP_PORT=8557
|
39
|
41
|
MATRIX_PORT=8448
|
40
|
42
|
MATRIX_ID_PORT=8081
|
|
43
|
+MATRIX_ONION_PORT=8109
|
|
44
|
+MATRIX_ID_ONION_PORT=8111
|
41
|
45
|
MATRIX_REPO="https://github.com/matrix-org/synapse"
|
42
|
46
|
MATRIX_COMMIT='f5a4001bb116c468cc5e8e0ae04a1c570e2cb171'
|
43
|
47
|
SYDENT_REPO="https://github.com/matrix-org/sydent"
|
|
@@ -51,124 +55,115 @@ matrix_variables=(ONION_ONLY
|
51
|
55
|
DEFAULT_DOMAIN_NAME)
|
52
|
56
|
|
53
|
57
|
function matrix_nginx {
|
54
|
|
- matrix_identityserver_proxy_str=' \
|
55
|
|
- location /_matrixid { \
|
56
|
|
- proxy_pass http://localhost:8081; \
|
57
|
|
- proxy_set_header X-Forwarded-For $remote_addr; \
|
58
|
|
- }'
|
59
|
|
- matrix_proxy_str=' \
|
60
|
|
- location /_matrix { \
|
61
|
|
- proxy_pass https://localhost:8448; \
|
62
|
|
- proxy_set_header X-Forwarded-For $remote_addr; \
|
63
|
|
- }'
|
64
|
|
- turn_proxy_str=' \
|
65
|
|
- location /_turn { \
|
66
|
|
- proxy_pass https://localhost:3478; \
|
67
|
|
- proxy_set_header X-Forwarded-For $remote_addr; \
|
68
|
|
- }'
|
69
|
|
-
|
70
|
|
- if [[ $ONION_ONLY != 'no' ]]; then
|
71
|
|
- matrix_proxy_str=' \
|
72
|
|
- location /_matrix { \
|
73
|
|
- proxy_pass http://localhost:8448; \
|
74
|
|
- proxy_set_header X-Forwarded-For $remote_addr; \
|
75
|
|
- }'
|
76
|
|
- turn_proxy_str=' \
|
77
|
|
- location /_turn { \
|
78
|
|
- proxy_pass http://localhost:3478; \
|
79
|
|
- proxy_set_header X-Forwarded-For $remote_addr; \
|
80
|
|
- }'
|
81
|
|
- fi
|
|
58
|
+ create_default_web_site
|
82
|
59
|
|
83
|
|
- if [ ! -f /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME} ]; then
|
84
|
|
- matrix_nginx_site=/etc/nginx/sites-available/$DEFAULT_DOMAIN_NAME
|
85
|
|
- if [[ $ONION_ONLY == "no" ]]; then
|
86
|
|
- function_check nginx_http_redirect
|
87
|
|
- nginx_http_redirect $DEFAULT_DOMAIN_NAME
|
88
|
|
- echo 'server {' >> $matrix_nginx_site
|
89
|
|
- echo ' listen 443 ssl;' >> $matrix_nginx_site
|
90
|
|
- echo ' listen [::]:443 ssl;' >> $matrix_nginx_site
|
91
|
|
- echo " server_name $DEFAULT_DOMAIN_NAME;" >> $matrix_nginx_site
|
92
|
|
- echo '' >> $matrix_nginx_site
|
93
|
|
- echo ' # Security' >> $matrix_nginx_site
|
94
|
|
- function_check nginx_ssl
|
95
|
|
- nginx_ssl $DEFAULT_DOMAIN_NAME
|
96
|
|
-
|
97
|
|
- function_check nginx_disable_sniffing
|
98
|
|
- nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
|
99
|
|
-
|
100
|
|
- echo ' add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
|
101
|
|
- echo '' >> $matrix_nginx_site
|
102
|
|
- echo ' # Logs' >> $matrix_nginx_site
|
103
|
|
- echo ' access_log /dev/null;' >> $matrix_nginx_site
|
104
|
|
- echo ' error_log /dev/null;' >> $matrix_nginx_site
|
105
|
|
- echo '' >> $matrix_nginx_site
|
106
|
|
- echo ' # Root' >> $matrix_nginx_site
|
107
|
|
- echo " root /var/www/$DEFAULT_DOMAIN_NAME/htdocs;" >> $matrix_nginx_site
|
108
|
|
- echo '' >> $matrix_nginx_site
|
109
|
|
- echo ' # Index' >> $matrix_nginx_site
|
110
|
|
- echo ' index index.html;' >> $matrix_nginx_site
|
111
|
|
- echo '' >> $matrix_nginx_site
|
112
|
|
- echo ' # Location' >> $matrix_nginx_site
|
113
|
|
- echo ' location / {' >> $matrix_nginx_site
|
114
|
|
- function_check nginx_limits
|
115
|
|
- nginx_limits $DEFAULT_DOMAIN_NAME '15m'
|
116
|
|
- echo ' }' >> $matrix_nginx_site
|
117
|
|
- echo '' >> $matrix_nginx_site
|
118
|
|
- echo ' # Restrict access that is unnecessary anyway' >> $matrix_nginx_site
|
119
|
|
- echo ' location ~ /\.(ht|git) {' >> $matrix_nginx_site
|
120
|
|
- echo ' deny all;' >> $matrix_nginx_site
|
121
|
|
- echo ' }' >> $matrix_nginx_site
|
122
|
|
- echo '}' >> $matrix_nginx_site
|
123
|
|
- else
|
124
|
|
- echo -n '' > $matrix_nginx_site
|
125
|
|
- fi
|
|
60
|
+ # append the matrix server to the web site config
|
|
61
|
+ matrix_nginx_site=/etc/nginx/sites-available/$DEFAULT_DOMAIN_NAME
|
|
62
|
+ if [[ $ONION_ONLY == "no" ]]; then
|
|
63
|
+ echo '# Matrix Server' >> $matrix_nginx_site
|
126
|
64
|
echo 'server {' >> $matrix_nginx_site
|
127
|
|
- echo " listen 127.0.0.1:$MATRIX_PORT default_server;" >> $matrix_nginx_site
|
128
|
|
- echo " server_name $DEFAULT_DOMAIN_NAME;" >> $matrix_nginx_site
|
|
65
|
+ echo " listen ${MATRIX_HTTP_PORT} ssl;" >> $matrix_nginx_site
|
|
66
|
+ echo ' listen [::]:${MATRIX_HTTP_PORT} ssl;' >> $matrix_nginx_site
|
|
67
|
+ echo " server_name ${DEFAULT_DOMAIN_NAME};" >> $matrix_nginx_site
|
129
|
68
|
echo '' >> $matrix_nginx_site
|
|
69
|
+ echo ' # Security' >> $matrix_nginx_site
|
|
70
|
+ function_check nginx_ssl
|
|
71
|
+ nginx_ssl ${DEFAULT_DOMAIN_NAME}
|
|
72
|
+
|
130
|
73
|
function_check nginx_disable_sniffing
|
131
|
|
- nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
|
|
74
|
+ nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
|
|
75
|
+
|
|
76
|
+ echo ' add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
|
132
|
77
|
echo '' >> $matrix_nginx_site
|
133
|
78
|
echo ' # Logs' >> $matrix_nginx_site
|
134
|
79
|
echo ' access_log /dev/null;' >> $matrix_nginx_site
|
135
|
80
|
echo ' error_log /dev/null;' >> $matrix_nginx_site
|
136
|
81
|
echo '' >> $matrix_nginx_site
|
137
|
|
- echo ' # Root' >> $matrix_nginx_site
|
138
|
|
- echo " root /var/www/$DEFAULT_DOMAIN_NAME/htdocs;" >> $matrix_nginx_site
|
|
82
|
+ echo ' # Index' >> $matrix_nginx_site
|
|
83
|
+ echo ' index index.html;' >> $matrix_nginx_site
|
139
|
84
|
echo '' >> $matrix_nginx_site
|
140
|
85
|
echo ' # Location' >> $matrix_nginx_site
|
141
|
86
|
echo ' location / {' >> $matrix_nginx_site
|
142
|
87
|
function_check nginx_limits
|
143
|
|
- nginx_limits $DEFAULT_DOMAIN_NAME '15m'
|
144
|
|
- echo ' }' >> $matrix_nginx_site
|
145
|
|
- echo '' >> $matrix_nginx_site
|
146
|
|
- echo ' # Restrict access that is unnecessary anyway' >> $matrix_nginx_site
|
147
|
|
- echo ' location ~ /\.(ht|git) {' >> $matrix_nginx_site
|
148
|
|
- echo ' deny all;' >> $matrix_nginx_site
|
|
88
|
+ nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
|
|
89
|
+ echo " proxy_pass http://localhost:${MATRIX_PORT};" >> $matrix_nginx_site
|
|
90
|
+ echo ' proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
|
149
|
91
|
echo ' }' >> $matrix_nginx_site
|
150
|
92
|
echo '}' >> $matrix_nginx_site
|
|
93
|
+ echo '' >> $matrix_nginx_site
|
|
94
|
+ echo 'server {' >> $matrix_nginx_site
|
|
95
|
+ echo " listen ${MATRIX_ID_HTTP_PORT} ssl;" >> $matrix_nginx_site
|
|
96
|
+ echo ' listen [::]:${MATRIX_ID_HTTP_PORT} ssl;' >> $matrix_nginx_site
|
|
97
|
+ echo " server_name ${DEFAULT_DOMAIN_NAME};" >> $matrix_nginx_site
|
|
98
|
+ echo '' >> $matrix_nginx_site
|
|
99
|
+ echo ' # Security' >> $matrix_nginx_site
|
|
100
|
+ function_check nginx_ssl
|
|
101
|
+ nginx_ssl ${DEFAULT_DOMAIN_NAME}
|
151
|
102
|
|
152
|
|
- if [ ! -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
|
153
|
|
- function_check create_site_certificate
|
154
|
|
- create_site_certificate $DEFAULT_DOMAIN_NAME 'yes'
|
155
|
|
- fi
|
156
|
|
-
|
157
|
|
- nginx_ensite $DEFAULT_DOMAIN_NAME
|
158
|
|
- fi
|
|
103
|
+ function_check nginx_disable_sniffing
|
|
104
|
+ nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
|
159
|
105
|
|
160
|
|
- if ! grep "localhost:${MATRIX_ID_PORT}" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}; then
|
161
|
|
- sed -i "s|:443 ssl;|:443 ssl;${matrix_identityserver_proxy_str}|g" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
|
162
|
|
- sed -i "s| default_server;| default_server;${matrix_identityserver_proxy_str}|g" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
|
163
|
|
- fi
|
164
|
|
- if ! grep "localhost:${MATRIX_PORT}" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}; then
|
165
|
|
- sed -i "s|:443 ssl;|:443 ssl;${matrix_proxy_str}|g" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
|
166
|
|
- sed -i "s| default_server;| default_server;${matrix_proxy_str}|g" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
|
167
|
|
- fi
|
168
|
|
- if ! grep "localhost:${TURN_PORT}" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}; then
|
169
|
|
- sed -i "s|:443 ssl;|:443 ssl;${turn_proxy_str}|g" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
|
170
|
|
- sed -i "s| default_server;| default_server;${turn_proxy_str}|g" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
|
|
106
|
+ echo ' add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
|
|
107
|
+ echo '' >> $matrix_nginx_site
|
|
108
|
+ echo ' # Logs' >> $matrix_nginx_site
|
|
109
|
+ echo ' access_log /dev/null;' >> $matrix_nginx_site
|
|
110
|
+ echo ' error_log /dev/null;' >> $matrix_nginx_site
|
|
111
|
+ echo '' >> $matrix_nginx_site
|
|
112
|
+ echo ' # Index' >> $matrix_nginx_site
|
|
113
|
+ echo ' index index.html;' >> $matrix_nginx_site
|
|
114
|
+ echo '' >> $matrix_nginx_site
|
|
115
|
+ echo ' # Location' >> $matrix_nginx_site
|
|
116
|
+ echo ' location / {' >> $matrix_nginx_site
|
|
117
|
+ function_check nginx_limits
|
|
118
|
+ nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
|
|
119
|
+ echo " proxy_pass http://localhost:${MATRIX_ID_PORT};" >> $matrix_nginx_site
|
|
120
|
+ echo ' proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
|
|
121
|
+ echo ' }' >> $matrix_nginx_site
|
|
122
|
+ echo '}' >> $matrix_nginx_site
|
|
123
|
+ echo '' >> $matrix_nginx_site
|
|
124
|
+ else
|
|
125
|
+ echo '# Matrix Server' >> $matrix_nginx_site
|
171
|
126
|
fi
|
|
127
|
+ echo 'server {' >> $matrix_nginx_site
|
|
128
|
+ echo " listen 127.0.0.1:$MATRIX_ONION_PORT default_server;" >> $matrix_nginx_site
|
|
129
|
+ echo " server_name $DEFAULT_DOMAIN_NAME;" >> $matrix_nginx_site
|
|
130
|
+ echo '' >> $matrix_nginx_site
|
|
131
|
+ function_check nginx_disable_sniffing
|
|
132
|
+ nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
|
|
133
|
+ echo '' >> $matrix_nginx_site
|
|
134
|
+ echo ' # Logs' >> $matrix_nginx_site
|
|
135
|
+ echo ' access_log /dev/null;' >> $matrix_nginx_site
|
|
136
|
+ echo ' error_log /dev/null;' >> $matrix_nginx_site
|
|
137
|
+ echo '' >> $matrix_nginx_site
|
|
138
|
+ echo ' # Location' >> $matrix_nginx_site
|
|
139
|
+ echo ' location / {' >> $matrix_nginx_site
|
|
140
|
+ function_check nginx_limits
|
|
141
|
+ nginx_limits $DEFAULT_DOMAIN_NAME '15m'
|
|
142
|
+ echo " proxy_pass http://localhost:${MATRIX_PORT};" >> $matrix_nginx_site
|
|
143
|
+ echo ' proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
|
|
144
|
+ echo ' }' >> $matrix_nginx_site
|
|
145
|
+ echo '}' >> $matrix_nginx_site
|
|
146
|
+ echo '' >> $matrix_nginx_site
|
|
147
|
+ echo 'server {' >> $matrix_nginx_site
|
|
148
|
+ echo " listen 127.0.0.1:$MATRIX_ID_ONION_PORT default_server;" >> $matrix_nginx_site
|
|
149
|
+ echo " server_name $DEFAULT_DOMAIN_NAME;" >> $matrix_nginx_site
|
|
150
|
+ echo '' >> $matrix_nginx_site
|
|
151
|
+ function_check nginx_disable_sniffing
|
|
152
|
+ nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
|
|
153
|
+ echo '' >> $matrix_nginx_site
|
|
154
|
+ echo ' # Logs' >> $matrix_nginx_site
|
|
155
|
+ echo ' access_log /dev/null;' >> $matrix_nginx_site
|
|
156
|
+ echo ' error_log /dev/null;' >> $matrix_nginx_site
|
|
157
|
+ echo '' >> $matrix_nginx_site
|
|
158
|
+ echo ' # Location' >> $matrix_nginx_site
|
|
159
|
+ echo ' location / {' >> $matrix_nginx_site
|
|
160
|
+ function_check nginx_limits
|
|
161
|
+ nginx_limits $DEFAULT_DOMAIN_NAME '15m'
|
|
162
|
+ echo " proxy_pass http://localhost:${MATRIX_ID_PORT};" >> $matrix_nginx_site
|
|
163
|
+ echo ' proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
|
|
164
|
+ echo ' }' >> $matrix_nginx_site
|
|
165
|
+ echo '}' >> $matrix_nginx_site
|
|
166
|
+ echo '# End of Matrix Server' >> $matrix_nginx_site
|
172
|
167
|
|
173
|
168
|
systemctl restart nginx
|
174
|
169
|
systemctl restart turn
|
|
@@ -207,7 +202,7 @@ function matrix_configure_homeserver_yaml {
|
207
|
202
|
|
208
|
203
|
local ymltemp="$(mktemp)"
|
209
|
204
|
|
210
|
|
- awk -v TURNURIES="turn_uris: [\"turn:${DEFAULT_DOMAIN_NAME}/_turn?transport=udp\", \"turn:${DEFAULT_DOMAIN_NAME}/_turn?transport=tcp\"]" \
|
|
205
|
+ awk -v TURNURIES="turn_uris: [\"turn:${DEFAULT_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=udp\", \"turn:${DEFAULT_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=tcp\"]" \
|
211
|
206
|
-v TURNSHAREDSECRET="turn_shared_secret: \"${turnkey}\"" \
|
212
|
207
|
-v PIDFILE="pid_file: ${MATRIX_DATA_DIR}/homeserver.pid" \
|
213
|
208
|
-v DATABASE="database: \"${MATRIX_DATA_DIR}/homeserver.db\"" \
|
|
@@ -225,15 +220,14 @@ function matrix_configure_homeserver_yaml {
|
225
|
220
|
|
226
|
221
|
mv ${ymltemp} "${filepath}"
|
227
|
222
|
|
228
|
|
- if [[ $ONION_ONLY != 'no' ]]; then
|
229
|
|
- sed -i 's|no_tls: .*|no_tls: True|g' "${filepath}"
|
230
|
|
- fi
|
|
223
|
+ sed -i 's|no_tls: .*|no_tls: true|g' "${filepath}"
|
|
224
|
+ sed -i 's| tls: .*| tls: false|g' "${filepath}"
|
231
|
225
|
sed -i 's|enable_registration_captcha.*|enable_registration_captcha: False|g' "${filepath}"
|
232
|
226
|
sed -i "s|database: \".*|database: \"${MATRIX_DATA_DIR}/homeserver.db\"|g" "${filepath}"
|
233
|
227
|
sed -i "s|media_store_path:.*|media_store_path: \"${MATRIX_DATA_DIR}/media_store\"|g" "${filepath}"
|
234
|
228
|
sed -i "s|pid_file:.*|pid_file: \"${MATRIX_DATA_DIR}/homeserver.pid\"|g" "${filepath}"
|
235
|
229
|
sed -i "s|log_file:.*|log_file: \"/dev/null\"|g" "${filepath}"
|
236
|
|
- sed -i '0,/bind_address:.*/s//bind_address: 127.0.0.1/' "${filepath}"
|
|
230
|
+ sed -i 's|bind_address:.*|bind_address: 127.0.0.1|g' "${filepath}"
|
237
|
231
|
sed -i '0,/x_forwarded:.*/s//x_forwarded: true/' "${filepath}"
|
238
|
232
|
sed -i "s|server_name:.*|server_name: \"${DEFAULT_DOMAIN_NAME}\"|g" "${filepath}"
|
239
|
233
|
sed -i "/trusted_third_party_id_servers:/a - ${DEFAULT_DOMAIN_NAME}" "${filepath}"
|
|
@@ -473,6 +467,8 @@ function restore_remote_matrix {
|
473
|
467
|
}
|
474
|
468
|
|
475
|
469
|
function remove_matrix {
|
|
470
|
+ firewall_remove ${MATRIX_HTTP_PORT}
|
|
471
|
+
|
476
|
472
|
systemctl stop matrix
|
477
|
473
|
systemctl stop sydent
|
478
|
474
|
|
|
@@ -497,11 +493,10 @@ function remove_matrix {
|
497
|
493
|
rm -rf /etc/sydent
|
498
|
494
|
deluser matrix
|
499
|
495
|
delgroup matrix
|
500
|
|
- remove_onion_service matrix ${MATRIX_PORT}
|
|
496
|
+ remove_onion_service matrix ${MATRIX_ONION_PORT}
|
|
497
|
+ remove_onion_service matrix ${MATRIX_ID_ONION_PORT}
|
501
|
498
|
|
502
|
|
- sed -i "/location \/_matrix {/,/}/d" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
|
503
|
|
- sed -i "/location \/_matrixid {/,/}/d" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
|
504
|
|
- sed -i "/location \/_turn {/,/}/d" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
|
|
499
|
+ sed -i "/# Matrix Server{/,/# End of Matrix Server/d" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
|
505
|
500
|
systemctl restart nginx
|
506
|
501
|
|
507
|
502
|
remove_completion_param install_matrix
|
|
@@ -644,7 +639,8 @@ function install_home_server {
|
644
|
639
|
fi
|
645
|
640
|
chmod -R 700 $MATRIX_DATA_DIR/homeserver.db
|
646
|
641
|
|
647
|
|
- MATRIX_ONION_HOSTNAME=$(add_onion_service matrix ${MATRIX_PORT} ${MATRIX_PORT})
|
|
642
|
+ MATRIX_ONION_HOSTNAME=$(add_onion_service matrix ${MATRIX_PORT} ${MATRIX_ONION_PORT})
|
|
643
|
+ MATRIX_ID_ONION_HOSTNAME=$(add_onion_service matrixid ${MATRIX_ID_PORT} ${MATRIX_ID_ONION_PORT})
|
648
|
644
|
if [ ! ${MATRIX_PASSWORD} ]; then
|
649
|
645
|
if [ -f ${IMAGE_PASSWORD_FILE} ]; then
|
650
|
646
|
MATRIX_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
|
|
@@ -653,6 +649,8 @@ function install_home_server {
|
653
|
649
|
fi
|
654
|
650
|
fi
|
655
|
651
|
|
|
652
|
+ firewall_add matrix ${MATRIX_HTTP_PORT}
|
|
653
|
+
|
656
|
654
|
rm -rf ${MATRIX_DATA_DIR}/Maildir
|
657
|
655
|
rm -rf ${MATRIX_DATA_DIR}/.mutt
|
658
|
656
|
rm -f ${MATRIX_DATA_DIR}/.muttrc
|