119 lines
3.7 KiB
Bash
Executable File
119 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
info() { echo -e "${BLUE}INFO: $1${NC}"; }
|
|
success() { echo -e "${GREEN}SUCCESS: $1${NC}"; }
|
|
warning() { echo -e "${YELLOW}WARNING: $1${NC}"; }
|
|
error() { echo -e "${RED}ERROR: $1${NC}"; }
|
|
|
|
HOSTNAME="mail.terrible.dev"
|
|
|
|
info "Configuring Apache for PostfixAdmin..."
|
|
|
|
# Check if PostfixAdmin directory exists
|
|
if [[ ! -d "/var/www/postfixadmin" ]]; then
|
|
error "PostfixAdmin directory not found at /var/www/postfixadmin"
|
|
echo "This means the PostfixAdmin installation step was not completed."
|
|
echo "You may need to run the resume-setup.sh script first."
|
|
exit 1
|
|
fi
|
|
|
|
# Create PostfixAdmin Apache configuration
|
|
info "Creating PostfixAdmin Apache site configuration..."
|
|
sudo tee /etc/apache2/sites-available/postfixadmin.conf > /dev/null << EOF
|
|
<VirtualHost *:80>
|
|
ServerName $HOSTNAME
|
|
Redirect permanent / https://$HOSTNAME/
|
|
</VirtualHost>
|
|
|
|
<VirtualHost *:443>
|
|
ServerName $HOSTNAME
|
|
DocumentRoot /var/www/postfixadmin/public
|
|
|
|
SSLEngine on
|
|
SSLCertificateFile /etc/letsencrypt/live/$HOSTNAME/fullchain.pem
|
|
SSLCertificateKeyFile /etc/letsencrypt/live/$HOSTNAME/privkey.pem
|
|
|
|
# Modern SSL configuration
|
|
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
|
|
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384
|
|
SSLHonorCipherOrder on
|
|
|
|
<Directory /var/www/postfixadmin/public>
|
|
Options -Indexes
|
|
AllowOverride All
|
|
Require all granted
|
|
</Directory>
|
|
|
|
# Alternative document root if public folder doesn't exist
|
|
<Directory /var/www/postfixadmin>
|
|
Options -Indexes
|
|
AllowOverride All
|
|
Require all granted
|
|
</Directory>
|
|
|
|
ErrorLog \${APACHE_LOG_DIR}/postfixadmin_error.log
|
|
CustomLog \${APACHE_LOG_DIR}/postfixadmin_access.log combined
|
|
</VirtualHost>
|
|
EOF
|
|
|
|
# Check if public directory exists, if not use main directory
|
|
if [[ ! -d "/var/www/postfixadmin/public" ]]; then
|
|
warning "PostfixAdmin public directory not found, using main directory"
|
|
sudo sed -i 's|DocumentRoot /var/www/postfixadmin/public|DocumentRoot /var/www/postfixadmin|' /etc/apache2/sites-available/postfixadmin.conf
|
|
fi
|
|
|
|
# Disable default site and enable PostfixAdmin
|
|
info "Enabling PostfixAdmin site..."
|
|
sudo a2dissite 000-default 2>/dev/null || true
|
|
sudo a2ensite postfixadmin
|
|
|
|
# Test Apache configuration
|
|
if sudo apache2ctl configtest; then
|
|
success "Apache configuration is valid"
|
|
else
|
|
error "Apache configuration test failed"
|
|
exit 1
|
|
fi
|
|
|
|
# Reload Apache
|
|
sudo systemctl reload apache2
|
|
|
|
# Test PostfixAdmin access
|
|
info "Testing PostfixAdmin access..."
|
|
sleep 2
|
|
|
|
if curl -I -k https://$HOSTNAME/postfixadmin/ 2>/dev/null | grep -q "200\|302\|301"; then
|
|
success "PostfixAdmin is accessible!"
|
|
echo
|
|
echo "🎉 PostfixAdmin URLs:"
|
|
echo " Setup: https://$HOSTNAME/postfixadmin/setup.php"
|
|
echo " Login: https://$HOSTNAME/postfixadmin/"
|
|
echo
|
|
elif curl -I -k https://$HOSTNAME/ 2>/dev/null | grep -q "200\|302\|301"; then
|
|
warning "Site accessible but PostfixAdmin may need setup"
|
|
echo
|
|
echo "📋 Try these URLs:"
|
|
echo " Main: https://$HOSTNAME/"
|
|
echo " Setup: https://$HOSTNAME/setup.php"
|
|
echo " Admin: https://$HOSTNAME/admin/"
|
|
else
|
|
error "PostfixAdmin not accessible"
|
|
echo "Check Apache error logs:"
|
|
echo "sudo tail -f /var/log/apache2/error.log"
|
|
fi
|
|
|
|
info "Current site status:"
|
|
echo "Available sites:"
|
|
sudo ls -la /etc/apache2/sites-available/ | grep postfixadmin || echo " No postfixadmin config found"
|
|
echo "Enabled sites:"
|
|
sudo ls -la /etc/apache2/sites-enabled/
|