Browse Source

Use a separate domain for matrix homeserver

Bob Mottram 8 years ago
parent
commit
c44180aa8e
1 changed files with 137 additions and 107 deletions
  1. 137
    107
      src/freedombone-app-matrix

+ 137
- 107
src/freedombone-app-matrix View File

15
 # License
15
 # License
16
 # =======
16
 # =======
17
 #
17
 #
18
-# Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
18
+# Copyright (C) 2016-2017 Bob Mottram <bob@freedombone.net>
19
 #
19
 #
20
 # This program is free software: you can redistribute it and/or modify
20
 # This program is free software: you can redistribute it and/or modify
21
 # it under the terms of the GNU Affero General Public License as published by
21
 # it under the terms of the GNU Affero General Public License as published by
37
 IN_DEFAULT_INSTALL=0
37
 IN_DEFAULT_INSTALL=0
38
 SHOW_ON_ABOUT=1
38
 SHOW_ON_ABOUT=1
39
 
39
 
40
+MATRIX_DOMAIN_NAME=
41
+MATRIX_CODE=
42
+
40
 MATRIX_DATA_DIR='/var/lib/matrix'
43
 MATRIX_DATA_DIR='/var/lib/matrix'
41
-MATRIX_HTTP_PORT=8558
44
+MATRIX_HTTP_PORT=8448
42
 MATRIX_ID_HTTP_PORT=8557
45
 MATRIX_ID_HTTP_PORT=8557
43
 MATRIX_PORT=8008
46
 MATRIX_PORT=8008
44
 MATRIX_ID_PORT=8081
47
 MATRIX_ID_PORT=8081
54
 matrix_variables=(ONION_ONLY
57
 matrix_variables=(ONION_ONLY
55
                   MY_USERNAME
58
                   MY_USERNAME
56
                   MATRIX_SECRET
59
                   MATRIX_SECRET
57
-                  DEFAULT_DOMAIN_NAME)
60
+                  DEFAULT_DOMAIN_NAME
61
+                  MATRIX_DOMAIN_NAME
62
+                  MATRIX_CODE)
58
 
63
 
59
 function matrix_nginx {
64
 function matrix_nginx {
60
-    create_default_web_site
61
-
62
-    # append the matrix server to the web site config
63
-    matrix_nginx_site=/etc/nginx/sites-available/$DEFAULT_DOMAIN_NAME
64
-    if ! grep -q '# End of Matrix Server' $matrix_nginx_site; then
65
-        if [[ $ONION_ONLY == "no" ]]; then
66
-            echo '# Matrix Server' >> $matrix_nginx_site
67
-            echo 'server {' >> $matrix_nginx_site
68
-            echo "  listen ${MATRIX_HTTP_PORT} ssl;" >> $matrix_nginx_site
69
-            echo "  listen [::]:${MATRIX_HTTP_PORT} ssl;" >> $matrix_nginx_site
70
-            echo "  server_name ${DEFAULT_DOMAIN_NAME};" >> $matrix_nginx_site
71
-            echo '' >> $matrix_nginx_site
72
-            echo '  # Security' >> $matrix_nginx_site
73
-            function_check nginx_ssl
74
-            nginx_ssl ${DEFAULT_DOMAIN_NAME}
75
-
76
-            function_check nginx_disable_sniffing
77
-            nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
78
-
79
-            echo '  add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
80
-            echo '' >> $matrix_nginx_site
81
-            echo '  # Logs' >> $matrix_nginx_site
82
-            echo '  access_log /dev/null;' >> $matrix_nginx_site
83
-            echo '  error_log /dev/null;' >> $matrix_nginx_site
84
-            echo '' >> $matrix_nginx_site
85
-            echo '  # Index' >> $matrix_nginx_site
86
-            echo '  index index.html;' >> $matrix_nginx_site
87
-            echo '' >> $matrix_nginx_site
88
-            echo '  # Location' >> $matrix_nginx_site
89
-            echo '  location / {' >> $matrix_nginx_site
90
-            function_check nginx_limits
91
-            nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
92
-            echo "      proxy_pass http://localhost:${MATRIX_PORT}/_matrix;" >> $matrix_nginx_site
93
-            echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
94
-            echo '  }' >> $matrix_nginx_site
95
-            echo '}' >> $matrix_nginx_site
96
-            echo '' >> $matrix_nginx_site
97
-            echo 'server {' >> $matrix_nginx_site
98
-            echo "  listen ${MATRIX_ID_HTTP_PORT} ssl;" >> $matrix_nginx_site
99
-            echo "  listen [::]:${MATRIX_ID_HTTP_PORT} ssl;" >> $matrix_nginx_site
100
-            echo "  server_name ${DEFAULT_DOMAIN_NAME};" >> $matrix_nginx_site
101
-            echo '' >> $matrix_nginx_site
102
-            echo '  # Security' >> $matrix_nginx_site
103
-            function_check nginx_ssl
104
-            nginx_ssl ${DEFAULT_DOMAIN_NAME}
105
-
106
-            function_check nginx_disable_sniffing
107
-            nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
108
-
109
-            echo '  add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
110
-            echo '' >> $matrix_nginx_site
111
-            echo '  # Logs' >> $matrix_nginx_site
112
-            echo '  access_log /dev/null;' >> $matrix_nginx_site
113
-            echo '  error_log /dev/null;' >> $matrix_nginx_site
114
-            echo '' >> $matrix_nginx_site
115
-            echo '  # Index' >> $matrix_nginx_site
116
-            echo '  index index.html;' >> $matrix_nginx_site
117
-            echo '' >> $matrix_nginx_site
118
-            echo '  # Location' >> $matrix_nginx_site
119
-            echo '  location / {' >> $matrix_nginx_site
120
-            function_check nginx_limits
121
-            nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
122
-            echo "      proxy_pass http://localhost:${MATRIX_ID_PORT};" >> $matrix_nginx_site
123
-            echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
124
-            echo '  }' >> $matrix_nginx_site
125
-            echo '}' >> $matrix_nginx_site
126
-            echo '' >> $matrix_nginx_site
127
-        else
128
-            echo '# Matrix Server' >> $matrix_nginx_site
129
-        fi
130
-        echo 'server {' >> $matrix_nginx_site
131
-        echo "    listen 127.0.0.1:$MATRIX_ONION_PORT default_server;" >> $matrix_nginx_site
132
-        echo "    server_name $DEFAULT_DOMAIN_NAME;" >> $matrix_nginx_site
65
+    matrix_nginx_site=/etc/nginx/sites-available/$MATRIX_DOMAIN_NAME
66
+    if [[ $ONION_ONLY == "no" ]]; then
67
+        echo 'server {' > $matrix_nginx_site
68
+        echo "  listen 443 ssl;" >> $matrix_nginx_site
69
+        echo "  listen [::]:443 ssl;" >> $matrix_nginx_site
70
+        echo "  server_name ${MATRIX_DOMAIN_NAME};" >> $matrix_nginx_site
133
         echo '' >> $matrix_nginx_site
71
         echo '' >> $matrix_nginx_site
72
+        echo '  # Security' >> $matrix_nginx_site
73
+        function_check nginx_ssl
74
+        nginx_ssl ${MATRIX_DOMAIN_NAME}
75
+
134
         function_check nginx_disable_sniffing
76
         function_check nginx_disable_sniffing
135
-        nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
77
+        nginx_disable_sniffing ${MATRIX_DOMAIN_NAME}
78
+
79
+        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
136
         echo '' >> $matrix_nginx_site
80
         echo '' >> $matrix_nginx_site
137
         echo '  # Logs' >> $matrix_nginx_site
81
         echo '  # Logs' >> $matrix_nginx_site
138
         echo '  access_log /dev/null;' >> $matrix_nginx_site
82
         echo '  access_log /dev/null;' >> $matrix_nginx_site
139
         echo '  error_log /dev/null;' >> $matrix_nginx_site
83
         echo '  error_log /dev/null;' >> $matrix_nginx_site
140
         echo '' >> $matrix_nginx_site
84
         echo '' >> $matrix_nginx_site
85
+        echo '  # Index' >> $matrix_nginx_site
86
+        echo '  index index.html;' >> $matrix_nginx_site
87
+        echo '' >> $matrix_nginx_site
141
         echo '  # Location' >> $matrix_nginx_site
88
         echo '  # Location' >> $matrix_nginx_site
142
         echo '  location / {' >> $matrix_nginx_site
89
         echo '  location / {' >> $matrix_nginx_site
143
         function_check nginx_limits
90
         function_check nginx_limits
144
-        nginx_limits $DEFAULT_DOMAIN_NAME '15m'
91
+        nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
145
         echo "      proxy_pass http://localhost:${MATRIX_PORT}/_matrix;" >> $matrix_nginx_site
92
         echo "      proxy_pass http://localhost:${MATRIX_PORT}/_matrix;" >> $matrix_nginx_site
146
         echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
93
         echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
147
         echo '  }' >> $matrix_nginx_site
94
         echo '  }' >> $matrix_nginx_site
148
         echo '}' >> $matrix_nginx_site
95
         echo '}' >> $matrix_nginx_site
149
         echo '' >> $matrix_nginx_site
96
         echo '' >> $matrix_nginx_site
150
         echo 'server {' >> $matrix_nginx_site
97
         echo 'server {' >> $matrix_nginx_site
151
-        echo "    listen 127.0.0.1:$MATRIX_ID_ONION_PORT default_server;" >> $matrix_nginx_site
152
-        echo "    server_name $DEFAULT_DOMAIN_NAME;" >> $matrix_nginx_site
98
+        echo "  listen ${MATRIX_ID_HTTP_PORT} ssl;" >> $matrix_nginx_site
99
+        echo "  listen [::]:${MATRIX_ID_HTTP_PORT} ssl;" >> $matrix_nginx_site
100
+        echo "  server_name ${MATRIX_DOMAIN_NAME};" >> $matrix_nginx_site
153
         echo '' >> $matrix_nginx_site
101
         echo '' >> $matrix_nginx_site
102
+        echo '  # Security' >> $matrix_nginx_site
103
+        function_check nginx_ssl
104
+        nginx_ssl ${MATRIX_DOMAIN_NAME}
105
+
154
         function_check nginx_disable_sniffing
106
         function_check nginx_disable_sniffing
155
-        nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
107
+        nginx_disable_sniffing ${MATRIX_DOMAIN_NAME}
108
+
109
+        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
156
         echo '' >> $matrix_nginx_site
110
         echo '' >> $matrix_nginx_site
157
         echo '  # Logs' >> $matrix_nginx_site
111
         echo '  # Logs' >> $matrix_nginx_site
158
         echo '  access_log /dev/null;' >> $matrix_nginx_site
112
         echo '  access_log /dev/null;' >> $matrix_nginx_site
159
         echo '  error_log /dev/null;' >> $matrix_nginx_site
113
         echo '  error_log /dev/null;' >> $matrix_nginx_site
160
         echo '' >> $matrix_nginx_site
114
         echo '' >> $matrix_nginx_site
115
+        echo '  # Index' >> $matrix_nginx_site
116
+        echo '  index index.html;' >> $matrix_nginx_site
117
+        echo '' >> $matrix_nginx_site
161
         echo '  # Location' >> $matrix_nginx_site
118
         echo '  # Location' >> $matrix_nginx_site
162
         echo '  location / {' >> $matrix_nginx_site
119
         echo '  location / {' >> $matrix_nginx_site
163
         function_check nginx_limits
120
         function_check nginx_limits
164
-        nginx_limits $DEFAULT_DOMAIN_NAME '15m'
121
+        nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
165
         echo "      proxy_pass http://localhost:${MATRIX_ID_PORT};" >> $matrix_nginx_site
122
         echo "      proxy_pass http://localhost:${MATRIX_ID_PORT};" >> $matrix_nginx_site
166
         echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
123
         echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
167
         echo '  }' >> $matrix_nginx_site
124
         echo '  }' >> $matrix_nginx_site
168
         echo '}' >> $matrix_nginx_site
125
         echo '}' >> $matrix_nginx_site
169
-        echo '# End of Matrix Server' >> $matrix_nginx_site
170
-    fi
126
+        echo '' >> $matrix_nginx_site
127
+    else
128
+        echo -n '' > $matrix_nginx_site
129
+    fi
130
+    echo 'server {' >> $matrix_nginx_site
131
+    echo "    listen 127.0.0.1:$MATRIX_ONION_PORT default_server;" >> $matrix_nginx_site
132
+    echo "    server_name $MATRIX_DOMAIN_NAME;" >> $matrix_nginx_site
133
+    echo '' >> $matrix_nginx_site
134
+    function_check nginx_disable_sniffing
135
+    nginx_disable_sniffing $MATRIX_DOMAIN_NAME
136
+    echo '' >> $matrix_nginx_site
137
+    echo '  # Logs' >> $matrix_nginx_site
138
+    echo '  access_log /dev/null;' >> $matrix_nginx_site
139
+    echo '  error_log /dev/null;' >> $matrix_nginx_site
140
+    echo '' >> $matrix_nginx_site
141
+    echo '  # Location' >> $matrix_nginx_site
142
+    echo '  location / {' >> $matrix_nginx_site
143
+    function_check nginx_limits
144
+    nginx_limits $MATRIX_DOMAIN_NAME '15m'
145
+    echo "      proxy_pass http://localhost:${MATRIX_PORT}/_matrix;" >> $matrix_nginx_site
146
+    echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
147
+    echo '  }' >> $matrix_nginx_site
148
+    echo '}' >> $matrix_nginx_site
149
+    echo '' >> $matrix_nginx_site
150
+    echo 'server {' >> $matrix_nginx_site
151
+    echo "    listen 127.0.0.1:$MATRIX_ID_ONION_PORT default_server;" >> $matrix_nginx_site
152
+    echo "    server_name $MATRIX_DOMAIN_NAME;" >> $matrix_nginx_site
153
+    echo '' >> $matrix_nginx_site
154
+    function_check nginx_disable_sniffing
155
+    nginx_disable_sniffing $MATRIX_DOMAIN_NAME
156
+    echo '' >> $matrix_nginx_site
157
+    echo '  # Logs' >> $matrix_nginx_site
158
+    echo '  access_log /dev/null;' >> $matrix_nginx_site
159
+    echo '  error_log /dev/null;' >> $matrix_nginx_site
160
+    echo '' >> $matrix_nginx_site
161
+    echo '  # Location' >> $matrix_nginx_site
162
+    echo '  location / {' >> $matrix_nginx_site
163
+    function_check nginx_limits
164
+    nginx_limits $MATRIX_DOMAIN_NAME '15m'
165
+    echo "      proxy_pass http://localhost:${MATRIX_ID_PORT};" >> $matrix_nginx_site
166
+    echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
167
+    echo '  }' >> $matrix_nginx_site
168
+    echo '}' >> $matrix_nginx_site
169
+
170
+    if [ ! -d /var/www/$MATRIX_DOMAIN_NAME ]; then
171
+        mkdir -p /var/www/$MATRIX_DOMAIN_NAME/htdocs
172
+    fi
173
+
174
+    function_check add_ddns_domain
175
+    add_ddns_domain $MATRIX_DOMAIN_NAME
176
+
177
+    function_check create_site_certificate
178
+    create_site_certificate $MATRIX_DOMAIN_NAME
171
 
179
 
172
     systemctl restart nginx
180
     systemctl restart nginx
173
     systemctl restart turn
181
     systemctl restart turn
188
            --config-path "${filepath}" \
196
            --config-path "${filepath}" \
189
            --generate-config \
197
            --generate-config \
190
            --report-stats ${REPORT_STATS} \
198
            --report-stats ${REPORT_STATS} \
191
-           --server-name ${DEFAULT_DOMAIN_NAME}
199
+           --server-name ${MATRIX_DOMAIN_NAME}
192
 }
200
 }
193
 
201
 
194
 function matrix_generate_identityserver_file {
202
 function matrix_generate_identityserver_file {
199
            --config-path "${filepath}" \
207
            --config-path "${filepath}" \
200
            --generate-config \
208
            --generate-config \
201
            --report-stats ${REPORT_STATS} \
209
            --report-stats ${REPORT_STATS} \
202
-           --server-name ${DEFAULT_DOMAIN_NAME}
210
+           --server-name ${MATRIX_DOMAIN_NAME}
203
 }
211
 }
204
 
212
 
205
 function matrix_configure_homeserver_yaml {
213
 function matrix_configure_homeserver_yaml {
208
 
216
 
209
     local ymltemp="$(mktemp)"
217
     local ymltemp="$(mktemp)"
210
 
218
 
211
-    awk -v TURNURIES="turn_uris: [\"turn:${DEFAULT_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=udp\", \"turn:${DEFAULT_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=tcp\"]" \
219
+    awk -v TURNURIES="turn_uris: [\"turn:${MATRIX_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=udp\", \"turn:${DEFAULT_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=tcp\"]" \
212
         -v TURNSHAREDSECRET="turn_shared_secret: \"${turnkey}\"" \
220
         -v TURNSHAREDSECRET="turn_shared_secret: \"${turnkey}\"" \
213
         -v PIDFILE="pid_file: ${MATRIX_DATA_DIR}/homeserver.pid" \
221
         -v PIDFILE="pid_file: ${MATRIX_DATA_DIR}/homeserver.pid" \
214
         -v DATABASE="database: \"${MATRIX_DATA_DIR}/homeserver.db\"" \
222
         -v DATABASE="database: \"${MATRIX_DATA_DIR}/homeserver.db\"" \
235
     sed -i "s|log_file:.*|log_file: \"/dev/null\"|g" "${filepath}"
243
     sed -i "s|log_file:.*|log_file: \"/dev/null\"|g" "${filepath}"
236
     sed -i 's|bind_address:.*|bind_address: 127.0.0.1|g' "${filepath}"
244
     sed -i 's|bind_address:.*|bind_address: 127.0.0.1|g' "${filepath}"
237
     sed -i '0,/x_forwarded:.*/s//x_forwarded: true/' "${filepath}"
245
     sed -i '0,/x_forwarded:.*/s//x_forwarded: true/' "${filepath}"
238
-    sed -i "s|server_name:.*|server_name: \"${DEFAULT_DOMAIN_NAME}\"|g" "${filepath}"
239
-    sed -i "/trusted_third_party_id_servers:/a     - ${DEFAULT_DOMAIN_NAME}" "${filepath}"
240
-    sed -i "s|- ${DEFAULT_DOMAIN_NAME}|    - ${DEFAULT_DOMAIN_NAME}|g" "${filepath}"
241
-    sed -i "s|enable_registration:.*|enable_registration: False|g" "${filepath}"
246
+    sed -i "s|server_name:.*|server_name: \"${MATRIX_DOMAIN_NAME}\"|g" "${filepath}"
247
+    sed -i "/trusted_third_party_id_servers:/a     - ${MATRIX_DOMAIN_NAME}" "${filepath}"
248
+    sed -i "s|- ${MATRIX_DOMAIN_NAME}|    - ${MATRIX_DOMAIN_NAME}|g" "${filepath}"
249
+    sed -i "s|enable_registration:.*|enable_registration: True|g" "${filepath}"
242
 }
250
 }
243
 
251
 
244
 function matrix_configure_identityserver {
252
 function matrix_configure_identityserver {
249
     sed -i "s|Sydent Validation|Freedombone Matrix Account Validation|g" ${filepath}
257
     sed -i "s|Sydent Validation|Freedombone Matrix Account Validation|g" ${filepath}
250
     sed -i "s|pidfile.path.*|pidfile.path = /etc/sydent/sydent.pid|g" ${filepath}
258
     sed -i "s|pidfile.path.*|pidfile.path = /etc/sydent/sydent.pid|g" ${filepath}
251
     sed -i "s|log.path.*|log.path = /dev/null|g" ${filepath}
259
     sed -i "s|log.path.*|log.path = /dev/null|g" ${filepath}
252
-    sed -i "s|server.name.*|server.name = ${DEFAULT_DOMAIN_NAME}|g" ${filepath}
260
+    sed -i "s|server.name.*|server.name = ${MATRIX_DOMAIN_NAME}|g" ${filepath}
253
 }
261
 }
254
 
262
 
255
 function matrix_diff {
263
 function matrix_diff {
256
     DIFFPARAMS="${DIFFPARAMS:-Naur}"
264
     DIFFPARAMS="${DIFFPARAMS:-Naur}"
257
-    DEFAULT_DOMAIN_NAME="${DEFAULT_DOMAIN_NAME:-demo_server_name}"
265
+    MATRIX_DOMAIN_NAME="${MATRIX_DOMAIN_NAME:-demo_server_name}"
258
     REPORT_STATS="${REPORT_STATS:-no_or_yes}"
266
     REPORT_STATS="${REPORT_STATS:-no_or_yes}"
259
-    export DEFAULT_DOMAIN_NAME REPORT_STATS
267
+    export MATRIX_DOMAIN_NAME REPORT_STATS
260
 
268
 
261
     matrix_generate_synapse_file $INSTALL_DIR/homeserver.synapse.yaml
269
     matrix_generate_synapse_file $INSTALL_DIR/homeserver.synapse.yaml
262
     diff -${DIFFPARAMS} $INSTALL_DIR/homeserver.synapse.yaml ${MATRIX_DATA_DIR}/homeserver.yaml
270
     diff -${DIFFPARAMS} $INSTALL_DIR/homeserver.synapse.yaml ${MATRIX_DATA_DIR}/homeserver.yaml
265
 
273
 
266
 function matrix_generate {
274
 function matrix_generate {
267
     breakup="0"
275
     breakup="0"
268
-    [[ -z "${DEFAULT_DOMAIN_NAME}" ]] && echo "STOP! environment variable DEFAULT_DOMAIN_NAME must be set" && breakup="1"
276
+    [[ -z "${MATRIX_DOMAIN_NAME}" ]] && echo "STOP! environment variable MATRIX_DOMAIN_NAME must be set" && breakup="1"
269
     [[ -z "${REPORT_STATS}" ]] && echo "STOP! environment variable REPORT_STATS must be set to 'no' or 'yes'" && breakup="1"
277
     [[ -z "${REPORT_STATS}" ]] && echo "STOP! environment variable REPORT_STATS must be set to 'no' or 'yes'" && breakup="1"
270
     [[ "${breakup}" == "1" ]] && exit 1
278
     [[ "${breakup}" == "1" ]] && exit 1
271
 
279
 
295
     ${PROJECT_NAME}-pass -u $new_username -a matrix -p "$new_user_password"
303
     ${PROJECT_NAME}-pass -u $new_username -a matrix -p "$new_user_password"
296
 
304
 
297
     if [[ $ONION_ONLY == 'no' ]]; then
305
     if [[ $ONION_ONLY == 'no' ]]; then
298
-        retval=$(register_new_matrix_user -c ${MATRIX_DATA_DIR}/homeserver.yaml -u "${new_username}" -p "${new_user_password}" -a https://${DEFAULT_DOMAIN_NAME}:${MATRIX_HTTP_PORT})
306
+        retval=$(register_new_matrix_user -c ${MATRIX_DATA_DIR}/homeserver.yaml -u "${new_username}" -p "${new_user_password}" -a https://${MATRIX_DOMAIN_NAME})
299
     else
307
     else
300
-        retval=$(register_new_matrix_user -c ${MATRIX_DATA_DIR}/homeserver.yaml -u "${new_username}" -p "${new_user_password}" -a http://${DEFAULT_DOMAIN_NAME}:${MATRIX_HTTP_PORT})
308
+        retval=$(register_new_matrix_user -c ${MATRIX_DATA_DIR}/homeserver.yaml -u "${new_username}" -p "${new_user_password}" -a http://${MATRIX_DOMAIN_NAME})
301
     fi
309
     fi
302
     echo "0"
310
     echo "0"
303
 }
311
 }
304
 
312
 
305
 function install_interactive_matrix {
313
 function install_interactive_matrix {
314
+    if [ ! $ONION_ONLY ]; then
315
+        ONION_ONLY='no'
316
+    fi
317
+
318
+    if [[ $ONION_ONLY != "no" ]]; then
319
+        MATRIX_DOMAIN_NAME='matrix.local'
320
+        write_config_param "MATRIX_DOMAIN_NAME" "$MATRIX_DOMAIN_NAME"
321
+    else
322
+        function_check interactive_site_details
323
+        interactive_site_details "matrix" "MATRIX_DOMAIN_NAME" "MATRIX_CODE"
324
+    fi
306
     APP_INSTALLED=1
325
     APP_INSTALLED=1
307
 }
326
 }
308
 
327
 
487
 function remove_matrix {
506
 function remove_matrix {
488
     #firewall_remove ${MATRIX_HTTP_PORT}
507
     #firewall_remove ${MATRIX_HTTP_PORT}
489
 
508
 
509
+    nginx_dissite $MATRIX_DOMAIN_NAME
510
+    remove_certs $MATRIX_DOMAIN_NAME
511
+    if [ -f /etc/nginx/sites-available/$MATRIX_DOMAIN_NAME ]; then
512
+        rm /etc/nginx/sites-available/$MATRIX_DOMAIN_NAME
513
+    fi
514
+    if [ ! -d /var/www/$MATRIX_DOMAIN_NAME ]; then
515
+        rm -rf /var/www/$MATRIX_DOMAIN_NAME
516
+    fi
517
+    function_check remove_ddns_domain
518
+    remove_ddns_domain $MATRIX_DOMAIN_NAME
519
+
490
     systemctl stop matrix
520
     systemctl stop matrix
491
     if [ -f /etc/systemd/system/sydent.service ]; then
521
     if [ -f /etc/systemd/system/sydent.service ]; then
492
         systemctl stop sydent
522
         systemctl stop sydent
518
     remove_onion_service matrix ${MATRIX_ONION_PORT}
548
     remove_onion_service matrix ${MATRIX_ONION_PORT}
519
     remove_onion_service matrix ${MATRIX_ID_ONION_PORT}
549
     remove_onion_service matrix ${MATRIX_ID_ONION_PORT}
520
 
550
 
521
-    sed -i "/# Matrix Server/,/# End of Matrix Server/d" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
551
+    #sed -i "/# Matrix Server/,/# End of Matrix Server/d" /etc/nginx/sites-available/${MATRIX_DOMAIN_NAME}
522
     systemctl restart nginx
552
     systemctl restart nginx
523
 
553
 
524
     remove_completion_param install_matrix
554
     remove_completion_param install_matrix
574
     echo 'Type=simple' >> /etc/systemd/system/sydent.service
604
     echo 'Type=simple' >> /etc/systemd/system/sydent.service
575
     echo 'User=matrix' >> /etc/systemd/system/sydent.service
605
     echo 'User=matrix' >> /etc/systemd/system/sydent.service
576
     echo "WorkingDirectory=/etc/sydent" >> /etc/systemd/system/sydent.service
606
     echo "WorkingDirectory=/etc/sydent" >> /etc/systemd/system/sydent.service
577
-    echo "ExecStart=/usr/bin/python -m sydent.sydent --config-path /etc/sydent/sydent.conf --report-stats ${REPORT_STATS} --server-name ${DEFAULT_DOMAIN_NAME}" >> /etc/systemd/system/sydent.service
607
+    echo "ExecStart=/usr/bin/python -m sydent.sydent --config-path /etc/sydent/sydent.conf --report-stats ${REPORT_STATS} --server-name ${MATRIX_DOMAIN_NAME}" >> /etc/systemd/system/sydent.service
578
     echo 'Restart=always' >> /etc/systemd/system/sydent.service
608
     echo 'Restart=always' >> /etc/systemd/system/sydent.service
579
     echo 'RestartSec=10' >> /etc/systemd/system/sydent.service
609
     echo 'RestartSec=10' >> /etc/systemd/system/sydent.service
580
     echo '' >> /etc/systemd/system/sydent.service
610
     echo '' >> /etc/systemd/system/sydent.service
709
     fi
739
     fi
710
 
740
 
711
     if [[ ${ONION_ONLY} == 'no' ]]; then
741
     if [[ ${ONION_ONLY} == 'no' ]]; then
712
-        if [ ! -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
742
+        if [ ! -f /etc/ssl/certs/${MATRIX_DOMAIN_NAME}.pem ]; then
713
             echo $'Obtaining certificate for the main domain'
743
             echo $'Obtaining certificate for the main domain'
714
-            create_site_certificate ${DEFAULT_DOMAIN_NAME} 'yes'
744
+            create_site_certificate ${MATRIX_DOMAIN_NAME} 'yes'
715
         fi
745
         fi
716
     fi
746
     fi
717
 
747
 
737
     function_check install_home_server
767
     function_check install_home_server
738
     install_home_server
768
     install_home_server
739
 
769
 
740
-    function_check install_identity_server
741
-    install_identity_server
770
+    #function_check install_identity_server
771
+    #install_identity_server
742
 
772
 
743
     function_check update_default_domain
773
     function_check update_default_domain
744
     update_default_domain
774
     update_default_domain
748
     function_check matrix_nginx
778
     function_check matrix_nginx
749
     matrix_nginx
779
     matrix_nginx
750
 
780
 
751
-    if [[ $(add_user_matrix "${MY_USERNAME}" "${MATRIX_PASSWORD}" | tail -n 1) != "0" ]]; then
752
-        echo $'Failed to add matrix admin user';
753
-        exit 879352
754
-    fi
781
+    #if [[ $(add_user_matrix "${MY_USERNAME}" "${MATRIX_PASSWORD}" | tail -n 1) != "0" ]]; then
782
+    #    echo $'Failed to add matrix admin user';
783
+    #    exit 879352
784
+    #fi
755
 
785
 
756
     APP_INSTALLED=1
786
     APP_INSTALLED=1
757
 }
787
 }