Files
StandalonePasswordChange/python-flask/smeserver-password-app/install.sh

170 lines
5.8 KiB
Bash
Raw Normal View History

#!/bin/bash
# Enhanced SME Server Password Change Application Installation Script
# Compatible with Python 3.6.8 and Flask 2.0.3
# Features: Configurable password strength, visibility toggles, real-time validation
set -e
# Configuration
APP_NAME="smeserver-password-app-enhanced"
APP_DIR="/opt/$APP_NAME"
SERVICE_NAME="smeserver-password-enhanced"
SERVICE_PORT=5000
PYTHON_BIN="/usr/bin/python3"
echo "Installing Enhanced SME Server Password Change Application..."
echo "Features: Configurable strength, password visibility, real-time validation"
# 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 enhanced 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 compatible with Python 3.6.8
echo "Installing Python dependencies (Enhanced version)..."
if command -v pip3 &> /dev/null; then
pip3 install Flask==2.0.3 Flask-CORS==3.0.10 Werkzeug==2.0.3
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
else
echo "Warning: Could not install Python dependencies automatically"
echo "Please install Flask 2.0.3 and Flask-CORS 3.0.10 manually"
fi
# Initialize password strength setting if not exists
echo "Initializing password strength configuration..."
if command -v db &> /dev/null; then
# Check if passwordstrength entry exists
if ! db configuration show passwordstrength &> /dev/null; then
echo "Creating passwordstrength configuration entry..."
db configuration set passwordstrength service
db configuration setprop passwordstrength Passwordstrength normal
echo "Password strength set to 'normal' (default)"
else
CURRENT_STRENGTH=$(db configuration getprop passwordstrength Passwordstrength 2>/dev/null || echo "normal")
echo "Existing password strength setting: $CURRENT_STRENGTH"
fi
else
echo "Warning: SME Server database tools not available"
echo "Password strength will default to 'normal' in demo mode"
fi
# Create systemd service file
echo "Creating enhanced systemd service..."
cat > "/etc/systemd/system/$SERVICE_NAME.service" << EOF
[Unit]
Description=Enhanced 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 enhanced service..."
systemctl daemon-reload
systemctl enable "$SERVICE_NAME"
# Start the service
echo "Starting enhanced 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 "✓ Enhanced SME Server Password Change Application installed successfully!"
echo ""
echo "🔒 Features Available:"
echo " ✓ Configurable password strength validation (None/Normal/Strong)"
echo " ✓ Password visibility toggles for all password fields"
echo " ✓ Real-time password strength indicator"
echo " ✓ Admin configuration panel"
echo " ✓ Enhanced crypto validation and pattern detection"
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 "⚙️ Configuration:"
if command -v db &> /dev/null; then
CURRENT_STRENGTH=$(db configuration getprop passwordstrength Passwordstrength 2>/dev/null || echo "normal")
echo " Current password strength: $CURRENT_STRENGTH"
echo " Change via admin panel or: db configuration setprop passwordstrength Passwordstrength [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 5002)"
echo ""
else
echo "✗ Failed to start enhanced 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 "Enhanced SME Server Password Change Application installation completed!"
echo "Enjoy the new configurable password strength and visibility features!"