. * Nutzt denselben ZIP-Slip-Schutz wie der Self-Updater. Ein vorhandenes Plugin * mit gleichem Kürzel wird ersetzt (Update), seine Daten bleiben erhalten. */ class PluginInstaller { public function __construct( private readonly PluginManager $plugins, private readonly ZipExtractor $extractor, ) {} public static function uploadsAllowed(): bool { return ! filter_var(config('inhaus.disallow_file_mods'), FILTER_VALIDATE_BOOL); } public function install(string $zipFile): PluginManifest { if (! self::uploadsAllowed()) { throw new RuntimeException('Das Installieren von Plugins ist in dieser Installation abgeschaltet.'); } $staging = storage_path('framework/plugin-upload-'.bin2hex(random_bytes(4))); try { $this->extractor->extract($zipFile, $staging); try { $manifest = PluginManifest::fromDirectory($staging, core: false); } catch (Throwable $e) { throw new RuntimeException('Das Archiv enthält kein gültiges Plugin: '.$e->getMessage()); } $existing = $this->plugins->find($manifest->slug); if ($existing?->core) { throw new RuntimeException("Das Kürzel „{$manifest->slug}“ gehört zu einem mitgelieferten Plugin."); } if (! is_file($staging.'/src/'.str_replace('\\', '/', substr($manifest->class, strlen($manifest->namespace))).'.php')) { throw new RuntimeException("Die Plugin-Klasse {$manifest->class} fehlt im Archiv (erwartet unter src/)."); } $target = $this->plugins->customerPath().'/'.$manifest->slug; if (! is_dir(dirname($target)) && ! @mkdir(dirname($target), 0775, true)) { throw new RuntimeException('Das Verzeichnis plugins/ ist nicht beschreibbar.'); } Filesystem::deleteDirectory($target); if (! Filesystem::moveDirectory($staging, $target)) { throw new RuntimeException('Das Plugin konnte nicht nach plugins/ verschoben werden. Bitte Schreibrechte prüfen.'); } $this->plugins->forgetDiscovered(); Audit::log($existing ? 'plugin.updated' : 'plugin.installed', ['plugin' => $manifest->slug, 'version' => $manifest->version]); return PluginManifest::fromDirectory($target, core: false); } finally { Filesystem::deleteDirectory($staging); } } }