526 lines
17 KiB
PHP
526 lines
17 KiB
PHP
<?php
|
|
/**
|
|
* Copyright seit 2024 Webshop System
|
|
*
|
|
* Admin Controller für Marketplace-, Security- und Performance-Verwaltung
|
|
*
|
|
* @author Webshop System
|
|
* @license GPL v3
|
|
*/
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Core\ModuleMarketplace;
|
|
use App\Core\SecuritySystem;
|
|
use App\Core\PerformanceOptimizer;
|
|
use App\Core\Logger;
|
|
use Doctrine\DBAL\DriverManager;
|
|
use Doctrine\DBAL\Exception;
|
|
|
|
class MarketplaceController extends BaseAdminController
|
|
{
|
|
private $marketplace;
|
|
private $securitySystem;
|
|
private $performanceOptimizer;
|
|
private $logger;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->marketplace = ModuleMarketplace::getInstance();
|
|
$this->securitySystem = SecuritySystem::getInstance();
|
|
$this->performanceOptimizer = PerformanceOptimizer::getInstance();
|
|
$this->logger = Logger::getInstance();
|
|
}
|
|
|
|
/**
|
|
* Marketplace-Übersicht anzeigen
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->checkPermission('marketplace_management');
|
|
|
|
$modules = $this->marketplace->getMarketplaceModules();
|
|
$purchaseHistory = $this->marketplace->getPurchaseHistory();
|
|
$marketplaceStats = $this->marketplace->getMarketplaceStatistics();
|
|
|
|
$this->render('admin/marketplace/index', [
|
|
'modules' => $modules,
|
|
'purchase_history' => $purchaseHistory,
|
|
'marketplace_stats' => $marketplaceStats,
|
|
'page_title' => 'Marketplace-Verwaltung'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Marketplace-Module anzeigen
|
|
*/
|
|
public function modules()
|
|
{
|
|
$this->checkPermission('marketplace_management');
|
|
|
|
$filters = $_GET;
|
|
$modules = $this->marketplace->getMarketplaceModules($filters);
|
|
|
|
$this->render('admin/marketplace/modules', [
|
|
'modules' => $modules,
|
|
'filters' => $filters,
|
|
'page_title' => 'Marketplace-Module'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Modul-Details anzeigen
|
|
*/
|
|
public function moduleDetails()
|
|
{
|
|
$this->checkPermission('marketplace_management');
|
|
|
|
$moduleId = $_GET['id'] ?? '';
|
|
|
|
if (empty($moduleId)) {
|
|
$this->addError('Modul-ID ist erforderlich');
|
|
$this->redirect('/admin/marketplace/modules');
|
|
return;
|
|
}
|
|
|
|
$moduleDetails = $this->marketplace->getMarketplaceModuleDetails($moduleId);
|
|
|
|
if (!$moduleDetails) {
|
|
$this->addError('Modul nicht gefunden');
|
|
$this->redirect('/admin/marketplace/modules');
|
|
return;
|
|
}
|
|
|
|
$this->render('admin/marketplace/module_details', [
|
|
'module' => $moduleDetails,
|
|
'page_title' => 'Modul-Details: ' . $moduleDetails['name']
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Modul kaufen
|
|
*/
|
|
public function purchaseModule()
|
|
{
|
|
$this->checkPermission('marketplace_management');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$moduleId = $_POST['module_id'] ?? '';
|
|
$paymentData = $_POST['payment_data'] ?? [];
|
|
|
|
if (empty($moduleId)) {
|
|
$this->addError('Modul-ID ist erforderlich');
|
|
$this->redirect('/admin/marketplace/modules');
|
|
return;
|
|
}
|
|
|
|
$result = $this->marketplace->purchaseModule($moduleId, $paymentData);
|
|
|
|
if ($result['success']) {
|
|
$this->addSuccess('Modul erfolgreich gekauft und installiert');
|
|
$this->redirect('/admin/modules');
|
|
} else {
|
|
$this->addError('Kauf fehlgeschlagen: ' . $result['error']);
|
|
$this->redirect('/admin/marketplace/module-details?id=' . urlencode($moduleId));
|
|
}
|
|
} else {
|
|
$this->addError('Ungültige Anfrage');
|
|
$this->redirect('/admin/marketplace/modules');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Modul bewerten
|
|
*/
|
|
public function rateModule()
|
|
{
|
|
$this->checkPermission('marketplace_management');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$moduleId = $_POST['module_id'] ?? '';
|
|
$rating = (int)($_POST['rating'] ?? 0);
|
|
$review = $_POST['review'] ?? '';
|
|
|
|
if (empty($moduleId) || $rating < 1 || $rating > 5) {
|
|
$this->addError('Modul-ID und Bewertung (1-5) sind erforderlich');
|
|
$this->redirect('/admin/marketplace/module-details?id=' . urlencode($moduleId));
|
|
return;
|
|
}
|
|
|
|
$result = $this->marketplace->rateModule($moduleId, $rating, $review);
|
|
|
|
if ($result['success']) {
|
|
$this->addSuccess('Bewertung erfolgreich abgegeben');
|
|
} else {
|
|
$this->addError('Bewertung fehlgeschlagen: ' . $result['error']);
|
|
}
|
|
|
|
$this->redirect('/admin/marketplace/module-details?id=' . urlencode($moduleId));
|
|
} else {
|
|
$this->addError('Ungültige Anfrage');
|
|
$this->redirect('/admin/marketplace/modules');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Purchase-Historie anzeigen
|
|
*/
|
|
public function purchaseHistory()
|
|
{
|
|
$this->checkPermission('marketplace_management');
|
|
|
|
$purchaseHistory = $this->marketplace->getPurchaseHistory();
|
|
|
|
$this->render('admin/marketplace/purchase_history', [
|
|
'purchase_history' => $purchaseHistory,
|
|
'page_title' => 'Purchase-Historie'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Marketplace-Einstellungen
|
|
*/
|
|
public function marketplaceSettings()
|
|
{
|
|
$this->checkPermission('marketplace_management');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$enabled = isset($_POST['enabled']);
|
|
$marketplaceUrl = $_POST['marketplace_url'] ?? '';
|
|
$apiKey = $_POST['api_key'] ?? '';
|
|
$paymentProvider = $_POST['payment_provider'] ?? 'stripe';
|
|
|
|
$settings = [
|
|
'enabled' => $enabled ? '1' : '0',
|
|
'marketplace_url' => $marketplaceUrl,
|
|
'api_key' => $apiKey,
|
|
'payment_provider' => $paymentProvider
|
|
];
|
|
|
|
$result = $this->marketplace->saveSettings($settings);
|
|
|
|
if ($result) {
|
|
$this->addSuccess('Marketplace-Einstellungen erfolgreich gespeichert');
|
|
} else {
|
|
$this->addError('Fehler beim Speichern der Einstellungen');
|
|
}
|
|
|
|
$this->redirect('/admin/marketplace/settings');
|
|
} else {
|
|
$this->render('admin/marketplace/settings', [
|
|
'page_title' => 'Marketplace-Einstellungen'
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Security-Übersicht anzeigen
|
|
*/
|
|
public function security()
|
|
{
|
|
$this->checkPermission('security_management');
|
|
|
|
$this->render('admin/marketplace/security', [
|
|
'page_title' => 'Security-Verwaltung'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Security-Scan durchführen
|
|
*/
|
|
public function securityScan()
|
|
{
|
|
$this->checkPermission('security_management');
|
|
|
|
$moduleName = $_GET['module'] ?? '';
|
|
|
|
if (empty($moduleName)) {
|
|
$this->addError('Modul-Name ist erforderlich');
|
|
$this->redirect('/admin/marketplace/security');
|
|
return;
|
|
}
|
|
|
|
$modulePath = __DIR__ . '/../../../../modules/' . $moduleName;
|
|
|
|
if (!is_dir($modulePath)) {
|
|
$this->addError('Modul-Verzeichnis nicht gefunden');
|
|
$this->redirect('/admin/marketplace/security');
|
|
return;
|
|
}
|
|
|
|
$scanResult = $this->securitySystem->scanModule($moduleName, $modulePath);
|
|
|
|
$this->render('admin/marketplace/security_scan', [
|
|
'module_name' => $moduleName,
|
|
'scan_result' => $scanResult,
|
|
'page_title' => 'Security-Scan: ' . $moduleName
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Code signieren
|
|
*/
|
|
public function signCode()
|
|
{
|
|
$this->checkPermission('security_management');
|
|
|
|
$moduleName = $_GET['module'] ?? '';
|
|
$filePath = $_GET['file'] ?? '';
|
|
|
|
if (empty($moduleName) || empty($filePath)) {
|
|
$this->addError('Modul-Name und Datei-Pfad sind erforderlich');
|
|
$this->redirect('/admin/marketplace/security');
|
|
return;
|
|
}
|
|
|
|
$result = $this->securitySystem->signCode($filePath, $moduleName);
|
|
|
|
if ($result['success']) {
|
|
$this->addSuccess('Code erfolgreich signiert');
|
|
} else {
|
|
$this->addError('Code-Signierung fehlgeschlagen: ' . $result['error']);
|
|
}
|
|
|
|
$this->redirect('/admin/marketplace/security');
|
|
}
|
|
|
|
/**
|
|
* Code-Signatur verifizieren
|
|
*/
|
|
public function verifySignature()
|
|
{
|
|
$this->checkPermission('security_management');
|
|
|
|
$moduleName = $_GET['module'] ?? '';
|
|
$filePath = $_GET['file'] ?? '';
|
|
|
|
if (empty($moduleName) || empty($filePath)) {
|
|
$this->addError('Modul-Name und Datei-Pfad sind erforderlich');
|
|
$this->redirect('/admin/marketplace/security');
|
|
return;
|
|
}
|
|
|
|
$result = $this->securitySystem->verifySignature($filePath, $moduleName);
|
|
|
|
if ($result['success'] && $result['verified']) {
|
|
$this->addSuccess('Code-Signatur erfolgreich verifiziert');
|
|
} else {
|
|
$this->addError('Code-Signatur-Verifikation fehlgeschlagen: ' . $result['error']);
|
|
}
|
|
|
|
$this->redirect('/admin/marketplace/security');
|
|
}
|
|
|
|
/**
|
|
* Security-Einstellungen
|
|
*/
|
|
public function securitySettings()
|
|
{
|
|
$this->checkPermission('security_management');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$enabled = isset($_POST['enabled']);
|
|
$codeSigningEnabled = isset($_POST['code_signing_enabled']);
|
|
$malwareScanningEnabled = isset($_POST['malware_scanning_enabled']);
|
|
$sandboxEnabled = isset($_POST['sandbox_enabled']);
|
|
|
|
$settings = [
|
|
'enabled' => $enabled ? '1' : '0',
|
|
'code_signing_enabled' => $codeSigningEnabled ? '1' : '0',
|
|
'malware_scanning_enabled' => $malwareScanningEnabled ? '1' : '0',
|
|
'sandbox_enabled' => $sandboxEnabled ? '1' : '0'
|
|
];
|
|
|
|
$result = $this->securitySystem->saveSettings($settings);
|
|
|
|
if ($result) {
|
|
$this->addSuccess('Security-Einstellungen erfolgreich gespeichert');
|
|
} else {
|
|
$this->addError('Fehler beim Speichern der Einstellungen');
|
|
}
|
|
|
|
$this->redirect('/admin/marketplace/security-settings');
|
|
} else {
|
|
$this->render('admin/marketplace/security_settings', [
|
|
'page_title' => 'Security-Einstellungen'
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Performance-Übersicht anzeigen
|
|
*/
|
|
public function performance()
|
|
{
|
|
$this->checkPermission('performance_management');
|
|
|
|
$performanceStats = $this->performanceOptimizer->getPerformanceStatistics();
|
|
$currentMetrics = $this->performanceOptimizer->monitorPerformance();
|
|
|
|
$this->render('admin/marketplace/performance', [
|
|
'performance_stats' => $performanceStats,
|
|
'current_metrics' => $currentMetrics,
|
|
'page_title' => 'Performance-Verwaltung'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Database optimieren
|
|
*/
|
|
public function optimizeDatabase()
|
|
{
|
|
$this->checkPermission('performance_management');
|
|
|
|
$result = $this->performanceOptimizer->optimizeDatabase();
|
|
|
|
if ($result) {
|
|
$this->addSuccess('Database erfolgreich optimiert');
|
|
} else {
|
|
$this->addError('Database-Optimierung fehlgeschlagen');
|
|
}
|
|
|
|
$this->redirect('/admin/marketplace/performance');
|
|
}
|
|
|
|
/**
|
|
* Memory optimieren
|
|
*/
|
|
public function optimizeMemory()
|
|
{
|
|
$this->checkPermission('performance_management');
|
|
|
|
$result = $this->performanceOptimizer->optimizeMemory();
|
|
|
|
if ($result) {
|
|
$this->addSuccess('Memory erfolgreich optimiert');
|
|
} else {
|
|
$this->addError('Memory-Optimierung fehlgeschlagen');
|
|
}
|
|
|
|
$this->redirect('/admin/marketplace/performance');
|
|
}
|
|
|
|
/**
|
|
* Performance-Monitoring
|
|
*/
|
|
public function performanceMonitoring()
|
|
{
|
|
$this->checkPermission('performance_management');
|
|
|
|
$metrics = $this->performanceOptimizer->monitorPerformance();
|
|
|
|
$this->render('admin/marketplace/performance_monitoring', [
|
|
'metrics' => $metrics,
|
|
'page_title' => 'Performance-Monitoring'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Performance-Einstellungen
|
|
*/
|
|
public function performanceSettings()
|
|
{
|
|
$this->checkPermission('performance_management');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$enabled = isset($_POST['enabled']);
|
|
$redisEnabled = isset($_POST['redis_enabled']);
|
|
$memcachedEnabled = isset($_POST['memcached_enabled']);
|
|
$lazyLoadingEnabled = isset($_POST['lazy_loading_enabled']);
|
|
$databaseOptimizationEnabled = isset($_POST['database_optimization_enabled']);
|
|
$memoryOptimizationEnabled = isset($_POST['memory_optimization_enabled']);
|
|
|
|
$settings = [
|
|
'enabled' => $enabled ? '1' : '0',
|
|
'redis_enabled' => $redisEnabled ? '1' : '0',
|
|
'memcached_enabled' => $memcachedEnabled ? '1' : '0',
|
|
'lazy_loading_enabled' => $lazyLoadingEnabled ? '1' : '0',
|
|
'database_optimization_enabled' => $databaseOptimizationEnabled ? '1' : '0',
|
|
'memory_optimization_enabled' => $memoryOptimizationEnabled ? '1' : '0'
|
|
];
|
|
|
|
$result = $this->performanceOptimizer->saveSettings($settings);
|
|
|
|
if ($result) {
|
|
$this->addSuccess('Performance-Einstellungen erfolgreich gespeichert');
|
|
} else {
|
|
$this->addError('Fehler beim Speichern der Einstellungen');
|
|
}
|
|
|
|
$this->redirect('/admin/marketplace/performance-settings');
|
|
} else {
|
|
$this->render('admin/marketplace/performance_settings', [
|
|
'page_title' => 'Performance-Einstellungen'
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Analytics anzeigen
|
|
*/
|
|
public function analytics()
|
|
{
|
|
$this->checkPermission('analytics_management');
|
|
|
|
try {
|
|
$conn = DriverManager::getConnection([
|
|
'url' => getenv('DATABASE_URL') ?: 'mysql://root:password@localhost/webshop'
|
|
]);
|
|
|
|
// Download-Statistiken
|
|
$stmt = $conn->prepare('
|
|
SELECT module_id, module_name, COUNT(*) as download_count
|
|
FROM ws_marketplace_purchases
|
|
WHERE status = "completed"
|
|
GROUP BY module_id
|
|
ORDER BY download_count DESC
|
|
LIMIT 10
|
|
');
|
|
$stmt->execute();
|
|
$downloadStats = $stmt->fetchAllAssociative();
|
|
|
|
// Revenue-Statistiken
|
|
$stmt = $conn->prepare('
|
|
SELECT
|
|
DATE(purchase_date) as date,
|
|
SUM(amount) as daily_revenue,
|
|
COUNT(*) as daily_purchases
|
|
FROM ws_marketplace_purchases
|
|
WHERE status = "completed"
|
|
AND purchase_date > DATE_SUB(NOW(), INTERVAL 30 DAY)
|
|
GROUP BY DATE(purchase_date)
|
|
ORDER BY date DESC
|
|
');
|
|
$stmt->execute();
|
|
$revenueStats = $stmt->fetchAllAssociative();
|
|
|
|
// Performance-Statistiken
|
|
$stmt = $conn->prepare('
|
|
SELECT
|
|
DATE(created_at) as date,
|
|
AVG(execution_time) as avg_execution_time,
|
|
AVG(memory_usage) as avg_memory_usage,
|
|
COUNT(*) as request_count
|
|
FROM ws_performance_metrics
|
|
WHERE created_at > DATE_SUB(NOW(), INTERVAL 7 DAY)
|
|
GROUP BY DATE(created_at)
|
|
ORDER BY date DESC
|
|
');
|
|
$stmt->execute();
|
|
$performanceStats = $stmt->fetchAllAssociative();
|
|
|
|
$this->render('admin/marketplace/analytics', [
|
|
'download_stats' => $downloadStats,
|
|
'revenue_stats' => $revenueStats,
|
|
'performance_stats' => $performanceStats,
|
|
'page_title' => 'Analytics'
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
$this->addError('Analytics-Daten laden Fehler: ' . $e->getMessage());
|
|
$this->redirect('/admin/marketplace');
|
|
}
|
|
}
|
|
}
|