[ 'password' => 'admin123', 'roots' => [ '🏠Thuis' => 'D:', '💻Bestanden' => 'D:\Bestanden openbaar', '⬇️Documenten' => 'D:\Documenten openbaar', ], ], 'kees' => [ 'password' => 'kees123', 'roots' => [ '🦸Kees' => 'D:\KEES', '💻Bestanden' => 'D:\Bestanden openbaar', '⬇️Documenten' => 'D:\Documenten openbaar', ], ], 'gast' => [ 'password' => 'gast123', 'roots' => [ '⬇️Downloads' => 'D:\Bestanden openbaar', ], ], ]; /* ============================================ BASIS RECHTEN ============================================ */ $PERMISSIONS = [ 'admin' => ['read'=>true,'write'=>true,'delete'=>true,'rename'=>true,'zip'=>true,'unzip'=>true,'edit'=>true,'upload'=>true,'newfolder'=>true,'copy'=>true,'cut'=>true,'paste'=>true], 'kees' => ['read'=>true,'write'=>true,'delete'=>true,'rename'=>true,'zip'=>true,'unzip'=>true,'edit'=>true,'upload'=>true,'newfolder'=>true,'copy'=>true,'cut'=>true,'paste'=>true], // cut op false: gast kan niet meer verplaatsen (logisch bij read-only) 'gast' => ['read'=>true,'write'=>false,'delete'=>false,'rename'=>false,'zip'=>false,'unzip'=>false,'edit'=>false,'upload'=>false,'newfolder'=>false,'copy'=>false,'cut'=>false,'paste'=>false], ]; /* ============================================ UITZONDERINGEN / READ=>FALSE DOWNLOAD KNOP WEG ============================================ */ $FOLDER_PERMISSIONS = [ 'kees' => [ 'D:\Documenten openbaar' => ['read'=>true,'write'=>false,'delete'=>false,'rename'=>false,'zip'=>false,'unzip'=>false,'edit'=>false,'upload'=>false,'newfolder'=>false,'copy'=>false,'cut'=>false,'paste'=>false], ] ]; $HIDDEN_NAMES = ['Desktop.ini','desktop.ini','Thumbs.db','$RECYCLE.BIN','System Volume Information']; //$MAX_UPLOAD_BYTES = PHP_INT_MAX; (onbeperkt) //$MAX_UPLOAD_BYTES = 50 * 1024 * 1024; (50MB) //$MAX_UPLOAD_BYTES = 500 * 1024 * 1024; (500MB) //$MAX_UPLOAD_BYTES = 10 * 1024 * 1024 * 1024; (10GB) $MAX_UPLOAD_BYTES = 5 * 1024 * 1024 * 1024; // Realistische uploadlimiet (5GB) $MAX_EDIT_BYTES = 1 * 1024 * 1024; // svg verwijderd i.v.m. XSS-risico $ALLOWED_UPLOAD_EXT = [ 'txt','log','pdf','jpg','jpeg','png','gif','bmp','webp','tiff','exe', 'mp4','avi','mkv','mov','wmv','flv','webm', 'mp3','wav','flac','aac','ogg','m4a', 'zip','rar','7z','tar','gz','bz2','xz', 'csv','doc','docx','xls','xlsx','ppt','pptx','odt','ods','odp', 'json','xml','ini','cfg','rtf','md' ]; $ALLOWED_MIME = [ 'text/plain', 'image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'application/zip', 'application/x-dosexec', 'application/x-rar', 'application/x-7z-compressed', 'audio/mpeg', 'video/mp4', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/msword', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint' ]; /* ============================================ CSRF ============================================ */ if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } function csrf_token() { return isset($_SESSION['csrf_token']) ? $_SESSION['csrf_token'] : ''; } function csrf_check($token) { return hash_equals(isset($_SESSION['csrf_token']) ? $_SESSION['csrf_token'] : '', $token ? $token : ''); } /* ============================================ LOGGING ============================================ */ function fm_log($msg) { $file = __DIR__ . DS . 'filemanager.log'; $line = date('Y-m-d H:i:s') . ' ' . $msg . PHP_EOL; @file_put_contents($file, $line, FILE_APPEND); } function fm_error($msg) { global $currentRootKey, $relPath; header( "Location: ?root=" . urlencode($currentRootKey) . "&path=" . urlencode(str_replace('\\','/',$relPath)) . "&error=" . urlencode($msg) ); exit; } /* ============================================ HELPER FUNCTIES ============================================ */ function is_hidden($name) { global $HIDDEN_NAMES; if ($name === '.' || $name === '..') return true; if (substr($name,0,1)==='.') return true; return in_array($name, $HIDDEN_NAMES, true); } function normalize_path($path) { $path = str_replace(array('/', '\\'), DS, $path); $parts = []; foreach (explode(DS, $path) as $p) { if ($p === '' || $p === '.') continue; if ($p === '..') { array_pop($parts); } else { $parts[] = $p; } } $final = implode(DS, $parts); if (preg_match('/^[A-Za-z]:$/', $final)) $final .= DS; return $final; } function list_directory($path) { static $cache = []; if (!is_dir($path)) return []; if (isset($cache[$path])) return $cache[$path]; $entries = @scandir($path, SCANDIR_SORT_NONE); if ($entries === false) return []; $items = []; foreach ($entries as $e) { if (is_hidden($e)) continue; $full = $path . DS . $e; $isDir = is_dir($full); $size = $isDir ? 0 : @filesize($full); $mtime = @filemtime($full); $items[] = [ 'name' => $e, 'is_dir' => $isDir, 'size' => $size, 'mtime' => $mtime, ]; } usort($items, function($a, $b) { if ($a['is_dir'] && !$b['is_dir']) return -1; if (!$a['is_dir'] && $b['is_dir']) return 1; return strcasecmp($a['name'], $b['name']); }); $cache[$path] = $items; return $items; } function is_binary_string($str) { return (strpos($str, "\0") !== false); }