simplify static download
This commit is contained in:
55
config.php
55
config.php
@@ -13,59 +13,8 @@ define('MAX_FILE_SIZE', '10GB');
|
|||||||
define('CHUNK_SIZE', '2MB');
|
define('CHUNK_SIZE', '2MB');
|
||||||
|
|
||||||
// Разрешенные расширения файлов (whitelist)
|
// Разрешенные расширения файлов (whitelist)
|
||||||
define('ALLOWED_EXTENSIONS', [
|
// Установите ['*'], чтобы разрешить все типы файлов.
|
||||||
// Изображения
|
define('ALLOWED_EXTENSIONS', ['*']);
|
||||||
'jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp', 'tiff', 'tif', 'ico', 'heic', 'heif', 'avif',
|
|
||||||
|
|
||||||
// Документы
|
|
||||||
'pdf', 'doc', 'docx', 'txt', 'rtf', 'odt', 'ods', 'odp', 'pages', 'key', 'numbers',
|
|
||||||
'ppt', 'pptx', 'xps', 'epub', 'mobi', 'fb2',
|
|
||||||
|
|
||||||
// Видео
|
|
||||||
'mp4', 'avi', 'mkv', 'mov', 'webm', 'flv', 'wmv', 'mpg', 'mpeg', 'm4v', '3gp', 'ogv', 'ts', 'mts',
|
|
||||||
|
|
||||||
// Аудио
|
|
||||||
'mp3', 'wav', 'flac', 'ogg', 'aac', 'm4a', 'wma', 'opus', 'oga', 'aiff', 'au', 'ra',
|
|
||||||
|
|
||||||
// Архивы
|
|
||||||
'zip', 'rar', '7z', 'tar', 'gz', 'bz2', 'xz', 'lzma', 'cab', 'iso', 'dmg', 'deb', 'rpm',
|
|
||||||
|
|
||||||
// Данные и таблицы
|
|
||||||
'json', 'xml', 'csv', 'xls', 'xlsx', 'ods', 'tsv', 'yaml', 'yml', 'toml', 'ini', 'conf', 'cfg',
|
|
||||||
|
|
||||||
// Код и разработка
|
|
||||||
'html', 'htm', 'css', 'js', 'php', 'py', 'java', 'cpp', 'c', 'h', 'cs', 'rb', 'go', 'rs', 'swift',
|
|
||||||
'kt', 'scala', 'pl', 'sh', 'bat', 'cmd', 'ps1', 'vbs', 'r', 'sql', 'md', 'tex', 'log',
|
|
||||||
|
|
||||||
// Веб и CMS
|
|
||||||
'wpress', 'sql', 'backup', 'bak', 'db', 'sqlite', 'sqlite3',
|
|
||||||
|
|
||||||
// Шрифты
|
|
||||||
'ttf', 'otf', 'woff', 'woff2', 'eot',
|
|
||||||
|
|
||||||
// CAD и дизайн
|
|
||||||
'dwg', 'dxf', 'skp', 'blend', 'obj', 'fbx', '3ds', 'dae', 'stl', 'ply',
|
|
||||||
'psd', 'ai', 'eps', 'indd', 'sketch', 'fig', 'xd',
|
|
||||||
|
|
||||||
// Виртуализация и образы
|
|
||||||
'vmdk', 'vdi', 'vhd', 'vhdx', 'qcow2', 'img', 'bin', 'cue',
|
|
||||||
|
|
||||||
// Мобильные приложения и исполняемые файлы
|
|
||||||
'apk', 'ipa', 'appx', 'msix', 'exe', 'msi', 'deb', 'rpm', 'dmg', 'pkg',
|
|
||||||
|
|
||||||
// Научные данные
|
|
||||||
'mat', 'hdf5', 'nc', 'fits', 'sdf', 'mol', 'pdb',
|
|
||||||
|
|
||||||
// Игры и мультимедиа
|
|
||||||
'unity', 'unitypackage', 'pak', 'wad', 'pk3', 'vpk',
|
|
||||||
|
|
||||||
// Электронные книги и документы
|
|
||||||
'djvu', 'chm', 'hlp',
|
|
||||||
|
|
||||||
// Прочие полезные форматы
|
|
||||||
'torrent', 'magnet', 'desktop', 'lnk', 'url',
|
|
||||||
'ics', 'vcf', 'vcard', 'gpx', 'kml', 'kmz'
|
|
||||||
]);
|
|
||||||
|
|
||||||
// В конце файла config.php добавьте:
|
// В конце файла config.php добавьте:
|
||||||
error_log("Config loaded. MAX_FILE_SIZE: " . MAX_FILE_SIZE);
|
error_log("Config loaded. MAX_FILE_SIZE: " . MAX_FILE_SIZE);
|
||||||
|
|||||||
@@ -105,9 +105,10 @@ function validateFileName($filename)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем расширение
|
// Проверяем расширение (если не разрешены все типы)
|
||||||
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
||||||
if (!in_array($extension, ALLOWED_EXTENSIONS)) {
|
$allowAllExtensions = empty(ALLOWED_EXTENSIONS) || in_array('*', ALLOWED_EXTENSIONS, true);
|
||||||
|
if (!$allowAllExtensions && !in_array($extension, ALLOWED_EXTENSIONS, true)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
184
index.php
184
index.php
@@ -7,185 +7,6 @@ require_once __DIR__ . '/functions.php';
|
|||||||
if (!file_exists(UPLOAD_DIR)) mkdir(UPLOAD_DIR, 0755, true);
|
if (!file_exists(UPLOAD_DIR)) mkdir(UPLOAD_DIR, 0755, true);
|
||||||
if (!file_exists(CHUNK_DIR)) mkdir(CHUNK_DIR, 0755, true);
|
if (!file_exists(CHUNK_DIR)) mkdir(CHUNK_DIR, 0755, true);
|
||||||
|
|
||||||
// Обработка запросов файлов напрямую из корня
|
|
||||||
$requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
||||||
$requestedFile = ltrim($requestUri, '/');
|
|
||||||
|
|
||||||
// Если запрашивается файл (не административный интерфейс)
|
|
||||||
if (
|
|
||||||
!empty($requestedFile) &&
|
|
||||||
$requestedFile !== 'index.php' &&
|
|
||||||
$requestedFile !== 'upload_chunk.php' &&
|
|
||||||
$requestedFile !== 'merge_chunks.php' &&
|
|
||||||
!isset($_GET['action']) &&
|
|
||||||
!isset($_GET['delete']) &&
|
|
||||||
!isset($_POST['password'])
|
|
||||||
) {
|
|
||||||
$requestedFile = rawurldecode($requestedFile);
|
|
||||||
$filename = basename($requestedFile);
|
|
||||||
$filepath = UPLOAD_DIR . $filename;
|
|
||||||
|
|
||||||
if (file_exists($filepath)) {
|
|
||||||
// Определение MIME типа
|
|
||||||
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
|
||||||
$mimeTypes = [
|
|
||||||
// Изображения
|
|
||||||
'jpg' => 'image/jpeg',
|
|
||||||
'jpeg' => 'image/jpeg',
|
|
||||||
'png' => 'image/png',
|
|
||||||
'gif' => 'image/gif',
|
|
||||||
'webp' => 'image/webp',
|
|
||||||
'svg' => 'image/svg+xml',
|
|
||||||
'bmp' => 'image/bmp',
|
|
||||||
'tiff' => 'image/tiff',
|
|
||||||
'tif' => 'image/tiff',
|
|
||||||
'ico' => 'image/x-icon',
|
|
||||||
'heic' => 'image/heic',
|
|
||||||
'heif' => 'image/heif',
|
|
||||||
'avif' => 'image/avif',
|
|
||||||
|
|
||||||
// Документы
|
|
||||||
'pdf' => 'application/pdf',
|
|
||||||
'txt' => 'text/plain',
|
|
||||||
'rtf' => 'application/rtf',
|
|
||||||
'doc' => 'application/msword',
|
|
||||||
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
||||||
'odt' => 'application/vnd.oasis.opendocument.text',
|
|
||||||
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
|
||||||
'odp' => 'application/vnd.oasis.opendocument.presentation',
|
|
||||||
'ppt' => 'application/vnd.ms-powerpoint',
|
|
||||||
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
||||||
'epub' => 'application/epub+zip',
|
|
||||||
'mobi' => 'application/x-mobipocket-ebook',
|
|
||||||
|
|
||||||
// Архивы
|
|
||||||
'zip' => 'application/zip',
|
|
||||||
'rar' => 'application/vnd.rar',
|
|
||||||
'7z' => 'application/x-7z-compressed',
|
|
||||||
'tar' => 'application/x-tar',
|
|
||||||
'gz' => 'application/gzip',
|
|
||||||
'bz2' => 'application/x-bzip2',
|
|
||||||
'xz' => 'application/x-xz',
|
|
||||||
'iso' => 'application/x-iso9660-image',
|
|
||||||
|
|
||||||
// Видео
|
|
||||||
'mp4' => 'video/mp4',
|
|
||||||
'avi' => 'video/x-msvideo',
|
|
||||||
'mkv' => 'video/x-matroska',
|
|
||||||
'mov' => 'video/quicktime',
|
|
||||||
'webm' => 'video/webm',
|
|
||||||
'flv' => 'video/x-flv',
|
|
||||||
'wmv' => 'video/x-ms-wmv',
|
|
||||||
'mpg' => 'video/mpeg',
|
|
||||||
'mpeg' => 'video/mpeg',
|
|
||||||
'm4v' => 'video/x-m4v',
|
|
||||||
'3gp' => 'video/3gpp',
|
|
||||||
'ogv' => 'video/ogg',
|
|
||||||
|
|
||||||
// Аудио
|
|
||||||
'mp3' => 'audio/mpeg',
|
|
||||||
'wav' => 'audio/wav',
|
|
||||||
'flac' => 'audio/flac',
|
|
||||||
'ogg' => 'audio/ogg',
|
|
||||||
'aac' => 'audio/aac',
|
|
||||||
'm4a' => 'audio/mp4',
|
|
||||||
'wma' => 'audio/x-ms-wma',
|
|
||||||
'opus' => 'audio/opus',
|
|
||||||
'aiff' => 'audio/aiff',
|
|
||||||
|
|
||||||
// Данные
|
|
||||||
'json' => 'application/json',
|
|
||||||
'xml' => 'application/xml',
|
|
||||||
'csv' => 'text/csv',
|
|
||||||
'xls' => 'application/vnd.ms-excel',
|
|
||||||
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
||||||
'yaml' => 'text/yaml',
|
|
||||||
'yml' => 'text/yaml',
|
|
||||||
'toml' => 'text/toml',
|
|
||||||
|
|
||||||
// Код
|
|
||||||
'html' => 'text/html',
|
|
||||||
'htm' => 'text/html',
|
|
||||||
'css' => 'text/css',
|
|
||||||
'js' => 'text/javascript',
|
|
||||||
'php' => 'text/x-php',
|
|
||||||
'py' => 'text/x-python',
|
|
||||||
'java' => 'text/x-java-source',
|
|
||||||
'cpp' => 'text/x-c++src',
|
|
||||||
'c' => 'text/x-csrc',
|
|
||||||
'h' => 'text/x-chdr',
|
|
||||||
'cs' => 'text/x-csharp',
|
|
||||||
'rb' => 'text/x-ruby',
|
|
||||||
'go' => 'text/x-go',
|
|
||||||
'rs' => 'text/x-rust',
|
|
||||||
'sql' => 'text/x-sql',
|
|
||||||
'md' => 'text/markdown',
|
|
||||||
'log' => 'text/plain',
|
|
||||||
'sh' => 'text/x-shellscript',
|
|
||||||
'bat' => 'text/x-msdos-batch',
|
|
||||||
|
|
||||||
// Веб и CMS
|
|
||||||
'wpress' => 'application/octet-stream',
|
|
||||||
'backup' => 'application/octet-stream',
|
|
||||||
'bak' => 'application/octet-stream',
|
|
||||||
'db' => 'application/x-sqlite3',
|
|
||||||
'sqlite' => 'application/x-sqlite3',
|
|
||||||
'sqlite3' => 'application/x-sqlite3',
|
|
||||||
|
|
||||||
// Шрифты
|
|
||||||
'ttf' => 'font/ttf',
|
|
||||||
'otf' => 'font/otf',
|
|
||||||
'woff' => 'font/woff',
|
|
||||||
'woff2' => 'font/woff2',
|
|
||||||
'eot' => 'application/vnd.ms-fontobject',
|
|
||||||
|
|
||||||
// Дизайн
|
|
||||||
'psd' => 'image/vnd.adobe.photoshop',
|
|
||||||
'ai' => 'application/postscript',
|
|
||||||
'eps' => 'application/postscript',
|
|
||||||
'indd' => 'application/x-indesign',
|
|
||||||
|
|
||||||
// CAD
|
|
||||||
'dwg' => 'image/vnd.dwg',
|
|
||||||
'dxf' => 'image/vnd.dxf',
|
|
||||||
'obj' => 'model/obj',
|
|
||||||
'stl' => 'model/stl',
|
|
||||||
|
|
||||||
// Мобильные приложения и исполняемые файлы
|
|
||||||
'apk' => 'application/vnd.android.package-archive',
|
|
||||||
'ipa' => 'application/octet-stream',
|
|
||||||
'exe' => 'application/x-msdownload',
|
|
||||||
'msi' => 'application/x-msi',
|
|
||||||
'deb' => 'application/vnd.debian.binary-package',
|
|
||||||
'rpm' => 'application/x-rpm',
|
|
||||||
'dmg' => 'application/x-apple-diskimage',
|
|
||||||
'pkg' => 'application/x-newton-compatible-pkg',
|
|
||||||
|
|
||||||
// Прочие
|
|
||||||
'torrent' => 'application/x-bittorrent',
|
|
||||||
'ics' => 'text/calendar',
|
|
||||||
'vcf' => 'text/vcard',
|
|
||||||
'gpx' => 'application/gpx+xml',
|
|
||||||
'kml' => 'application/vnd.google-earth.kml+xml',
|
|
||||||
'kmz' => 'application/vnd.google-earth.kmz'
|
|
||||||
];
|
|
||||||
|
|
||||||
$mimeType = $mimeTypes[$extension] ?? 'application/octet-stream';
|
|
||||||
|
|
||||||
header('Content-Type: ' . $mimeType);
|
|
||||||
header('Content-Length: ' . filesize($filepath));
|
|
||||||
header('Content-Disposition: inline; filename="' . $filename . '"');
|
|
||||||
header('Cache-Control: public, max-age=31536000'); // Кеш на год
|
|
||||||
|
|
||||||
readfile($filepath);
|
|
||||||
exit;
|
|
||||||
} else {
|
|
||||||
http_response_code(404);
|
|
||||||
echo '404 - Файл не найден';
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Проверка авторизации
|
// Проверка авторизации
|
||||||
if (!isset($_SESSION['logged_in']) || ($_GET['action'] ?? '') === 'logout') {
|
if (!isset($_SESSION['logged_in']) || ($_GET['action'] ?? '') === 'logout') {
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
@@ -314,7 +135,7 @@ $csrf_token = generateCSRFToken();
|
|||||||
<?php foreach ($files as $file):
|
<?php foreach ($files as $file):
|
||||||
$filepath = UPLOAD_DIR . $file;
|
$filepath = UPLOAD_DIR . $file;
|
||||||
$filesize = file_exists($filepath) ? filesize($filepath) : 0;
|
$filesize = file_exists($filepath) ? filesize($filepath) : 0;
|
||||||
$url = rawurlencode($file);
|
$url = 'upload/' . rawurlencode($file);
|
||||||
$delete_url = '?delete=' . urlencode($file) . '&csrf_token=' . urlencode($csrf_token);
|
$delete_url = '?delete=' . urlencode($file) . '&csrf_token=' . urlencode($csrf_token);
|
||||||
?>
|
?>
|
||||||
<li class="file-item">
|
<li class="file-item">
|
||||||
@@ -338,6 +159,7 @@ $csrf_token = generateCSRFToken();
|
|||||||
const MAX_FILE_SIZE = <?= getMaxFileSize() ?>;
|
const MAX_FILE_SIZE = <?= getMaxFileSize() ?>;
|
||||||
const CHUNK_SIZE = <?= getChunkSize() ?>;
|
const CHUNK_SIZE = <?= getChunkSize() ?>;
|
||||||
const ALLOWED_EXTENSIONS = <?= json_encode(ALLOWED_EXTENSIONS) ?>;
|
const ALLOWED_EXTENSIONS = <?= json_encode(ALLOWED_EXTENSIONS) ?>;
|
||||||
|
const ALLOW_ALL_EXTENSIONS = ALLOWED_EXTENSIONS.length === 0 || ALLOWED_EXTENSIONS.includes('*');
|
||||||
const CSRF_TOKEN = '<?= htmlspecialchars($csrf_token) ?>';
|
const CSRF_TOKEN = '<?= htmlspecialchars($csrf_token) ?>';
|
||||||
|
|
||||||
// Показать серверные сообщения при загрузке страницы
|
// Показать серверные сообщения при загрузке страницы
|
||||||
@@ -451,11 +273,13 @@ $csrf_token = generateCSRFToken();
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Проверка расширения
|
// Проверка расширения
|
||||||
|
if (!ALLOW_ALL_EXTENSIONS) {
|
||||||
const extension = file.name.split('.').pop().toLowerCase();
|
const extension = file.name.split('.').pop().toLowerCase();
|
||||||
if (!ALLOWED_EXTENSIONS.includes(extension)) {
|
if (!ALLOWED_EXTENSIONS.includes(extension)) {
|
||||||
showNotification(`Недопустимый тип файла. Разрешены: ${ALLOWED_EXTENSIONS.join(', ')}`, 'error');
|
showNotification(`Недопустимый тип файла. Разрешены: ${ALLOWED_EXTENSIONS.join(', ')}`, 'error');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Проверка имени файла
|
// Проверка имени файла
|
||||||
if (!/^[a-zA-Z0-9а-яА-Я._\-\s()]+$/u.test(file.name)) {
|
if (!/^[a-zA-Z0-9а-яА-Я._\-\s()]+$/u.test(file.name)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user