179 lines
4.6 KiB
Bash
Executable File
179 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# filepath: finalize-postfixadmin-config.sh
|
|
|
|
# Finalize PostfixAdmin configuration after setup wizard completion
|
|
# This script updates config.local.php to mark PostfixAdmin as configured
|
|
|
|
set -euo pipefail
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
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}" >&2
|
|
}
|
|
|
|
# Check if running as root
|
|
if [[ $EUID -ne 0 ]]; then
|
|
error "This script must be run as root"
|
|
exit 1
|
|
fi
|
|
|
|
WEBROOT="/var/www/postfixadmin"
|
|
CONFIG_FILE="$WEBROOT/config.local.php"
|
|
|
|
# Check if config file exists
|
|
if [[ ! -f "$CONFIG_FILE" ]]; then
|
|
error "PostfixAdmin config file not found: $CONFIG_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
info "Finalizing PostfixAdmin configuration..."
|
|
|
|
# Get current configuration values
|
|
read -p "Enter your domain name (e.g., example.com): " DOMAIN
|
|
read -p "Enter your hostname (e.g., mail.example.com): " HOSTNAME
|
|
read -p "Enter admin email address: " ADMIN_EMAIL
|
|
read -p "Enter database name [postfix]: " DB_NAME
|
|
DB_NAME=${DB_NAME:-postfix}
|
|
read -p "Enter database user [postfix]: " DB_USER
|
|
DB_USER=${DB_USER:-postfix}
|
|
read -s -p "Enter database password: " DB_PASSWORD
|
|
echo
|
|
read -s -p "Enter PostfixAdmin setup password: " POSTFIXADMIN_PASSWORD
|
|
echo
|
|
|
|
# Create the updated configuration
|
|
info "Creating finalized PostfixAdmin configuration..."
|
|
|
|
cat > "$CONFIG_FILE" << EOF
|
|
<?php
|
|
// PostfixAdmin Configuration
|
|
// This file contains the final configuration after setup wizard completion
|
|
|
|
\$CONF['configured'] = true; // Setup completed
|
|
|
|
// Database configuration
|
|
\$CONF['database_type'] = 'pgsql';
|
|
\$CONF['database_host'] = 'localhost';
|
|
\$CONF['database_user'] = '$DB_USER';
|
|
\$CONF['database_password'] = '$DB_PASSWORD';
|
|
\$CONF['database_name'] = '$DB_NAME';
|
|
|
|
// Setup password (hashed)
|
|
\$CONF['setup_password'] = '$(php -r "echo password_hash('$POSTFIXADMIN_PASSWORD', PASSWORD_DEFAULT);")';
|
|
|
|
// Site configuration
|
|
\$CONF['postfix_admin_url'] = 'https://$HOSTNAME';
|
|
\$CONF['postfix_admin_path'] = '$WEBROOT';
|
|
\$CONF['admin_email'] = '$ADMIN_EMAIL';
|
|
\$CONF['default_language'] = 'en';
|
|
|
|
// Mail configuration - use supported encryption method
|
|
\$CONF['encrypt'] = 'dovecot:SHA512-CRYPT';
|
|
\$CONF['dovecotpw'] = '/usr/bin/doveadm pw';
|
|
\$CONF['page_size'] = '10';
|
|
|
|
// Default aliases
|
|
\$CONF['default_aliases'] = array (
|
|
'abuse' => 'abuse@$DOMAIN',
|
|
'hostmaster' => 'hostmaster@$DOMAIN',
|
|
'postmaster' => 'postmaster@$DOMAIN',
|
|
'webmaster' => 'webmaster@$DOMAIN'
|
|
);
|
|
|
|
// Virtual domain configuration
|
|
\$CONF['domain_path'] = 'YES';
|
|
\$CONF['domain_in_mailbox'] = 'YES';
|
|
\$CONF['maildir_name_hook'] = 'maildir_name_hook';
|
|
|
|
// Template configuration
|
|
\$CONF['templates_c'] = '$WEBROOT/templates_c';
|
|
|
|
// Custom maildir naming function
|
|
function maildir_name_hook(\$domain, \$user) {
|
|
return \$domain . '/' . \$user . '/';
|
|
}
|
|
|
|
// Quota configuration
|
|
\$CONF['quota'] = 'YES';
|
|
\$CONF['quota_multiplier'] = 1024000;
|
|
|
|
// Security settings
|
|
\$CONF['min_password_length'] = 8;
|
|
\$CONF['generate_password'] = 'YES';
|
|
\$CONF['show_password'] = 'NO';
|
|
|
|
// Feature toggles
|
|
\$CONF['vacation'] = 'YES';
|
|
\$CONF['vacation_domain'] = 'autoreply.$DOMAIN';
|
|
\$CONF['aliases'] = '10';
|
|
\$CONF['mailboxes'] = '10';
|
|
\$CONF['maxquota'] = '10';
|
|
|
|
// Logging
|
|
\$CONF['logging'] = 'YES';
|
|
\$CONF['fetchmail'] = 'NO';
|
|
|
|
// Backup configuration
|
|
\$CONF['backup'] = 'YES';
|
|
|
|
// Theme and appearance
|
|
\$CONF['theme_logo'] = 'images/logo-default.png';
|
|
\$CONF['theme_css'] = 'default.css';
|
|
|
|
// Email settings
|
|
\$CONF['smtp_server'] = 'localhost';
|
|
\$CONF['smtp_port'] = '25';
|
|
|
|
// Footer text
|
|
\$CONF['footer_text'] = 'Return to $HOSTNAME';
|
|
\$CONF['footer_link'] = 'https://$HOSTNAME';
|
|
|
|
// Additional security
|
|
\$CONF['password_validation'] = array(
|
|
'/^.{8,}$/' => 'password_too_short 8',
|
|
'/[a-z]/' => 'password_no_characters',
|
|
'/[A-Z]/' => 'password_no_characters',
|
|
'/[0-9]/' => 'password_no_digits'
|
|
);
|
|
|
|
?>
|
|
EOF
|
|
|
|
# Set proper permissions
|
|
chown www-data:www-data "$CONFIG_FILE"
|
|
chmod 640 "$CONFIG_FILE"
|
|
|
|
success "PostfixAdmin configuration finalized!"
|
|
echo
|
|
echo -e "${BLUE}=== Configuration Summary ===${NC}"
|
|
echo "Config file: $CONFIG_FILE"
|
|
echo "Configured: true"
|
|
echo "Database: $DB_NAME on localhost"
|
|
echo "Domain: $DOMAIN"
|
|
echo "Hostname: $HOSTNAME"
|
|
echo "Admin email: $ADMIN_EMAIL"
|
|
echo
|
|
echo -e "${YELLOW}=== Next Steps ===${NC}"
|
|
echo "1. Access PostfixAdmin: https://$HOSTNAME/"
|
|
echo "2. Log in with your admin credentials"
|
|
echo "3. Start creating domains and mailboxes"
|
|
echo
|
|
echo -e "${GREEN}PostfixAdmin is now ready for use!${NC}" |