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.
 
 
 
 
 
 

129 lines
4.2 KiB

  1. #!/usr/bin/env bash
  2. DIR="$( cd "$( dirname "$0" )" && pwd )"
  3. CWD=$(pwd)
  4. cd "$DIR/.."
  5. mkdir -p demo/etc
  6. export PYTHONPATH=$(readlink -f $(pwd))
  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
  13. #rm $DIR/etc/$port.config
  14. python3 -m synapse.app.homeserver \
  15. --generate-config \
  16. -H "localhost:$https_port" \
  17. --config-path "$DIR/etc/$port.config" \
  18. --report-stats no
  19. if ! grep -F "Customisation made by demo/start.sh" -q $DIR/etc/$port.config; then
  20. printf '\n\n# Customisation made by demo/start.sh\n' >> $DIR/etc/$port.config
  21. echo "public_baseurl: http://localhost:$port/" >> $DIR/etc/$port.config
  22. echo 'enable_registration: true' >> $DIR/etc/$port.config
  23. # Warning, this heredoc depends on the interaction of tabs and spaces. Please don't
  24. # accidentaly bork me with your fancy settings.
  25. listeners=$(cat <<-PORTLISTENERS
  26. # Configure server to listen on both $https_port and $port
  27. # This overides some of the default settings above
  28. listeners:
  29. - port: $https_port
  30. type: http
  31. tls: true
  32. resources:
  33. - names: [client, federation]
  34. - port: $port
  35. tls: false
  36. bind_addresses: ['::1', '127.0.0.1']
  37. type: http
  38. x_forwarded: true
  39. resources:
  40. - names: [client, federation]
  41. compress: false
  42. PORTLISTENERS
  43. )
  44. echo "${listeners}" >> $DIR/etc/$port.config
  45. # Disable tls for the servers
  46. printf '\n\n# Disable tls on the servers.' >> $DIR/etc/$port.config
  47. echo '# DO NOT USE IN PRODUCTION' >> $DIR/etc/$port.config
  48. echo 'use_insecure_ssl_client_just_for_testing_do_not_use: true' >> $DIR/etc/$port.config
  49. echo 'federation_verify_certificates: false' >> $DIR/etc/$port.config
  50. # Set tls paths
  51. echo "tls_certificate_path: \"$DIR/etc/localhost:$https_port.tls.crt\"" >> $DIR/etc/$port.config
  52. echo "tls_private_key_path: \"$DIR/etc/localhost:$https_port.tls.key\"" >> $DIR/etc/$port.config
  53. # Generate tls keys
  54. 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"
  55. # Ignore keys from the trusted keys server
  56. echo '# Ignore keys from the trusted keys server' >> $DIR/etc/$port.config
  57. echo 'trusted_key_servers:' >> $DIR/etc/$port.config
  58. echo ' - server_name: "matrix.org"' >> $DIR/etc/$port.config
  59. echo ' accept_keys_insecurely: true' >> $DIR/etc/$port.config
  60. # Reduce the blacklist
  61. blacklist=$(cat <<-BLACK
  62. # Set the blacklist so that it doesn't include 127.0.0.1, ::1
  63. federation_ip_range_blacklist:
  64. - '10.0.0.0/8'
  65. - '172.16.0.0/12'
  66. - '192.168.0.0/16'
  67. - '100.64.0.0/10'
  68. - '169.254.0.0/16'
  69. - 'fe80::/64'
  70. - 'fc00::/7'
  71. BLACK
  72. )
  73. echo "${blacklist}" >> $DIR/etc/$port.config
  74. fi
  75. # Check script parameters
  76. if [ $# -eq 1 ]; then
  77. if [ $1 = "--no-rate-limit" ]; then
  78. # messages rate limit
  79. echo 'rc_messages_per_second: 1000' >> $DIR/etc/$port.config
  80. echo 'rc_message_burst_count: 1000' >> $DIR/etc/$port.config
  81. # registration rate limit
  82. printf 'rc_registration:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  83. # login rate limit
  84. echo 'rc_login:' >> $DIR/etc/$port.config
  85. printf ' address:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  86. printf ' account:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  87. printf ' failed_attempts:\n per_second: 1000\n burst_count: 1000\n' >> $DIR/etc/$port.config
  88. fi
  89. fi
  90. if ! grep -F "full_twisted_stacktraces" -q $DIR/etc/$port.config; then
  91. echo "full_twisted_stacktraces: true" >> $DIR/etc/$port.config
  92. fi
  93. if ! grep -F "report_stats" -q $DIR/etc/$port.config ; then
  94. echo "report_stats: false" >> $DIR/etc/$port.config
  95. fi
  96. python3 -m synapse.app.homeserver \
  97. --config-path "$DIR/etc/$port.config" \
  98. -D \
  99. popd
  100. done
  101. cd "$CWD"