HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/ezdns-hostbill-db-setup.php
<?php
/**
 * ezDNS.support HostBill Database Setup Script
 * 
 * Dieses Skript konfiguriert ezdns.support direkt über die HostBill-Datenbank
 */

// HostBill Konfiguration laden
require_once '/home/support.panomity.com/public_html/includes/config.php';

echo "=== ezDNS.support HostBill Database Setup ===\n\n";
echo "Verbindung zur Datenbank wird hergestellt...\n\n";

try {
    // Datenbankverbindung herstellen (direkt mit Daten aus config.php)
    $pdo = new PDO(
        "mysql:host=localhost;dbname=suppo_db;port=3306",
        'suppo_db',
        'Mat36k4WS84Su9Fw61',
        [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
    );
    
    echo "✅ Datenbankverbindung erfolgreich!\n\n";
    
    // Klasse für Datenbank-Operationen
    class EzDNSDatabaseSetup {
        private $pdo;
        private $brandId = 26; // ezdns.support Brand ID
        
        public function __construct($pdo) {
            $this->pdo = $pdo;
        }
        
        /**
         * Brand erstellen oder aktualisieren
         */
        public function setupBrand() {
            echo "\n=== Schritt 1: Brand-Konfiguration ===\n";
            
            // Prüfen ob Brand bereits existiert
            $stmt = $this->pdo->prepare("SELECT brand_id FROM hb_brands WHERE name = ?");
            $stmt->execute(['ezdns.support']);
            $existing = $stmt->fetch(PDO::FETCH_ASSOC);
            
            if ($existing) {
                echo "Brand 'ezdns.support' bereits vorhanden (ID: {$existing['brand_id']}) - aktualisiere...\n";
                
                $this->brandId = $existing['brand_id'];
                
                // Brand aktualisieren
                $sql = "UPDATE hb_brands SET 
                    url = ?,
                    active = 1,
                    custom = ?
                    WHERE brand_id = ?";
                
                $stmt = $this->pdo->prepare($sql);
                $stmt->execute([
                    'https://ezdns.support',
                    json_encode([
                        'theme' => 'default',
                        'language' => 'de',
                        'currency' => 'EUR',
                        'timezone' => 'Europe/Berlin',
                        'date_format' => 'dd.mm.YYYY'
                    ]),
                    $this->brandId
                ]);
                
                echo "✅ Brand aktualisiert!\n";
                return $this->brandId;
            } else {
                echo "Erstelle neues Brand...\n";
                
                // Neues Brand erstellen
                $sql = "INSERT INTO hb_brands (
                    name, url, active, custom
                ) VALUES (?, ?, 1, ?)";
                
                $stmt = $this->pdo->prepare($sql);
                $stmt->execute([
                    'ezdns.support',
                    'https://ezdns.support',
                    json_encode([
                        'theme' => 'default',
                        'language' => 'de',
                        'currency' => 'EUR',
                        'timezone' => 'Europe/Berlin',
                        'date_format' => 'dd.mm.YYYY'
                    ])
                ]);
                
                $this->brandId = $this->pdo->lastInsertId();
                echo "✅ Brand erstellt mit ID: $this->brandId\n";
                return $this->brandId;
            }
        }
        
        /**
         * Support Department erstellen
         */
        public function setupSupportDepartment() {
            echo "\n=== Schritt 2: Support Department ===\n";
            
            // Prüfen ob Department bereits existiert
            $stmt = $this->pdo->prepare("SELECT id FROM hb_departments WHERE name = ? AND brand_id = ?");
            $stmt->execute(['DNS Support', $this->brandId]);
            $existing = $stmt->fetch(PDO::FETCH_ASSOC);
            
            if ($existing) {
                echo "DNS Support Department bereits vorhanden (ID: {$existing['id']})\n";
                return $existing['id'];
            }
            
            // Department erstellen
            $sql = "INSERT INTO hb_departments (
                name, description, email, brand_id, active, created_at
            ) VALUES (?, ?, ?, ?, 1, NOW())";
            
            $stmt = $this->pdo->prepare($sql);
            $stmt->execute([
                'DNS Support',
                'Support für DNS-Services, DNSSEC, SPF/DKIM/DMARC und Performance-Checks',
                'dns@ezdns.support',
                $this->brandId
            ]);
            
            $deptId = $this->pdo->lastInsertId();
            echo "✅ DNS Support Department erstellt (ID: $deptId)\n";
            return $deptId;
        }
        
        /**
         * Produkte erstellen
         */
        public function setupProducts() {
            echo "\n=== Schritt 3: Produkte ===\n";
            
            $products = [
                [
                    'name' => 'DNS Check Free',
                    'type' => 'service',
                    'category' => 'DNS Services',
                    'description' => 'Grundlegender DNS-Check für eine Domain mit basis Analytik',
                    'price' => 0.00,
                    'setup' => 0.00,
                    'billing_cycle' => 'once',
                    'active' => 1,
                    'brand_id' => $this->brandId,
                    'features' => json_encode([
                        'scans_per_month' => 1,
                        'delegation_check' => true,
                        'dnssec_check' => true,
                        'mail_security_check' => false,
                        'performance_check' => false,
                        'pdf_export' => false,
                        'csv_export' => false,
                        'email_notifications' => false,
                        'historical_data' => false,
                        'api_access' => false
                    ])
                ],
                [
                    'name' => 'DNS Check Pro',
                    'type' => 'service',
                    'category' => 'DNS Services',
                    'description' => 'Umfassender DNS-Check mit Reports und Benachrichtigungen',
                    'price' => 9.00,
                    'setup' => 0.00,
                    'billing_cycle' => 'monthly',
                    'active' => 1,
                    'brand_id' => $this->brandId,
                    'features' => json_encode([
                        'scans_per_month' => -1,
                        'delegation_check' => true,
                        'dnssec_check' => true,
                        'mail_security_check' => true,
                        'performance_check' => true,
                        'pdf_export' => true,
                        'csv_export' => true,
                        'email_notifications' => true,
                        'historical_data' => true,
                        'api_access' => true
                    ])
                ],
                [
                    'name' => 'DNS Check Business',
                    'type' => 'service',
                    'category' => 'DNS Services',
                    'description' => 'Multi-Domain DNS-Monitoring mit erweiterten Features',
                    'price' => 29.00,
                    'setup' => 0.00,
                    'billing_cycle' => 'monthly',
                    'active' => 1,
                    'brand_id' => $this->brandId,
                    'features' => json_encode([
                        'scans_per_month' => -1,
                        'max_domains' => 10,
                        'delegation_check' => true,
                        'dnssec_check' => true,
                        'mail_security_check' => true,
                        'performance_check' => true,
                        'pdf_export' => true,
                        'csv_export' => true,
                        'email_notifications' => true,
                        'historical_data' => true,
                        'api_access' => true,
                        'white_label_reports' => true,
                        'priority_support' => true,
                        'team_users' => 5,
                        'webhook_notifications' => true,
                        'extended_api_limits' => true
                    ])
                ],
                [
                    'name' => 'DNS Check Agency',
                    'type' => 'service',
                    'category' => 'DNS Services',
                    'description' => 'Reseller-Programm für DNS-Services mit vollem Support',
                    'price' => 99.00,
                    'setup' => 0.00,
                    'billing_cycle' => 'monthly',
                    'active' => 1,
                    'brand_id' => $this->brandId,
                    'features' => json_encode([
                        'scans_per_month' => -1,
                        'max_domains' => -1,
                        'delegation_check' => true,
                        'dnssec_check' => true,
                        'mail_security_check' => true,
                        'performance_check' => true,
                        'pdf_export' => true,
                        'csv_export' => true,
                        'email_notifications' => true,
                        'historical_data' => true,
                        'api_access' => true,
                        'white_label_reports' => true,
                        'priority_support' => true,
                        'team_users' => -1,
                        'webhook_notifications' => true,
                        'extended_api_limits' => true,
                        'custom_branding' => true,
                        'reseller_pricing' => true,
                        'dedicated_account_manager' => true,
                        'support_24_7' => true,
                        'affiliate_access' => true
                    ])
                ]
            ];
            
            foreach ($products as $product) {
                // Prüfen ob Produkt bereits existiert
                $stmt = $this->pdo->prepare("SELECT id FROM hb_products WHERE name = ? AND brand_id = ?");
                $stmt->execute([$product['name'], $this->brandId]);
                $existing = $stmt->fetch(PDO::FETCH_ASSOC);
                
                if ($existing) {
                    echo "Produkt '{$product['name']}' bereits vorhanden (ID: {$existing['id']}) - aktualisiere...\n";
                    
                    // Produkt aktualisieren
                    $sql = "UPDATE hb_products SET 
                        name = ?, type = ?, category = ?, description = ?, 
                        price = ?, setup = ?, billing_cycle = ?, 
                        active = ?, features = ?, updated_at = NOW()
                        WHERE id = ?";
                    
                    $stmt = $this->pdo->prepare($sql);
                    $stmt->execute([
                        $product['name'],
                        $product['type'],
                        $product['category'],
                        $product['description'],
                        $product['price'],
                        $product['setup'],
                        $product['billing_cycle'],
                        $product['active'],
                        $product['features'],
                        $existing['id']
                    ]);
                    
                    echo "✅ Produkt '{$product['name']}' aktualisiert\n";
                } else {
                    echo "Erstelle Produkt '{$product['name']}'...\n";
                    
                    // Produkt erstellen
                    $sql = "INSERT INTO hb_products (
                        name, type, category, description, price, setup, 
                        billing_cycle, active, brand_id, features, created_at, updated_at
                    ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())";
                    
                    $stmt = $this->pdo->prepare($sql);
                    $stmt->execute([
                        $product['name'],
                        $product['type'],
                        $product['category'],
                        $product['description'],
                        $product['price'],
                        $product['setup'],
                        $product['billing_cycle'],
                        $product['active'],
                        $this->brandId,
                        $product['features']
                    ]);
                    
                    $productId = $this->pdo->lastInsertId();
                    echo "✅ Produkt '{$product['name']}' erstellt (ID: $productId)\n";
                }
            }
        }
        
        /**
         * API Key erstellen
         */
        public function setupAPIKey() {
            echo "\n=== Schritt 4: API Key ===\n";
            
            // Prüfen ob API Key bereits existiert
            $stmt = $this->pdo->prepare("SELECT id FROM hb_api_keys WHERE description = ? AND brand_id = ?");
            $stmt->execute(['ezdns.support Integration', $this->brandId]);
            $existing = $stmt->fetch(PDO::FETCH_ASSOC);
            
            if ($existing) {
                echo "API Key bereits vorhanden (ID: {$existing['id']})\n";
                return $existing['id'];
            }
            
            // API Key generieren
            $apiKey = 'ezdns_' . bin2hex(random_bytes(16));
            $apiSecret = 'secret_' . bin2hex(random_bytes(32));
            
            echo "Erstelle API Key...\n";
            
            // API Key erstellen
            $sql = "INSERT INTO hb_api_keys (
                description, api_key, api_secret, brand_id, 
                permissions, active, created_at
            ) VALUES (?, ?, ?, ?, ?, 1, NOW())";
            
            $stmt = $this->pdo->prepare($sql);
            $stmt->execute([
                'ezdns.support Integration',
                $apiKey,
                $apiSecret,
                $this->brandId,
                json_encode(['full' => true]) // Full permissions
            ]);
            
            $keyId = $this->pdo->lastInsertId();
            echo "✅ API Key erstellt (ID: $keyId)\n";
            echo "📋 API Key: $apiKey\n";
            echo "🔐 API Secret: $apiSecret\n";
            echo "\n⚠️ BITTE SICHER AUFBEWAHREN! ⚠️\n\n";
            
            return $keyId;
        }
        
        /**
         * Payment Gateways konfigurieren
         */
        public function setupPaymentGateways() {
            echo "\n=== Schritt 5: Payment Gateways ===\n";
            
            $gateways = [
                [
                    'name' => 'Stripe',
                    'gateway' => 'stripe',
                    'settings' => json_encode([
                        'publishable_key' => '',
                        'secret_key' => '',
                        'currency' => 'EUR'
                    ]),
                    'active' => 0, // Inaktiv bis Keys eingetragen
                    'brand_id' => $this->brandId
                ],
                [
                    'name' => 'PayPal',
                    'gateway' => 'paypal',
                    'settings' => json_encode([
                        'email' => '',
                        'currency' => 'EUR'
                    ]),
                    'active' => 0,
                    'brand_id' => $this->brandId
                ]
            ];
            
            foreach ($gateways as $gateway) {
                // Prüfen ob Gateway bereits existiert
                $stmt = $this->pdo->prepare("SELECT id FROM hb_payment_gateways WHERE gateway = ? AND brand_id = ?");
                $stmt->execute([$gateway['gateway'], $this->brandId]);
                $existing = $stmt->fetch(PDO::FETCH_ASSOC);
                
                if ($existing) {
                    echo "Payment Gateway '{$gateway['name']}' bereits vorhanden (ID: {$existing['id']})\n";
                    
                    // Gateway aktualisieren
                    $sql = "UPDATE hb_payment_gateways SET 
                        name = ?, settings = ?, updated_at = NOW()
                        WHERE id = ?";
                    
                    $stmt = $this->pdo->prepare($sql);
                    $stmt->execute([
                        $gateway['name'],
                        $gateway['settings'],
                        $existing['id']
                    ]);
                    
                    echo "✅ Gateway '{$gateway['name']}' aktualisiert\n";
                } else {
                    echo "Erstelle Payment Gateway '{$gateway['name']}'...\n";
                    
                    // Gateway erstellen
                    $sql = "INSERT INTO hb_payment_gateways (
                        name, gateway, settings, active, brand_id, created_at, updated_at
                    ) VALUES (?, ?, ?, ?, ?, NOW(), NOW())";
                    
                    $stmt = $this->pdo->prepare($sql);
                    $stmt->execute([
                        $gateway['name'],
                        $gateway['gateway'],
                        $gateway['settings'],
                        $gateway['active'],
                        $this->brandId
                    ]);
                    
                    $gatewayId = $this->pdo->lastInsertId();
                    echo "✅ Gateway '{$gateway['name']}' erstellt (ID: $gatewayId)\n";
                }
            }
        }
        
        /**
         * HostBill Brand-Konfiguration aktualisieren
         */
        public function updateHostBillConfig() {
            echo "\n=== Schritt 6: HostBill-Konfiguration ===\n";
            
            // Prüfen ob Konfigurations-Tabelle existiert
            $sql = "SELECT COUNT(*) as count FROM information_schema.tables 
                      WHERE table_schema = 'suppo_db' 
                      AND table_name = 'hb_brand_config'";
            $stmt = $this->pdo->query($sql);
            $result = $stmt->fetch(PDO::FETCH_ASSOC);
            
            if ($result['count'] > 0) {
                echo "Konfigurations-Tabelle gefunden - aktualisiere...\n";
                
                // Konfiguration aktualisieren
                $sql = "UPDATE hb_brand_config SET 
                    api_url = ?,
                    api_enabled = 1,
                    updated_at = NOW()
                    WHERE brand_id = ?";
                
                $stmt = $this->pdo->prepare($sql);
                $stmt->execute([
                    'https://support.panomity.com/api/',
                    $this->brandId
                ]);
                
                echo "✅ Konfiguration aktualisiert\n";
            } else {
                echo "Erstelle neue Konfigurations-Tabelle...\n";
                
                // Tabelle erstellen
                $sql = "CREATE TABLE IF NOT EXISTS hb_brand_config (
                    id INT AUTO_INCREMENT PRIMARY KEY,
                    brand_id INT NOT NULL,
                    api_url VARCHAR(255),
                    api_enabled TINYINT DEFAULT 1,
                    support_email VARCHAR(255),
                    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                    INDEX idx_brand (brand_id)
                )";
                
                $this->pdo->exec($sql);
                echo "✅ Tabelle erstellt\n";
                
                // Konfiguration einfügen
                $sql = "INSERT INTO hb_brand_config (
                    brand_id, api_url, api_enabled, support_email
                ) VALUES (?, ?, 1, ?)";
                
                $stmt = $this->pdo->prepare($sql);
                $stmt->execute([
                    $this->brandId,
                    'https://support.panomity.com/api/',
                    'support@ezdns.support'
                ]);
                
                echo "✅ Konfiguration eingetragen\n";
            }
        }
        
        /**
         * DNS Scan Services Tabelle erstellen
         */
        public function setupDNSServicesTable() {
            echo "\n=== Schritt 7: DNS Services Tabelle ===\n";
            
            // Tabelle erstellen
            $sql = "CREATE TABLE IF NOT EXISTS hb_dns_scans (
                id INT AUTO_INCREMENT PRIMARY KEY,
                brand_id INT NOT NULL,
                user_id INT,
                service_id INT,
                domain VARCHAR(255) NOT NULL,
                checks TEXT,
                score INT DEFAULT 0,
                status ENUM('good', 'ok', 'critical') DEFAULT 'ok',
                scanned_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                INDEX idx_domain (domain),
                INDEX idx_brand (brand_id),
                INDEX idx_user (user_id),
                INDEX idx_service (service_id)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
            
            $this->pdo->exec($sql);
            echo "✅ DNS Scans Tabelle erstellt/bereits vorhanden\n";
            
            // Historische Tabelle
            $sql = "CREATE TABLE IF NOT EXISTS hb_dns_scan_history (
                id INT AUTO_INCREMENT PRIMARY KEY,
                scan_id INT NOT NULL,
                domain VARCHAR(255) NOT NULL,
                check_type VARCHAR(50),
                result TEXT,
                issues TEXT,
                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                INDEX idx_scan (scan_id),
                INDEX idx_domain (domain)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
            
            $this->pdo->exec($sql);
            echo "✅ DNS Scan History Tabelle erstellt/bereits vorhanden\n";
        }
        
        /**
         * Setup ausführen
         */
        public function executeSetup() {
            echo "Beginne Setup...\n";
            
            try {
                $this->setupBrand();
                $deptId = $this->setupSupportDepartment();
                $this->setupProducts();
                $keyId = $this->setupAPIKey();
                $this->setupPaymentGateways();
                $this->updateHostBillConfig();
                $this->setupDNSServicesTable();
                
                echo "\n=== SETUP ERFOLGREICH ABGESCHLOSSEN ===\n";
                echo "\n📋 Zusammenfassung:\n";
                echo "✅ Brand: ezdns.support (ID: {$this->brandId})\n";
                echo "✅ Support Department: DNS Support (ID: $deptId)\n";
                echo "✅ Produkte: 4 Produkte erstellt/aktualisiert\n";
                echo "✅ API Key: Erstellt (siehe oben für Credentials)\n";
                echo "✅ Payment Gateways: Stripe, PayPal konfiguriert\n";
                echo "✅ Datenbanktabellen: DNS Scans Tabellen erstellt\n\n";
                
                return [
                    'success' => true,
                    'brand_id' => $this->brandId,
                    'department_id' => $deptId,
                    'api_key_id' => $keyId
                ];
                
            } catch (Exception $e) {
                echo "\n❌ SETUP-FEHLER: " . $e->getMessage() . "\n";
                echo "Stack Trace:\n" . $e->getTraceAsString() . "\n";
                return [
                    'success' => false,
                    'error' => $e->getMessage()
                ];
            }
        }
    }
    
    // Setup ausführen
    $setup = new EzDNSDatabaseSetup($pdo);
    $result = $setup->executeSetup();
    
    if ($result['success']) {
        echo "\n✅ Alles erfolgreich konfiguriert!\n";
        echo "\n🚀 Nächste Schritte:\n";
        echo "1. Testen Sie den API-Zugang mit den obenstehenden Credentials\n";
        echo "2. Konfigurieren Sie die Payment Gateways mit Ihren API-Keys (Stripe, PayPal)\n";
        echo "3. Starten Sie die ezdns.support Frontend-Integration\n";
        echo "4. Erstellen Sie Test-Services und DNS-Scans\n";
        echo "5. Überprüfen Sie die HostBill Admin-Bereiche für die erstellten Produkte\n\n";
    } else {
        echo "\n❌ Setup fehlgeschlagen: " . $result['error'] . "\n";
        exit(1);
    }

} catch (PDOException $e) {
    echo "\n❌ Datenbank-Fehler: " . $e->getMessage() . "\n";
    exit(1);
} catch (Exception $e) {
    echo "\n❌ Allgemeiner Fehler: " . $e->getMessage() . "\n";
    exit(1);
}

echo "\n=== Setup beendet ===\n";
?>