cleanup
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#!/bin/bash
|
||||
# user-patches.sh - Optimized version with dynamic transport_maps generation
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
CFG_ROOT="/tmp/docker-mailserver"
|
||||
@@ -8,8 +10,15 @@ DST_DIR="/etc/postfix"
|
||||
echo "[user-patches.sh] Starting Postfix customizations..."
|
||||
|
||||
# Existing patches (header_checks, etc.)
|
||||
install -D -m 0644 "$SRC_DIR/header_checks" "$DST_DIR/header_checks"
|
||||
install -D -m 0644 "$SRC_DIR/smtp_header_checks" "$DST_DIR/maps/sender_header_filter.pcre"
|
||||
if [ -f "$SRC_DIR/header_checks" ]; then
|
||||
install -D -m 0644 "$SRC_DIR/header_checks" "$DST_DIR/header_checks"
|
||||
echo "[user-patches.sh] ✓ header_checks installed"
|
||||
fi
|
||||
|
||||
if [ -f "$SRC_DIR/smtp_header_checks" ]; then
|
||||
install -D -m 0644 "$SRC_DIR/smtp_header_checks" "$DST_DIR/maps/sender_header_filter.pcre"
|
||||
echo "[user-patches.sh] ✓ smtp_header_checks installed"
|
||||
fi
|
||||
|
||||
# NEW: Append content filter configuration to main.cf
|
||||
if [ -f "$SRC_DIR/main.cf.append" ]; then
|
||||
@@ -29,24 +38,79 @@ else
|
||||
echo "[user-patches.sh] ⚠ master.cf.append not found, skipping"
|
||||
fi
|
||||
|
||||
# NEW: Create and postmap local_transport_maps for selective filtering
|
||||
echo "[user-patches.sh] Creating local_transport_maps..."
|
||||
install -D -m 0644 /dev/null "$DST_DIR/local_transport_maps"
|
||||
cat > "$DST_DIR/local_transport_maps" << 'EOF'
|
||||
# Filter only local/internal deliveries (adjust to your domains)
|
||||
/^.*@example\.com$/ smtp:[localhost]:10025 # Replace with your domains, e.g. /^.*@andreasknuth\.de$/
|
||||
/^.*@another-domain\.com$/ smtp:[localhost]:10025
|
||||
# NEW: Generate local_transport_maps dynamically from postfix-accounts.cf
|
||||
echo "[user-patches.sh] Generating local_transport_maps..."
|
||||
|
||||
TRANSPORT_MAP="$DST_DIR/local_transport_maps"
|
||||
ACCOUNTS_FILE="$CFG_ROOT/postfix-accounts.cf"
|
||||
|
||||
# Create empty transport map
|
||||
> "$TRANSPORT_MAP"
|
||||
|
||||
if [ -f "$ACCOUNTS_FILE" ]; then
|
||||
# Extract unique domains from postfix-accounts.cf
|
||||
# Format of postfix-accounts.cf: user@domain.com|{PLAIN}password
|
||||
|
||||
echo "# Auto-generated transport map for content filter" >> "$TRANSPORT_MAP"
|
||||
echo "# Generated at: $(date)" >> "$TRANSPORT_MAP"
|
||||
echo "" >> "$TRANSPORT_MAP"
|
||||
|
||||
# Extract domains and create regex patterns
|
||||
awk -F'@|\\|' '{print $2}' "$ACCOUNTS_FILE" | \
|
||||
sort -u | \
|
||||
while read -r domain; do
|
||||
if [ -n "$domain" ]; then
|
||||
# Escape dots for regex
|
||||
escaped_domain=$(echo "$domain" | sed 's/\./\\./g')
|
||||
echo "/^.*@${escaped_domain}\$/ smtp:[localhost]:10025" >> "$TRANSPORT_MAP"
|
||||
echo "[user-patches.sh] - Added filter for: $domain"
|
||||
fi
|
||||
done
|
||||
|
||||
# Compile the map
|
||||
if [ -s "$TRANSPORT_MAP" ]; then
|
||||
postmap "$TRANSPORT_MAP"
|
||||
echo "[user-patches.sh] ✓ local_transport_maps created with $(grep -c '^/' "$TRANSPORT_MAP" || echo 0) domains"
|
||||
else
|
||||
echo "[user-patches.sh] ⚠ No domains found in $ACCOUNTS_FILE"
|
||||
fi
|
||||
else
|
||||
echo "[user-patches.sh] ⚠ $ACCOUNTS_FILE not found, creating minimal transport_maps"
|
||||
|
||||
# Fallback: Create minimal config
|
||||
cat > "$TRANSPORT_MAP" << 'EOF'
|
||||
# Minimal transport map - edit manually or populate postfix-accounts.cf
|
||||
# Format: /^.*@domain\.com$/ smtp:[localhost]:10025
|
||||
|
||||
# Example (replace with your domains):
|
||||
# /^.*@example\.com$/ smtp:[localhost]:10025
|
||||
# /^.*@another\.com$/ smtp:[localhost]:10025
|
||||
EOF
|
||||
postmap "$DST_DIR/local_transport_maps"
|
||||
echo "[user-patches.sh] ✓ local_transport_maps created and mapped"
|
||||
postmap "$TRANSPORT_MAP"
|
||||
fi
|
||||
|
||||
# Verify content filter script exists and is executable
|
||||
if [ -x "/usr/local/bin/content_filter.py" ]; then
|
||||
echo "[user-patches.sh] ✓ Content filter script found"
|
||||
|
||||
# Test Python dependencies
|
||||
if python3 -c "import boto3" 2>/dev/null; then
|
||||
echo "[user-patches.sh] ✓ boto3 installed"
|
||||
else
|
||||
echo "[user-patches.sh] ⚠ WARNING: boto3 not installed!"
|
||||
fi
|
||||
else
|
||||
echo "[user-patches.sh] ⚠ WARNING: content_filter.py not found or not executable!"
|
||||
fi
|
||||
|
||||
# Create log file if it doesn't exist
|
||||
if [ ! -f "/var/log/mail/content_filter.log" ]; then
|
||||
touch /var/log/mail/content_filter.log
|
||||
chown mail:mail /var/log/mail/content_filter.log
|
||||
chmod 644 /var/log/mail/content_filter.log
|
||||
echo "[user-patches.sh] ✓ Created content_filter.log"
|
||||
fi
|
||||
|
||||
echo "[user-patches.sh] Postfix customizations complete"
|
||||
|
||||
# Postfix neu laden (nachdem docker-mailserver seine eigene Konfig geladen hat)
|
||||
|
||||
Reference in New Issue
Block a user