-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
84 lines (73 loc) · 3.08 KB
/
index.html
File metadata and controls
84 lines (73 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<title>Web 文件管理系统</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
h2 { color: #333; }
form { margin-bottom: 20px; padding: 10px; border: 1px solid #ccc; max-width: 600px; }
input[type="text"], input[type="file"] { margin-bottom: 10px; width: 100%; padding: 8px; box-sizing: border-box; }
input[type="submit"] { padding: 8px 16px; }
pre { background: #f4f4f4; padding: 10px; }
small { color: #666; }
iframe { border: 1px solid #ccc; }
</style>
</head>
<body>
<h1>Web 文件管理与爬虫系统</h1>
<h2>📂 上传文件</h2>
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" multiple><br />
<input type="submit" value="上传" />
</form>
<h2>📁 新建目录</h2>
<form action="/mkdir" method="post">
<input type="text" name="name" placeholder="目录名" required><br />
<input type="submit" value="创建目录" />
</form>
<h2>🗑️ 删除文件或目录</h2>
<form action="/delete" method="post">
<input type="text" name="name" placeholder="文件或目录名" required><br />
<input type="submit" value="删除" />
</form>
<h2>🌐 网络爬虫</h2>
<form action="/crawl" method="post">
<input type="text" name="url" placeholder="输入网址"><br>
<input type="submit" value="爬取页面">
</form>
<h2>📋 文件列表</h2>
<iframe id="fileList" src="/files" width="100%" height="300"></iframe>
<h2>⬇️ 下载文件</h2>
<form id="downloadForm" onsubmit="return downloadFile(event)">
<input type="text" id="downloadPath" name="f" placeholder="文件路径,相对 upload_dir" required><br />
<small>提示:填写相对于 upload_dir 的路径,例如:images/pic.jpg 或 data/report.pdf</small><br />
<input type="submit" value="下载" />
</form>
<script>
function downloadFile(event) {
event.preventDefault();
const filename = document.getElementById('downloadPath').value.trim();
if (!filename) {
alert("请输入文件路径!");
return false;
}
// 简单安全校验,防止目录穿越攻击
if (filename.includes("..") || filename.startsWith("/") || filename.startsWith("\\")) {
alert("路径不合法,不能包含 \"..\" 或以斜杠开头!");
return false;
}
const encoded = encodeURIComponent(filename);
const url = `/download?f=${encoded}`;
// 创建一个临时隐藏的 <a> 标签触发下载
const link = document.createElement('a');
link.href = url;
link.download = ''; // 告诉浏览器这是下载
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
return false;
}
</script>
</body>
</html>