# Whitelist Manager - Manual Deployment Guide

## Prerequisites
- SSH access to Billing VPS (38.68.14.188)
- Root privileges
- DNS record configured: `whitelist.firefrostgaming.com` → `38.68.14.188`

## Step-by-Step Deployment

### 1. Connect to Billing VPS
```bash
ssh root@38.68.14.188
```

### 2. Install System Dependencies
```bash
apt update
```

```bash
apt install -y python3 python3-pip python3-venv nginx certbot python3-certbot-nginx
```

### 3. Create Application Directory
```bash
mkdir -p /opt/whitelist-manager/templates
```

```bash
cd /opt/whitelist-manager
```

### 4. Create app.py
```bash
nano app.py
```
Copy the contents from: `deployments/whitelist-manager/app.py`
Save with: Ctrl+O, Enter, Ctrl+X

### 5. Create requirements.txt
```bash
nano requirements.txt
```
Copy the contents from: `deployments/whitelist-manager/requirements.txt`
Save with: Ctrl+O, Enter, Ctrl+X

### 6. Create .env file
```bash
nano .env
```
Copy the contents from: `deployments/whitelist-manager/.env`
Save with: Ctrl+O, Enter, Ctrl+X

### 7. Create HTML Template
```bash
nano templates/index.html
```
Copy the contents from: `deployments/whitelist-manager/templates/index.html`
Save with: Ctrl+O, Enter, Ctrl+X

### 8. Install Python Dependencies
```bash
pip3 install -r requirements.txt --break-system-packages
```

### 9. Test the Application
```bash
python3 app.py
```
You should see: `Running on http://0.0.0.0:5001`
Press Ctrl+C to stop

### 10. Create systemd Service
```bash
nano /etc/systemd/system/whitelist-manager.service
```
Copy the contents from: `deployments/whitelist-manager/whitelist-manager.service`
Save with: Ctrl+O, Enter, Ctrl+X

### 11. Enable and Start Service
```bash
systemctl daemon-reload
```

```bash
systemctl enable whitelist-manager
```

```bash
systemctl start whitelist-manager
```

```bash
systemctl status whitelist-manager
```
Should show "active (running)" in green

### 12. Configure Nginx
```bash
nano /etc/nginx/sites-available/whitelist.firefrostgaming.com
```
Copy the contents from: `deployments/whitelist-manager/nginx.conf`
Save with: Ctrl+O, Enter, Ctrl+X

### 13. Enable Nginx Site
```bash
ln -s /etc/nginx/sites-available/whitelist.firefrostgaming.com /etc/nginx/sites-enabled/
```

```bash
nginx -t
```
Should say "syntax is ok" and "test is successful"

```bash
systemctl reload nginx
```

### 14. Obtain SSL Certificate
**IMPORTANT:** Make sure DNS is configured first!

Check DNS propagation:
```bash
nslookup whitelist.firefrostgaming.com
```
Should return: 38.68.14.188

If DNS is ready:
```bash
certbot --nginx -d whitelist.firefrostgaming.com --email mkrause612@gmail.com
```

Follow the prompts:
- Agree to terms: Yes
- Share email: Your choice
- Redirect HTTP to HTTPS: Yes (recommended)

### 15. Verify Deployment

Test the service:
```bash
curl http://localhost:5001/health
```
Should return: `{"service":"whitelist-manager","status":"healthy"}`

Test via web browser:
```
https://whitelist.firefrostgaming.com
```

Login with:
- Username: `mkrause612`
- Password: `Butter2018!!`

## Useful Commands

### Service Management
```bash
# View service status
systemctl status whitelist-manager

# View live logs
journalctl -u whitelist-manager -f

# Restart service
systemctl restart whitelist-manager

# Stop service
systemctl stop whitelist-manager
```

### Nginx Management
```bash
# Test configuration
nginx -t

# Reload configuration
systemctl reload nginx

# View access logs
tail -f /var/log/nginx/whitelist.access.log

# View error logs
tail -f /var/log/nginx/whitelist.error.log
```

### Application Logs
```bash
# Last 50 lines
journalctl -u whitelist-manager -n 50

# Follow logs in real-time
journalctl -u whitelist-manager -f

# Logs from last hour
journalctl -u whitelist-manager --since "1 hour ago"
```

## Troubleshooting

### Service won't start
```bash
# Check detailed status
systemctl status whitelist-manager

# Check logs
journalctl -u whitelist-manager -n 100

# Common issues:
# - Missing .env file
# - Wrong Python path
# - Port 5001 already in use
```

### Can't access via browser
```bash
# Check if service is running
systemctl status whitelist-manager

# Check if Nginx is running
systemctl status nginx

# Check if port 5001 is listening
netstat -tuln | grep 5001

# Check Nginx error logs
tail -f /var/log/nginx/whitelist.error.log
```

### SSL certificate issues
```bash
# Verify DNS first
nslookup whitelist.firefrostgaming.com

# Check certificate status
certbot certificates

# Renew certificate manually
certbot renew --force-renewal
```

## Post-Deployment

After successful deployment:

1. **Test all functions:**
   - Login works
   - Server list displays
   - Add player works
   - Remove player works
   - Bulk operations work

2. **Backup credentials:**
   - Store in Vaultwarden
   - API key: `ptlc_vudB5oRaeoJGPip4fH5PDiymgi28uc39OjJsCbTDVEK`
   - Dashboard login: `mkrause612 / Butter2018!!`

3. **Documentation:**
   - Update infrastructure manifest
   - Create usage guide for Meg and staff
   - Document in Wiki.js

## Fire + Frost + Foundation = Where Love Builds Legacy 💙🔥❄️
