Files
EmailHostingPlatform/toggle-postfixadmin-configured.sh
Tommy Parnell 86fdc0b3ba stop for now
2025-08-04 04:16:00 -04:00

103 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# Quick PostfixAdmin Configuration Toggle
# This script simply sets configured = true after setup wizard completion
# Use this if you've already completed the setup wizard via web interface
# Author: Email Server Setup Script
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
WEBROOT="/var/www/postfixadmin"
CONFIG_FILE="$WEBROOT/config.local.php"
error() {
echo -e "${RED}ERROR: $1${NC}" >&2
exit 1
}
info() {
echo -e "${BLUE}INFO: $1${NC}"
}
success() {
echo -e "${GREEN}SUCCESS: $1${NC}"
}
warning() {
echo -e "${YELLOW}WARNING: $1${NC}"
}
# Check if running as root
if [[ $EUID -ne 0 ]]; then
error "This script must be run as root"
fi
# Check if config file exists
if [[ ! -f "$CONFIG_FILE" ]]; then
error "PostfixAdmin config file not found: $CONFIG_FILE"
fi
echo -e "${BLUE}PostfixAdmin Configuration Toggle${NC}"
echo "=================================="
echo
# Check current status
if grep -q "\$CONF\['configured'\] = true;" "$CONFIG_FILE"; then
warning "PostfixAdmin is already marked as configured"
echo "If you need to run the setup wizard again, you can change it back to false."
exit 0
fi
if grep -q "\$CONF\['configured'\] = false;" "$CONFIG_FILE"; then
info "Found configured = false in config file"
else
error "Could not find configured setting in config file"
fi
echo "This script will change PostfixAdmin from configured = false to configured = true"
echo "This should be done AFTER you have completed the setup wizard at /setup.php"
echo
read -p "Have you completed the PostfixAdmin setup wizard? (y/N): " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
info "Please complete the setup wizard first at https://your-hostname/setup.php"
exit 0
fi
# Create backup
backup_file="$CONFIG_FILE.backup.$(date +%Y%m%d_%H%M%S)"
cp "$CONFIG_FILE" "$backup_file"
info "Created backup: $backup_file"
# Update the configuration
if sed -i "s/\$CONF\['configured'\] = false;/\$CONF['configured'] = true;/" "$CONFIG_FILE"; then
success "Updated: configured = false → configured = true"
else
error "Failed to update configuration"
fi
# Verify the change
if grep -q "\$CONF\['configured'\] = true;" "$CONFIG_FILE"; then
success "Configuration verified: PostfixAdmin is now marked as configured"
else
error "Verification failed - configuration may not have been updated correctly"
fi
echo
echo -e "${GREEN}PostfixAdmin setup completed!${NC}"
echo
echo -e "${BLUE}What this means:${NC}"
echo "• The setup wizard (/setup.php) is now disabled for security"
echo "• PostfixAdmin is ready for normal use"
echo "• You can now create domains and mailboxes"
echo
echo -e "${YELLOW}Note: If you need to run the setup wizard again,${NC}"
echo -e "${YELLOW}restore the backup file or manually change configured back to false${NC}"