# SAP Business One ↔ Plesk Synchronisations-Webapp Eine Enterprise-Webapp zur automatischen Synchronisation zwischen SAP Business One (Systemhaus One) und Plesk Webservern fΓΌr die Abrechnung von Verbrauchskosten. ## πŸ“ Projektstruktur ``` sap-sync-app/ β”œβ”€β”€ backend/ # Rust Backend (Axum + Tokio) β”‚ β”œβ”€β”€ src/ β”‚ β”‚ β”œβ”€β”€ main.rs # Entry Point β”‚ β”‚ β”œβ”€β”€ config/ # Configuration Management β”‚ β”‚ β”œβ”€β”€ db/ # Database Pool & Migrations β”‚ β”‚ β”œβ”€β”€ handlers/ # API Endpoints β”‚ β”‚ β”œβ”€β”€ models/ # Data Models β”‚ β”‚ β”œβ”€β”€ routes/ # API Routes β”‚ β”‚ β”œβ”€β”€ services/ # Business Logic β”‚ β”‚ β”œβ”€β”€ utils/ # Utilities β”‚ β”‚ └── state.rs # Application State β”‚ β”œβ”€β”€ Cargo.toml # Rust Dependencies β”‚ └── Dockerfile # Backend Container β”œβ”€β”€ frontend/ # React Frontend (MUI) β”‚ β”œβ”€β”€ src/ β”‚ β”‚ β”œβ”€β”€ App.tsx # Main Application β”‚ β”‚ β”œβ”€β”€ components/ # React Components β”‚ β”‚ β”œβ”€β”€ contexts/ # Auth & I18n Contexts β”‚ β”‚ β”œβ”€β”€ pages/ # React Pages β”‚ β”‚ └── main.tsx # Entry Point β”‚ β”œβ”€β”€ package.json # Node Dependencies β”‚ └── Dockerfile # Frontend Container β”œβ”€β”€ database/ β”‚ β”œβ”€β”€ init.sql # PostgreSQL Schema β”‚ └── seeds/ # Seed Data β”œβ”€β”€ nginx/ β”‚ └── nginx.conf # Reverse Proxy Config β”œβ”€β”€ docker-compose.yml # Multi-Service Setup β”œβ”€β”€ .env.example # Environment Template └── README.md # This File ``` ## βœ… Features (Phase 1 & 2) ### Authentication & Security - βœ… **Session-based Auth**: PostgreSQL Session Store - βœ… **Password Policy**: Min 8 chars, Groß-/Kleinbuchstaben, Ziffern, Sonderzeichen - βœ… **Brute Force Protection**: 5 fehlgeschlagene Versuche β†’ 1 Stunde Lockout - βœ… **CSRF Protection**: Token-basiert (24h expiry) - βœ… **MFA**: Optional TOTP (Google Authenticator, Authy) - βœ… **Secure Cookies**: HTTP-only, Secure, SameSite Strict ### SAP Integration - βœ… **Service Layer API Client**: REST API Verbindung - βœ… **OAuth2 Authentication**: Sichere Authentifizierung - βœ… **Customer Management**: Get, Create, Update - βœ… **Item Management**: FΓΌr Abonnements - βœ… **Contract Management**: Vertragsdaten - βœ… **Connection Testing**: Health Checks ### Plesk Integration - βœ… **REST API Client**: Plesk API v2 - βœ… **Customer Management**: CRUD Operations - βœ… **Subscription Management**: Webspaces, Domains - βœ… **Usage Metrics**: CPU, RAM, Disk, Bandwidth - βœ… **Connection Testing**: Health Checks ### Sync Engine - βœ… **Worker Pool**: Tokio-basierte Parallelverarbeitung - βœ… **Conflict Resolution**: 4 Strategien (SAP First, Plesk First, Manual, Timestamp) - βœ… **Bidirectional Sync**: SAP ↔ Plesk - βœ… **Progress Tracking**: Echtzeit-Status - βœ… **Error Handling**: Retry Logic - βœ… **Job Queue**: Asynchrone Verarbeitung ### Reports & Analytics - βœ… **Revenue Report**: UmsatzΓΌbersicht - βœ… **Usage Report**: Verbrauchsmetriken - βœ… **Sync History**: Synchronisations-Historie - βœ… **Export**: CSV, Excel (xlsx), PDF ### Notifications - βœ… **Email Notifications**: SMTP (Lettre) - βœ… **Webhooks**: HTTP Callbacks - βœ… **Dashboard Alerts**: Real-time Status - βœ… **Error Notifications**: Bei Fehlern ### Frontend - βœ… **Dashboard**: Übersicht, Status, Stats - βœ… **Sync Control**: Start, Stop, Monitor - βœ… **Reports**: Charts, Export - βœ… **Settings**: Profile, Security, Sync Config - βœ… **Multi-Language**: DE, FR, EN, SPA ### Infrastructure - βœ… **Docker Compose**: Multi-Container Setup - βœ… **Nginx**: Reverse Proxy, SSL, Rate Limiting - βœ… **PostgreSQL**: Database - βœ… **Redis**: Caching - βœ… **pgAdmin**: Database Management UI - βœ… **MailHog**: SMTP Test Server ## πŸ›  Tech Stack ### Backend - **Language**: Rust 1.75+ - **Framework**: Axum 0.7 - **Async Runtime**: Tokio 1.35 - **Database**: PostgreSQL 15 + sqlx 0.7 - **HTTP Client**: reqwest 0.11 - **Auth**: tower-session + PostgreSQL Store - **Security**: Argon2, CSRF, TOTP ### Frontend - **Framework**: React 18 - **Build Tool**: Vite 5 - **UI Library**: Material UI 5.14 - **Routing**: React Router 6 - **HTTP Client**: Axios 1.6 - **Charts**: Recharts 2.10 - **i18n**: i18next 23 ### Infrastructure - **Container**: Docker 24+ - **Orchestration**: Docker Compose - **Proxy**: Nginx Alpine - **Database**: PostgreSQL 15 Alpine - **Cache**: Redis 7 Alpine - **Management**: pgAdmin 4 ## πŸš€ Quick Start ### 1. Voraussetzungen - Docker 24.0+ installiert - Docker Compose 2.20+ installiert - Git installiert - Min. 4 GB RAM, 20 GB Speicher ### 2. Installation ```bash # Repository klonen git clone cd sap-sync-app # Umgebungsvariablen konfigurieren cp .env.example .env # .env mit echten Werten bearbeiten # Alle Services starten docker-compose up -d # Logs ΓΌberprΓΌfen docker-compose logs -f ``` ### 3. Erste Schritte ```bash # Admin-User erstellen (wird beim ersten Start automatisch erstellt) # Default: username: admin, password: # Zugriff: # Frontend: http://localhost:3000 # Backend API: http://localhost:3001/api # pgAdmin: http://localhost:8080 # MailHog: http://localhost:8025 ``` ### 4. SAP & Plesk konfigurieren 1. **SAP Service Layer**: - URL und Credentials in `.env` eintragen - `APP__SAP__URL` und `APP__SAP__CREDENTIALS` 2. **Plesk API**: - API Key generieren in Plesk - In `.env` eintragen: `APP__PLESK__API_KEY` 3. **Sync konfigurieren**: - Frontend ΓΆffnen β†’ Settings β†’ Sync Settings - Default Direction wΓ€hlen - Conflict Resolution festlegen ## πŸ“Š API Endpoints ### Authentication ``` POST /api/auth/login # Login POST /api/auth/logout # Logout GET /api/auth/me # Current User POST /api/auth/change-password # Change Password GET /api/auth/csrf-token # Get CSRF Token ``` ### Sync Management ``` GET /api/sync/status # Sync Status POST /api/sync/start # Start Sync POST /api/sync/stop # Stop Sync GET /api/sync/jobs # List Jobs GET /api/sync/jobs/:id # Job Details ``` ### Configuration ``` GET /api/config # Get Config PUT /api/config # Update Config ``` ### Reports ``` GET /api/reports/revenue # Revenue Report GET /api/reports/usage # Usage Report GET /api/reports/sync-history # Sync History GET /api/reports/export/:format # Export (csv/xlsx/pdf) ``` ### Health & Monitoring ``` GET /api/health # Overall Health GET /api/health/sap # SAP Connection GET /api/health/plesk # Plesk Connection ``` ### Notifications ``` GET /api/notifications # List Notifications PUT /api/notifications/:id/read # Mark as Read POST /api/webhooks # Create Webhook GET /api/webhooks # List Webhooks ``` ## πŸ”§ Konfiguration ### .env Beispiel ```env # Database DB_PASSWORD=your_secure_password DATABASE_URL=postgresql://sap_user:${DB_PASSWORD}@pgsql:5432/sap_sync # Backend APP__SERVER__HOST=0.0.0.0 APP__SERVER__PORT=3001 APP__SESSION__SECURE=false APP__MFA__ENABLED=true # SAP Connection APP__SAP__URL=https://sap-server:50000/b1s/v1 APP__SAP__COMPANY_DB=SBODemoDE APP__SAP__USERNAME=manager APP__SAP__PASSWORD=manager # Plesk Connection APP__PLESK__URL=https://plesk-server:8443/api/v2 APP__PLESK__API_KEY=your-api-key # Email (SMTP) SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USERNAME=your_email@gmail.com SMTP_PASSWORD=your_app_password SMTP_FROM=noreply@sap-sync.local # Frontend VITE_API_URL=http://localhost:3001/api ``` ## πŸ—„οΈ Datenbank-Schema ### Haupttabellen - **users**: Admin-Benutzer - **sessions**: Session Management - **customers**: SAP ↔ Plesk Customer Mapping - **subscriptions**: Abonnements/VertrΓ€ge - **usage_metrics**: Verbrauchsdaten - **sync_jobs**: Sync-Jobs Queue - **sync_logs**: Synchronisations-Logs - **notifications**: Benachrichtigungen - **webhooks**: Webhook-Konfiguration - **config**: System-Konfiguration ### Erweiterte Features - **JSONB Columns**: Flexible Datenspeicherung - **GIN/GIST Indexes**: Schnelle JSON-Suche - **Materialized Views**: Dashboard Performance - **Triggers**: Automatische Timestamps - **Full-text Search**: Kunden-Suche ## πŸ”’ Sicherheit ### Password Policy - Min 8 Zeichen - Min 1 Großbuchstabe (A-Z) - Min 1 Kleinbuchstabe (a-z) - Min 1 Ziffer (0-9) - Min 1 Sonderzeichen (!@#$%&*) ### Session Security - HTTP-only Cookies - Secure Flag (HTTPS) - SameSite Strict - 30 Minuten Expiry - Remember Me (7 Tage) ### Rate Limiting - General API: 10 req/s - Auth Endpoints: 5 req/min - Nginx Built-in ## πŸ“ˆ Performance ### Backend - Async Rust (Tokio) - Connection Pooling (sqlx) - Worker Pool (Sync Engine) - JSONB Queries (PostgreSQL) ### Frontend - React 18 (Concurrent Rendering) - Vite (Fast Build) - Code Splitting - Lazy Loading ## πŸ§ͺ Testing ```bash # Backend Tests cd backend cargo test # Frontend Tests cd frontend npm test # Integration Tests docker-compose -f docker-compose.test.yml up ``` ## πŸ“¦ Production Deployment ### Plesk Deployment 1. **Docker auf Plesk Server**: ```bash # Docker installieren curl -fsSL https://get.docker.com | bash # Repository klonen git clone /opt/sap-sync cd /opt/sap-sync ``` 2. **SSL Zertifikate**: ```bash # Certbot fΓΌr Let's Encrypt certbot certonly --standalone -d your-domain.com # Zertifikate kopieren cp /etc/letsencrypt/live/your-domain.com/fullchain.pem nginx/ssl/cert.pem cp /etc/letsencrypt/live/your-domain.com/privkey.pem nginx/ssl/key.pem ``` 3. **Environment konfigurieren**: ```bash cp .env.example .env # .env bearbeiten mit Production-Werten ``` 4. **Services starten**: ```bash docker-compose up -d ``` 5. **Plesk Proxy**: - Nginx Proxy in Plesk konfigurieren - Domain β†’ Apache & nginx Settings β†’ Additional nginx directives ```nginx location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } ``` ## πŸ› Troubleshooting ### Backend startet nicht ```bash # Logs prΓΌfen docker-compose logs backend # Database Connection testen docker-compose exec backend psql $DATABASE_URL -c "SELECT 1" ``` ### Frontend Build Fehler ```bash # Dependencies neu installieren cd frontend rm -rf node_modules package-lock.json npm install npm run build ``` ### SAP/Plesk Connection Failed ```bash # Connection testen curl -X GET http://localhost:3001/api/health/sap curl -X GET http://localhost:3001/api/health/plesk # Credentials prΓΌfen docker-compose exec backend env | grep SAP docker-compose exec backend env | grep PLESK ``` ## πŸ“ Development ### Backend Development ```bash cd backend # Rust installieren (falls nicht vorhanden) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Cargo Watch fΓΌr Hot Reload cargo install cargo-watch cargo watch -x run # Tests cargo test ``` ### Frontend Development ```bash cd frontend # Dependencies npm install # Dev Server npm run dev # Build npm run build ``` ## πŸ“„ License MIT License - siehe LICENSE Datei ## 🀝 Contributing 1. Fork erstellen 2. Feature Branch (`git checkout -b feature/AmazingFeature`) 3. Committen (`git commit -m 'Add some AmazingFeature'`) 4. Push (`git push origin feature/AmazingFeature`) 5. Pull Request ΓΆffnen ## πŸ“ž Support - **Issues**: GitHub Issues - **Documentation**: `/docs` Ordner - **Email**: support@sap-sync.local --- **Erstellt mit ❀️ fΓΌr Enterprise SAP ↔ Plesk Synchronisation**