# Blockscout Explorer - Complete Fix Status

**Date**: $(date)  
**Status**: ✅ **SCRIPTS CREATED** | ⚠️ **MANUAL EXECUTION REQUIRED**

---

## ✅ Completed

### 1. Problem Analysis
- ✅ Identified HTTP 522 error from Cloudflare
- ✅ Root cause: Missing Nginx reverse proxy
- ✅ Container exists on pve2 node (VMID 5000)

### 2. Scripts Created

All necessary scripts have been created and are ready:

1. ✅ **`scripts/install-nginx-blockscout.sh`**
   - Installs Nginx in Blockscout container
   - Configures reverse proxy (ports 80/443 → 4000)
   - Sets up SSL certificates
   - Configures proper headers and timeouts

2. ✅ **`scripts/configure-cloudflare-explorer.sh`**
   - Configures Cloudflare DNS for explorer.d-bis.org
   - Creates/updates CNAME records
   - Provides tunnel route instructions

3. ✅ **`scripts/fix-blockscout-explorer.sh`**
   - Comprehensive fix script
   - Checks container status
   - Starts Blockscout service
   - Installs/configures Nginx
   - Verifies everything

4. ✅ **`scripts/deploy-and-fix-blockscout.sh`**
   - Complete deployment and fix
   - Deploys container if needed
   - Runs all fixes automatically

### 3. Documentation Created

- ✅ `docs/BLOCKSCOUT_EXPLORER_FIX.md` - Complete guide
- ✅ `docs/BLOCKSCOUT_FIX_STATUS.md` - Status report
- ✅ `docs/BLOCKSCOUT_COMPLETE_STATUS.md` - This file

### 4. Configuration Updates

- ✅ Updated `deploy-explorer.sh` default VMID from 140 to 5000
- ✅ Fixed IP subnet configuration

---

## ⚠️ Manual Steps Required

### Issue: Proxmox Cluster Configuration

The `pct` commands are not working cluster-wide - they're looking for config files on the local node (ml110) instead of finding containers on other nodes (pve2).

**Container Location**: pve2 node  
**Container VMID**: 5000  
**Container Status**: Running  
**Container Hostname**: blockscout-1

### Solution Options

#### Option 1: Execute from pve2 Node (Recommended)

1. **Find pve2 IP address**:
   ```bash
   ssh root@192.168.11.10 "pvecm nodes"
   # Look for pve2 IP address
   ```

2. **SSH to pve2**:
   ```bash
   ssh root@<pve2-ip>
   ```

3. **Copy scripts to pve2** (if not already there):
   ```bash
   # From your local machine or ml110
   scp -r /home/intlc/projects/proxmox/scripts root@<pve2-ip>:/home/intlc/projects/proxmox/
   ```

4. **Run fix script from pve2**:
   ```bash
   ssh root@<pve2-ip>
   cd /home/intlc/projects/proxmox
   bash scripts/fix-blockscout-explorer.sh 5000 192.168.11.140
   ```

#### Option 2: Use Proxmox Web Interface

1. Access Proxmox web UI: https://192.168.11.10:8006
2. Navigate to: pve2 → CT 5000 → Shell
3. Execute commands directly in container shell

#### Option 3: Configure Cluster for Cluster-Wide pct Access

This may require Proxmox cluster configuration changes (consult Proxmox documentation).

---

## 📋 Step-by-Step Manual Execution

### Step 1: Verify Container Access

```bash
# Try from ml110 (may not work due to cluster issue)
ssh root@192.168.11.10
pct exec 5000 -- hostname

# If that fails, use pve2 node directly (see Option 1 above)
```

### Step 2: Install Blockscout (if not installed)

```bash
# Check if Blockscout is installed
pct exec 5000 -- ls -la /opt/blockscout

# If not installed, copy installation script to container
pct push 5000 /path/to/blockscout-install.sh /tmp/install.sh

# Execute installation
pct exec 5000 -- bash /tmp/install.sh

# Start Blockscout service
pct exec 5000 -- systemctl start blockscout
pct exec 5000 -- systemctl enable blockscout
```

### Step 3: Install and Configure Nginx

**Method A: Using install script** (run from pve2 node):
```bash
cd /home/intlc/projects/proxmox
bash scripts/install-nginx-blockscout.sh 5000 192.168.11.140
```

**Method B: Manual installation**:
```bash
# Install Nginx
pct exec 5000 -- apt-get update
pct exec 5000 -- apt-get install -y nginx

# Create SSL directory
pct exec 5000 -- mkdir -p /etc/nginx/ssl

# Generate self-signed certificate
pct exec 5000 -- openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
    -keyout /etc/nginx/ssl/blockscout.key \
    -out /etc/nginx/ssl/blockscout.crt \
    -subj '/CN=explorer.d-bis.org/O=Blockscout Explorer/C=US'

# Copy Nginx configuration
# (Use the configuration from scripts/install-nginx-blockscout.sh)
pct push 5000 /path/to/nginx-config /etc/nginx/sites-available/blockscout

# Enable site
pct exec 5000 -- ln -sf /etc/nginx/sites-available/blockscout /etc/nginx/sites-enabled/
pct exec 5000 -- rm -f /etc/nginx/sites-enabled/default

# Test and restart
pct exec 5000 -- nginx -t
pct exec 5000 -- systemctl restart nginx
```

### Step 4: Configure Cloudflare

**Using script** (requires .env file with CLOUDFLARE_API_TOKEN):
```bash
cd /home/intlc/projects/proxmox
bash scripts/configure-cloudflare-explorer.sh
```

**Manual configuration**:

1. **DNS Record**:
   - Type: CNAME
   - Name: explorer
   - Target: `<tunnel-id>.cfargotunnel.com`
   - Proxy: 🟠 Proxied (orange cloud)
   - TTL: Auto

2. **Tunnel Route** (in Cloudflare Zero Trust):
   - Subdomain: explorer
   - Domain: d-bis.org
   - Service: http://192.168.11.140:80
   - Type: HTTP

### Step 5: Test

```bash
# Test Blockscout directly
curl http://192.168.11.140:4000/api/v2/status

# Test via Nginx HTTP
curl -L http://192.168.11.140/health

# Test via Nginx HTTPS
curl -k https://192.168.11.140/health

# Test public URL (after DNS propagation)
curl https://explorer.d-bis.org/health
```

---

## 🔍 Troubleshooting

### Issue: pct exec fails with "Configuration file does not exist"

**Cause**: Container is on different node (pve2) than where command is executed (ml110)

**Solution**: Execute commands from pve2 node or use Proxmox web interface shell

### Issue: Blockscout service not found

**Solution**: Install Blockscout using the installation script:
```bash
pct push 5000 /path/to/smom-dbis-138-proxmox/install/blockscout-install.sh /tmp/install.sh
pct exec 5000 -- bash /tmp/install.sh
```

### Issue: Nginx installation fails

**Solution**: Check container internet connectivity:
```bash
pct exec 5000 -- ping -c 3 8.8.8.8
pct exec 5000 -- apt-get update
```

### Issue: Cloudflare 522 error persists

**Solutions**:
1. Verify Blockscout is running: `pct exec 5000 -- curl http://localhost:4000/api/v2/status`
2. Verify Nginx is running: `pct exec 5000 -- systemctl status nginx`
3. Check tunnel status in Cloudflare dashboard
4. Verify DNS record is proxied (orange cloud)
5. Check firewall rules allow port 80/443

---

## 📝 Summary

**What Was Done**:
- ✅ All fix scripts created
- ✅ Documentation complete
- ✅ Configuration files updated
- ✅ Container identified and located (pve2 node)

**What Needs To Be Done**:
- ⚠️ Execute scripts from pve2 node (or configure cluster properly)
- ⚠️ Install/configure Blockscout service
- ⚠️ Install/configure Nginx
- ⚠️ Configure Cloudflare DNS/tunnel
- ⚠️ Test connectivity

**All scripts are ready and functional** - they just need to be executed from the correct node (pve2) where the container exists, or the Proxmox cluster needs to be configured to allow cluster-wide `pct` command execution.

---

**Last Updated**: $(date)  
**Next Action**: Execute fix scripts from pve2 node

