#!/bin/bash # Corrected SME Server Password Change Application Installation Script # Compatible with Python 3.6.8 and Flask 2.0.3 # Features: Correct DB structure (Users/Admin/Ibays), zxcvbn validation, visibility toggles set -e # Configuration APP_NAME="smeserver-password-app-corrected" APP_DIR="/opt/$APP_NAME" SERVICE_NAME="smeserver-password-corrected" SERVICE_PORT=5000 PYTHON_BIN="/usr/bin/python3" echo "Installing Corrected SME Server Password Change Application..." echo "Features: Correct DB structure, zxcvbn validation, password visibility toggles" # Check if running as root if [ "$EUID" -ne 0 ]; then echo "Please run this script as root" exit 1 fi # Check if we're on an SME Server if [ ! -f "/etc/e-smith-release" ] && [ ! -f "/etc/sme-release" ]; then echo "Warning: This doesn't appear to be an SME Server system" echo "The application may not work correctly without SME Server tools" fi # Check Python version PYTHON_VERSION=$(python3 -c "import sys; print('{}.{}'.format(sys.version_info.major, sys.version_info.minor))") echo "Detected Python version: $PYTHON_VERSION" if [ "$PYTHON_VERSION" != "3.6" ]; then echo "Warning: This application is optimized for Python 3.6.8" echo "Current version: $PYTHON_VERSION" echo "Continuing with installation..." fi # Stop existing service if running if systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then echo "Stopping existing service..." systemctl stop "$SERVICE_NAME" fi # Create application directory echo "Creating application directory..." mkdir -p "$APP_DIR" # Copy application files echo "Copying corrected application files..." cp -r ./* "$APP_DIR/" # Set permissions echo "Setting permissions..." chown -R root:root "$APP_DIR" chmod +x "$APP_DIR/app.py" chmod +x "$APP_DIR/demo_mode.py" chmod +x "$APP_DIR/install.sh" # Install Python dependencies including zxcvbn echo "Installing Python dependencies (including zxcvbn)..." if command -v pip3 &> /dev/null; then pip3 install Flask==2.0.3 Flask-CORS==3.0.10 Werkzeug==2.0.3 zxcvbn==4.4.28 elif command -v yum &> /dev/null; then yum install -y python3-pip pip3 install Flask==2.0.3 Flask-CORS==3.0.10 Werkzeug==2.0.3 zxcvbn==4.4.28 else echo "Warning: Could not install Python dependencies automatically" echo "Please install Flask 2.0.3, Flask-CORS 3.0.10, and zxcvbn 4.4.28 manually" fi # Verify correct passwordstrength database structure echo "Verifying passwordstrength database structure..." if command -v db &> /dev/null; then # Check if passwordstrength entry exists with correct structure if db configuration show passwordstrength &> /dev/null; then echo "Existing passwordstrength configuration found:" db configuration show passwordstrength # Check for Users, Admin, Ibays properties USERS_SETTING=$(db configuration getprop passwordstrength Users 2>/dev/null || echo "") ADMIN_SETTING=$(db configuration getprop passwordstrength Admin 2>/dev/null || echo "") IBAYS_SETTING=$(db configuration getprop passwordstrength Ibays 2>/dev/null || echo "") if [ -z "$USERS_SETTING" ] || [ -z "$ADMIN_SETTING" ] || [ -z "$IBAYS_SETTING" ]; then echo "Warning: passwordstrength database structure may be incomplete" echo "Expected structure:" echo " passwordstrength=configuration" echo " Admin=strong" echo " Ibays=strong" echo " Users=strong" else echo "โœ“ Correct passwordstrength structure detected:" echo " Users: $USERS_SETTING" echo " Admin: $ADMIN_SETTING" echo " Ibays: $IBAYS_SETTING" fi else echo "Warning: passwordstrength configuration not found" echo "The application will work but may not reflect actual SME Server settings" fi else echo "Warning: SME Server database tools not available" echo "Password strength will use demo mode defaults" fi # Create systemd service file echo "Creating corrected systemd service..." cat > "/etc/systemd/system/$SERVICE_NAME.service" << EOF [Unit] Description=Corrected SME Server Password Change Web Application After=network.target [Service] Type=simple User=root WorkingDirectory=$APP_DIR Environment=FLASK_APP=app.py Environment=FLASK_ENV=production ExecStart=$PYTHON_BIN $APP_DIR/app.py Restart=always RestartSec=10 [Install] WantedBy=multi-user.target EOF # Reload systemd and enable service echo "Enabling corrected service..." systemctl daemon-reload systemctl enable "$SERVICE_NAME" # Start the service echo "Starting corrected service..." systemctl start "$SERVICE_NAME" # Wait a moment for service to start sleep 3 # Check service status if systemctl is-active --quiet "$SERVICE_NAME"; then echo "" echo "โœ“ Corrected SME Server Password Change Application installed successfully!" echo "" echo "๐Ÿ”’ Features Available:" echo " โœ“ Correct SME Server database structure (Users/Admin/Ibays)" echo " โœ“ External zxcvbn password validation library" echo " โœ“ Password visibility toggles for all password fields" echo " โœ“ Real-time password strength indicator" echo " โœ“ Admin configuration panel for all account types" echo " โœ“ Python 3.6.8 and Flask 2.0.3 compatibility" echo "" echo "๐ŸŒ Access URLs:" echo " Main Application: http://your-server-ip:$SERVICE_PORT" echo " Admin Panel: http://your-server-ip:$SERVICE_PORT/admin" echo " Health Check: http://your-server-ip:$SERVICE_PORT/health" echo "" echo "โš™๏ธ Database Structure:" if command -v db &> /dev/null; then echo " Current passwordstrength settings:" if db configuration show passwordstrength &> /dev/null; then USERS_SETTING=$(db configuration getprop passwordstrength Users 2>/dev/null || echo "not set") ADMIN_SETTING=$(db configuration getprop passwordstrength Admin 2>/dev/null || echo "not set") IBAYS_SETTING=$(db configuration getprop passwordstrength Ibays 2>/dev/null || echo "not set") echo " Users: $USERS_SETTING" echo " Admin: $ADMIN_SETTING" echo " Ibays: $IBAYS_SETTING" else echo " passwordstrength configuration not found" fi echo " Configure via admin panel or:" echo " db configuration setprop passwordstrength Users [none|normal|strong]" echo " db configuration setprop passwordstrength Admin [none|normal|strong]" echo " db configuration setprop passwordstrength Ibays [none|normal|strong]" else echo " Use admin panel to configure password strength levels" fi echo "" echo "๐Ÿ”ง Service Management:" echo " Status: systemctl status $SERVICE_NAME" echo " Logs: journalctl -u $SERVICE_NAME -f" echo " Stop: systemctl stop $SERVICE_NAME" echo " Restart: systemctl restart $SERVICE_NAME" echo "" echo "๐Ÿงช Testing:" echo " Demo mode: python3 $APP_DIR/demo_mode.py (runs on port 5003)" echo "" else echo "โœ— Failed to start corrected service" echo "Check logs with: journalctl -u $SERVICE_NAME" echo "Check if port $SERVICE_PORT is available: netstat -tlnp | grep $SERVICE_PORT" exit 1 fi echo "Corrected SME Server Password Change Application installation completed!" echo "Now using the correct database structure and zxcvbn validation library!"