start.sh 4.2 KB

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