/* ZIP */ if ($action === 'zip' && !empty($perms['zip'])) { $resolved = resolve_targets($targets, $rootPath); if (empty($resolved)) fm_error("Geen items geselecteerd om te zippen."); $first = $resolved[0]['real']; $base = pathinfo($first, PATHINFO_FILENAME); $zipName = $base . ".zip"; $zipPath = $currentPathReal . DS . $zipName; if (file_exists($zipPath)) { $zipName = $base . '_' . time() . '.zip'; $zipPath = $currentPathReal . DS . $zipName; } $zip = new ZipArchive(); if ($zip->open($zipPath, ZipArchive::CREATE) !== true) { fm_error("Zip aanmaken mislukt."); } foreach ($resolved as $t) { $real = $t['real']; if (is_dir($real)) { $it = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($real, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST ); foreach ($it as $file) { $filePath = $file->getRealPath(); $localPath = substr($filePath, strlen($real) + 1); if ($file->isDir()) { $zip->addEmptyDir($t['rel'] . '/' . $localPath); } else { $zip->addFile($filePath, $t['rel'] . '/' . $localPath); } } } else { $zip->addFile($real, basename($real)); } } $zip->close(); fm_log($user." zip: ".$zipPath); header("Location: ?root=$currentRootKey&path=".urlencode(str_replace('\\','/',$relPath))); exit; } /* UNZIP (met Zip-Slip check) */ if ($action === 'unzip' && !empty($perms['unzip'])) { $resolved = resolve_targets($targets, $rootPath); if (count($resolved) !== 1) fm_error("Selecteer precies één zipbestand."); $zipFile = $resolved[0]['real']; if (!is_file($zipFile)) fm_error("Geen geldig zipbestand."); $zip = new ZipArchive(); if ($zip->open($zipFile) !== true) { fm_error("Zip openen mislukt."); } // Zip-Slip check: geen ../ en geen absolute paden for ($i = 0; $i < $zip->numFiles; $i++) { $name = $zip->getNameIndex($i); if (strpos($name, '..') !== false || preg_match('#^([a-zA-Z]:|/)#', $name)) { $zip->close(); fm_error("Zip bevat onveilige paden."); } } $zip->extractTo($currentPathReal); $zip->close(); fm_log($user." unzip: ".$zipFile); header("Location: ?root=$currentRootKey&path=".urlencode(str_replace('\\','/',$relPath))); exit; } /* EDIT */ if ($action === 'edit' && !empty($perms['edit'])) { $resolved = resolve_targets($targets, $rootPath); if (count($resolved) !== 1) fm_error("Selecteer precies één bestand om te bewerken."); $relItem = $resolved[0]['rel']; header( "Location: ?root=$currentRootKey". "&path=".urlencode(str_replace('\\','/',$relPath)). "&edit=".urlencode(str_replace('\\','/',$relItem)) ); exit; } /* EDIT SAVE */ if ($action === 'edit_save' && !empty($perms['edit'])) { $targetRel = isset($_POST['target']) ? $_POST['target'] : ''; $targetRel = ltrim($targetRel, '/\\'); $targetRel = normalize_path($targetRel); $targetFull = normalize_path($rootPath . DS . $targetRel); $targetFullReal = realpath($targetFull); if (!$targetFullReal || !ensure_within_root($targetFullReal) || !is_file($targetFullReal)) { fm_error("Ongeldig bestand voor opslaan."); } $content = isset($_POST['file_content']) ? $_POST['file_content'] : ''; if (file_put_contents($targetFullReal, $content) === false) { fm_error("Opslaan mislukt."); } fm_log($user." edit_save: ".$targetFullReal); header("Location: ?root=$currentRootKey&path=".urlencode(str_replace('\\','/',$relPath))); exit; } }