# 🌐 Panel Admin Web Sentinel - Production

## 🎯 Accès Production

### URL Publique
👉 **https://admin.web-sentinel.taaazzz-prog.fr**

### Connexion depuis le site
1. Aller sur https://web-sentinel.taaazzz-prog.fr/account.html
2. Se connecter avec un compte **SYSOP**
3. Cliquer sur **"🛠️ Panel Admin"** (bouton violet à droite de "Se déconnecter")

## 🏗️ Architecture Déployée

```
┌─────────────────────────────────────────────────────────┐
│              Internet (HTTPS/443)                        │
└───────────────────────┬─────────────────────────────────┘
                        │
              ┌─────────▼──────────┐
              │ Traefik Reverse    │
              │ Proxy + SSL        │
              └─────────┬──────────┘
                        │
          ┌─────────────┴──────────────┐
          │                            │
  ┌───────▼────────┐         ┌────────▼─────────┐
  │ Frontend       │   API   │ Backend          │
  │ React (Nginx)  ├────────▶│ FastAPI          │
  │ Port 80        │         │ Port 8000        │
  └────────────────┘         └────────┬─────────┘
                                      │
                            ┌─────────▼──────────┐
                            │ PostgreSQL         │
                            │ (web-sentinel-db)  │
                            └────────────────────┘
```

## 🚀 Déploiement

### Méthode automatique (recommandée)

```bash
cd deployment
./deploy_admin.sh
```

### Méthode manuelle

```powershell
# 1. Copier les fichiers
scp -r admin/ taaazzz@web-sentinel.taaazzz-prog.fr:~/web-sentinel/
scp deployment/docker-compose.admin.yml taaazzz@web-sentinel.taaazzz-prog.fr:~/web-sentinel/deployment/
scp deployment/.env.admin taaazzz@web-sentinel.taaazzz-prog.fr:~/web-sentinel/deployment/

# 2. Build et démarrage
ssh taaazzz@web-sentinel.taaazzz-prog.fr
cd ~/web-sentinel/deployment
docker-compose -f docker-compose.admin.yml build
docker-compose -f docker-compose.admin.yml up -d

# 3. Vérification
docker ps | grep admin
docker logs web-sentinel-admin-backend
docker logs web-sentinel-admin-frontend
```

## 📝 Configuration DNS

Ajouter ces enregistrements DNS chez OVH :

| Type | Nom | Valeur |
|------|-----|--------|
| A | `admin.web-sentinel.taaazzz-prog.fr` | IP du serveur OVH |
| A | `admin-api.web-sentinel.taaazzz-prog.fr` | IP du serveur OVH |

⏱️ **Propagation DNS** : 1-24h

## 🔧 Configuration

### 1. Générer la clé secrète

```bash
ssh taaazzz@web-sentinel.taaazzz-prog.fr
openssl rand -hex 32
```

### 2. Modifier .env.admin

```bash
cd ~/web-sentinel/deployment
nano .env.admin
```

Remplacer `CHANGE_ME_RANDOM_STRING_HERE` par la clé générée.

### 3. Redémarrer le backend

```bash
docker-compose -f docker-compose.admin.yml restart admin-backend
```

## 🔄 Mise à jour du bouton account.html

Actuellement, le bouton pointe vers `http://localhost:5173`. Il faut le modifier :

### Fichier : `web/account.html` (ligne ~250)

**Avant :**
```javascript
onclick="window.open('http://localhost:5173', '_blank')"
```

**Après :**
```javascript
onclick="window.open('https://admin.web-sentinel.taaazzz-prog.fr', '_blank')"
```

### Déploiement de la modification

```powershell
scp web/account.html taaazzz@web-sentinel.taaazzz-prog.fr:~/web-sentinel/web/
ssh taaazzz@web-sentinel.taaazzz-prog.fr "docker restart web-sentinel-web"
```

## ✅ Tests

### 1. Vérifier les conteneurs

```bash
ssh taaazzz@web-sentinel.taaazzz-prog.fr
docker ps | grep admin
```

Devrait afficher :
```
web-sentinel-admin-backend    (running)
web-sentinel-admin-frontend   (running)
```

### 2. Tester l'API

```bash
curl https://admin-api.web-sentinel.taaazzz-prog.fr/api/health
```

### 3. Accéder au panel

1. Ouvrir https://admin.web-sentinel.taaazzz-prog.fr
2. Vérifier que la page charge
3. Vérifier qu'il n'y a pas d'erreur CORS dans la console

## 🐛 Dépannage

### Problème : 502 Bad Gateway

**Cause** : Le backend ne répond pas

**Solution** :
```bash
docker logs web-sentinel-admin-backend
docker restart web-sentinel-admin-backend
```

### Problème : CORS Error

**Cause** : Configuration CORS incorrecte

**Solution** : Vérifier `.env.admin` :
```bash
cat ~/web-sentinel/deployment/.env.admin
```

Doit contenir :
```
ALLOWED_ORIGINS=https://admin.web-sentinel.taaazzz-prog.fr
CORS_ORIGINS=https://admin.web-sentinel.taaazzz-prog.fr
```

### Problème : Cannot connect to database

**Cause** : Le backend n'accède pas à PostgreSQL

**Solution** : Connecter au même réseau Docker :
```bash
# Vérifier quel réseau utilise web-sentinel-db
docker inspect web-sentinel-db | grep NetworkMode

# Connecter admin-backend au même réseau
docker network connect faildaily-network web-sentinel-admin-backend
docker network connect faildaily-network web-sentinel-admin-frontend
docker restart web-sentinel-admin-backend
```

### Problème : Le panel affiche "Failed to fetch"

**Cause** : Le frontend ne peut pas joindre l'API backend

**Solution** :
```bash
# Vérifier que l'API est accessible publiquement
curl https://admin-api.web-sentinel.taaazzz-prog.fr/api/licenses

# Vérifier les logs backend
docker logs web-sentinel-admin-backend -f
```

## 📊 Monitoring

### Logs en temps réel

```bash
# Backend
docker logs -f web-sentinel-admin-backend

# Frontend
docker logs -f web-sentinel-admin-frontend

# Traefik (pour les routes)
docker logs -f faildaily-traefik-ssl | grep admin
```

### Utilisation des ressources

```bash
docker stats web-sentinel-admin-backend web-sentinel-admin-frontend
```

## 🔐 Sécurité

### ✅ Ce qui est sécurisé
- ✅ HTTPS obligatoire (Let's Encrypt)
- ✅ Reverse proxy Traefik
- ✅ Pas d'accès direct aux ports
- ✅ Base de données non exposée publiquement

### ⚠️ Recommandations
- Changer régulièrement `ADMIN_SECRET_KEY`
- Limiter l'accès au bouton (tier SYSOP uniquement)
- Surveiller les logs d'accès
- Sauvegarder la configuration `.env.admin`

## 🔄 Maintenance

### Mise à jour du panel

```bash
# Depuis le PC local
git pull origin main
cd deployment
./deploy_admin.sh
```

### Sauvegarde

```bash
ssh taaazzz@web-sentinel.taaazzz-prog.fr
tar -czf ~/backup_admin_$(date +%Y%m%d).tar.gz \
  ~/web-sentinel/admin \
  ~/web-sentinel/deployment/.env.admin \
  ~/web-sentinel/deployment/docker-compose.admin.yml
```

### Restauration

```bash
ssh taaazzz@web-sentinel.taaazzz-prog.fr
cd ~
tar -xzf backup_admin_YYYYMMDD.tar.gz
cd ~/web-sentinel/deployment
docker-compose -f docker-compose.admin.yml up -d --build
```

## 📞 Support

Guide complet : [DEPLOY_ADMIN_PRODUCTION.md](DEPLOY_ADMIN_PRODUCTION.md)

En cas de problème :
1. Vérifier les logs Docker
2. Vérifier la configuration DNS
3. Vérifier les certificats SSL (Traefik)
4. Vérifier la connectivité réseau
5. Vérifier le fichier `.env.admin`
