# This is not a standalone script. It provides common functions to server-*.sh scripts if hash firewall-cmd 2>/dev/null; then firewallCmdExists=yes fi function installPrerequisities { yum -y install epel-release curl --silent --location https://rpm.nodesource.com/setup_10.x | bash - cat > /etc/yum.repos.d/mongodb-org.repo < server/config/production.yaml <> server/services/workers/reports/config/production.yaml < /etc/logrotate.d/mailtrain /var/log/mailtrain.log { daily rotate 12 compress delaycompress missingok notifempty copytruncate nomail } EOT # Set up systemd service script cp setup/mailtrain-centos7.service /etc/systemd/system/mailtrain.service systemctl enable mailtrain.service # Start the service systemctl daemon-reload systemctl start mailtrain.service echo echo echo "Success! Open http://$urlBaseTrusted/ and login as admin:test" if [ -z "$firewallCmdExists" ]; then echo "Note that firewall was not setup because firewall-cmd is missing on your system. Please make sure your firewall is correctly setup. If you are on AWS, this means to enable HTTPS and HTTP in your security group." fi } function installHttps { local hostTrusted="$1" local portTrusted="$2" local hostSandbox="$3" local portSandbox="$4" local hostPublic="$5" local portPublic="$6" local certificateFile="$7" local certificateKey="$8" local caChainFile="$9" yum -y install httpd mod_ssl echo > /etc/httpd/conf.d/mailtrain.conf cat >> /etc/httpd/conf.d/mailtrain.conf < ServerName ${hostTrusted} ServerSignature Off RewriteEngine On RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] ErrorLog logs/${hostTrusted}_redirect_error.log LogLevel warn ServerName ${hostSandbox} ServerSignature Off RewriteEngine On RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] ErrorLog logs/${hostSandbox}_redirect_error.log LogLevel warn ServerName ${hostPublic} ServerSignature Off RewriteEngine On RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] ErrorLog logs/${hostPublic}_redirect_error.log LogLevel warn EOT if [ -n "$firewallCmdExists" ]; then # Enable port 80 on the firewall firewall-cmd --add-port=80/tcp --permanent fi cat >> /etc/httpd/conf.d/mailtrain.conf < ServerName ${hostTrusted}:${portTrusted} ErrorLog logs/${hostTrusted}_ssl_error.log TransferLog logs/${hostTrusted}_ssl_access.log LogLevel warn SSLEngine on SSLCertificateFile ${certificateFile} SSLCertificateKeyFile ${certificateKey} SSLCertificateChainFile ${caChainFile} ProxyPreserveHost On ProxyPass "/" "http://127.0.0.1:3000/" ProxyPassReverse "/" "http://127.0.0.1:3000/" ServerName ${hostSandbox}:${portSandbox} ErrorLog logs/${hostSandbox}_ssl_error.log TransferLog logs/${hostSandbox}_ssl_access.log LogLevel warn SSLEngine on SSLCertificateFile ${certificateFile} SSLCertificateKeyFile ${certificateKey} SSLCertificateChainFile ${caChainFile} ProxyPreserveHost On ProxyPass "/" "http://127.0.0.1:3003/" ProxyPassReverse "/" "http://127.0.0.1:3003/" ServerName ${hostPublic}:${portPublic} ErrorLog logs/${hostPublic}_ssl_error.log TransferLog logs/${hostPublic}_ssl_access.log LogLevel warn SSLEngine on SSLCertificateFile ${certificateFile} SSLCertificateKeyFile ${certificateKey} SSLCertificateChainFile ${caChainFile} ProxyPreserveHost On ProxyPass "/" "http://127.0.0.1:3004/" ProxyPassReverse "/" "http://127.0.0.1:3004/" EOT # Enable and start httpd systemctl start httpd systemctl enable httpd if [ -n "$firewallCmdExists" ]; then # Enable SSL ports on the firewall for port in "${portTrusted}/tcp" "${portSandbox}/tcp" "${portPublic}/tcp"; do firewall-cmd --add-port=$port --permanent done # Activate the firefall settings firewall-cmd --reload fi } function createCertificates { # This assumes that HTTPD is not yet running local hostTrusted="$1" local hostSandbox="$2" local hostPublic="$3" local email="$4" yum install -y certbot if [ -n "$firewallCmdExists" ]; then # Temporarily enable port 80 on the firewall firewall-cmd --add-port=80/tcp fi certbot certonly --agree-tos --email "${email}" --standalone -n -d "${hostPublic}" -d "${hostTrusted}" -d "${hostSandbox}" # Install cron echo "0 3 * * * /usr/bin/certbot certonly --apache -n -d \"${hostPublic}\" -d \"${hostTrusted}\" -d \"${hostSandbox}\"" > crontab crontab crontab rm -rf crontab if [ -n "$firewallCmdExists" ]; then # Revert firewall to original state firewall-cmd --reload fi } function installService { cat > /etc/systemd/system/mailtrain.service <