You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

160 lines
4.1 KiB

  1. #!/usr/bin/env bash
  2. DIR="$( cd "$( dirname "$0" )" && pwd )"
  3. CWD=$(pwd)
  4. cd "$DIR/.." || exit
  5. PYTHONPATH=$(readlink -f "$(pwd)")
  6. export PYTHONPATH
  7. echo "$PYTHONPATH"
  8. for port in 8080 8081 8082; do
  9. echo "Starting server on port $port... "
  10. https_port=$((port + 400))
  11. mkdir -p demo/$port
  12. pushd demo/$port || exit
  13. # Generate the configuration for the homeserver at localhost:848x.
  14. python3 -m synapse.app.homeserver \
  15. --generate-config \
  16. --server-name "localhost:$port" \
  17. --config-path "$port.config" \
  18. --report-stats no
  19. if ! grep -F "Customisation made by demo/start.sh" -q "$port.config"; then
  20. # Generate TLS keys.
  21. openssl req -x509 -newkey rsa:4096 \
  22. -keyout "localhost:$port.tls.key" \
  23. -out "localhost:$port.tls.crt" \
  24. -days 365 -nodes -subj "/O=matrix"
  25. # Add customisations to the configuration.
  26. {
  27. printf '\n\n# Customisation made by demo/start.sh\n\n'
  28. echo "public_baseurl: http://localhost:$port/"
  29. echo 'enable_registration: true'
  30. echo ''
  31. # Warning, this heredoc depends on the interaction of tabs and spaces.
  32. # Please don't accidentaly bork me with your fancy settings.
  33. listeners=$(cat <<-PORTLISTENERS
  34. # Configure server to listen on both $https_port and $port
  35. # This overides some of the default settings above
  36. listeners:
  37. - port: $https_port
  38. type: http
  39. tls: true
  40. resources:
  41. - names: [client, federation]
  42. - port: $port
  43. tls: false
  44. bind_addresses: ['::1', '127.0.0.1']
  45. type: http
  46. x_forwarded: true
  47. resources:
  48. - names: [client, federation]
  49. compress: false
  50. PORTLISTENERS
  51. )
  52. echo "${listeners}"
  53. # Disable TLS for the servers
  54. printf '\n\n# Disable TLS for the servers.'
  55. echo '# DO NOT USE IN PRODUCTION'
  56. echo 'use_insecure_ssl_client_just_for_testing_do_not_use: true'
  57. echo 'federation_verify_certificates: false'
  58. # Set paths for the TLS certificates.
  59. echo "tls_certificate_path: \"$DIR/$port/localhost:$port.tls.crt\""
  60. echo "tls_private_key_path: \"$DIR/$port/localhost:$port.tls.key\""
  61. # Ignore keys from the trusted keys server
  62. echo '# Ignore keys from the trusted keys server'
  63. echo 'trusted_key_servers:'
  64. echo ' - server_name: "matrix.org"'
  65. echo ' accept_keys_insecurely: true'
  66. echo ''
  67. # Allow the servers to communicate over localhost.
  68. allow_list=$(cat <<-ALLOW_LIST
  69. # Allow the servers to communicate over localhost.
  70. ip_range_whitelist:
  71. - '127.0.0.1/8'
  72. - '::1/128'
  73. ALLOW_LIST
  74. )
  75. echo "${allow_list}"
  76. } >> "$port.config"
  77. fi
  78. # Check script parameters
  79. if [ $# -eq 1 ]; then
  80. if [ "$1" = "--no-rate-limit" ]; then
  81. # Disable any rate limiting
  82. ratelimiting=$(cat <<-RC
  83. rc_message:
  84. per_second: 1000
  85. burst_count: 1000
  86. rc_registration:
  87. per_second: 1000
  88. burst_count: 1000
  89. rc_login:
  90. address:
  91. per_second: 1000
  92. burst_count: 1000
  93. account:
  94. per_second: 1000
  95. burst_count: 1000
  96. failed_attempts:
  97. per_second: 1000
  98. burst_count: 1000
  99. rc_admin_redaction:
  100. per_second: 1000
  101. burst_count: 1000
  102. rc_joins:
  103. local:
  104. per_second: 1000
  105. burst_count: 1000
  106. remote:
  107. per_second: 1000
  108. burst_count: 1000
  109. rc_3pid_validation:
  110. per_second: 1000
  111. burst_count: 1000
  112. rc_invites:
  113. per_room:
  114. per_second: 1000
  115. burst_count: 1000
  116. per_user:
  117. per_second: 1000
  118. burst_count: 1000
  119. RC
  120. )
  121. echo "${ratelimiting}" >> "$port.config"
  122. fi
  123. fi
  124. # Always disable reporting of stats if the option is not there.
  125. if ! grep -F "report_stats" -q "$port.config" ; then
  126. echo "report_stats: false" >> "$port.config"
  127. fi
  128. # Run the homeserver in the background.
  129. python3 -m synapse.app.homeserver \
  130. --config-path "$port.config" \
  131. -D \
  132. popd || exit
  133. done
  134. cd "$CWD" || exit