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.5 KiB

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